]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/makedefs.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$Id: makedefs.c,v 1.2 1993/08/02 17:19:44 mycroft Exp $";
11 /* construct definitions of object constants */
22 register int index
= 0;
23 register int propct
= 0;
26 (void)fprintf(stderr
, "usage: makedefs file\n");
29 if ((fd
= open(argv
[1], 0)) < 0) {
33 skipuntil("objects[] = {");
39 for(sp
= string
; *sp
; sp
++)
40 if(*sp
== ' ' || *sp
== '\t' || *sp
== '-')
42 if(!strncmp(string
, "RIN_", 4)){
44 printf("#define %s u.uprops[%d].p_flgs\n",
47 for(sp
= string
; *sp
; sp
++) capitalize(sp
);
48 /* avoid trouble with stupid C preprocessors */
49 if(!strncmp(string
, "WORTHLESS_PIECE_OF_", 19))
50 printf("/* #define %s %d */\n", string
, index
);
52 printf("#define %s %d\n", string
, index
);
55 printf("\n#define CORPSE DEAD_HUMAN\n");
56 printf("#define LAST_GEM (JADE+1)\n");
57 printf("#define LAST_RING %d\n", propct
);
58 printf("#define NROFOBJECTS %d\n", index
-1);
62 char line
[LINSZ
], *lp
= line
, *lp0
= line
, *lpe
= line
;
66 register int n
= read(fd
, lp0
, (line
+LINSZ
)-lp0
);
68 printf("Input error.\n");
81 return((lp
== lpe
) ? 0 : *lp
++);
84 skipuntil(s
) char *s
; {
85 register char *sp0
, *sp1
;
87 while(*s
!= nextchar())
89 printf("Cannot skipuntil %s\n", s
);
92 if(strlen(s
) > lpe
-lp
+1){
93 register char *lp1
, *lp2
;
96 while(lp2
!= lpe
) *lp1
++ = *lp2
++;
97 lp2
= lp0
; /* save value */
101 if(strlen(s
) > lpe
-lp
+1) {
102 printf("error in skipuntil");
108 while(*sp0
&& *sp0
== *sp1
) sp0
++, sp1
++;
117 int inbraces
= 0, inparens
= 0, stringseen
= 0, commaseen
= 0;
121 char identif
[NSZ
], *ip
;
122 string
[0] = string
[4] = 0;
123 /* read until {...} or XXX(...) followed by ,
124 skip comment and #define lines
133 if(ip
< identif
+NSZ
-1) *ip
++ = ch
;
135 } while(letter(ch
) || digit(ch
));
137 while(ch
== ' ' || ch
== '\t') ch
= nextchar();
138 if(ch
== '(' && !inparens
&& !stringseen
)
139 if(!strcmp(identif
, "WAND") ||
140 !strcmp(identif
, "RING") ||
141 !strcmp(identif
, "POTION") ||
142 !strcmp(identif
, "SCROLL"))
143 (void) strncpy(string
, identif
, 3),
149 /* watch for comment */
150 if((ch
= nextchar()) == '*')
161 if(inbraces
< 0) return(0);
166 printf("too many ) ?");
171 /* watch for #define at begin of line */
172 if((ch
= nextchar()) == '#'){
174 /* skip until '\n' not preceded by '\\' */
178 } while(ch
!= '\n' || pch
== '\\');
183 if(!inparens
&& !inbraces
){
184 if(prefix
&& !string
[prefix
])
186 if(stringseen
) return(1);
187 printf("unexpected ,\n");
193 if((ch
= nextchar()) == '\\') ch
= nextchar();
194 if(nextchar() != '\''){
195 printf("strange character denotation?\n");
201 register char *sp
= string
+ prefix
;
203 register int store
= (inbraces
|| inparens
)
204 && !stringseen
++ && !commaseen
;
208 if(store
&& sp
< string
+STRSZ
)
210 } while(ch
!= '"' || pch
== '\\');
218 capitalize(sp
) register char *sp
; {
219 if('a' <= *sp
&& *sp
<= 'z') *sp
+= 'A'-'a';
222 letter(ch
) register char ch
; {
223 return( ('a' <= ch
&& ch
<= 'z') ||
224 ('A' <= ch
&& ch
<= 'Z') );
227 digit(ch
) register char ch
; {
228 return( '0' <= ch
&& ch
<= '9' );