]> icculus.org git repositories - btb/d2x.git/blob - misc/args.c
This commit was manufactured by cvs2svn to create branch
[btb/d2x.git] / misc / args.c
1 /* $Id: args.c,v 1.8 2003-02-18 20:35:35 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.8 2003-02-18 20:35:35 btb Exp $";
61 #endif
62
63 #include <stdio.h>
64 #include <stdlib.h>
65 #include <string.h>
66 #include "u_mem.h"
67 #include "strio.h"
68 #include "strutil.h"
69
70 int Num_args=0;
71 char * Args[100];
72
73 int FindArg( char * s ) {
74         int i;
75
76         for (i=0; i<Num_args; i++ )
77                 if (! strcasecmp( Args[i], s))
78                         return i;
79
80         return 0;
81 }
82
83 void args_exit(void)
84 {
85         int i;
86         for (i=0; i< Num_args; i++ )
87                 d_free(Args[i]);
88 }
89
90 void InitArgs( int argc,char **argv )
91 {
92         int i;
93         FILE *f;
94         char *line,*word;
95         
96         Num_args=0;
97         
98         for (i=0; i<argc; i++ )
99                 Args[Num_args++] = d_strdup( argv[i] );
100         
101         
102         for (i=0; i< Num_args; i++ ) {
103                 if ( Args[i][0] == '-' )
104                         strlwr( Args[i]  );  // Convert all args to lowercase
105         }
106         if((i=FindArg("-ini")))
107                 f=fopen(Args[i+1],"rt");
108         else
109                 f=fopen("d2x.ini","rt");
110         
111         if(f) {
112                 while(!feof(f)) {
113                         line=fsplitword(f,'\n');
114                         word=splitword(line,' ');
115                         
116                         Args[Num_args++] = d_strdup(word);
117                         
118                         if(line)
119                                 Args[Num_args++] = d_strdup(line);
120                         
121                         d_free(line); d_free(word);
122                 }
123                 fclose(f);
124         }
125         
126         atexit(args_exit);
127 }