]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/makedefs.c
1 /* $NetBSD: makedefs.c,v 1.7 2001/03/25 20:44:04 jsm Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
8 static const char rcsid
[] =
9 "$NetBSD: makedefs.c,v 1.7 2001/03/25 20:44:04 jsm Exp $";
18 /* construct definitions of object constants */
25 static void readline(void);
26 static char nextchar(void);
27 static int skipuntil(const char *);
28 static int getentry(void);
29 static void capitalize(char *);
30 static int letter(int);
31 static int digit(int);
33 int main(int, char **);
44 (void) fprintf(stderr
, "usage: makedefs file\n");
47 if ((fd
= open(argv
[1], O_RDONLY
)) < 0) {
51 skipuntil("objects[] = {");
57 for (sp
= string
; *sp
; sp
++)
58 if (*sp
== ' ' || *sp
== '\t' || *sp
== '-')
60 if (!strncmp(string
, "RIN_", 4)) {
61 capitalize(string
+ 4);
62 printf("#define %s u.uprops[%d].p_flgs\n",
63 string
+ 4, propct
++);
65 for (sp
= string
; *sp
; sp
++)
67 /* avoid trouble with stupid C preprocessors */
68 if (!strncmp(string
, "WORTHLESS_PIECE_OF_", 19))
69 printf("/* #define %s %d */\n", string
, i
);
71 printf("#define %s %d\n", string
, i
);
74 printf("\n#define CORPSE DEAD_HUMAN\n");
75 printf("#define LAST_GEM (JADE+1)\n");
76 printf("#define LAST_RING %d\n", propct
);
77 printf("#define NROFOBJECTS %d\n", i
- 1);
80 perror("standard output");
86 char line
[LINSZ
], *lp
= line
, *lp0
= line
, *lpe
= line
;
92 int n
= read(fd
, lp0
, (line
+ LINSZ
) - lp0
);
94 printf("Input error.\n");
109 return ((lp
== lpe
) ? 0 : *lp
++);
119 while (*s
!= nextchar())
121 printf("Cannot skipuntil %s\n", s
);
124 if (strlen(s
) > lpe
- lp
+ 1) {
130 lp2
= lp0
; /* save value */
134 if (strlen(s
) > lpe
- lp
+ 1) {
135 printf("error in skipuntil");
141 while (*sp0
&& *sp0
== *sp1
)
153 int inbraces
= 0, inparens
= 0, stringseen
= 0, commaseen
= 0;
157 char identif
[NSZ
], *ip
;
158 string
[0] = string
[4] = 0;
160 * read until {...} or XXX(...) followed by , skip comment and
161 * #define lines deliver 0 on failure
169 if (ip
< identif
+ NSZ
- 1)
172 } while (letter(ch
) || digit(ch
));
174 while (ch
== ' ' || ch
== '\t')
176 if (ch
== '(' && !inparens
&& !stringseen
)
177 if (!strcmp(identif
, "WAND") ||
178 !strcmp(identif
, "RING") ||
179 !strcmp(identif
, "POTION") ||
180 !strcmp(identif
, "SCROLL"))
181 (void) strncpy(string
, identif
, 3),
187 /* watch for comment */
188 if ((ch
= nextchar()) == '*')
205 printf("too many ) ?");
210 /* watch for #define at begin of line */
211 if ((ch
= nextchar()) == '#') {
213 /* skip until '\n' not preceded by '\\' */
217 } while (ch
!= '\n' || pch
== '\\');
222 if (!inparens
&& !inbraces
) {
223 if (prefix
&& !string
[prefix
])
227 printf("unexpected ,\n");
233 if ((ch
= nextchar()) == '\\')
235 if (nextchar() != '\'') {
236 printf("strange character denotation?\n");
242 char *sp
= string
+ prefix
;
244 int store
= (inbraces
|| inparens
)
245 && !stringseen
++ && !commaseen
;
249 if (store
&& sp
< string
+ STRSZ
)
251 } while (ch
!= '"' || pch
== '\\');
264 if ('a' <= *sp
&& *sp
<= 'z')
272 return (('a' <= ch
&& ch
<= 'z') ||
273 ('A' <= ch
&& ch
<= 'Z'));
280 return ('0' <= ch
&& ch
<= '9');