]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/makedefs.c
1 /* $NetBSD: makedefs.c,v 1.5 1997/10/19 16:59:36 christos Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: makedefs.c,v 1.5 1997/10/19 16:59:36 christos Exp $");
17 /* construct definitions of object constants */
24 static void readline
__P((void));
25 static char nextchar
__P((void));
26 static int skipuntil
__P((char *));
27 static int getentry
__P((void));
28 static void capitalize
__P((char *));
29 static int letter
__P((int));
30 static int digit
__P((int));
32 int main
__P((int, char **));
43 (void) fprintf(stderr
, "usage: makedefs file\n");
46 if ((fd
= open(argv
[1], 0)) < 0) {
50 skipuntil("objects[] = {");
56 for (sp
= string
; *sp
; sp
++)
57 if (*sp
== ' ' || *sp
== '\t' || *sp
== '-')
59 if (!strncmp(string
, "RIN_", 4)) {
60 capitalize(string
+ 4);
61 printf("#define %s u.uprops[%d].p_flgs\n",
62 string
+ 4, propct
++);
64 for (sp
= string
; *sp
; sp
++)
66 /* avoid trouble with stupid C preprocessors */
67 if (!strncmp(string
, "WORTHLESS_PIECE_OF_", 19))
68 printf("/* #define %s %d */\n", string
, i
);
70 printf("#define %s %d\n", string
, i
);
73 printf("\n#define CORPSE DEAD_HUMAN\n");
74 printf("#define LAST_GEM (JADE+1)\n");
75 printf("#define LAST_RING %d\n", propct
);
76 printf("#define NROFOBJECTS %d\n", i
- 1);
80 char line
[LINSZ
], *lp
= line
, *lp0
= line
, *lpe
= line
;
86 int n
= read(fd
, lp0
, (line
+ LINSZ
) - lp0
);
88 printf("Input error.\n");
103 return ((lp
== lpe
) ? 0 : *lp
++);
112 while (*s
!= nextchar())
114 printf("Cannot skipuntil %s\n", s
);
117 if (strlen(s
) > lpe
- lp
+ 1) {
123 lp2
= lp0
; /* save value */
127 if (strlen(s
) > lpe
- lp
+ 1) {
128 printf("error in skipuntil");
134 while (*sp0
&& *sp0
== *sp1
)
146 int inbraces
= 0, inparens
= 0, stringseen
= 0, commaseen
= 0;
150 char identif
[NSZ
], *ip
;
151 string
[0] = string
[4] = 0;
153 * read until {...} or XXX(...) followed by , skip comment and
154 * #define lines deliver 0 on failure
162 if (ip
< identif
+ NSZ
- 1)
165 } while (letter(ch
) || digit(ch
));
167 while (ch
== ' ' || ch
== '\t')
169 if (ch
== '(' && !inparens
&& !stringseen
)
170 if (!strcmp(identif
, "WAND") ||
171 !strcmp(identif
, "RING") ||
172 !strcmp(identif
, "POTION") ||
173 !strcmp(identif
, "SCROLL"))
174 (void) strncpy(string
, identif
, 3),
180 /* watch for comment */
181 if ((ch
= nextchar()) == '*')
198 printf("too many ) ?");
203 /* watch for #define at begin of line */
204 if ((ch
= nextchar()) == '#') {
206 /* skip until '\n' not preceded by '\\' */
210 } while (ch
!= '\n' || pch
== '\\');
215 if (!inparens
&& !inbraces
) {
216 if (prefix
&& !string
[prefix
])
220 printf("unexpected ,\n");
226 if ((ch
= nextchar()) == '\\')
228 if (nextchar() != '\'') {
229 printf("strange character denotation?\n");
235 char *sp
= string
+ prefix
;
237 int store
= (inbraces
|| inparens
)
238 && !stringseen
++ && !commaseen
;
242 if (store
&& sp
< string
+ STRSZ
)
244 } while (ch
!= '"' || pch
== '\\');
257 if ('a' <= *sp
&& *sp
<= 'z')
265 return (('a' <= ch
&& ch
<= 'z') ||
266 ('A' <= ch
&& ch
<= 'Z'));
273 return ('0' <= ch
&& ch
<= '9');