-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathqcommon_parsecmdline.c
136 lines (110 loc) · 3.61 KB
/
qcommon_parsecmdline.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of CoD4X17a-Server source code.
CoD4X17a-Server source code is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
CoD4X17a-Server source code 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================
*/
#include <string.h>
#include "cmd.h"
#include "cvar.h"
/*
========================================================================
Command line parsing
========================================================================
*/
#define MAX_CONSOLE_LINES 32
int com_numConsoleLines;
char *com_consoleLines[MAX_CONSOLE_LINES];
/*
===============
Com_StartupVariable
Searches for command line parameters that are set commands.
If match is not NULL, only that cvar will be looked for.
That is necessary because cddir and basedir need to be set
before the filesystem is started, but all other sets should
be after execing the config and default.
===============
*/
void Com_StartupVariable( const char *match ) {
int i;
for (i=0 ; i < com_numConsoleLines ; i++) {
Cmd_TokenizeString( com_consoleLines[i] );
if(!match || !strcmp(Cmd_Argv(1), match))
{
if ( !strcmp( Cmd_Argv(0), "set" )){
Cvar_Set_f();
Cmd_EndTokenizeString();
continue;
}else if( !strcmp( Cmd_Argv(0), "seta" ) ) {
Cvar_SetA_f();
}
}
Cmd_EndTokenizeString();
}
}
/*
=================
Com_AddStartupCommands
Adds command line parameters as script statements
Commands are seperated by + signs
Returns qtrue if any late commands were added, which
will keep the demoloop from immediately starting
=================
*/
qboolean Com_AddStartupCommands( void ) {
int i;
qboolean added;
char buf[1024];
added = qfalse;
// quote every token, so args with semicolons can work
for (i=0 ; i < com_numConsoleLines ; i++) {
if ( !com_consoleLines[i] || !com_consoleLines[i][0] ) {
continue;
}
// set commands already added with Com_StartupVariable
if ( !Q_stricmpn( com_consoleLines[i], "set", 3 )) {
continue;
}
added = qtrue;
Com_sprintf(buf,sizeof(buf),"%s\n",com_consoleLines[i]);
Cbuf_ExecuteBuffer( 0,0, buf);
}
return added;
}
/*
==================
Com_ParseCommandLine
Break it up into multiple console lines
==================
*/
void Com_ParseCommandLine( char *commandLine ) {
int inq = 0;
com_consoleLines[0] = commandLine;
com_numConsoleLines = 1;
while ( *commandLine ) {
if (*commandLine == '"') {
inq = !inq;
}
// look for a + seperating character
// if commandLine came from a file, we might have real line seperators
if ( (*commandLine == '+' && !inq) || *commandLine == '\n' || *commandLine == '\r' ) {
if ( com_numConsoleLines == MAX_CONSOLE_LINES ) {
return;
}
com_consoleLines[com_numConsoleLines] = commandLine + 1;
com_numConsoleLines = (com_numConsoleLines)+1;
*commandLine = 0;
}
commandLine++;
}
}