aboutsummaryrefslogtreecommitdiffhomepage
path: root/libslang/src/untic.c
blob: 418ce3bd0dd75cbfd7664e843f7668e70470ff16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#define SLANG_UNTIC
char *SLang_Untic_Terminfo_File;
#include "sltermin.c"

static void usage (void)
{
   fprintf (stderr, "Usage: untic [[--terminfo filename] | [term]]\n");
   exit (1);
}

int main (int argc, char **argv)
{
   SLterminfo_Type *t;
   Tgetstr_Map_Type *map = Tgetstr_Map;
   unsigned char *str;
   char *term;

   term = getenv ("TERM");
   if (argc > 1)
     {
	if (!strcmp ("--help", argv[1])) usage ();
	if (argc == 2)
	  term = argv[1];
	else if ((argc == 3) && !strcmp(argv[1], "--terminfo"))
	  {
	     SLang_Untic_Terminfo_File = argv[2];
	  }
	else usage ();
     }
   else if (term == NULL) return -1;

   SLtt_Try_Termcap = 0;
   t = _SLtt_tigetent (term);
   if (t == NULL) return -1;

   puts (t->terminal_names);
   while (*map->name != 0)
     {
	str = (unsigned char *) SLtt_tigetstr (map->name, (char **) &t);
	if (str == NULL)
	  {
	     map++;
	     continue;
	     /* str = (unsigned char *) "NULL"; */
	  }

	fprintf (stdout, "\t%s=", map->name);
	while (*str)
	  {
	     if ((int) (*str & 0x7F) < ' ')
	       {
		  putc ('^', stdout);
		  *str += '@';
	       }
	     putc (*str, stdout);
	     str++;
	  }
	if (map->comment != NULL)
	  fprintf (stdout, "\t\t%s", map->comment);
	putc ('\n', stdout);
	map++;
     }

   map = Tgetflag_Map;
   while (*map->name != 0)
     {
	if (_SLtt_tigetflag (t, map->name) > 0)
	  {
	     fprintf (stdout, "\t%s\t\t%s\n",
		      map->name,
		      ((map->comment == NULL) ? "" : map->comment));
	  }
	map++;
     }
   map = Tgetnum_Map;
   while (*map->name != 0)
     {
	int val;
	if ((val = SLtt_tigetnum (map->name, (char **) &t)) >= 0)
	  {
	     fprintf (stdout, "\t%s#%d\t\t%s\n",
		      map->name, val,
		      ((map->comment == NULL) ? "" : map->comment));
	  }
	map++;
     }

   return 0;
}