Exemple #1
0
int
main (int argc, char **argv)
{
  VteTermcap *tc;
  char *str;
  gssize len;
  int i;

  if (argc < 4)
  {
    g_printerr("vtetc /path/to/termcap termname attrs...\n"
                     "  where attrs are\n"
                     "    :xx for boolean\n"
                     "    =xx for string\n"
                     "    +xx for string displayed in hex\n"
                     "    #xx for numeric\n");
    return 1;
  }

  tc = _vte_termcap_new (argv[1]);

  if (tc == NULL)
  {
    perror ("open");
    return 1;
  }

  for (i = 3; i < argc; i++)
  {
    printf ("%s -> ", argv[i]);

    switch (argv[i][0])
    {
      case ':':
        printf ("%s\n", _vte_termcap_find_boolean (tc, argv[2], argv[i] + 1)?
                        "true" : "false");
        break;

      case '=':
      case '+':
        str = _vte_termcap_find_string_length (tc, argv[2], argv[i] + 1, &len);

        if (argv[i][0] == '=')
          printf ("'%s' (%d)\n", str, (int)len);
        else
        {
          int i;

          for (i = 0; str[i]; i++)
            printf ("%02x", str[i]);
          printf (" (%d) \n", (int)len);
        }
        g_free (str);
        break;

      case '#':
        printf ("%ld\n", _vte_termcap_find_numeric (tc, argv[2], argv[i] + 1));
        break;

      default:
        g_printerr("unrecognised type '%c'\n", argv[i][0]);
    }
  }

  _vte_termcap_free(tc);

  return 0;
}
Exemple #2
0
int
main(int argc, char **argv)
{
	char *terminal = NULL;
	struct _vte_matcher *matcher = NULL;
	struct _vte_termcap *termcap = NULL;
	GArray *array;
	unsigned int i, j;
	int l;
	unsigned char buf[4096];
	GValue *value;
	int infile;
	struct _vte_iso2022_state *subst;
	const char *tmp;
	GQuark quark;
	GValueArray *values;

	_vte_debug_init();

	if (argc < 2) {
		g_print("usage: %s terminal [file]\n", argv[0]);
		return 1;
	}

	if ((argc > 2) && (strcmp(argv[2], "-") != 0)) {
		infile = open (argv[2], O_RDONLY);
		if (infile == -1) {
			g_print("error opening %s: %s\n", argv[2],
				strerror(errno));
			exit(1);
		}
	} else {
		infile = 1;
	}

	g_type_init();
	terminal = argv[1];
	termcap = _vte_termcap_new(g_strdup_printf(DATADIR "/" PACKAGE
						   "/termcap/%s", terminal));
	if (termcap == NULL) {
		termcap = _vte_termcap_new("/etc/termcap");
	}
	array = g_array_new(FALSE, FALSE, sizeof(gunichar));

	matcher = _vte_matcher_new(terminal, termcap);

	subst = _vte_iso2022_state_new(NULL, NULL, NULL);

	for (;;) {
		l = read (infile, buf, sizeof (buf));
		if (!l)
			break;
		if (l == -1) {
			if (errno == EAGAIN)
				continue;
			exit (1);
		}
		g_array_set_size (array, 0);
		_vte_iso2022_process(subst, buf, (unsigned int) l, array);

		i = 0;
		while (i <= array->len) {
			tmp = NULL;
			values = NULL;
			for (j = 1; j < (array->len - i); j++) {
				_vte_matcher_match(matcher,
						   &g_array_index(array, gunichar, i),
						   j,
						   &tmp,
						   NULL,
						   &quark,
						   &values);
				if ((tmp == NULL) || (strlen(tmp) > 0)) {
					break;
				}
			}
			if (i + j == array->len) {
				break;
			}
			if (tmp == NULL) {
				gunichar c;
				c = g_array_index(array, gunichar, i);
				if (VTE_ISO2022_HAS_ENCODED_WIDTH(c)) {
					c &= ~VTE_ISO2022_ENCODED_WIDTH_MASK;
				}
				if (c < 32) {
					g_print("`^%c'\n", c + 64);
				} else
				if (c < 127) {
					g_print("`%c'\n", c);
				} else {
					g_print("`0x%x'\n", c);
				}
				i++;
				continue;
			}

			l = j;
			g_print("%s(", g_quark_to_string(quark));
			for (j = 0; (values != NULL) && (j < values->n_values); j++) {
				if (j > 0) {
					g_print(", ");
				}
				value = g_value_array_get_nth(values, j);
				if (G_VALUE_HOLDS_LONG(value)) {
					g_print("%ld", g_value_get_long(value));
				}
				if (G_VALUE_HOLDS_STRING(value)) {
					g_print("`%s'",
						g_value_get_string(value));
				}
				if (G_VALUE_HOLDS_POINTER(value)) {
					g_print("`%ls'",
						(wchar_t*)
						g_value_get_pointer(value));
				}
			}
			if (values != NULL) {
				_vte_matcher_free_params_array(matcher, values);
			}
			g_print(")\n");
			i += l;
		}
	}
	g_print("End of data.\n");

	close (infile);

	_vte_iso2022_state_free(subst);
	g_array_free(array, TRUE);
	_vte_termcap_free(termcap);
	_vte_matcher_free(matcher);
	return 0;
}