summaryrefslogtreecommitdiffstats
path: root/lib/libmytinfo/mkbinorder.c
blob: 0bcc47436b748a500b5ee0c51ff8ef956380055b (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
/*
 * mkbinorder.c
 *
 * By Ross Ridge
 * Public Domain
 * 92/02/01 07:30:04
 *
 */

#define NOTLIB
#include "defs.h"
#include <term.h>

const char SCCSid[] = "@(#) mytinfo mkbinorder.c 3.2 92/02/01 public domain, By Ross Ridge";

char cap[MAX_NAME];
char *p2c = cap;
char **p2p2c = &p2c;

int
main(argc, argv)
int argc;
char **argv; {
	int r;
	int ind;
	FILE *f;

	if (argc == 1)
		f = stdin;
	else if (argc == 2) {
		f = fopen(argv[1], "r");
		if (f == NULL) {
			fprintf(stderr, "can't open %s\n", argv[1]);
			exit(1);
		}
	} else {
		fprintf(stderr, "argument count\n");
		exit(1);
	}

	do {
		r = fscanf(f, "%s", cap);
	} while(r == 1 && strcmp(cap, "!") != 0);
	if (r != 1) {
		fprintf(stderr, "expected '!'\n");
		exit(1);
	}

	puts("/*");
	puts(" * binorder.c");
	puts(" *");
	puts(" * This file was generated automatically");
	puts(" *");
	puts(" */\n");

	puts("int _boolorder[] = {");

	while(1) {
		r = fscanf(f, "%s", cap);
		cap[MAX_TINFONAME] = '\0';
		if (r != 1) {
			fprintf(stderr, "unexpected EOF\n");
			exit(1);
		}
		if (strcmp(cap, "#") == 0)
			break;
		ind = _findboolname(cap);
		if (ind == -1) {
			fprintf(stderr, "unknown bool name '%s'\n", cap);
			continue;
		}
		printf("\t%d,\n", ind);
	}
	puts("\t-1");
	puts("};\n");

	puts("int _numorder[] = {");

	while(1) {
		r = fscanf(f, "%s", cap);
		cap[MAX_TINFONAME] = '\0';
		if (r != 1) {
			fprintf(stderr, "unexpected EOF\n");
			exit(1);
		}
		if (strcmp(cap, "$") == 0)
			break;
		ind = _findnumname(cap);
		if (ind == -1) {
			fprintf(stderr, "unknown num name '%s'\n", cap);
			continue;
		}
		printf("\t%d,\n", ind);
	}
	puts("\t-1");
	puts("};\n");

	puts("int _strorder[] = {");

	while(1) {
		r = fscanf(f, "%s", cap);
		cap[MAX_TINFONAME] = '\0';
		if (r != 1)
			break;
		ind = _findstrname(cap);
		if (ind == -1) {
			fprintf(stderr, "unknown str name '%s'\n", cap);
			continue;
		}
		printf("\t%d,\n", ind);
	}
	puts("\t-1");
	puts("};\n");

	return 0;
}
OpenPOWER on IntegriCloud