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
This commit is contained in:
Simon Howard 2010-12-18 23:55:07 +00:00
parent 1ef81eb5f7
commit 463bcf013c
16 changed files with 70 additions and 61 deletions

4
NEWS
View file

@ -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

View file

@ -293,10 +293,10 @@ def add_parameter(param, line, config_file):
# 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

View file

@ -658,7 +658,7 @@ char *D_FindIWAD(void)
// @arg <file>
//
iwadparm = M_CheckParm("-iwad");
iwadparm = M_CheckParmWithArgs("-iwad", 1);
if (iwadparm)
{

View file

@ -672,9 +672,9 @@ static void InitGameVersion(void)
// "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 @@ void D_DoomMain (void)
// 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 @@ void D_DoomMain (void)
// 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 @@ void D_DoomMain (void)
// 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 @@ void D_DoomMain (void)
// 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 @@ void D_DoomMain (void)
// 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 @@ void D_DoomMain (void)
// Equivalent to "-af <files> -as <files>".
//
p = M_CheckParm("-aa");
p = M_CheckParmWithArgs("-aa", 1);
if (p > 0)
{
@ -1139,7 +1139,7 @@ void D_DoomMain (void)
// 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 @@ void D_DoomMain (void)
//
// 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 @@ void D_DoomMain (void)
// Play back the demo named demo.lmp.
//
p = M_CheckParm ("-playdemo");
p = M_CheckParmWithArgs ("-playdemo", 1);
if (!p)
{
@ -1212,11 +1212,11 @@ void D_DoomMain (void)
// 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 @@ void D_DoomMain (void)
// 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 @@ void D_DoomMain (void)
// 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 @@ void D_DoomMain (void)
// 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 @@ void D_DoomMain (void)
p = M_CheckParm ("-avg");
if (p && p < myargc-1)
if (p)
{
timelimit = 20;
}
@ -1359,9 +1359,9 @@ void D_DoomMain (void)
// (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 @@ void D_DoomMain (void)
// 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,24 +1507,24 @@ void D_DoomMain (void)
// 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);
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

View file

@ -317,7 +317,7 @@ void D_CheckNetGame (void)
// address.
//
i = M_CheckParm("-connect");
i = M_CheckParmWithArgs("-connect", 1);
if (i > 0)
{

View file

@ -2068,8 +2068,8 @@ void G_RecordDemo (char* name)
// 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;

View file

@ -171,7 +171,7 @@ byte *I_ZoneBase (int *size)
// Specify the heap size, in MiB (default 16).
//
p = M_CheckParm("-mb");
p = M_CheckParmWithArgs("-mb", 1);
if (p > 0)
{

View file

@ -1442,7 +1442,7 @@ static void CheckCommandLine(void)
// Specify the screen width, in pixels.
//
i = M_CheckParm("-width");
i = M_CheckParmWithArgs("-width", 1);
if (i > 0)
{
@ -1456,7 +1456,7 @@ static void CheckCommandLine(void)
// Specify the screen height, in pixels.
//
i = M_CheckParm("-height");
i = M_CheckParmWithArgs("-height", 1);
if (i > 0)
{
@ -1470,7 +1470,7 @@ static void CheckCommandLine(void)
// 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 @@ static void CheckCommandLine(void)
// 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)
{

View file

@ -47,19 +47,24 @@ char** myargv;
// 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
static void LoadResponseFile(int argv_index)

View file

@ -38,6 +38,10 @@ extern char** myargv;
// 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

View file

@ -1409,9 +1409,9 @@ void M_LoadDefaults (void)
// 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 @@ void M_LoadDefaults (void)
// 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",

View file

@ -411,7 +411,7 @@ void NET_CL_StartGame(void)
// packets.
//
i = M_CheckParm("-extratics");
i = M_CheckParmWithArgs("-extratics", 1);
if (i > 0)
settings.extratics = atoi(myargv[i+1]);
@ -426,7 +426,7 @@ void NET_CL_StartGame(void)
// the amount of network bandwidth needed.
//
i = M_CheckParm("-dup");
i = M_CheckParmWithArgs("-dup", 1);
if (i > 0)
settings.ticdup = atoi(myargv[i+1]);

View file

@ -170,7 +170,7 @@ static boolean NET_SDL_InitClient(void)
// the default (2342).
//
p = M_CheckParm("-port");
p = M_CheckParmWithArgs("-port", 1);
if (p > 0)
port = atoi(myargv[p+1]);
@ -196,7 +196,7 @@ static boolean NET_SDL_InitServer(void)
{
int p;
p = M_CheckParm("-port");
p = M_CheckParmWithArgs("-port", 1);
if (p > 0)
port = atoi(myargv[p+1]);

View file

@ -1121,9 +1121,9 @@ void NET_SV_SendQueryResponse(net_addr_t *addr)
// 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];
}

View file

@ -1426,7 +1426,7 @@ static void SpechitOverrun(line_t *ld)
// Use the specified magic value when emulating spechit overruns.
//
p = M_CheckParm("-spechit");
p = M_CheckParmWithArgs("-spechit", 1);
if (p > 0)
{

View file

@ -1213,9 +1213,9 @@ static void DonutOverrun(fixed_t *s3_floorheight, short *s3_floorpic,
// 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
//