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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
/*
* PARSEC - Command Line Options
*
* $Author: uberlinuxguy $ - $Date: 2004/09/15 12:25:33 $
*
* Orginally written by:
* Copyright (c) Markus Hadwiger <msh@parsec.org> 1998-2001
*
* 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
*/
// compilation flags/debug support
#include "config.h"
// C library
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "debug.h"
// general definitions
#include "general.h"
#include "objstruc.h"
// global externals
#include "globals.h"
// subsystem headers
#include "vid_defs.h"
// local module header
#include "sl_opt.h"
// proprietary module headers
#include "con_aux.h"
#include "con_ext.h"
#include "e_getopt.h"
#include "e_loader.h"
#include "sys_bind.h"
#include "sys_file.h"
#include "vid_init.h"
#include "vid_plug.h"
// flags
#define DISABLE_DEMO_OPTION
// string constants -----------------------------------------------------------
//
static char options_invalid[] = "\nUse \"--help\" for a list of command line options.\n";
static char default_player_name[] = "fragme";
// print a list of valid command line options ---------------------------------
//
PRIVATE
int SLm_PrintCommandLineOptions()
{
MSGOUT( "\nSome valid command line options:\n\n" );
MSGOUT( " -h or --help display this help page.\n\n" );
MSGOUT( " -n or --playername <name> set nickname for network game.\n" );
MSGOUT( " -p or --pack <filename> register additional data package.\n\n" );
MSGOUT( " -m or --mod <dirname> register mod directory.\n\n" );
MSGOUT( " -f or --modforce <dirname> register mod directory with override.\n\n" );
MSGOUT( " -j or --nojoystick disable joystick.\n" );
MSGOUT( " -s or --nosound disable music and sound effects.\n\n" );
MSGOUT( " --vidmode <mode> specify video mode (like: 1024x768x32).\n" );
MSGOUT( " --fullscreen use fullscreen mode.\n" );
MSGOUT( " --windowed use windowed mode.\n" );
MSGOUT( " --flipsync synchronize with screen.\n" );
MSGOUT( " --noflipsync do not synchronize with screen.\n\n" );
MSGOUT( "\n" );
exit( EXIT_SUCCESS );
}
// disable joystick code ------------------------------------------------------
//
PRIVATE
int SLm_DisableJoystickCode()
{
Op_Joystick = 0;
SkipCalibrationCode = 1;
return TRUE;
}
// disable sound code ---------------------------------------------------------
//
PRIVATE
int SLm_DisableSoundCode()
{
SoundDisabled = 1;
return TRUE;
}
// set flag for demo start-through --------------------------------------------
//
PRIVATE
int SLm_StartDemo()
{
PlayDemo = 1;
return TRUE;
}
// set loader flag to display file names --------------------------------------
//
PRIVATE
int SLm_ShowLoadedFiles()
{
ShowFilesLoaded( TRUE );
return TRUE;
}
// check user supplied network nickname ---------------------------------------
//
INLINE
int SLm_CheckPlayerName( char *name )
{
ASSERT( name != NULL );
for ( ; *name != 0; name++ ) {
*name = tolower( *name );
if ( !isalpha( *name ) ) {
return FALSE;
}
}
return TRUE;
}
// set player name ------------------------------------------------------------
//
PRIVATE
int SLm_SetPlayerName( char **playername )
{
char *name = playername[ 0 ];
int len = strlen( name );
if ( ( len < 2 ) || ( len > MAX_PLAYER_NAME ) ) {
return FALSE;
}
strncpy( ForcedPlayerName, name, MAX_PLAYER_NAME );
ForcedPlayerName[ MAX_PLAYER_NAME ] = 0;
if ( !SLm_CheckPlayerName( ForcedPlayerName ) ) {
MSGOUT( "CLI error: player name contains invalid characters.\n" );
return FALSE;
}
return TRUE;
}
// set startup video mode -----------------------------------------------------
//
PRIVATE
int SLm_SetVideoMode( char ** modespec )
{
int modearray[] = {0, 0, 0}; // xres, yres, bpp
VID_MapSpecifierToMode(modespec[0], modearray);
int xres = modearray[0];
int yres = modearray[1];
int bpp = modearray[2];
if ( xres == 0 || yres == 0 || bpp == 0 )
return FALSE;
InitOp_ColorDepth = VID_MapBppToOpt(bpp);
InitOp_Resolution.set(xres, yres);
return TRUE;
}
// set windowed startup video mode flag ---------------------------------------
//
PRIVATE
int SLm_SetWindowedMode()
{
InitOp_WindowedMode = TRUE;
return TRUE;
}
// set full screen startup video mode flag ------------------------------------
//
PRIVATE
int SLm_SetFullscreenMode()
{
InitOp_WindowedMode = FALSE;
return TRUE;
}
// set flipsync to on ---------------------------------------------------------
//
PRIVATE
int SLm_EnableFlipSync()
{
InitOp_FlipSynched = TRUE;
return TRUE;
}
// set flipsync to off --------------------------------------------------------
//
PRIVATE
int SLm_DisableFlipSync()
{
InitOp_FlipSynched = FALSE;
return TRUE;
}
// register additional data package -------------------------------------------
//
PRIVATE
int SLm_RegisterPackage( char **packagename )
{
char *name = packagename[ 0 ];
if ( !SYS_RegisterPackage( name, 0, NULL ) ) {
MSGOUT( "CLI error: package registration failed (%s).\n", name );
MSGOUT( "CLI error: continuing without package.\n" );
}
return TRUE;
}
// register mod ---------------------------------------------------------------
//
PRIVATE
int SLm_RegisterMod( char **modname )
{
char *name = modname[ 0 ];
//NOTE:
// mod_names[] is the global storage for the current mod names,
// declared in CON_EXT.C
// If mod_names[ 0 ] != NULL, a mod is currently active
if ( mod_numnames >= MAX_REGISTERED_MODS ) {
return FALSE;
}
mod_names[ mod_numnames ] = (char *) ALLOCMEM( strlen( name ) + 1 );
if ( mod_names[ mod_numnames ] == NULL ) {
return FALSE;
}
strcpy( mod_names[ mod_numnames ], name );
// allocate memory for "name/name.dat" string
char *packagename = (char *) ALLOCMEM( strlen( name ) * 2 + 6 );
if ( packagename == NULL ) {
return FALSE;
}
strcpy( packagename, name );
strcat( packagename, "/" );
strcat( packagename, name );
strcat( packagename, ".dat" );
if ( !SYS_RegisterPackage( packagename, 0, name ) ) {
MSGOUT( "CLI error: package registration failed (%s).\n", name );
MSGOUT( "CLI error: continuing without package.\n" );
}
mod_numnames++;
FREEMEM( packagename );
return TRUE;
}
// register mod which overrides internal packages -----------------------------
//
PRIVATE
int SLm_RegisterModForce( char **modname )
{
char *name = modname[ 0 ];
//NOTE:
// mod_names[] is the global storage for the current mod names,
// declared in CON_EXT.C
// If mod_names[ 0 ] != NULL, a mod is currently active
if ( mod_numnames >= MAX_REGISTERED_MODS ) {
return FALSE;
}
mod_names[ mod_numnames ] = (char *) ALLOCMEM( strlen( name ) + 1 );
if ( mod_names[ mod_numnames ] == NULL ) {
return FALSE;
}
strcpy( mod_names[ mod_numnames ], name );
// allocate memory for "name/name.dat" string
char *packagename = (char *) ALLOCMEM( strlen( name ) * 2 + 6 );
if ( packagename == NULL ) {
return FALSE;
}
strcpy( packagename, name );
strcat( packagename, "/" );
strcat( packagename, name );
strcat( packagename, ".dat" );
if ( !SYS_RegisterPackage( packagename, 0, name ) ) {
MSGOUT( "CLI error: package registration failed (%s).\n", name );
MSGOUT( "CLI error: continuing without package.\n" );
}
mod_numnames++;
FREEMEM( packagename );
// set override flag
mod_override = TRUE;
return TRUE;
}
// set a global aux flag to the specified value -------------------------------
//
PRIVATE
int SLm_SetAuxFlag( int *auxinfo )
{
int auxflag = auxinfo[ 0 ];
int auxval = auxinfo[ 1 ];
// check flag id
if ( ( auxflag < 0 ) || ( auxflag >= MAX_AUX_ENABLING ) ) {
MSGOUT( "CLI error: auxflag out of range.\n" );
return FALSE;
}
//NOTE:
// the value will not be checked against any bounds here.
// as long as the flag id is valid, the value will be used as is.
// set value for flag
AuxEnabling[ auxflag ] = auxval;
return TRUE;
}
// register option for setting aux flags from the command line ----------------
//
PRIVATE
int SLm_RegisterAuxOption()
{
cli_option_s clioption;
memset( &clioption, 0, sizeof( cli_option_s ) );
clioption.opt_short = NULL;
clioption.opt_long = "aux";
clioption.num_int = 2;
clioption.exec_int = SLm_SetAuxFlag;
return OPT_RegisterOption( &clioption );
}
// register default command line options --------------------------------------
//
PRIVATE
void RegisterDefaultOptions()
{
OPT_RegisterSetOption( "h", "help", SLm_PrintCommandLineOptions );
OPT_RegisterSetOption( "j", "nojoystick", SLm_DisableJoystickCode );
OPT_RegisterSetOption( "s", "nosound", SLm_DisableSoundCode );
OPT_RegisterSetOption( "o", "showfiles", SLm_ShowLoadedFiles );
OPT_RegisterSetOption( NULL, "windowed", SLm_SetWindowedMode );
OPT_RegisterSetOption( NULL, "fullscreen", SLm_SetFullscreenMode );
OPT_RegisterSetOption( NULL, "flipsync", SLm_EnableFlipSync );
OPT_RegisterSetOption( NULL, "noflipsync", SLm_DisableFlipSync );
#ifndef DISABLE_DEMO_OPTION
OPT_RegisterSetOption( "x", "startdemo", SLm_StartDemo );
#endif
SLm_RegisterAuxOption();
OPT_RegisterStringOption( "n", "playername", SLm_SetPlayerName );
OPT_RegisterStringOption( NULL, "vidmode", SLm_SetVideoMode );
OPT_RegisterStringOption( "p", "pack", SLm_RegisterPackage );
OPT_RegisterStringOption( "m", "mod", SLm_RegisterMod );
OPT_RegisterStringOption( "f", "modforce", SLm_RegisterModForce );
}
// register default command line options and exec all registered options ------
//
void SYSs_CheckCommandLine( int argc, char **argv )
{
// set default name of local player
strncpy( LocalPlayerName, default_player_name, MAX_PLAYER_NAME );
LocalPlayerName[ MAX_PLAYER_NAME ] = 0;
// register default command line options
RegisterDefaultOptions();
// exec all registered command line options
if ( !OPT_ExecRegisteredOptions( argc, argv ) ) {
MSGOUT( options_invalid );
exit( EXIT_SUCCESS );
}
}
|