summaryrefslogtreecommitdiffstats
path: root/lib/libmytinfo/mktermhead.c
blob: bacf051e69a74a24a84252056ed6e213016fb01a (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * mktermhead.c
 *
 * By Ross Ridge
 * Public Domain
 * 92/06/04 11:38:57
 *
 * mktermhead [-n caps] file
 *
 * generates term.head
 *
 */

#define NOTLIB
#include "defs.h"

const char SCCSid[] = "@(#) mytinfo mktermhead.c 3.3 92/06/04 public domain, By Ross Ridge";

#define DEFAULT_CAPS	1000


int
main(argc, argv)
int argc;
char **argv; {
	FILE *f;
	int caps = DEFAULT_CAPS;
	int n;
	register int i;
	int nb, ns, nn;
	struct caplist *list;

	if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'n') {
		caps = atoi(argv[2]);
		argv += 2;
		argc -= 2;
	}

	if (argc == 1) {
		f = stdin;
	} else if (argc == 2) {
		f = fopen(argv[1], "r");
		if (f == NULL) {
			fprintf(stderr, "%s: can't open '%s'\n", argv[0],
				argv[1]);
			return 1;
		}
	} else {
		fprintf(stderr, "%s: too many arguments\n", argv[0]);
		fprintf(stderr, "usage: %s [-n caps] [file]\n", argv[0]);
		return 1;
	}

	list = (struct caplist *) malloc(caps * sizeof(struct caplist));
	if (list == NULL) {
		fprintf(stderr, "%s: malloc failed.\n", argv[0]);
		return 1;
	}

	n = readcaps(f, list, caps);
	if (n > caps) {
		fprintf(stderr, "%s: too many caps, use -n.\n", argv[0]);
		return 1;
	}
	switch(n) {
	case 0:
		fprintf(stderr, "%s: no caps in file.\n", argv[0]);
		return 1;
	case -1:
		fprintf(stderr, "%s: bad caps line.\n", argv[0]);
		return 1;
	case -2:
		fprintf(stderr, "%s: unexpected EOF.\n", argv[0]);
		return 1;
	}

	puts("/*");
	puts(" * term.h ");
	puts(" *");
	puts(" * This file was generated automatically.");
	puts(" *");
	puts(" */");
	putchar('\n');
	puts("#ifndef _TERM_H_");
	puts("#define _TERM_H_");
	putchar('\n');
	nb = 0;
	for (i = 0; i < n; i++) {
		if (list[i].type == '!') {
			printf("#define %-*s (_CUR_TERM.bools[%d])\n",
			       MAX_VARNAME, list[i].var, nb);
			nb++;
		}
	}

	nn = 0;
	for (i = 0; i < n; i++) {
		if (list[i].type == '#') {
			printf("#define %-*s (_CUR_TERM.nums[%d])\n",
			       MAX_VARNAME, list[i].var, nn);
			nn++;
		}
	}

	ns = 0;
	for (i = 0; i < n; i++) {
		if (list[i].type == '$') {
			printf("#define %-*s (_CUR_TERM.strs[%d])\n",
			       MAX_VARNAME, list[i].var, ns);
			ns++;
		}
	}

	putchar('\n');

	printf ("#define NUM_OF_BOOLS\t%d\n", nb);
	printf ("#define NUM_OF_NUMS\t%d\n", nn);
	printf ("#define NUM_OF_STRS\t%d\n", ns);

	putchar('\n');
	puts("#ifndef OVERRIDE");
	puts("#undef _USE_SGTTY");
#ifdef USE_SGTTY
	puts("#define _USE_SGTTY");
#endif
	puts("#undef _USE_TERMIO");
#ifdef USE_TERMIO
	puts("#define _USE_TERMIO");
#endif
	puts("#undef _USE_TERMIOS");
#ifdef USE_TERMIOS
	puts("#define _USE_TERMIOS");
#endif
	puts("#undef _USE_SMALLMEM");
#ifdef USE_SMALLMEM
	puts("#define _USE_SMALLMEM");
#endif
	puts("#undef _USE_PROTOTYPES");
#ifdef USE_PROTOTYPES
	puts("#define _USE_PROTOTYPES");
#endif
	puts("#undef _USE_WINSZ");
#ifdef USE_WINSZ
	puts("#define _USE_WINSZ");
#endif
	puts("#undef _USE_TERMINFO");
#ifdef USE_TERMINFO
	puts("#define _USE_TERMINFO");
#endif
	puts("#undef _USE_TERMCAP");
#ifdef USE_TERMCAP
	puts("#define _USE_TERMCAP");
#endif
	puts("#undef _MAX_CHUNK");
	printf("#define _MAX_CHUNK %d\n", MAX_CHUNK);
	puts("#endif /* OVERRIDE */");
	putchar('\n');

	return 0;
}
OpenPOWER on IntegriCloud