]> icculus.org git repositories - btb/d2x.git/blob - misc/args.c
Visual C, PocketPC fixes
[btb/d2x.git] / misc / args.c
1 /* $Id: args.c,v 1.10 2003-11-26 12:26:33 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Functions for accessing arguments.
18  *
19  * Old Log:
20  * Revision 2.0  1995/02/27  11:31:22  john
21  * New version 2.0, which has no anonymous unions, builds with
22  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
23  *
24  * Revision 1.9  1994/11/29  01:07:57  john
25  * Took out some unused vars.
26  *
27  * Revision 1.8  1994/11/29  01:04:30  john
28  * Took out descent.ini stuff.
29  *
30  * Revision 1.7  1994/09/20  19:29:15  matt
31  * Made args require exact (not substring), though still case insensitive.
32  *
33  * Revision 1.6  1994/07/25  12:33:11  john
34  * Network "pinging" in.
35  *
36  * Revision 1.5  1994/06/17  18:07:50  matt
37  * Took out printf
38  *
39  * Revision 1.4  1994/05/11  19:45:33  john
40  * *** empty log message ***
41  *
42  * Revision 1.3  1994/05/11  18:42:11  john
43  * Added Descent.ini config file.
44  *
45  * Revision 1.2  1994/05/09  17:03:30  john
46  * Split command line parameters into arg.c and arg.h.
47  * Also added /dma, /port, /irq to digi.c
48  *
49  * Revision 1.1  1994/05/09  16:49:11  john
50  * Initial revision
51  *
52  *
53  */
54
55 #ifdef HAVE_CONFIG_H
56 #include <conf.h>
57 #endif
58
59 #ifdef RCS
60 static char rcsid[] = "$Id: args.c,v 1.10 2003-11-26 12:26:33 btb Exp $";
61 #endif
62
63 #include <stdlib.h>
64 #include <string.h>
65
66 #include "cfile.h"
67 #include "u_mem.h"
68 #include "strio.h"
69 #include "strutil.h"
70
71 int Num_args=0;
72 char * Args[100];
73
74 int FindArg( char * s ) {
75         int i;
76
77         for (i=0; i<Num_args; i++ )
78                 if (! stricmp( Args[i], s))
79                         return i;
80
81         return 0;
82 }
83
84 void args_exit(void)
85 {
86         int i;
87         for (i=0; i< Num_args; i++ )
88                 d_free(Args[i]);
89 }
90
91 void InitArgs( int argc,char **argv )
92 {
93         int i;
94         CFILE *f;
95         char *line,*word;
96         
97         Num_args=0;
98         
99         for (i=0; i<argc; i++ )
100                 Args[Num_args++] = d_strdup( argv[i] );
101         
102         
103         for (i=0; i< Num_args; i++ ) {
104                 if ( Args[i][0] == '-' )
105                         strlwr( Args[i]  );  // Convert all args to lowercase
106         }
107         if((i=FindArg("-ini")))
108                 f = cfopen(Args[i+1], "rt");
109         else
110                 f = cfopen("d2x.ini", "rt");
111         
112         if(f) {
113                 while(!cfeof(f))
114                 {
115                         line=fsplitword(f,'\n');
116                         word=splitword(line,' ');
117                         
118                         Args[Num_args++] = d_strdup(word);
119                         
120                         if(line)
121                                 Args[Num_args++] = d_strdup(line);
122                         
123                         d_free(line); d_free(word);
124                 }
125                 cfclose(f);
126         }
127         
128         atexit(args_exit);
129 }