1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* makedefs.c - version 1.0.2 */
8 /* construct definitions of object constants */
23 (void)fprintf(stderr, "usage: makedefs file\n");
26 if ((fd = open(argv[1], 0)) < 0) {
30 skipuntil("objects[] = {");
36 for(sp = string; *sp; sp++)
37 if(*sp == ' ' || *sp == '\t' || *sp == '-')
39 if(!strncmp(string, "RIN_", 4)){
41 printf("#define %s u.uprops[%d].p_flgs\n",
44 for(sp = string; *sp; sp++) capitalize(sp);
45 /* avoid trouble with stupid C preprocessors */
46 if(!strncmp(string, "WORTHLESS_PIECE_OF_", 19))
47 printf("/* #define %s %d */\n", string, index);
49 printf("#define %s %d\n", string, index);
52 printf("\n#define CORPSE DEAD_HUMAN\n");
53 printf("#define LAST_GEM (JADE+1)\n");
54 printf("#define LAST_RING %d\n", propct);
55 printf("#define NROFOBJECTS %d\n", index-1);
59 char line[LINSZ], *lp = line, *lp0 = line, *lpe = line;
63 int n = read(fd, lp0, (line+LINSZ)-lp0);
65 printf("Input error.\n");
78 return((lp == lpe) ? 0 : *lp++);
81 skipuntil(s) char *s; {
84 while(*s != nextchar())
86 printf("Cannot skipuntil %s\n", s);
89 if(strlen(s) > lpe-lp+1){
93 while(lp2 != lpe) *lp1++ = *lp2++;
94 lp2 = lp0; /* save value */
98 if(strlen(s) > lpe-lp+1) {
99 printf("error in skipuntil");
105 while(*sp0 && *sp0 == *sp1) sp0++, sp1++;
114 int inbraces = 0, inparens = 0, stringseen = 0, commaseen = 0;
118 char identif[NSZ], *ip;
119 string[0] = string[4] = 0;
120 /* read until {...} or XXX(...) followed by ,
121 skip comment and #define lines
130 if(ip < identif+NSZ-1) *ip++ = ch;
132 } while(letter(ch) || digit(ch));
134 while(ch == ' ' || ch == '\t') ch = nextchar();
135 if(ch == '(' && !inparens && !stringseen)
136 if(!strcmp(identif, "WAND") ||
137 !strcmp(identif, "RING") ||
138 !strcmp(identif, "POTION") ||
139 !strcmp(identif, "SCROLL"))
140 (void) strncpy(string, identif, 3),
146 /* watch for comment */
147 if((ch = nextchar()) == '*')
158 if(inbraces < 0) return(0);
163 printf("too many ) ?");
168 /* watch for #define at begin of line */
169 if((ch = nextchar()) == '#'){
171 /* skip until '\n' not preceded by '\\' */
175 } while(ch != '\n' || pch == '\\');
180 if(!inparens && !inbraces){
181 if(prefix && !string[prefix])
183 if(stringseen) return(1);
184 printf("unexpected ,\n");
190 if((ch = nextchar()) == '\\') ch = nextchar();
191 if(nextchar() != '\''){
192 printf("strange character denotation?\n");
198 char *sp = string + prefix;
200 int store = (inbraces || inparens)
201 && !stringseen++ && !commaseen;
205 if(store && sp < string+STRSZ)
207 } while(ch != '"' || pch == '\\');
215 capitalize(sp) char *sp; {
216 if('a' <= *sp && *sp <= 'z') *sp += 'A'-'a';
219 letter(ch) char ch; {
220 return( ('a' <= ch && ch <= 'z') ||
221 ('A' <= ch && ch <= 'Z') );
225 return( '0' <= ch && ch <= '9' );