ref: 30b2e71c09f4de8d8f1d643da27e06ae6b0ea98e
parent: 9326506e95b39059718ce02a72a58c43e6f89424
author: Simon Howard <[email protected]>
date: Mon Oct 23 14:00:30 EDT 2006
Add m_argv.[ch] from Doom, fix up configfile.c so that it compiles properly. Add to build. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 719
--- a/setup/Makefile.am
+++ b/setup/Makefile.am
@@ -8,8 +8,10 @@
chocolate_setup_LDADD = @LDFLAGS@ @SDL_LIBS@ ../textscreen/libtextscreen.a
chocolate_setup_SOURCES = \
compatibility.c compatibility.h \
+ configfile.c configfile.h \
display.c display.h \
keyboard.c keyboard.h \
+ m_argv.c m_argv.h \
mainmenu.c \
mouse.c mouse.h \
multiplayer.c multiplayer.h \
--- a/setup/configfile.c
+++ b/setup/configfile.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
+#include <string.h>
// for mkdir:
@@ -41,6 +42,7 @@
#include "config.h"
#include "doomkeys.h"
+#include "m_argv.h"
#include "compatibility.h"
#include "display.h"
@@ -49,7 +51,72 @@
#include "multiplayer.h"
#include "sound.h"
+char *configdir;
+
//
+// Create a directory
+//
+
+void M_MakeDirectory(char *path)
+{
+#ifdef _WIN32
+ mkdir(path);
+#else
+ mkdir(path, 0755);
+#endif
+}
+
+
+//
+// SetConfigDir:
+//
+// Sets the location of the configuration directory, where configuration
+// files are stored - default.cfg, chocolate-doom.cfg, savegames, etc.
+//
+
+void M_SetConfigDir(void)
+{
+ char *homedir;
+
+ homedir = getenv("HOME");
+
+ if (homedir != NULL)
+ {
+ // put all configuration in a config directory off the
+ // homedir
+
+ configdir = malloc(strlen(homedir) + strlen(PACKAGE_TARNAME) + 5);
+
+ sprintf(configdir, "%s/.%s/", homedir, PACKAGE_TARNAME);
+
+ // make the directory if it doesnt already exist
+
+ M_MakeDirectory(configdir);
+ }
+ else
+ {
+#ifdef _WIN32
+ // when given the -cdrom option, save config+savegames in
+ // c:\doomdata. This only applies under Windows.
+
+ if (M_CheckParm("-cdrom") > 0)
+ {
+ printf(D_CDROM);
+ configdir = strdup("c:\\doomdata\\");
+
+ M_MakeDirectory(configdir);
+ }
+ else
+#endif
+ {
+ configdir = strdup("");
+ }
+ }
+}
+
+
+
+//
// DEFAULTS
//
@@ -57,9 +124,10 @@
static int showMessages = 1;
static int screenblocks = 9;
-static int detaillevel = 0;
+static int detailLevel = 0;
static int usegamma = 0;
-static int use_joystick = 0;
+
+static int usejoystick = 0;
static int joybfire = 0;
static int joybstrafe = 1;
static int joybuse = 2;
--- /dev/null
+++ b/setup/m_argv.c
@@ -1,0 +1,57 @@
+// Emacs style mode select -*- C++ -*-
+//-----------------------------------------------------------------------------
+//
+// Copyright(C) 1993-1996 Id Software, Inc.
+// Copyright(C) 2005 Simon Howard
+//
+// 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.
+//
+// DESCRIPTION:
+//
+//-----------------------------------------------------------------------------
+
+
+
+#include <string.h>
+
+int myargc;
+char** myargv;
+
+
+
+
+//
+// M_CheckParm
+// Checks for the given parameter
+// in the program's command line arguments.
+// Returns the argument number (1 to argc-1)
+// or 0 if not present
+int M_CheckParm (char *check)
+{
+ int i;
+
+ for (i = 1;i<myargc;i++)
+ {
+ if ( !strcasecmp(check, myargv[i]) )
+ return i;
+ }
+
+ return 0;
+}
+
+
+
+
--- /dev/null
+++ b/setup/m_argv.h
@@ -1,0 +1,42 @@
+// Emacs style mode select -*- C++ -*-
+//-----------------------------------------------------------------------------
+//
+// Copyright(C) 1993-1996 Id Software, Inc.
+// Copyright(C) 2005 Simon Howard
+//
+// 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.
+//
+// DESCRIPTION:
+// Nil.
+//
+//-----------------------------------------------------------------------------
+
+
+#ifndef __M_ARGV__
+#define __M_ARGV__
+
+//
+// MISC
+//
+extern int myargc;
+extern char** myargv;
+
+// Returns the position of the given parameter
+// in the arg list (0 if not found).
+int M_CheckParm (char* check);
+
+
+#endif