1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* makedefs.c - version 1.0.2 */
3 /* $FreeBSD: src/games/hack/makedefs.c,v 1.4 1999/11/16 02:57:15 billf Exp $ */
4 /* $DragonFly: src/games/hack/makedefs.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ */
9 /* construct definitions of object constants */
24 (void)fprintf(stderr, "usage: makedefs file\n");
27 if ((fd = open(argv[1], 0)) < 0) {
31 skipuntil("objects[] = {");
37 for(sp = string; *sp; sp++)
38 if(*sp == ' ' || *sp == '\t' || *sp == '-')
40 if(!strncmp(string, "RIN_", 4)){
42 printf("#define %s u.uprops[%d].p_flgs\n",
45 for(sp = string; *sp; sp++) capitalize(sp);
46 /* avoid trouble with stupid C preprocessors */
47 if(!strncmp(string, "WORTHLESS_PIECE_OF_", 19))
48 printf("/* #define %s %d */\n", string, index);
50 printf("#define %s %d\n", string, index);
53 printf("\n#define CORPSE DEAD_HUMAN\n");
54 printf("#define LAST_GEM (JADE+1)\n");
55 printf("#define LAST_RING %d\n", propct);
56 printf("#define NROFOBJECTS %d\n", index-1);
60 char line[LINSZ], *lp = line, *lp0 = line, *lpe = line;
64 int n = read(fd, lp0, (line+LINSZ)-lp0);
66 printf("Input error.\n");
79 return((lp == lpe) ? 0 : *lp++);
82 skipuntil(s) char *s; {
85 while(*s != nextchar())
87 printf("Cannot skipuntil %s\n", s);
90 if(strlen(s) > lpe-lp+1){
94 while(lp2 != lpe) *lp1++ = *lp2++;
95 lp2 = lp0; /* save value */
99 if(strlen(s) > lpe-lp+1) {
100 printf("error in skipuntil");
106 while(*sp0 && *sp0 == *sp1) sp0++, sp1++;
115 int inbraces = 0, inparens = 0, stringseen = 0, commaseen = 0;
119 char identif[NSZ], *ip;
120 string[0] = string[4] = 0;
121 /* read until {...} or XXX(...) followed by ,
122 skip comment and #define lines
131 if(ip < identif+NSZ-1) *ip++ = ch;
133 } while(letter(ch) || digit(ch));
135 while(ch == ' ' || ch == '\t') ch = nextchar();
136 if(ch == '(' && !inparens && !stringseen)
137 if(!strcmp(identif, "WAND") ||
138 !strcmp(identif, "RING") ||
139 !strcmp(identif, "POTION") ||
140 !strcmp(identif, "SCROLL"))
141 (void) strncpy(string, identif, 3),
147 /* watch for comment */
148 if((ch = nextchar()) == '*')
159 if(inbraces < 0) return(0);
164 printf("too many ) ?");
169 /* watch for #define at begin of line */
170 if((ch = nextchar()) == '#'){
172 /* skip until '\n' not preceded by '\\' */
176 } while(ch != '\n' || pch == '\\');
181 if(!inparens && !inbraces){
182 if(prefix && !string[prefix])
184 if(stringseen) return(1);
185 printf("unexpected ,\n");
191 if((ch = nextchar()) == '\\') ch = nextchar();
192 if(nextchar() != '\''){
193 printf("strange character denotation?\n");
199 char *sp = string + prefix;
201 int store = (inbraces || inparens)
202 && !stringseen++ && !commaseen;
206 if(store && sp < string+STRSZ)
208 } while(ch != '"' || pch == '\\');
216 capitalize(sp) char *sp; {
217 if('a' <= *sp && *sp <= 'z') *sp += 'A'-'a';
220 letter(ch) char ch; {
221 return( ('a' <= ch && ch <= 'z') ||
222 ('A' <= ch && ch <= 'Z') );
226 return( '0' <= ch && ch <= '9' );