]> icculus.org git repositories - btb/d2x.git/blob - misc/args.c
junk removal
[btb/d2x.git] / misc / args.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13 /*
14  * $Source: /cvs/cvsroot/d2x/misc/args.c,v $
15  * $Revision: 1.2 $
16  * $Author: bradleyb $
17  * $Date: 2001-01-24 04:29:48 $
18  * 
19  * Functions for accessing arguments.
20  * 
21  * $Log: not supported by cvs2svn $
22  * Revision 1.1.1.1  2001/01/19 03:30:14  bradleyb
23  * Import of d2x-0.0.8
24  *
25  * Revision 1.3  1999/08/05 22:53:41  sekmu
26  *
27  * D3D patch(es) from ADB
28  *
29  * Revision 1.2  1999/06/14 23:44:11  donut
30  * Orulz' svgalib/ggi/noerror patches.
31  *
32  * Revision 1.1.1.1  1999/06/14 22:05:15  donut
33  * Import of d1x 1.37 source.
34  *
35  * Revision 2.0  1995/02/27  11:31:22  john
36  * New version 2.0, which has no anonymous unions, builds with
37  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
38  * 
39  * Revision 1.9  1994/11/29  01:07:57  john
40  * Took out some unused vars.
41  * 
42  * Revision 1.8  1994/11/29  01:04:30  john
43  * Took out descent.ini stuff.
44  * 
45  * Revision 1.7  1994/09/20  19:29:15  matt
46  * Made args require exact (not substring), though still case insensitive.
47  * 
48  * Revision 1.6  1994/07/25  12:33:11  john
49  * Network "pinging" in.
50  * 
51  * Revision 1.5  1994/06/17  18:07:50  matt
52  * Took out printf
53  * 
54  * Revision 1.4  1994/05/11  19:45:33  john
55  * *** empty log message ***
56  * 
57  * Revision 1.3  1994/05/11  18:42:11  john
58  * Added Descent.ini config file.
59  * 
60  * Revision 1.2  1994/05/09  17:03:30  john
61  * Split command line parameters into arg.c and arg.h.
62  * Also added /dma, /port, /irq to digi.c
63  * 
64  * Revision 1.1  1994/05/09  16:49:11  john
65  * Initial revision
66  * 
67  * 
68  */
69
70
71 #ifdef RCS
72 static char rcsid[] = "$Id: args.c,v 1.2 2001-01-24 04:29:48 bradleyb Exp $";
73 #endif
74
75 #include <conf.h>
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <string.h>
79 #include "u_mem.h"
80 #include "strio.h"
81 //added 6/15/99 - Owen Evans
82 #include "strutil.h"
83 //end added - OE
84
85 int Num_args=0;
86 char * Args[100];
87
88 int FindArg( char * s ) {
89         int i;
90
91         for (i=0; i<Num_args; i++ )
92                 if (! strcasecmp( Args[i], s))
93                         return i;
94
95         return 0;
96 }
97
98 //added 7/11/99 by adb to free arguments (prevent memleak msg)
99 void args_exit(void)
100 {
101    int i;
102    for (i=0; i< Num_args; i++ )
103     d_free(Args[i]);
104 }
105 //end additions - adb
106
107 void args_init( int argc,char **argv )
108 {
109  int i;
110  FILE *f;
111  char *line,*word;
112
113   Num_args=0;
114
115    for (i=0; i<argc; i++ )
116     Args[Num_args++] = d_strdup( argv[i] );
117         
118
119    for (i=0; i< Num_args; i++ )
120     {
121 //killed 02/06/99 Matthew Mueller - interferes with filename args which might start with /
122 //     if ( Args[i][0] == '/' )  
123 //      Args[i][0] = '-';
124 //end kill -MM
125      if ( Args[i][0] == '-' )
126       strlwr( Args[i]  );             // Convert all args to lowercase
127     }
128   if((i=FindArg("-ini")))
129    f=fopen(Args[i+1],"rt");
130   else
131    f=fopen("d1x.ini","rt");
132
133      if(f)
134       {
135        while(!feof(f))
136         {
137          line=fsplitword(f,'\n');
138          word=splitword(line,' ');
139
140          Args[Num_args++] = d_strdup(word);
141
142           if(line)
143            Args[Num_args++] = d_strdup(line);
144
145          d_free(line); d_free(word);
146         }
147        fclose(f);
148       }
149    
150         atexit(args_exit);
151 }