]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/makedefs.c
aa113b9fed8d5981e96c7cbe143ab739457fe2ba
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* makedefs.c - version 1.0.2 */
6 /* construct definitions of object constants */
17 register int index
= 0;
18 register int propct
= 0;
21 (void)fprintf(stderr
, "usage: makedefs file\n");
24 if ((fd
= open(argv
[1], 0)) < 0) {
28 skipuntil("objects[] = {");
34 for(sp
= string
; *sp
; sp
++)
35 if(*sp
== ' ' || *sp
== '\t' || *sp
== '-')
37 if(!strncmp(string
, "RIN_", 4)){
39 printf("#define %s u.uprops[%d].p_flgs\n",
42 for(sp
= string
; *sp
; sp
++) capitalize(sp
);
43 /* avoid trouble with stupid C preprocessors */
44 if(!strncmp(string
, "WORTHLESS_PIECE_OF_", 19))
45 printf("/* #define %s %d */\n", string
, index
);
47 printf("#define %s %d\n", string
, index
);
50 printf("\n#define CORPSE DEAD_HUMAN\n");
51 printf("#define LAST_GEM (JADE+1)\n");
52 printf("#define LAST_RING %d\n", propct
);
53 printf("#define NROFOBJECTS %d\n", index
-1);
57 char line
[LINSZ
], *lp
= line
, *lp0
= line
, *lpe
= line
;
61 register int n
= read(fd
, lp0
, (line
+LINSZ
)-lp0
);
63 printf("Input error.\n");
76 return((lp
== lpe
) ? 0 : *lp
++);
79 skipuntil(s
) char *s
; {
80 register char *sp0
, *sp1
;
82 while(*s
!= nextchar())
84 printf("Cannot skipuntil %s\n", s
);
87 if(strlen(s
) > lpe
-lp
+1){
88 register char *lp1
, *lp2
;
91 while(lp2
!= lpe
) *lp1
++ = *lp2
++;
92 lp2
= lp0
; /* save value */
96 if(strlen(s
) > lpe
-lp
+1) {
97 printf("error in skipuntil");
103 while(*sp0
&& *sp0
== *sp1
) sp0
++, sp1
++;
112 int inbraces
= 0, inparens
= 0, stringseen
= 0, commaseen
= 0;
116 char identif
[NSZ
], *ip
;
117 string
[0] = string
[4] = 0;
118 /* read until {...} or XXX(...) followed by ,
119 skip comment and #define lines
128 if(ip
< identif
+NSZ
-1) *ip
++ = ch
;
130 } while(letter(ch
) || digit(ch
));
132 while(ch
== ' ' || ch
== '\t') ch
= nextchar();
133 if(ch
== '(' && !inparens
&& !stringseen
)
134 if(!strcmp(identif
, "WAND") ||
135 !strcmp(identif
, "RING") ||
136 !strcmp(identif
, "POTION") ||
137 !strcmp(identif
, "SCROLL"))
138 (void) strncpy(string
, identif
, 3),
144 /* watch for comment */
145 if((ch
= nextchar()) == '*')
156 if(inbraces
< 0) return(0);
161 printf("too many ) ?");
166 /* watch for #define at begin of line */
167 if((ch
= nextchar()) == '#'){
169 /* skip until '\n' not preceded by '\\' */
173 } while(ch
!= '\n' || pch
== '\\');
178 if(!inparens
&& !inbraces
){
179 if(prefix
&& !string
[prefix
])
181 if(stringseen
) return(1);
182 printf("unexpected ,\n");
188 if((ch
= nextchar()) == '\\') ch
= nextchar();
189 if(nextchar() != '\''){
190 printf("strange character denotation?\n");
196 register char *sp
= string
+ prefix
;
198 register int store
= (inbraces
|| inparens
)
199 && !stringseen
++ && !commaseen
;
203 if(store
&& sp
< string
+STRSZ
)
205 } while(ch
!= '"' || pch
== '\\');
213 capitalize(sp
) register char *sp
; {
214 if('a' <= *sp
&& *sp
<= 'z') *sp
+= 'A'-'a';
217 letter(ch
) register char ch
; {
218 return( ('a' <= ch
&& ch
<= 'z') ||
219 ('A' <= ch
&& ch
<= 'Z') );
222 digit(ch
) register char ch
; {
223 return( '0' <= ch
&& ch
<= '9' );