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.3 2006/08/21 19:45:32 pavalos Exp $ */
13 /* construct definitions of object constants */
20 static void readline(void);
21 static char nextchar(void);
22 static bool skipuntil(const char *);
23 static bool getentry(void);
24 static void capitalize(char *);
25 static bool letter(char);
26 static bool digit(char);
29 main(int argc, char **argv)
35 fprintf(stderr, "usage: makedefs file\n");
38 if ((fd = open(argv[1], 0)) < 0) {
42 skipuntil("objects[] = {");
48 for(sp = string; *sp; sp++)
49 if(*sp == ' ' || *sp == '\t' || *sp == '-')
51 if(!strncmp(string, "RIN_", 4)){
53 printf("#define %s u.uprops[%d].p_flgs\n",
56 for(sp = string; *sp; sp++) capitalize(sp);
57 /* avoid trouble with stupid C preprocessors */
58 if(!strncmp(string, "WORTHLESS_PIECE_OF_", 19))
59 printf("/* #define %s %d */\n", string, idx);
61 printf("#define %s %d\n", string, idx);
64 printf("\n#define CORPSE DEAD_HUMAN\n");
65 printf("#define LAST_GEM (JADE+1)\n");
66 printf("#define LAST_RING %d\n", propct);
67 printf("#define NROFOBJECTS %d\n", idx-1);
71 char line[LINSZ], *lp = line, *lp0 = line, *lpe = line;
77 int n = read(fd, lp0, (line+LINSZ)-lp0);
79 printf("Input error.\n");
93 return((lp == lpe) ? 0 : *lp++);
97 skipuntil(const char *s)
102 while(*s != nextchar())
104 printf("Cannot skipuntil %s\n", s);
107 if((int)strlen(s) > lpe-lp+1){
111 while(lp2 != lpe) *lp1++ = *lp2++;
112 lp2 = lp0; /* save value */
116 if((int)strlen(s) > lpe-lp+1) {
117 printf("error in skipuntil");
123 while(*sp0 && *sp0 == *sp1) sp0++, sp1++;
134 int inbraces = 0, inparens = 0, stringseen = 0, commaseen = 0;
138 char identif[NSZ], *ip;
139 string[0] = string[4] = 0;
140 /* read until {...} or XXX(...) followed by ,
141 skip comment and #define lines
150 if(ip < identif+NSZ-1) *ip++ = ch;
152 } while(letter(ch) || digit(ch));
154 while(ch == ' ' || ch == '\t') ch = nextchar();
155 if(ch == '(' && !inparens && !stringseen)
156 if(!strcmp(identif, "WAND") ||
157 !strcmp(identif, "RING") ||
158 !strcmp(identif, "POTION") ||
159 !strcmp(identif, "SCROLL"))
160 strncpy(string, identif, 3),
166 /* watch for comment */
167 if((ch = nextchar()) == '*')
178 if(inbraces < 0) return(0);
183 printf("too many ) ?");
188 /* watch for #define at begin of line */
189 if((ch = nextchar()) == '#'){
191 /* skip until '\n' not preceded by '\\' */
195 } while(ch != '\n' || pch == '\\');
200 if(!inparens && !inbraces){
201 if(prefix && !string[prefix])
203 if(stringseen) return(1);
204 printf("unexpected ,\n");
210 if((ch = nextchar()) == '\\') ch = nextchar();
211 if(nextchar() != '\''){
212 printf("strange character denotation?\n");
218 char *sp = string + prefix;
220 int store = (inbraces || inparens)
221 && !stringseen++ && !commaseen;
225 if(store && sp < string+STRSZ)
227 } while(ch != '"' || pch == '\\');
238 if('a' <= *sp && *sp <= 'z') *sp += 'A'-'a';
244 return( ('a' <= ch && ch <= 'z') ||
245 ('A' <= ch && ch <= 'Z') );
251 return( '0' <= ch && ch <= '9' );