]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/makedefs.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: makedefs.c,v 1.4 1995/04/24 12:23:39 cgd Exp $";
12 /* construct definitions of object constants */
23 register int index
= 0;
24 register int propct
= 0;
27 (void)fprintf(stderr
, "usage: makedefs file\n");
30 if ((fd
= open(argv
[1], 0)) < 0) {
34 skipuntil("objects[] = {");
40 for(sp
= string
; *sp
; sp
++)
41 if(*sp
== ' ' || *sp
== '\t' || *sp
== '-')
43 if(!strncmp(string
, "RIN_", 4)){
45 printf("#define %s u.uprops[%d].p_flgs\n",
48 for(sp
= string
; *sp
; sp
++) capitalize(sp
);
49 /* avoid trouble with stupid C preprocessors */
50 if(!strncmp(string
, "WORTHLESS_PIECE_OF_", 19))
51 printf("/* #define %s %d */\n", string
, index
);
53 printf("#define %s %d\n", string
, index
);
56 printf("\n#define CORPSE DEAD_HUMAN\n");
57 printf("#define LAST_GEM (JADE+1)\n");
58 printf("#define LAST_RING %d\n", propct
);
59 printf("#define NROFOBJECTS %d\n", index
-1);
63 char line
[LINSZ
], *lp
= line
, *lp0
= line
, *lpe
= line
;
67 register int n
= read(fd
, lp0
, (line
+LINSZ
)-lp0
);
69 printf("Input error.\n");
82 return((lp
== lpe
) ? 0 : *lp
++);
85 skipuntil(s
) char *s
; {
86 register char *sp0
, *sp1
;
88 while(*s
!= nextchar())
90 printf("Cannot skipuntil %s\n", s
);
93 if(strlen(s
) > lpe
-lp
+1){
94 register char *lp1
, *lp2
;
97 while(lp2
!= lpe
) *lp1
++ = *lp2
++;
98 lp2
= lp0
; /* save value */
102 if(strlen(s
) > lpe
-lp
+1) {
103 printf("error in skipuntil");
109 while(*sp0
&& *sp0
== *sp1
) sp0
++, sp1
++;
118 int inbraces
= 0, inparens
= 0, stringseen
= 0, commaseen
= 0;
122 char identif
[NSZ
], *ip
;
123 string
[0] = string
[4] = 0;
124 /* read until {...} or XXX(...) followed by ,
125 skip comment and #define lines
134 if(ip
< identif
+NSZ
-1) *ip
++ = ch
;
136 } while(letter(ch
) || digit(ch
));
138 while(ch
== ' ' || ch
== '\t') ch
= nextchar();
139 if(ch
== '(' && !inparens
&& !stringseen
)
140 if(!strcmp(identif
, "WAND") ||
141 !strcmp(identif
, "RING") ||
142 !strcmp(identif
, "POTION") ||
143 !strcmp(identif
, "SCROLL"))
144 (void) strncpy(string
, identif
, 3),
150 /* watch for comment */
151 if((ch
= nextchar()) == '*')
162 if(inbraces
< 0) return(0);
167 printf("too many ) ?");
172 /* watch for #define at begin of line */
173 if((ch
= nextchar()) == '#'){
175 /* skip until '\n' not preceded by '\\' */
179 } while(ch
!= '\n' || pch
== '\\');
184 if(!inparens
&& !inbraces
){
185 if(prefix
&& !string
[prefix
])
187 if(stringseen
) return(1);
188 printf("unexpected ,\n");
194 if((ch
= nextchar()) == '\\') ch
= nextchar();
195 if(nextchar() != '\''){
196 printf("strange character denotation?\n");
202 register char *sp
= string
+ prefix
;
204 register int store
= (inbraces
|| inparens
)
205 && !stringseen
++ && !commaseen
;
209 if(store
&& sp
< string
+STRSZ
)
211 } while(ch
!= '"' || pch
== '\\');
219 capitalize(sp
) register char *sp
; {
220 if('a' <= *sp
&& *sp
<= 'z') *sp
+= 'A'-'a';
223 letter(ch
) register char ch
; {
224 return( ('a' <= ch
&& ch
<= 'z') ||
225 ('A' <= ch
&& ch
<= 'Z') );
228 digit(ch
) register char ch
; {
229 return( '0' <= ch
&& ch
<= '9' );