empserver/src/doconfig/doconfig.c
Markus Armbruster 4a3f0b8146 Add some missing declarations to headers. Remove some redundant
declarations elsewhere.  Change linkage of some functions to static.
2004-02-20 10:51:03 +00:00

235 lines
9.1 KiB
C

/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ---
*
* See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
* related information and legal notices. It is expected that any future
* projects/authors will amend these files as needed.
*
* ---
*
* doconfig.c: Generates the gamesdef.h file used to build the game, and
* the various make include files needed to build correctly.
*
* Known contributors to this file:
* Steve McClure, 1996-2000
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#if !defined(_WIN32)
#include <unistd.h>
#else
#include <direct.h>
#include <io.h>
#endif
#include <string.h>
static void wrmakesrc(char *pathname);
static void wripglob(char *filename);
static void wrauth(char *filename);
static void wrgamesdef(char *filename);
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";
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";
int
main(void)
{
char buf[256];
char *cp;
char *pathname;
if ((pathname = getcwd(NULL, 255)) == NULL) {
printf("Can't get current path!\n");
exit(-1);
}
#if !defined(_WIN32)
cp = strrchr(pathname, '/');
*cp = '\0';
cp = strrchr(pathname, '/');
*cp = '\0';
#else
cp = strrchr(pathname, '\\');
*cp = '\0';
cp = strrchr(pathname, '\\');
*cp = '\0';
#endif
printf("Configuring...\n");
wrmakesrc(pathname);
sprintf(buf, "%s/include/gamesdef.h", pathname);
wrgamesdef(buf);
sprintf(buf, "%s/src/client/ipglob.c", pathname);
wripglob(buf);
if (access(EP, 0)) {
printf("making directory %s\n", EP);
if (mkdir(EP, 0755)) {
printf("mkdir failed on %s, exiting.\n", EP);
exit(-1);
}
}
sprintf(buf, "%s/data", EP);
if (access(buf, 0)) {
printf("making directory %s\n", buf);
if (mkdir(buf, 0755)) {
printf("mkdir failed on %s, exiting.\n", buf);
exit(-1);
}
}
sprintf(buf, "%s/data/auth", EP);
wrauth(buf);
exit(0);
}
static void
wrmakesrc(char *pathname)
{
FILE *fp;
char buf[256];
sprintf(buf, "%s/src/make.src", pathname);
if ((fp = fopen(buf, "w")) == NULL) {
printf("Cannot open %s for writing, exiting.\n", buf);
exit(-1);
}
fprintf(fp, "# make.src - Wolfpack, 1996-2000\n");
fprintf(fp,
"# Source tree absolute pathname - auto generated.\n\n");
fprintf(fp, "SRCDIR = %s\n", pathname);
fclose(fp);
}
static void
wripglob(char *filename)
{
FILE *fp;
printf("Writing %s\n", filename);
if ((fp = fopen(filename, "w")) == NULL) {
printf("Cannot open %s for writing, exiting.\n", filename);
exit(-1);
}
fprintf(fp, _ipglob_copyright_header);
fprintf(fp, "#include \"misc.h\"\n");
fprintf(fp, "s_char empirehost[] = \"%s\";\n", HN);
fprintf(fp, "s_char empireport[] = \"%d\";\n", PN);
fclose(fp);
}
static void
wrauth(char *filename)
{
FILE *fp;
printf("Writing %s\n", filename);
if ((fp = fopen(filename, "w")) == NULL) {
printf("Cannot open %s for writing, exiting.\n", filename);
exit(-1);
}
fprintf(fp, "# Wolfpack, 1996-2000\n#\n");
fprintf(fp,
"# Empire Authorization File - Users listed will be allowed to log in as deities.\n#\n");
fprintf(fp, "# Format is:\n");
fprintf(fp, "# hostname that authorized user uses on a line\n");
fprintf(fp, "# username that authorized user uses on a line\n#\n");
fprintf(fp, "# REMEMBER TO USE PAIRS OF LINES!\n#\n");
fprintf(fp, "# Example:\n#\n");
fprintf(fp, "#nowhere.land.edu\n#nowhereman\n");
fprintf(fp, "%s\n%s\n", HN, UN);
fprintf(fp, "%s\n%s\n", IP, UN);
fprintf(fp, "127.0.0.1\n%s\n", UN);
fclose(fp);
}
static void
wrgamesdef(char *filename)
{
FILE *fp;
char path[512];
char *cp;
unsigned int i;
int s_p_etu;
char buf[40];
char c = 'b';
cp = &path[0];
for (i = 0; i < strlen(EP); i++) {
*cp++ = EP[i];
if (EP[i] == '\\')
*cp++ = '\\';
}
*cp = 0;
strcpy(buf, EF);
if (strlen(buf) > 0)
c = buf[strlen(buf) - 1];
if (strchr("dhm", c) && strlen(buf) > 0) {
s_p_etu = atoi(buf);
if (c == 'd')
s_p_etu =
(((double)s_p_etu * 60.0 * 60.0 * 24.0) / (double)ET);
else if (c == 'h')
s_p_etu = (((double)s_p_etu * 60.0 * 60.0) / (double)ET);
else if (c == 'm')
s_p_etu = (((double)s_p_etu * 60.0) / (double)ET);
} else {
printf("ETU frequency is bad - using 10 minutes.\n");
s_p_etu = 600 / ET;
}
printf("Writing %s\n", filename);
if ((fp = fopen(filename, "w")) == NULL) {
printf("Cannot open %s for writing, exiting.\n", filename);
exit(-1);
}
fprintf(fp, _c_copyright_header);
fprintf(fp, "/*\n * Wolfpack, 1996-2000\n *\n");
fprintf(fp,
" * gamesdef.h - generated automatically by doconfig. Feel\n");
fprintf(fp,
" * free to change these, but if you rebuild with overwrite on\n");
fprintf(fp, " * this file will be overwritten again.\n");
fprintf(fp, " */\n\n");
fprintf(fp, "#ifndef _GAMESDEF_H_\n");
fprintf(fp, "#define _GAMESDEF_H_\n\n");
fprintf(fp, "#define EMPDIR \"%s\"\n", EP);
fprintf(fp, "#define PRVNAM \"%s\"\n", PV);
fprintf(fp, "#define PRVLOG \"%s\"\n", EM);
fprintf(fp, "#define GET_SOURCE \"using:\\n ftp://ftp.wolfpackempire.com/pub/empire/server or \\n http://www.wolfpackempire.com/\"\n");
fprintf(fp, "#define EMP_HOST \"%s\"\n", IP);
fprintf(fp, "#define EMP_PORT \"%d\"\n\n", PN);
fprintf(fp, "#define MAXNOC %d\n\n", MC);
fprintf(fp, "#define DEF_WORLD_X %d\n", WX);
fprintf(fp, "#define DEF_WORLD_Y %d\n\n", WY);
fprintf(fp, "#define DEF_S_P_ETU %d\n", s_p_etu);
fprintf(fp, "#define ETUS %d\n\n", ET);
if (BL)
fprintf(fp, "#define BLITZ 1\n\n");
fprintf(fp, "#endif /* _GAMESDEF_H_ */\n");
fclose(fp);
}