]> icculus.org git repositories - taylor/freespace2.git/blob - src/cmdline/cmdline.cpp
implement command line options
[taylor/freespace2.git] / src / cmdline / cmdline.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Cmdline/cmdline.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * $Log$
16  * Revision 1.5  2003/05/06 07:20:14  taylor
17  * implement command line options
18  *
19  * Revision 1.4  2002/06/21 03:34:05  relnev
20  * implemented a stub and fixed a path
21  *
22  * Revision 1.3  2002/06/09 04:41:15  relnev
23  * added copyright header
24  *
25  * Revision 1.2  2002/05/07 03:16:43  theoddone33
26  * The Great Newline Fix
27  *
28  * Revision 1.1.1.1  2002/05/03 03:28:08  root
29  * Initial import.
30  *
31  * 
32  * 8     8/26/99 8:51p Dave
33  * Gave multiplayer TvT messaging a heavy dose of sanity. Cheat codes.
34  * 
35  * 7     7/15/99 3:07p Dave
36  * 32 bit detection support. Mouse coord commandline.
37  * 
38  * 6     7/13/99 1:15p Dave
39  * 32 bit support. Whee!
40  * 
41  * 5     6/22/99 9:37p Dave
42  * Put in pof spewing.
43  * 
44  * 4     1/12/99 5:45p Dave
45  * Moved weapon pipeline in multiplayer to almost exclusively client side.
46  * Very good results. Bandwidth goes down, playability goes up for crappy
47  * connections. Fixed object update problem for ship subsystems.
48  * 
49  * 3     11/17/98 11:12a Dave
50  * Removed player identification by address. Now assign explicit id #'s.
51  * 
52  * 2     10/07/98 10:52a Dave
53  * Initial checkin.
54  * 
55  * 1     10/07/98 10:48a Dave
56  * 
57  * 38    10/02/98 3:22p Allender
58  * fix up the -connect option and fix the -port option
59  * 
60  * 37    9/15/98 4:04p Allender
61  * added back in the -ip_addr command line switch because it needs to be
62  * in the standalone server only executable
63  * 
64  * 36    9/14/98 11:52a Allender
65  * don't use cfile
66  * 
67  * 35    9/14/98 11:28a Allender
68  * support for server bashing of address when received from client.  Added
69  * a cmdline.cfg file to process command line arguments from a file
70  * 
71  * 34    9/08/98 2:20p Allender
72  * temporary code to force IP address to a specific value.
73  * 
74  * 33    8/20/98 5:30p Dave
75  * Put in handy multiplayer logfile system. Now need to put in useful
76  * applications of it all over the code.
77  * 
78  * 32    8/07/98 10:39a Allender
79  * fixed debug standalone problem where stats would continually get sent
80  * to tracker.  more debug code to help find stats problem
81  * 
82  * 31    7/24/98 11:14a Allender
83  * start of new command line options for version 1.04
84  * 
85  * 30    5/21/98 1:50a Dave
86  * Remove obsolete command line functions. Reduce shield explosion packets
87  * drastically. Tweak PXO screen even more. Fix file xfer system so that
88  * we can guarantee file uniqueness.
89  * 
90  * 29    5/18/98 9:10p Dave
91  * Put in many new PXO features. Fixed skill level bashing in multiplayer.
92  * Removed several old command line options. Put in network config files.
93  * 
94  * 28    5/09/98 7:16p Dave
95  * Put in CD checking. Put in standalone host password. Made pilot into
96  * popup scrollable.
97  * 
98  * 27    4/23/98 8:27p Allender
99  * basic support for cutscene playback.  Into movie code in place.  Tech
100  * room can view cutscenes stored in CDROM_dir variable
101  * 
102  * 26    4/09/98 5:43p Dave
103  * Remove all command line processing from the demo. Began work fixing up
104  * the new multi host options screen.
105  * 
106  * 25    4/02/98 11:40a Lawrance
107  * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
108  * 
109  * 24    4/01/98 5:56p Dave
110  * Fixed a messaging bug which caused msg_all mode in multiplayer not to
111  * work. Compile out a host of multiplayer options not available in the
112  * demo.
113  * 
114  * 23    3/14/98 2:48p Dave
115  * Cleaned up observer joining code. Put in support for file xfers to
116  * ingame joiners (observers or not). Revamped and reinstalled pseudo
117  * lag/loss system.
118  * 
119  * 22    2/22/98 12:19p John
120  * Externalized some strings
121  * 
122  * 21    1/31/98 4:32p Dave
123  * Put in new support for VMT player validation, game logging in and game
124  * logging out.
125  * 
126  * 20    12/10/97 4:45p Dave
127  * Added in more detailed support for multiplayer packet lag/loss. Fixed
128  * some multiplayer stuff. Added some controls to the standalone.
129  * 
130  * 19    12/09/97 6:14p Lawrance
131  * add -nomusic flag
132  * 
133  * 18    12/01/97 5:10p Dave
134  * Fixed a syntax bug.
135  * 
136  * 17    12/01/97 4:59p Dave
137  * Synchronized multiplayer debris objects. Put in pilot popup in main
138  * hall. Optimized simulated multiplayer lag module. Fixed a potential
139  * file_xfer bug.
140  * 
141  * 16    11/28/97 7:04p Dave
142  * Emergency checkin due to big system crash.
143  * 
144  * 15    11/28/97 5:06p Dave
145  * Put in facilities for simulating multiplayer lag.
146  * 
147  * 14    11/24/97 5:42p Dave
148  * Fixed a file xfer buffer free/malloc problem. Lengthened command line
149  * switch string parse length.
150  * 
151  * 13    11/12/97 4:39p Dave
152  * Put in multiplayer campaign support parsing, loading and saving. Made
153  * command-line variables better named. Changed some things on the initial
154  * pilot select screen.
155  * 
156  * 12    11/11/97 4:54p Dave
157  * Put in support for single vs. multiplayer pilots. Put in initial player
158  * selection screen (no command line option yet). Started work on
159  * multiplayer campaign file save gaming.
160  * 
161  * 11    11/11/97 11:55a Allender
162  * initialize network at beginning of application.  create new call to set
163  * which network protocol to use
164  * 
165  * 10    9/18/97 10:12p Dave
166  * Added -gimmemedals, which gives the current pilot all the medals in the
167  * game (debug)
168  * 
169  * 9     9/18/97 9:20a Dave
170  * Minor modifications
171  * 
172  * 8     9/15/97 11:40p Lawrance
173  * remove demo granularity switch
174  * 
175  * 7     9/09/97 3:39p Sandeep
176  * warning level 4 bugs
177  * 
178  * 6     9/03/97 5:03p Lawrance
179  * add support for -nosound command line parm
180  * 
181  * 5     8/22/97 8:52a Dave
182  * Removed a return statement which would have broken the parser out too
183  * early.
184  * 
185  * 4     8/21/97 4:55p Dave
186  * Added a switch for multiplayer chat streaming. Added a section for
187  * global command line vars.
188  * 
189  * 3     8/06/97 2:26p Dave
190  * Made the command line parse more robust. Made it easier to add and
191  * process new command-line switches.
192  * 
193  * 2     8/04/97 3:13p Dave
194  * Added command line functions. See cmdline.cpp for directions on adding
195  * new switches
196  * 
197  * 1     8/04/97 9:58a Dave
198  * 
199  * $NoKeywords: $
200  */
201
202 #include <string.h>
203 #include <stdlib.h>
204 #include "cmdline.h"
205 #include "linklist.h"
206 #include "systemvars.h"
207 #include "multi.h"
208 #include "cfile.h"
209 #include "osapi.h"
210 #include "osregistry.h"
211 #include "version.h"
212
213 // variables
214 class cmdline_parm {
215 public:
216         cmdline_parm *next, *prev;
217         char *name;                                             // name of parameter, must start with '-' char
218         char *help;                                             // help text for this parameter
219         char *args;                                             // string value for parameter arguements (NULL if no arguements)
220         int name_found;                         // true if parameter on command line, otherwise false
221
222         cmdline_parm(char *name, char *help);
223         ~cmdline_parm();
224         int found();
225         int get_int();
226         float get_float();
227         char *str();
228 };
229
230 // here are the command line parameters that we will be using for FreeSpace
231 #ifndef PLAT_UNIX
232 cmdline_parm standalone_arg("-standalone", NULL);
233 cmdline_parm nosound_arg("-nosound", NULL);
234 cmdline_parm nomusic_arg("-nomusic", NULL);
235 cmdline_parm startgame_arg("-startgame", NULL);
236 cmdline_parm gamename_arg("-gamename", NULL);
237 cmdline_parm gamepassword_arg("-password", NULL);
238 cmdline_parm gameclosed_arg("-closed", NULL);
239 cmdline_parm gamerestricted_arg("-restricted", NULL);
240 cmdline_parm allowabove_arg("-allowabove", NULL);
241 cmdline_parm allowbelow_arg("-allowbelow", NULL);
242 cmdline_parm port_arg("-port", NULL);
243 cmdline_parm connect_arg("-connect", NULL);
244 cmdline_parm multilog_arg("-multilog", NULL);
245 cmdline_parm server_firing_arg("-oldfire", NULL);
246 cmdline_parm client_dodamage("-clientdamage", NULL);
247 cmdline_parm pof_spew("-pofspew", NULL);
248 cmdline_parm d3d_32bit("-32bit", NULL);
249 cmdline_parm mouse_coords("-coords", NULL);
250 cmdline_parm timeout("-timeout", NULL);
251 cmdline_parm d3d_window("-window", NULL);
252 #else
253 // double hyphens on Unix options
254 cmdline_parm standalone_arg("--standalone", NULL);
255 cmdline_parm nosound_arg("--nosound", NULL);
256 cmdline_parm nomusic_arg("--nomusic", NULL);
257 cmdline_parm startgame_arg("--startgame", NULL);
258 cmdline_parm gamename_arg("--gamename", NULL);
259 cmdline_parm gamepassword_arg("--password", NULL);
260 cmdline_parm gameclosed_arg("--closed", NULL);
261 cmdline_parm gamerestricted_arg("--restricted", NULL);
262 cmdline_parm allowabove_arg("--allowabove", NULL);
263 cmdline_parm allowbelow_arg("--allowbelow", NULL);
264 cmdline_parm port_arg("--port", NULL);
265 cmdline_parm connect_arg("--connect", NULL);
266 cmdline_parm multilog_arg("--multilog", NULL);
267 cmdline_parm server_firing_arg("--oldfire", NULL);
268 cmdline_parm client_dodamage("--clientdamage", NULL);
269 cmdline_parm pof_spew("--pofspew", NULL);
270 cmdline_parm mouse_coords("--coords", NULL);
271 cmdline_parm timeout("--timeout", NULL);
272 cmdline_parm d3d_window("--window", NULL);
273 cmdline_parm d3d_fullscreen("--fullscreen", NULL);
274 cmdline_parm help("--help", NULL);
275 cmdline_parm no_grab("--nograb", NULL);
276 cmdline_parm fs_version("--version", NULL);
277 cmdline_parm no_movies("--nomovies", NULL);
278
279 // single letter version of above options
280 cmdline_parm standalone_arg_s("-d", NULL);
281 cmdline_parm nosound_arg_s("-s", NULL);
282 cmdline_parm startgame_arg_s("-S", NULL);
283 cmdline_parm gamename_arg_s("-N", NULL);
284 cmdline_parm gamepassword_arg_s("-p", NULL);
285 cmdline_parm gameclosed_arg_s("-c", NULL);
286 cmdline_parm gamerestricted_arg_s("-r", NULL);
287 cmdline_parm allowabove_arg_s("-a", NULL);
288 cmdline_parm allowbelow_arg_s("-b", NULL);
289 cmdline_parm port_arg_s("-o", NULL);
290 cmdline_parm connect_arg_s("-C", NULL);
291 cmdline_parm multilog_arg_s("-m", NULL);
292 cmdline_parm server_firing_arg_s("-F", NULL);
293 cmdline_parm client_dodamage_s("-D", NULL);
294 cmdline_parm pof_spew_s("-P", NULL);
295 cmdline_parm mouse_coords_s("-M", NULL);
296 cmdline_parm timeout_s("-t", NULL);
297 cmdline_parm d3d_window_s("-w", NULL);
298 cmdline_parm d3d_fullscreen_s("-f", NULL);
299 cmdline_parm help_s("-h", NULL);
300 cmdline_parm no_grab_s("-g", NULL);
301 cmdline_parm fs_version_s("-v", NULL);
302 cmdline_parm no_movies_s("-n", NULL);
303 #endif
304
305 int Cmdline_multi_stream_chat_to_file = 0;
306 int Cmdline_freespace_no_sound = 0;
307 int Cmdline_freespace_no_music = 0;
308 int Cmdline_gimme_all_medals = 0;
309 int Cmdline_use_last_pilot = 0;
310 int Cmdline_multi_protocol = -1;
311 int Cmdline_cd_check = 1;
312 int Cmdline_start_netgame = 0;
313 int Cmdline_closed_game = 0;
314 int Cmdline_restricted_game = 0;
315 int Cmdline_network_port = -1;
316 char *Cmdline_game_name = NULL;
317 char *Cmdline_game_password = NULL;
318 char *Cmdline_rank_above= NULL;
319 char *Cmdline_rank_below = NULL;
320 char *Cmdline_connect_addr = NULL;
321 int Cmdline_multi_log = 0;
322 int Cmdline_server_firing = 0;
323 int Cmdline_client_dodamage = 0;
324 int Cmdline_spew_pof_info = 0;
325 int Cmdline_force_32bit = 0;
326 int Cmdline_mouse_coords = 0;
327 int Cmdline_timeout = -1;
328 #ifdef PLAT_UNIX
329 int Cmdline_no_grab = 0;
330 int Cmdline_play_movies = 1;
331 int Cmdline_fullscreen = 0;
332 #endif
333
334 int Cmdline_window = 0;
335
336 static cmdline_parm Parm_list(NULL, NULL);
337 static int Parm_list_inited = 0;
338
339 #ifdef PLAT_UNIX
340 void print_instructions();
341 #endif
342
343 //      Return true if this character is an extra char (white space and quotes)
344 int is_extra_space(char ch)
345 {
346         return ((ch == ' ') || (ch == '\t') || (ch == 0x0a) || (ch == '\'') || (ch == '\"'));
347 }
348
349
350 // eliminates all leading and trailing extra chars from a string.  Returns pointer passed in.
351 char *drop_extra_chars(char *str)
352 {
353         int s, e;
354
355         s = 0;
356         while (str[s] && is_extra_space(str[s]))
357                 s++;
358
359         e = strlen(str) - 1;
360         while (e > s) {
361                 if (!is_extra_space(str[e])){
362                         break;
363                 }
364
365                 e--;
366         }
367
368         if (e > s){
369                 memmove(str, str + s, e - s + 1);
370         }
371
372         str[e - s + 1] = 0;
373         return str;
374 }
375
376
377 // internal function - copy the value for a parameter agruement into the cmdline_parm arg field
378 void parm_stuff_args(cmdline_parm *parm, char *cmdline)
379 {
380         char buffer[1024];
381         memset(buffer, 0, 1024);
382         char *dest = buffer;
383
384         cmdline += strlen(parm->name);
385
386         while ((*cmdline != 0) && (*cmdline != '-')) {
387                 *dest++ = *cmdline++;
388         }
389
390         drop_extra_chars(buffer);
391
392         // mwa 9/14/98 -- made it so that newer command line arguments found will overwrite
393         // the old arguments
394 //      Assert(parm->args == NULL);
395         if ( parm->args != NULL ) {
396                 delete( parm->args );
397                 parm->args = NULL;
398         }
399
400         int size = strlen(buffer) + 1;
401         if (size > 0) {
402                 parm->args = new char[size];
403                 memset(parm->args, 0, size);
404                 strcpy(parm->args, buffer);
405         }
406 }
407
408
409 // internal function - parse the command line, extracting parameter arguements if they exist
410 // cmdline - command line string passed to the application
411 void os_parse_parms(char *cmdline)
412 {
413         // locate command line parameters
414         cmdline_parm *parmp;
415         char *cmdline_offset;
416
417         for (parmp = GET_FIRST(&Parm_list); parmp !=END_OF_LIST(&Parm_list); parmp = GET_NEXT(parmp) ) {
418                 cmdline_offset = strstr(cmdline, parmp->name);
419 #ifdef PLAT_UNIX
420                 // verify that one hyphen and two hypen options don't collide
421                 if (cmdline_offset && (*(cmdline_offset-1) != '-')) {
422 #else
423                 if (cmdline_offset) {
424 #endif
425                         parmp->name_found = 1;
426                         parm_stuff_args(parmp, cmdline_offset);
427                 }
428         }
429 }
430
431
432 // validate the command line parameters.  Display an error if an unrecognized parameter is located.
433 void os_validate_parms(char *cmdline)
434 {
435         cmdline_parm *parmp;
436         char seps[] = " ,\t\n";
437         char *token;
438         int parm_found;
439
440    token = strtok(cmdline, seps);
441    while(token != NULL) {
442 #ifdef PLAT_UNIX
443                 // make sure double hypens are checked first to avoid clashing with single args
444                 if (token[0] == '-' && token[1] == '-') {
445                         parm_found = 0;
446                         for (parmp = GET_FIRST(&Parm_list); parmp !=END_OF_LIST(&Parm_list); parmp = GET_NEXT(parmp) ) {
447                                 if (!stricmp(parmp->name, token)) {
448                                         parm_found = 1;
449                                         break;
450                                 }
451                         }
452
453                         if (parm_found == 0) {
454                                 print_instructions();
455                         }
456                 } else if (token[0] == '-' && token[1] != '-') {
457 #else
458                 if (token[0] == '-') {
459 #endif
460                         parm_found = 0;
461                         for (parmp = GET_FIRST(&Parm_list); parmp !=END_OF_LIST(&Parm_list); parmp = GET_NEXT(parmp) ) {
462                                 if (!stricmp(parmp->name, token)) {
463                                         parm_found = 1;
464                                         break;
465                                 }
466                         }
467
468                         if (parm_found == 0) {
469 #ifndef PLAT_UNIX
470                                 Error(LOCATION,"Unrecogzined command line parameter %s", token);
471 #else
472                                 print_instructions();
473 #endif
474                         }
475                 }
476
477                 token = strtok(NULL, seps);
478         }
479 }
480
481
482 // Call once to initialize the command line system
483 //
484 // cmdline - command line string passed to the application
485 void os_init_cmdline(char *cmdline)
486 {
487         FILE *fp;
488
489         // read the cmdline.cfg file from the data folder, and pass the command line arguments to
490         // the the parse_parms and validate_parms line.  Read these first so anything actually on
491         // the command line will take precedence
492 #ifdef PLAT_UNIX
493         char cmdname[MAX_FILENAME_LENGTH];
494
495         snprintf(cmdname, MAX_FILENAME_LENGTH, "%s/%s/Data/cmdline.cfg", detect_home(), Osreg_user_dir);
496         fp = fopen(cmdname, "rt");
497         
498         if (!fp) {
499                 // if not already found check exec directory
500                 fp = fopen("Data/cmdline.cfg", "rt");
501         }
502 #else
503         fp = fopen("data\\cmdline.cfg", "rt");
504 #endif
505
506         // if the file exists, get a single line, and deal with it
507         if ( fp ) {
508                 char buf[1024], *p;
509
510                 fgets(buf, 1024, fp);
511
512                 // replace the newline character with a NUL:
513                 if ( (p = strrchr(buf, '\n')) != NULL ) {
514                         *p = '\0';
515                 }
516
517                 os_parse_parms(buf);
518                 os_validate_parms(buf);
519                 fclose(fp);
520         }
521
522
523
524         os_parse_parms(cmdline);
525         os_validate_parms(cmdline);
526
527 }
528
529 #ifdef PLAT_UNIX
530 // help for available cmdline options
531 void print_instructions()
532 {
533         printf("http://icculus.org/freespace2\n");
534         printf("Support - FAQ: http://icculus.org/lgfaq\n");
535         printf("          Web: http://bugzilla.icculus.org\n\n");
536
537         printf("Usage: freespace2 [options]\n");
538         printf("     [-h | --help]           Show this help message\n");
539         printf("     [-v | --version]        Show game version\n");
540         printf("     [-s | --nosound]        Do no access the sound card\n");
541         printf("     [-f | --fullscreen]     Run the game fullscreen\n");
542         printf("     [-w | --window]         Run the game in a window\n");
543         printf("     [-g | --nograb]         Do not automatically grab mouse\n");
544         printf("     [-n | --nomovies]       Do not play movies\n");
545         printf("     [-d | --standalone]     Run as a dedicated server\n");
546         printf("     [-S | --startgame]      Start a multiplayer game\n");
547         printf("     [-N | --gamename]       Name of the multiplayer game\n");
548         printf("     [-p | --password]       Use this password to connect\n");
549         printf("     [-c | --closed]         Closed multiplayer game\n");
550         printf("     [-r | --restricted]     Restricted multiplayer game\n");
551         printf("     [-a | --allowabove]     Only allow above certain rank\n");
552         printf("     [-b | --allowbelow]     Only allow below certain rank\n");
553         printf("     [-o | --port]           Port to use for multiplayer games\n");
554         printf("     [-C | --connect]        Connect to particular IP address\n");
555         printf("     [-m | --multilog]       Log multiplayer events\n");
556         printf("     [-F | --oldfire]        Server side firing\n");
557         printf("     [-D | --clientdamage]   Client does damage\n");
558         printf("     [-t | --timeout]        Multiplayer game timeout\n");
559         printf("     [-P | --pofspew]        Save model info to pofspew.txt\n");
560         printf("     [-M | --coords]         Show coordinates of the mouse cursor\n\n");
561
562         printf("Freespace 2 v%d.%02d -- Linux Client v%d.%02d\n\n", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_UNIX_VERSION_MAJOR, FS_UNIX_VERSION_MINOR);
563
564         exit(0);
565 }
566 #endif
567
568 // arg constructor
569 // name_ - name of the parameter, must start with '-' character
570 // help_ - help text for this parameter
571 cmdline_parm::cmdline_parm(char *name_, char *help_)
572 {
573         name = name_;
574         help = help_;
575         args = NULL;
576         name_found = 0;
577
578         if (Parm_list_inited == 0) {
579                 list_init(&Parm_list);
580                 Parm_list_inited = 1;
581         }
582
583         if (name != NULL) {
584                 list_append(&Parm_list, this);
585         }
586 }
587
588
589 // destructor - frees any allocated memory
590 cmdline_parm::~cmdline_parm()
591 {
592         if (args) {
593                 delete [] args;
594                 args = NULL;
595         }
596 }
597
598
599 // returns - true if the parameter exists on the command line, otherwise false
600 int cmdline_parm::found()
601 {
602         return name_found;
603 }
604
605
606 // returns - the interger representation for the parameter arguement
607 int cmdline_parm::get_int()
608 {
609         Assert(args);
610         return atoi(args);
611 }
612
613
614 // returns - the float representation for the parameter arguement
615 float cmdline_parm::get_float()
616 {
617         Assert(args);
618         return (float)atof(args);
619 }
620
621
622 // returns - the string value for the parameter arguement
623 char *cmdline_parm::str()
624 {
625         Assert(args);
626         return args;
627 }
628
629 // external entry point into this modules
630 int parse_cmdline(char *cmdline)
631 {
632         os_init_cmdline(cmdline);
633
634         // is this a standalone server??
635 #ifdef PLAT_UNIX
636         if (standalone_arg.found() || standalone_arg_s.found()) {
637 #else
638         if (standalone_arg.found()) {
639 #endif
640                 Is_standalone = 1;
641         }
642
643         // run with no sound
644 #ifdef PLAT_UNIX
645         if ( nosound_arg.found() || nosound_arg_s.found() ) {
646 #else
647         if ( nosound_arg.found() ) {
648 #endif
649                 Cmdline_freespace_no_sound = 1;
650         }
651
652         // run with no music
653         if ( nomusic_arg.found() ) {
654                 Cmdline_freespace_no_music = 1;
655         }
656
657         // should we start a network game
658 #ifdef PLAT_UNIX
659         if ( startgame_arg.found() || startgame_arg_s.found() ) {
660 #else
661         if ( startgame_arg.found() ) {
662 #endif
663                 Cmdline_use_last_pilot = 1;
664                 Cmdline_start_netgame = 1;
665         }
666
667         // closed network game
668 #ifdef PLAT_UNIX
669         if ( gameclosed_arg.found() || gameclosed_arg_s.found() ) {
670 #else
671         if ( gameclosed_arg.found() ) {
672 #endif
673                 Cmdline_closed_game = 1;
674         }
675
676         // restircted network game
677 #ifdef PLAT_UNIX
678         if ( gamerestricted_arg.found() || gamerestricted_arg_s.found() ) {
679 #else
680         if ( gamerestricted_arg.found() ) {
681 #endif
682                 Cmdline_restricted_game = 1;
683         }
684
685         // get the name of the network game
686 #ifdef PLAT_UNIX
687         if ( gamename_arg.found() || gamename_arg_s.found() ) {
688                 // be sure both options get checked if needed
689                 if ( gamename_arg.found() ) {
690                         Cmdline_game_name = gamename_arg.str();
691                 } else {
692                         Cmdline_game_name = gamename_arg_s.str();
693                 }
694 #else
695         if ( gamename_arg.found() ) {
696                 Cmdline_game_name = gamename_arg.str();
697 #endif
698
699 #ifdef PLAT_UNIX
700                 // if there wasn't an argument then complain and exit
701                 if ( !(strlen(Cmdline_game_name) > 0) ) {
702                         fprintf(stderr, "ERROR: The --gamename (-N) option requires an additional argument!\n");
703                         exit(0);
704                 }
705 #endif
706
707                 // be sure that this string fits in our limits
708                 if ( strlen(Cmdline_game_name) > MAX_GAMENAME_LEN ) {
709                         Cmdline_game_name[MAX_GAMENAME_LEN-1] = '\0';
710                 }
711         }
712
713         // get the password for a pssword game
714 #ifdef PLAT_UNIX
715         if ( gamepassword_arg.found() || gamepassword_arg_s.found() ) {
716                 // be sure both options get checked if needed
717                 if ( gamepassword_arg.found() ) {
718                         Cmdline_game_password = gamepassword_arg.str();
719                 } else {
720                         Cmdline_game_password = gamepassword_arg_s.str();
721                 }
722 #else
723         if ( gamepassword_arg.found() ) {
724                 Cmdline_game_password = gamepassword_arg.str();
725 #endif
726
727 #ifdef PLAT_UNIX
728                 // if there wasn't an argument then complain and exit
729                 if ( !(strlen(Cmdline_game_password) > 0) ) {
730                         fprintf(stderr, "ERROR: The --password (-p) option requires an additional argument!\n");
731                         exit(0);
732                 }
733 #endif
734
735                 // be sure that this string fits in our limits
736                 if ( strlen(Cmdline_game_password) > MAX_PASSWD_LEN ) {
737                         Cmdline_game_password[MAX_PASSWD_LEN-1] = '\0';
738                 }
739         }
740
741         // set the rank above/below arguments
742 #ifdef PLAT_UNIX
743         if ( allowabove_arg.found() || allowabove_arg_s.found() ) {
744                 Cmdline_rank_above = allowabove_arg.str();
745         }
746         if ( allowbelow_arg.found() || allowbelow_arg_s.found() ) {
747                 Cmdline_rank_below = allowbelow_arg.str();
748         }
749 #else
750         if ( allowabove_arg.found() ) {
751                 Cmdline_rank_above = allowabove_arg.str();
752         }
753         if ( allowbelow_arg.found() ) {
754                 Cmdline_rank_below = allowbelow_arg.str();
755         }
756 #endif
757
758         // get the port number for games
759 #ifdef PLAT_UNIX
760         if ( port_arg.found() || port_arg_s.found() ) {
761                 // be sure both options get checked if needed
762                 if ( port_arg.found() ) {
763                         Cmdline_network_port = port_arg.get_int();
764                 } else {
765                         Cmdline_network_port = port_arg_s.get_int();
766                 }
767 #else
768         if ( port_arg.found() ) {
769                 Cmdline_network_port = port_arg.get_int();
770 #endif
771
772 #ifdef PLAT_UNIX
773                 // if there wasn't an argument then complain and exit
774                 if ( !Cmdline_network_port ) {
775                         fprintf(stderr, "ERROR: The --port (-P) option requires an additional argument!\n");
776                         exit(0);
777                 }
778 #endif
779         }
780
781         // the connect argument specifies to join a game at this particular address
782 #ifdef PLAT_UNIX
783         if ( connect_arg.found() || connect_arg_s.found() ) {
784                 Cmdline_use_last_pilot = 1;
785                 // be sure both options get checked it needed
786                 if ( connect_arg.found() ) {
787                         Cmdline_connect_addr = connect_arg.str();
788                 } else {
789                         Cmdline_connect_addr = connect_arg_s.str();
790                 }
791 #else
792         if ( connect_arg.found() ) {
793                 Cmdline_use_last_pilot = 1;
794                 Cmdline_connect_addr = connect_arg.str();
795 #endif
796
797 #ifdef PLAT_UNIX
798                 // if there wasn't an argument then complain and exit
799                 if ( !(strlen(Cmdline_connect_addr) > 0) ) {
800                         fprintf(stderr, "ERROR: The --connect (-C) option requires an additional argument!\n");
801                         exit(0);
802                 }
803 #endif
804         }
805
806         // see if the multilog flag was set
807 #ifdef PLAT_UNIX
808         if ( multilog_arg.found() || multilog_arg_s.found() ){
809 #else
810         if ( multilog_arg.found() ){
811 #endif
812                 Cmdline_multi_log = 1;
813         }       
814
815         // maybe use old-school server-side firing
816 #ifdef PLAT_UNIX
817         if (server_firing_arg.found() || server_firing_arg_s.found() ){
818 #else
819         if (server_firing_arg.found() ){
820 #endif
821                 Cmdline_server_firing = 1;
822         }
823
824         // maybe use old-school client damage
825 #ifdef PLAT_UNIX
826         if(client_dodamage.found() || client_dodamage_s.found()){
827 #else
828         if(client_dodamage.found()){
829 #endif
830                 Cmdline_client_dodamage = 1;
831         }       
832
833         // spew pof info
834 #ifdef PLAT_UNIX
835         if(pof_spew.found() || pof_spew_s.found()){
836 #else
837         if(pof_spew.found()){
838 #endif
839                 Cmdline_spew_pof_info = 1;
840         }
841
842 #ifndef PLAT_UNIX
843         // 32 bit
844         if(d3d_32bit.found()){
845                 Cmdline_force_32bit = 1;
846         }
847 #endif
848
849         // mouse coords
850 #ifdef PLAT_UNIX
851         if(mouse_coords.found() || mouse_coords_s.found()){
852 #else
853         if(mouse_coords.found()){
854 #endif
855                 Cmdline_mouse_coords = 1;
856         }
857
858         // net timeout
859 #ifdef PLAT_UNIX
860         if(timeout.found() || timeout_s.found()){
861 #else
862         if(timeout.found()){
863 #endif
864                 Cmdline_timeout = timeout.get_int();
865         }
866
867         // d3d windowed
868 #ifdef PLAT_UNIX
869         if(d3d_window.found() || d3d_window_s.found()){
870 #else
871         if(d3d_window.found()){
872 #endif
873                 Cmdline_window = 1;
874         }
875
876 #ifdef PLAT_UNIX
877         // run fullscreen
878         if(d3d_fullscreen.found() || d3d_fullscreen_s.found()){
879                 Cmdline_fullscreen = 1;
880         }
881
882         // help!!
883         if(help.found() || help_s.found()){
884                 print_instructions();
885         }
886
887         // no key/mouse grab
888         if(no_grab.found() || no_grab_s.found()){
889                 Cmdline_no_grab = 1;
890         }
891
892         // play movies?
893         if(no_movies.found() || no_movies_s.found()){
894                 Cmdline_play_movies = 0;
895         }
896
897         // display game version
898         if(fs_version.found() || fs_version_s.found()){
899                 printf("Freespace 2 version:  %d.%02d\n", FS_VERSION_MAJOR, FS_VERSION_MINOR);
900                 printf("Linux client version:  %d.%02d\n", FS_UNIX_VERSION_MAJOR, FS_UNIX_VERSION_MINOR);
901                 exit(0);
902         }
903 #endif
904
905         return 1;
906 }