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
|
/*
* 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 <stdio.h>
#include <string.h>
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);
}
|