mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-04-22 02:00:50 +00:00
Get map name from multiple arguments
(This means you don't need quoting.) (cherry picked from commit 46fbed8b716f96a7e87ac4c68ca3ee98c8c6a25c)
This commit is contained in:
parent
fb858dd64b
commit
93c351a38e
1 changed files with 53 additions and 4 deletions
|
@ -2490,12 +2490,14 @@ enum
|
|||
|
||||
static size_t CheckOptions(
|
||||
int num_options,
|
||||
size_t *first_argumentp,
|
||||
size_t *user_options,
|
||||
const char ***option_names,
|
||||
int *option_num_arguments
|
||||
)
|
||||
{
|
||||
int arguments_used;
|
||||
int arguments_used;
|
||||
size_t first_argument;
|
||||
|
||||
int i;
|
||||
const char **pp;
|
||||
|
@ -2503,6 +2505,7 @@ static size_t CheckOptions(
|
|||
size_t n;
|
||||
|
||||
arguments_used = 0;
|
||||
first_argument = COM_Argc();
|
||||
|
||||
for (i = 0; i < num_options; ++i)
|
||||
{
|
||||
|
@ -2514,14 +2517,53 @@ static size_t CheckOptions(
|
|||
{
|
||||
user_options[i] = n;
|
||||
arguments_used += 1 + option_num_arguments[i];
|
||||
if (n < first_argument)
|
||||
first_argument = n;
|
||||
}
|
||||
}
|
||||
while (( name = *++pp )) ;
|
||||
}
|
||||
|
||||
(*first_argumentp) = first_argument;
|
||||
|
||||
return arguments_used;
|
||||
}
|
||||
|
||||
static char *
|
||||
ConcatCommandArgv (int start, int end)
|
||||
{
|
||||
char *final;
|
||||
|
||||
size_t size;
|
||||
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
size = 0;
|
||||
|
||||
for (i = start; i < end; ++i)
|
||||
{
|
||||
/*
|
||||
one space after each argument, but terminating
|
||||
character on final argument
|
||||
*/
|
||||
size += strlen(COM_Argv(i)) + 1;
|
||||
}
|
||||
|
||||
final = ZZ_Alloc(size);
|
||||
p = final;
|
||||
|
||||
--end;/* handle the final argument separately */
|
||||
for (i = start; i < end; ++i)
|
||||
{
|
||||
p += sprintf(p, "%s ", COM_Argv(i));
|
||||
}
|
||||
/* at this point "end" is actually the last argument's position */
|
||||
strcpy(p, COM_Argv(end));
|
||||
|
||||
return final;
|
||||
}
|
||||
|
||||
//
|
||||
// Warp to map code.
|
||||
// Called either from map <mapname> console command, or idclev cheat.
|
||||
|
@ -2562,6 +2604,7 @@ static void Command_Map_f(void)
|
|||
};
|
||||
|
||||
size_t acceptableargc;/* (this includes the command name itself!) */
|
||||
size_t first_argument;
|
||||
|
||||
size_t user_options [NUM_MAP_COMMAND_OPTIONS] = {0};
|
||||
|
||||
|
@ -2573,7 +2616,7 @@ static void Command_Map_f(void)
|
|||
|
||||
INT32 newmapnum;
|
||||
|
||||
const char *mapname;
|
||||
char * mapname;
|
||||
size_t mapnamelen;
|
||||
char *realmapname = NULL;
|
||||
|
||||
|
@ -2591,6 +2634,7 @@ static void Command_Map_f(void)
|
|||
|
||||
/* map name + options */
|
||||
acceptableargc = 2 + CheckOptions(NUM_MAP_COMMAND_OPTIONS,
|
||||
&first_argument,
|
||||
user_options, option_names, option_num_arguments);
|
||||
|
||||
newresetplayers = !user_options[MAP_COMMAND_NORESETPLAYERS_OPTION];
|
||||
|
@ -2616,7 +2660,7 @@ static void Command_Map_f(void)
|
|||
return;
|
||||
}
|
||||
|
||||
if (COM_Argc() != acceptableargc)
|
||||
if (COM_Argc() < acceptableargc)
|
||||
{
|
||||
/* I'm going over the fucking lines and I DON'T CAREEEEE */
|
||||
CONS_Printf("map <name / [MAP]code / number> [-gametype <type>] [-encore] [-force]:\n");
|
||||
|
@ -2629,7 +2673,7 @@ static void Command_Map_f(void)
|
|||
return;
|
||||
}
|
||||
|
||||
mapname = COM_Argv(1);
|
||||
mapname = ConcatCommandArgv(1, first_argument);
|
||||
mapnamelen = strlen(mapname);
|
||||
|
||||
if (mapnamelen == 2)/* maybe two digit code */
|
||||
|
@ -2642,6 +2686,7 @@ static void Command_Map_f(void)
|
|||
if (( newmapnum = M_MapNumber(mapname[3], mapname[4]) ) == 0)
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, M_GetText("Invalid map code '%s'.\n"), mapname);
|
||||
Z_Free(mapname);
|
||||
return;
|
||||
}
|
||||
usemapcode = true;
|
||||
|
@ -2656,6 +2701,7 @@ static void Command_Map_f(void)
|
|||
if (newmapnum < 1 || newmapnum > NUMMAPS)
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, M_GetText("Invalid map number %d.\n"), newmapnum);
|
||||
Z_Free(mapname);
|
||||
return;
|
||||
}
|
||||
usemapcode = true;
|
||||
|
@ -2669,6 +2715,7 @@ static void Command_Map_f(void)
|
|||
if (newmapnum == 0 || !mapheaderinfo[newmapnum-1])
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, M_GetText("Could not find any map described as '%s'.\n"), mapname);
|
||||
Z_Free(mapname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2726,6 +2773,7 @@ static void Command_Map_f(void)
|
|||
CONS_Alert(CONS_WARNING, M_GetText("Course %s (%s) doesn't support %s mode!\n(Use -force to override)\n"), realmapname, G_BuildMapName(newmapnum),
|
||||
(multiplayer ? gametype_cons_t[newgametype].strvalue : "Single Player"));
|
||||
Z_Free(realmapname);
|
||||
Z_Free(mapname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -2738,6 +2786,7 @@ static void Command_Map_f(void)
|
|||
{
|
||||
CONS_Alert(CONS_NOTICE, M_GetText("You need to unlock this level before you can warp to it!\n"));
|
||||
Z_Free(realmapname);
|
||||
Z_Free(mapname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue