]> icculus.org git repositories - btb/d2x.git/blob - misc/args.c
document -gl_refresh (d1x r1.20)
[btb/d2x.git] / misc / args.c
1 /* $Id: args.c,v 1.12 2004-05-19 22:28:08 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.12 2004-05-19 22:28:08 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 {
76         int i;
77
78         for (i=0; i<Num_args; i++ )
79                 if (! stricmp( Args[i], s))
80                         return i;
81
82         return 0;
83 }
84
85 int FindResArg(char *prefix, int *sw, int *sh)
86 {
87         int i;
88         int w, h;
89         char *endptr;
90         int prefixlen = strlen(prefix);
91
92         for (i = 0; i < Num_args; ++i)
93                 if (Args[i][0] == '-' && !strnicmp(Args[i] + 1, prefix, prefixlen))
94                 {
95                         w = strtol(Args[i] + 1 + prefixlen, &endptr, 10);
96                         if (w > 0 && endptr && endptr[0] == 'x')
97                         {
98                                 h = strtol(endptr + 1, &endptr, 10);
99                                 if (h > 0 && endptr[0] == '\0')
100                                 {
101                                         *sw = w;
102                                         *sh = h;
103                                         return i;
104                                 }
105                         }
106                 }
107
108         return 0;
109
110 }
111
112 void args_exit(void)
113 {
114         int i;
115         for (i=0; i< Num_args; i++ )
116                 d_free(Args[i]);
117 }
118
119 void InitArgs( int argc,char **argv )
120 {
121         int i;
122         CFILE *f;
123         char *line,*word;
124         
125         Num_args=0;
126         
127         for (i=0; i<argc; i++ )
128                 Args[Num_args++] = d_strdup( argv[i] );
129         
130         
131         for (i=0; i< Num_args; i++ ) {
132                 if ( Args[i][0] == '-' )
133                         strlwr( Args[i]  );  // Convert all args to lowercase
134         }
135         if((i=FindArg("-ini")))
136                 f = cfopen(Args[i+1], "rt");
137         else
138                 f = cfopen("d2x.ini", "rt");
139         
140         if(f) {
141                 while(!cfeof(f))
142                 {
143                         line=fsplitword(f,'\n');
144                         word=splitword(line,' ');
145                         
146                         Args[Num_args++] = d_strdup(word);
147                         
148                         if(line)
149                                 Args[Num_args++] = d_strdup(line);
150                         
151                         d_free(line); d_free(word);
152                 }
153                 cfclose(f);
154         }
155         
156         atexit(args_exit);
157 }