This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
infogen.c
169 lines (146 loc) · 3.56 KB
/
infogen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#define VERSION "1.0"
/*
=============================================================================
DOOM INFOGEN
by John Carmack
=============================================================================
*/
#include "cmdlib.h"
#include "scriplib.h"
#define MAXTYPES 128
#define MAXINFO 32
typedef struct
{
char *name;
char *base;
} info_t;
info_t baseinfo[MAXINFO];
char typename[MAXTYPES][32];
char *info[MAXTYPES][MAXINFO];
int numtypes;
int numinfo;
int nummisc;
/*
===================
=
= main
=
===================
*/
int main (void)
{
FILE *out;
int i,j;
printf ("\nINFOGEN "VERSION" by John Carmack, copyright (c) 1993 Id Software\n");
printf ("processing infogen.in\n");
LoadScriptFile ("infogen.in");
//
// parse defaults
//
GetToken (true);
if (token[0] != '$')
Error ("first command must be $ DEFAULT");
GetToken (false);
if (strcmp (token,"DEFAULT"))
Error ("first command must be $ DEFAULT");
numinfo = 0;
do
{
GetToken (true);
if (endofscript)
Error ("end of script in defaults");
if (token[0] == '$')
{
UnGetToken ();
break;
}
baseinfo[numinfo].name = malloc (strlen(token)+1);
strcpy (baseinfo[numinfo].name, token);
GetToken (false);
baseinfo[numinfo].base = malloc (strlen(token)+1);
strcpy (baseinfo[numinfo].base, token);
numinfo++;
} while (1);
//
// parse commands
//
numtypes = 0;
do
{
GetToken (true);
if (endofscript)
break;
if (token[0] == '$')
{
GetToken (false);
if (token[0] == '+')
{
sprintf (typename[numtypes],"MT_MISC%i",nummisc);
nummisc++;
}
else
strcpy (typename[numtypes], token);
numtypes++;
continue;
}
if (!numtypes)
Error ("A type mnust be defined before declaring info");
// find which field name
for (i=0 ; i<numinfo ; i++)
if (!strcmp (token, baseinfo[i].name))
break;
if (i==numinfo)
Error ("Unknown info type %s",token);
GetToken (false);
info[numtypes-1][i] = malloc(strlen(token)+1);
strcpy (info[numtypes-1][i], token);
} while (1);
//===========================================
//
// write mobjinfo.h file
//
//===========================================
out = fopen ("mobjinfo.h","w");
fprintf (out, "// generated by makeinfo\n\n");
fprintf (out, "typedef enum {\n");
for (i=0 ; i<numtypes ; i++)
fprintf (out,"%s,\n",typename[i]);
fprintf (out, "NUMMOBJTYPES} mobjtype_t;\n\n");
fprintf (out, "typedef struct {\n");
for (j=0 ; j<numinfo ; j++)
fprintf (out, " int %s;\n", baseinfo[j].name );
fprintf (out, "} mobjinfo_t;\n\n");
fprintf (out, "extern mobjinfo_t mobjinfo[NUMMOBJTYPES];\n\n");
fclose (out);
//===========================================
//
// write mobjinfo.c file
//
//===========================================
out = fopen ("mobjinfo.c","w");
fprintf (out, "// generated by makeinfo\n\n");
fprintf (out, "#include \"DoomDef.h\"\n\n");
fprintf (out, "mobjinfo_t mobjinfo[NUMMOBJTYPES] = {\n");
for (i=0 ; i<numtypes ; i++)
{
fprintf (out,"\n{ // %s\n", typename[i]);
for (j=0 ; j<numinfo ; j++)
{
if (info[i][j])
fprintf (out, "%s", info[i][j] );
else
fprintf (out, "%s", baseinfo[j].base );
if (j != numinfo-1)
fprintf (out, ",");
fprintf (out," // %s\n", baseinfo[j].name);
}
fprintf (out, " }");
if (i != numtypes-1)
fprintf (out, ",");
fprintf (out, "\n");
}
fprintf (out, "};\n\n");
fclose (out);
printf ("%i types parsed\n", numtypes);
return 0;
}