]> git.pond.sub.org Git - empserver/blob - src/doconfig/doconfig.c
Import of Empire 4.2.12
[empserver] / src / doconfig / doconfig.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  doconfig.c: Generates the gamesdef.h file used to build the game, and
29  *              the various make include files needed to build correctly.
30  * 
31  *  Known contributors to this file:
32  *     Steve McClure, 1996-2000
33  */
34
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #if !defined(_WIN32)
40 #include <unistd.h>
41 #endif
42 #include <string.h>
43
44 void wrmakesrc(char *pathname);
45 void wripglob(char *filename);
46 void wrauth(char *filename);
47 void wrgamesdef(char *filename);
48
49 char *_c_copyright_header = "/*\n *  Empire - A multi-player, client/server Internet based war game.\n *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,\n *                           Ken Stevens, Steve McClure\n *\n *  This program is free software; you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation; either version 2 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program; if not, write to the Free Software\n *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n *\n *  ---\n *\n *  See the \"LEGAL\", \"LICENSE\", \"CREDITS\" and \"README\" files for all the\n *  related information and legal notices. It is expected that any future\n *  projects/authors will amend these files as needed.\n *\n *  ---\n *\n *  gamesdef.h: This is an auto-generated file.\n * \n *  Known contributors to this file:\n *     Automatically generated by doconfig.c\n */\n\n";
50
51 char *_ipglob_copyright_header = "/*\n *  Empire - A multi-player, client/server Internet based war game.\n *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,\n *                           Ken Stevens, Steve McClure\n *\n *  This program is free software; you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation; either version 2 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program; if not, write to the Free Software\n *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n *\n *  ---\n *\n *  See the \"LEGAL\", \"LICENSE\", \"CREDITS\" and \"README\" files for all the\n *  related information and legal notices. It is expected that any future\n *  projects/authors will amend these files as needed.\n *\n *  ---\n *\n *  ipglob.c: This is an auto-generated file.\n * \n *  Known contributors to this file:\n *     Automatically generated by doconfig.c\n */\n\n";
52
53 #if defined(_WIN32)
54 char *
55 rindex(char *path, char c)
56 {
57         int i;
58         char *cp;
59
60         i = strlen(path);
61         cp = &path[i - 1];
62
63         while (i) {
64                 if (*cp == c)
65                         return cp;
66                 i--;
67                 cp--;
68         }
69         return (char *)0;
70 }
71
72 char *
73 index(char *path, char c)
74 {
75         int i;
76         char *cp;
77
78         cp = &path[0];
79
80         i = 0;
81         while (path[i]) {
82                 if (*cp == c)
83                         return cp;
84                 i++;
85                 cp++;
86         }
87         return (char *)0;
88 }
89
90 #endif
91
92 int
93 main()
94 {
95     char buf[256];
96     char *cp;
97         char *pathname;
98
99     if ((pathname = getcwd(NULL, 255)) == NULL) {
100                 printf("Can't get current path!\n");
101                 exit(-1);
102     }
103     
104 #if !defined(_WIN32)
105     cp = (char *)rindex(pathname, '/');
106     *cp = '\0';
107     cp = (char *)rindex(pathname, '/');
108     *cp = '\0';
109 #else
110     cp = (char *)rindex(pathname, '\\');
111     *cp = '\0';
112     cp = (char *)rindex(pathname, '\\');
113     *cp = '\0';
114 #endif
115     printf("Configuring...\n");
116     wrmakesrc(pathname);
117     sprintf(buf, "%s/include/gamesdef.h", pathname);
118     wrgamesdef(buf);
119     sprintf(buf, "%s/src/client/ipglob.c", pathname);
120     wripglob(buf);
121
122     if (access(EP, 0)) {
123                 printf("making directory %s\n", EP);
124                 if (mkdir(EP, 493)) {
125                         printf("mkdir failed on %s, exiting.\n", EP);
126                         exit(-1);
127                 }
128     }
129     sprintf(buf, "%s/data", EP);
130     if (access(buf, 0)) {
131                 printf("making directory %s\n", buf);
132                 if (mkdir(buf, 493)) {
133                         printf("mkdir failed on %s, exiting.\n", buf);
134                         exit(-1);
135                 }
136     }
137     sprintf(buf, "%s/data/auth", EP);
138     wrauth(buf);
139     exit(0);
140 }
141
142 void
143 wrmakesrc(char *pathname)
144 {
145     FILE *fp;
146     char buf[256];
147         
148     sprintf(buf, "%s/src/make.src", pathname);
149     if ((fp = fopen(buf, "w")) == NULL) {
150                 printf("Cannot open %s for writing, exiting.\n", buf);
151                 exit(-1);
152     }
153     fprintf(fp, "# make.src - Wolfpack, 1996-2000\n");
154     fprintf(fp, "#            Source tree absolute pathname - auto generated.\n\n");
155     fprintf(fp, "SRCDIR = %s\n", pathname);
156     fclose(fp);
157 }
158
159 void
160 wripglob(char *filename)
161 {
162     FILE *fp;
163
164     printf("Writing %s\n", filename);
165     if ((fp = fopen(filename, "w")) == NULL) {
166                 printf("Cannot open %s for writing, exiting.\n", filename);
167                 exit(-1);
168     }
169         fprintf(fp, _ipglob_copyright_header);
170     fprintf(fp, "#include <stdio.h>\n");
171     fprintf(fp, "#include <setjmp.h>\n");
172     fprintf(fp, "#include \"misc.h\"\n");
173     fprintf(fp, "#include \"fnlist.h\"\n");
174     fprintf(fp, "#include \"proto.h\"\n\n");
175     fprintf(fp, "s_char empirehost[] = \"%s\";\n", HN);
176     fprintf(fp, "s_char empireport[] = \"%d\";\n", PN);
177     fclose(fp);
178 }
179
180 void
181 wrauth(char *filename)
182 {
183     FILE *fp;
184
185     printf("Writing %s\n", filename);
186     if ((fp = fopen(filename, "w")) == NULL) {
187                 printf("Cannot open %s for writing, exiting.\n", filename);
188                 exit(-1);
189     }
190         
191     fprintf(fp, "# Wolfpack, 1996-2000\n#\n");
192     fprintf(fp, "# Empire Authorization File - Users listed will be allowed to log in as deities.\n#\n");
193     fprintf(fp, "# Format is:\n");
194     fprintf(fp, "# hostname that authorized user uses on a line\n");
195     fprintf(fp, "# username that authorized user uses on a line\n#\n");
196     fprintf(fp, "# REMEMBER TO USE PAIRS OF LINES!\n#\n");
197     fprintf(fp, "# Example:\n#\n");
198     fprintf(fp, "nowhere.land.edu\nnowhereman\n");
199     fprintf(fp, "%s\n%s\n", HN, UN);
200     fprintf(fp, "%s\n%s\n", IP, UN);
201     fprintf(fp, "127.0.0.1\n%s\n", UN);
202     fclose(fp);
203 }
204
205 void
206 wrgamesdef(char *filename)
207 {
208     FILE *fp;
209         char path[512];
210         char *cp;
211         unsigned int i;
212     int s_p_etu;
213     char buf[40];
214     char c = 'b';
215
216         cp = &path[0];
217         for (i = 0; i < strlen(EP); i++) {
218                 *cp++ = EP[i];
219                 if (EP[i] == '\\')
220                         *cp++ = '\\';
221         }
222         *cp = 0;
223
224     strcpy(buf, EF);
225     if (strlen(buf) > 0)
226                 c = buf[strlen(buf) - 1];
227     if (index("dhm", c) && strlen(buf) > 0) {
228                 s_p_etu = atoi(buf);
229                 if (c == 'd')
230                         s_p_etu = (((double)s_p_etu * 60.0 * 60.0 * 24.0) / (double)ET);
231                 else if (c == 'h')
232                         s_p_etu = (((double)s_p_etu * 60.0 * 60.0) / (double)ET);
233                 else if (c == 'm')
234                         s_p_etu = (((double)s_p_etu * 60.0) / (double)ET);
235     } else {
236                 printf("ETU frequency is bad - using 10 minutes.\n");
237                 s_p_etu = 600 / ET;
238     }
239
240     printf("Writing %s\n", filename);
241     if ((fp = fopen(filename, "w")) == NULL) {
242                 printf("Cannot open %s for writing, exiting.\n", filename);
243                 exit(-1);
244     }
245     fprintf(fp, _c_copyright_header);
246     fprintf(fp, "/*\n * Wolfpack, 1996-2000\n *\n");
247     fprintf(fp, " * gamesdef.h - generated automatically by doconfig.  Feel\n");
248     fprintf(fp, " * free to change these, but if you rebuild with overwrite on\n");
249     fprintf(fp, " * this file will be overwritten again.\n");
250     fprintf(fp, " */\n\n");
251     fprintf(fp, "#ifndef _GAMESDEF_H_\n");
252     fprintf(fp, "#define _GAMESDEF_H_\n\n");
253         fprintf(fp, "#if !defined(_WIN32)\n");
254     fprintf(fp, "#ifdef __STDC__\n");
255     fprintf(fp, "#define EMPPATH(xyz) \"%s/\" #xyz /* ANSI C */\n", EP);
256     fprintf(fp, "#else\n");
257     fprintf(fp, "#define EMPPATH(xyz) \"%s/xyz\" /* traditional */\n", EP);
258     fprintf(fp, "#endif /* __STDC__ */\n");
259         fprintf(fp, "#else\n");
260         fprintf(fp, "#define EMPPATH(xyz) \"%s\\\\\" #xyz /* ANSI C */\n", path);
261     fprintf(fp, "#endif /* _WIN32 */\n\n");
262     fprintf(fp, "#define PRVNAM \"%s\"\n", PV);
263     fprintf(fp, "#define PRVLOG \"%s\"\n", EM);
264     fprintf(fp, "#define GET_SOURCE \"using:\\n    ftp://ftp.wolfpackempire.com/pub/empire/server or \\n    http://www.wolfpackempire.com/\"\n");
265     fprintf(fp, "#define EMP_HOST \"%s\"\n", IP);
266     fprintf(fp, "#define EMP_PORT \"%d\"\n\n", PN);
267     fprintf(fp, "#define MAXNOC %d\n\n", MC);
268     fprintf(fp, "#define DEF_WORLD_X %d\n", WX);
269     fprintf(fp, "#define DEF_WORLD_Y %d\n\n", WY);
270     fprintf(fp, "#define DEF_S_P_ETU %d\n", s_p_etu);
271     fprintf(fp, "#define ETUS %d\n\n", ET);
272     if (BL)
273                 fprintf(fp, "#define BLITZ  1\n\n");
274     fprintf(fp, "#endif /* _GAMESDEF_H_ */\n");
275     fclose(fp);
276 }