shithub: choc

Download patch

ref: 463bcf013ce355398974953508d232ac88a6b2d6
parent: 1ef81eb5f7c336972fe56f15285f389cafdc96f5
author: Simon Howard <fraggle@gmail.com>
date: Sat Dec 18 18:55:07 EST 2010

Add a M_CheckParmWithArgs function, that behaves like M_CheckParm but
also checks that extra options were provided on the command line (thanks
Sander van Dijk).

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2223

--- a/NEWS
+++ b/NEWS
@@ -79,8 +79,8 @@
        exp(x)).
      * The controller player in a netgame is the first player to join,
        instead of just being someone who gets lucky.
-     * Check that an address is provided to the -query command line
-       option (thanks Sander van Dijk).
+     * Command line arguments that take an option now check that an
+       option is provided (thanks Sander van Dijk).
 
     libtextscreen:
      * The font used for the textscreen library can be forced by
--- a/man/docgen
+++ b/man/docgen
@@ -293,10 +293,10 @@
 
     # Is this documenting a command line parameter?
 
-    match = re.search('M_CheckParm\s*\(\s*"(.*?)"\s*\)', line)
+    match = re.search('M_CheckParm(WithArgs)?\s*\(\s*"(.*?)"', line)
 
     if match:
-        param.name = match.group(1)
+        param.name = match.group(2)
         categories[param.category].add_param(param)
         return
 
--- a/src/d_iwad.c
+++ b/src/d_iwad.c
@@ -658,7 +658,7 @@
     // @arg <file>
     //
 
-    iwadparm = M_CheckParm("-iwad");
+    iwadparm = M_CheckParmWithArgs("-iwad", 1);
 
     if (iwadparm)
     {
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -672,9 +672,9 @@
     // "ultimate" and "final".
     //
 
-    p = M_CheckParm("-gameversion");
+    p = M_CheckParmWithArgs("-gameversion", 1);
 
-    if (p > 0)
+    if (p)
     {
         for (i=0; gameversions[i].description != NULL; ++i)
         {
@@ -866,9 +866,9 @@
     // address.
     //
 
-    p = M_CheckParm("-query");
+    p = M_CheckParmWithArgs("-query", 1);
 
-    if (p && p < myargc-1)
+    if (p)
     {
         NET_QueryAddress(myargv[p+1]);
         exit(0);
@@ -1019,7 +1019,7 @@
     // into the main IWAD.  Multiple files may be specified.
     //
 
-    p = M_CheckParm("-merge");
+    p = M_CheckParmWithArgs("-merge", 1);
 
     if (p > 0)
     {
@@ -1045,7 +1045,7 @@
     // Simulates the behavior of NWT's -merge option.  Multiple files
     // may be specified.
 
-    p = M_CheckParm("-nwtmerge");
+    p = M_CheckParmWithArgs("-nwtmerge", 1);
 
     if (p > 0)
     {
@@ -1070,7 +1070,7 @@
     // the main IWAD directory.  Multiple files may be specified.
     //
 
-    p = M_CheckParm("-af");
+    p = M_CheckParmWithArgs("-af", 1);
 
     if (p > 0)
     {
@@ -1093,7 +1093,7 @@
     // into the main IWAD directory.  Multiple files may be specified.
     //
 
-    p = M_CheckParm("-as");
+    p = M_CheckParmWithArgs("-as", 1);
 
     if (p > 0)
     {
@@ -1115,7 +1115,7 @@
     // Equivalent to "-af <files> -as <files>".
     //
 
-    p = M_CheckParm("-aa");
+    p = M_CheckParmWithArgs("-aa", 1);
 
     if (p > 0)
     {
@@ -1139,7 +1139,7 @@
     // Load the specified PWAD files.
     //
 
-    p = M_CheckParm ("-file");
+    p = M_CheckParmWithArgs("-file", 1);
     if (p)
     {
 	// the parms after p are wadfile/lump names,
@@ -1163,7 +1163,7 @@
     //
     // convenience hack to allow -wart e m to add a wad file
     // prepend a tilde to the filename so wadfile will be reloadable
-    p = M_CheckParm ("-wart");
+    p = M_CheckParmWithArgs("-wart", 1);
     if (p)
     {
 	myargv[p][4] = 'p';     // big hack, change to -warp
@@ -1200,7 +1200,7 @@
     // Play back the demo named demo.lmp.
     //
 
-    p = M_CheckParm ("-playdemo");
+    p = M_CheckParmWithArgs ("-playdemo", 1);
 
     if (!p)
     {
@@ -1212,11 +1212,11 @@
         // Play back the demo named demo.lmp, determining the framerate
         // of the screen.
         //
-	p = M_CheckParm ("-timedemo");
+	p = M_CheckParmWithArgs("-timedemo", 1);
 
     }
 
-    if (p && p < myargc-1)
+    if (p)
     {
         if (!strcasecmp(myargv[p+1] + strlen(myargv[p+1]) - 4, ".lmp"))
         {
@@ -1296,9 +1296,9 @@
     // 0 disables all monsters.
     //
 
-    p = M_CheckParm ("-skill");
+    p = M_CheckParmWithArgs("-skill", 1);
 
-    if (p && p < myargc-1)
+    if (p)
     {
 	startskill = myargv[p+1][0]-'1';
 	autostart = true;
@@ -1311,9 +1311,9 @@
     // Start playing on episode n (1-4)
     //
 
-    p = M_CheckParm ("-episode");
+    p = M_CheckParmWithArgs("-episode", 1);
 
-    if (p && p < myargc-1)
+    if (p)
     {
 	startepisode = myargv[p+1][0]-'0';
 	startmap = 1;
@@ -1330,9 +1330,9 @@
     // For multiplayer games: exit each level after n minutes.
     //
 
-    p = M_CheckParm ("-timer");
+    p = M_CheckParmWithArgs("-timer", 1);
 
-    if (p && p < myargc-1)
+    if (p)
     {
 	timelimit = atoi(myargv[p+1]);
     }
@@ -1346,7 +1346,7 @@
 
     p = M_CheckParm ("-avg");
 
-    if (p && p < myargc-1)
+    if (p)
     {
 	timelimit = 20;
     }
@@ -1359,9 +1359,9 @@
     // (Doom 2)
     //
 
-    p = M_CheckParm ("-warp");
+    p = M_CheckParmWithArgs("-warp", 1);
 
-    if (p && p < myargc-1)
+    if (p)
     {
         if (gamemode == commercial)
             startmap = atoi (myargv[p+1]);
@@ -1405,9 +1405,9 @@
     // Load the game in slot s.
     //
 
-    p = M_CheckParm ("-loadgame");
+    p = M_CheckParmWithArgs("-loadgame", 1);
     
-    if (p && p < myargc-1)
+    if (p)
     {
         startloadgame = atoi(myargv[p+1]);
     }
@@ -1507,16 +1507,16 @@
     // Record a demo named x.lmp.
     //
 
-    p = M_CheckParm ("-record");
+    p = M_CheckParmWithArgs("-record", 1);
 
-    if (p && p < myargc-1)
+    if (p)
     {
 	G_RecordDemo (myargv[p+1]);
 	autostart = true;
     }
 
-    p = M_CheckParm ("-playdemo");
-    if (p && p < myargc-1)
+    p = M_CheckParmWithArgs("-playdemo", 1);
+    if (p)
     {
 	singledemo = true;              // quit after one demo
 	G_DeferedPlayDemo (demolumpname);
@@ -1523,8 +1523,8 @@
 	D_DoomLoop ();  // never returns
     }
 	
-    p = M_CheckParm ("-timedemo");
-    if (p && p < myargc-1)
+    p = M_CheckParmWithArgs("-timedemo", 1);
+    if (p)
     {
 	G_TimeDemo (demolumpname);
 	D_DoomLoop ();  // never returns
--- a/src/d_net.c
+++ b/src/d_net.c
@@ -317,7 +317,7 @@
             // address.
             //
             
-            i = M_CheckParm("-connect");
+            i = M_CheckParmWithArgs("-connect", 1);
 
             if (i > 0)
             {
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -2068,8 +2068,8 @@
     // Specify the demo buffer size (KiB)
     //
 
-    i = M_CheckParm ("-maxdemo");
-    if (i && i<myargc-1)
+    i = M_CheckParmWithArgs("-maxdemo", 1);
+    if (i)
 	maxsize = atoi(myargv[i+1])*1024;
     demobuffer = Z_Malloc (maxsize,PU_STATIC,NULL); 
     demoend = demobuffer + maxsize;
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -171,7 +171,7 @@
     // Specify the heap size, in MiB (default 16).
     //
 
-    p = M_CheckParm("-mb");
+    p = M_CheckParmWithArgs("-mb", 1);
 
     if (p > 0)
     {
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1442,7 +1442,7 @@
     // Specify the screen width, in pixels.
     //
 
-    i = M_CheckParm("-width");
+    i = M_CheckParmWithArgs("-width", 1);
 
     if (i > 0)
     {
@@ -1456,7 +1456,7 @@
     // Specify the screen height, in pixels.
     //
 
-    i = M_CheckParm("-height");
+    i = M_CheckParmWithArgs("-height", 1);
 
     if (i > 0)
     {
@@ -1470,7 +1470,7 @@
     // Specify the color depth of the screen, in bits per pixel.
     //
 
-    i = M_CheckParm("-bpp");
+    i = M_CheckParmWithArgs("-bpp", 1);
 
     if (i > 0)
     {
@@ -1497,7 +1497,7 @@
     // Specify the screen mode (when running fullscreen) or the window
     // dimensions (when running in windowed mode).
 
-    i = M_CheckParm("-geometry");
+    i = M_CheckParmWithArgs("-geometry", 1);
 
     if (i > 0)
     {
--- a/src/m_argv.c
+++ b/src/m_argv.c
@@ -47,17 +47,22 @@
 // or 0 if not present
 //
 
-int M_CheckParm (char *check)
+int M_CheckParmWithArgs(char *check, int num_args)
 {
-    int		i;
+    int i;
 
-    for (i = 1;i<myargc;i++)
+    for (i = 1; i < myargc - num_args; i++)
     {
-	if ( !strcasecmp(check, myargv[i]) )
+	if (!strcasecmp(check, myargv[i]))
 	    return i;
     }
 
     return 0;
+}
+
+int M_CheckParm(char *check)
+{
+    return M_CheckParmWithArgs(check, 0);
 }
 
 #define MAXARGVS        100
--- a/src/m_argv.h
+++ b/src/m_argv.h
@@ -38,6 +38,10 @@
 // in the arg list (0 if not found).
 int M_CheckParm (char* check);
 
+// Same as M_CheckParm, but checks that num_args arguments are available
+// following the specified argument.
+int M_CheckParmWithArgs(char *check, int num_args);
+
 void M_FindResponseFile(void);
 
 #endif
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -1409,9 +1409,9 @@
     // default.cfg.
     //
 
-    i = M_CheckParm ("-config");
+    i = M_CheckParmWithArgs("-config", 1);
 
-    if (i && i<myargc-1)
+    if (i)
     {
 	doom_defaults.filename = myargv[i+1];
 	printf ("	default file: %s\n",doom_defaults.filename);
@@ -1431,9 +1431,9 @@
     // of chocolate-doom.cfg.
     //
 
-    i = M_CheckParm("-extraconfig");
+    i = M_CheckParmWithArgs("-extraconfig", 1);
 
-    if (i && i<myargc-1)
+    if (i)
     {
         extra_defaults.filename = myargv[i+1];
         printf("        extra configuration file: %s\n", 
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -411,7 +411,7 @@
     // packets.
     //
 
-    i = M_CheckParm("-extratics");
+    i = M_CheckParmWithArgs("-extratics", 1);
 
     if (i > 0)
         settings.extratics = atoi(myargv[i+1]);
@@ -426,7 +426,7 @@
     // the amount of network bandwidth needed.
     //
 
-    i = M_CheckParm("-dup");
+    i = M_CheckParmWithArgs("-dup", 1);
 
     if (i > 0)
         settings.ticdup = atoi(myargv[i+1]);
--- a/src/net_sdl.c
+++ b/src/net_sdl.c
@@ -170,7 +170,7 @@
     // the default (2342).
     //
 
-    p = M_CheckParm("-port");
+    p = M_CheckParmWithArgs("-port", 1);
     if (p > 0)
         port = atoi(myargv[p+1]);
 
@@ -196,7 +196,7 @@
 {
     int p;
     
-    p = M_CheckParm("-port");
+    p = M_CheckParmWithArgs("-port", 1);
     if (p > 0)
         port = atoi(myargv[p+1]);
 
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -1121,9 +1121,9 @@
     // When starting a network server, specify a name for the server.
     //
 
-    p = M_CheckParm("-servername");
+    p = M_CheckParmWithArgs("-servername", 1);
 
-    if (p > 0 && p + 1 < myargc)
+    if (p > 0)
     {
         querydata.description = myargv[p + 1];
     }
--- a/src/p_map.c
+++ b/src/p_map.c
@@ -1426,7 +1426,7 @@
         // Use the specified magic value when emulating spechit overruns.
         //
 
-        p = M_CheckParm("-spechit");
+        p = M_CheckParmWithArgs("-spechit", 1);
         
         if (p > 0)
         {
--- a/src/p_spec.c
+++ b/src/p_spec.c
@@ -1213,9 +1213,9 @@
         // system.  The default (if this option is not specified) is to
         // emulate the behavior when running under Windows 98.
 
-        p = M_CheckParm("-donut");
+        p = M_CheckParmWithArgs("-donut", 2);
 
-        if (p > 0 && p < myargc - 2)
+        if (p > 0)
         {
             // Dump of needed memory: (fixed_t)0000:0000 and (short)0000:0008
             //