File: ctlwords.c

package info (click to toggle)
mgp 1.13a+upstream20090219-11
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,128 kB
  • sloc: ansic: 32,387; sh: 4,295; lisp: 1,405; yacc: 945; lex: 264; makefile: 158; perl: 117; awk: 9
file content (51 lines) | stat: -rw-r--r-- 1,142 bytes parent folder | download
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
/*
 * ctlwords.c
 * From: Luigi Rizzo <luigi@labinfo.iet.unipi.it>
 */

#if 0
 used to extract and create tokens for mgp
 Reads globals.c, produces ctlwords.h.
 Lines started by  /*CTL*/ and containing an identifier CTL_*
 generate tokens with increasing value.
 The perl code follows:

BEGIN {
	counter = 0;	# 0 origin
	printf("/* generated by ctlwords.awk. do not edit by hand. */\n");
}
/^\/\*CTL\*\// {
	word = substr($0, index($0, "CTL_"));
	word = substr(word, 0, index(word, ",") - 1);
	printf("#define\t%s\t%d\n", word, counter++);
}

#endif

#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[])
{
	char buf[1024];
	char *p, *q;
	int i = 0, l ;

	printf("/* Generated by ctlwords.c from globals.c. Do not edit. */\n");
	while (fgets(buf, sizeof(buf)-1, stdin)) {
		if (strlen(buf) > 12 /* there must be enough data... */
		 && !strncmp(buf, "/*CTL*/", 7)) { /* found marker */
			p = strstr(buf+7, "CTL_");
			if (p) {
				for (q = p; *q && (isalnum(*q) || *q=='_'); q++)
					;
				*q = '\0'; /* must exist */
				printf("#define %s\t%d\n", p, i++);
			}
		}
	}
	exit(0);
}