From 2184a3609c15250b8ad8f2546e651bae2a08cafb Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 5 Apr 2008 22:55:46 +0000 Subject: [PATCH] Allow any number of different games per dgl installation without needing to recompile. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@437 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- config.y | 18 ++++++++++++------ configure.ac | 9 --------- dgamelaunch.h | 3 --- dgl-common.c | 30 ++++-------------------------- 4 files changed, 16 insertions(+), 44 deletions(-) diff --git a/config.y b/config.y index 3f272fa..dd3a62d 100644 --- a/config.y +++ b/config.y @@ -414,19 +414,25 @@ game_definitions : game_definition definegame : TYPE_DEFINE_GAME '{' { - if ((ncnf < 0) || (ncnf >= DIFF_GAMES)) { - fprintf(stderr, "%s:%d: too many games defined, bailing out\n", + struct dg_config **tmpconfig = NULL; + + tmpconfig = calloc(ncnf + 1, sizeof(myconfig[0])); + if (!tmpconfig) { + fprintf(stderr, "%s:%d: could not allocate memory for config, bailing out\n", config, line); exit(1); } - if (!myconfig) { + if (myconfig) { int tmp; - myconfig = calloc(DIFF_GAMES, sizeof(myconfig[0])); - for (tmp = 0; tmp < DIFF_GAMES; tmp++) { - myconfig[tmp] = calloc(1, sizeof(struct dg_config)); + for (tmp = 0; tmp < ncnf; tmp++) { + tmpconfig[tmp] = myconfig[tmp]; } + free(myconfig); } + + tmpconfig[ncnf] = calloc(1, sizeof(struct dg_config)); + myconfig = tmpconfig; } game_definitions '}' { diff --git a/configure.ac b/configure.ac index 6d4d13f..6081ad0 100644 --- a/configure.ac +++ b/configure.ac @@ -87,15 +87,6 @@ if test "$enable_sqlite" = yes; then AC_DEFINE_UNQUOTED(USE_SQLITE_DB, "$dgl_sqlite_db", [Path and filename of the SQLite database.]) fi -def_dgl_num_games=4 - -AC_ARG_WITH(num-games, -[AC_HELP_STRING([--num-games=INT], [Max. number of games this dgamelaunch supports per dgl installation.])], -[dgl_num_games=$withval], [dgl_num_games=$def_dgl_num_games]) - -AC_DEFINE_UNQUOTED(DIFF_GAMES, $dgl_num_games, [Max. number of games this dgamelaunch supports per dgl installation.]) -AC_MSG_RESULT([Number of games this dgamelaunch supports: $dgl_num_games]); - AC_ARG_WITH(config-file, [AC_HELP_STRING([--with-config-file=PATH], [Define the path to the default configuration file.])], [configfile=$withval], [configfile="/etc/dgamelaunch.conf"]) diff --git a/dgamelaunch.h b/dgamelaunch.h index 3951bc3..351ebcb 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -14,9 +14,6 @@ #endif -/* max # of different games playable from within this dgl */ -/*#define DIFF_GAMES 4*/ - typedef enum { DGLTIME_DGLSTART = 0, /* when someone telnets in */ diff --git a/dgl-common.c b/dgl-common.c index 5bade11..be04fc2 100644 --- a/dgl-common.c +++ b/dgl-common.c @@ -559,9 +559,8 @@ create_config () } #else /* fprintf(stderr, "NO DEFCONFIG\n");*/ - myconfig = calloc(DIFF_GAMES, sizeof(myconfig[0])); - for (tmp = 0; tmp < DIFF_GAMES; tmp++) - myconfig[tmp] = NULL; + num_games = 0; + myconfig = calloc(1, sizeof(myconfig[0])); myconfig[0] = &defconfig; return; #endif @@ -569,25 +568,8 @@ create_config () if (!myconfig) /* a parse error occurred */ { - /* fprintf(stderr, "PARSE ERROR\n");*/ - myconfig = calloc(DIFF_GAMES, sizeof(myconfig[0])); - for (tmp = 0; tmp < DIFF_GAMES; tmp++) - myconfig[tmp] = NULL; - myconfig[0] = &defconfig; - return; - } - /* Fill the rest with defaults */ - - for (tmp = 0; tmp < DIFF_GAMES; tmp++) { - - if (!myconfig[tmp]->game_path) myconfig[tmp]->game_path = defconfig.game_path; - if (!myconfig[tmp]->game_name) myconfig[tmp]->game_name = defconfig.game_name; - if (!myconfig[tmp]->shortname) myconfig[tmp]->shortname = defconfig.shortname; - if (!myconfig[tmp]->rcfile) myconfig[tmp]->rcfile = defconfig.rcfile; - if (!myconfig[tmp]->spool) myconfig[tmp]->spool = defconfig.spool; - /*if (!myconfig[tmp]->savefilefmt) myconfig[tmp]->savefilefmt = defconfig.savefilefmt;*/ - if (!myconfig[tmp]->inprogressdir) myconfig[tmp]->inprogressdir = defconfig.inprogressdir; - + fprintf(stderr, "ERROR: configuration parsing failed\n"); + graceful_exit(113); } if (!globalconfig.chroot) globalconfig.chroot = "/var/lib/dgamelaunch/"; @@ -617,8 +599,4 @@ create_config () globalconfig.shed_gid = 60; /* games gid in debian */ } - for (tmp = 0; tmp < NUM_DGLTIMES; tmp++) { - globalconfig.cmdqueue[0] = NULL; - } - }