]> icculus.org git repositories - btb/d2x.git/blob - misc/args.c
This commit was manufactured by cvs2svn to create tag 'd2x-0_1_0'.
[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.3 $
16  * $Author: bradleyb $
17  * $Date: 2001-01-31 15:18:04 $
18  * 
19  * Functions for accessing arguments.
20  * 
21  * $Log: not supported by cvs2svn $
22  * Revision 1.2  2001/01/24 04:29:48  bradleyb
23  * changed args_find to FindArg
24  *
25  * Revision 1.1.1.1  2001/01/19 03:30:14  bradleyb
26  * Import of d2x-0.0.8
27  *
28  * Revision 1.3  1999/08/05 22:53:41  sekmu
29  *
30  * D3D patch(es) from ADB
31  *
32  * Revision 1.2  1999/06/14 23:44:11  donut
33  * Orulz' svgalib/ggi/noerror patches.
34  *
35  * Revision 1.1.1.1  1999/06/14 22:05:15  donut
36  * Import of d1x 1.37 source.
37  *
38  * Revision 2.0  1995/02/27  11:31:22  john
39  * New version 2.0, which has no anonymous unions, builds with
40  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
41  * 
42  * Revision 1.9  1994/11/29  01:07:57  john
43  * Took out some unused vars.
44  * 
45  * Revision 1.8  1994/11/29  01:04:30  john
46  * Took out descent.ini stuff.
47  * 
48  * Revision 1.7  1994/09/20  19:29:15  matt
49  * Made args require exact (not substring), though still case insensitive.
50  * 
51  * Revision 1.6  1994/07/25  12:33:11  john
52  * Network "pinging" in.
53  * 
54  * Revision 1.5  1994/06/17  18:07:50  matt
55  * Took out printf
56  * 
57  * Revision 1.4  1994/05/11  19:45:33  john
58  * *** empty log message ***
59  * 
60  * Revision 1.3  1994/05/11  18:42:11  john
61  * Added Descent.ini config file.
62  * 
63  * Revision 1.2  1994/05/09  17:03:30  john
64  * Split command line parameters into arg.c and arg.h.
65  * Also added /dma, /port, /irq to digi.c
66  * 
67  * Revision 1.1  1994/05/09  16:49:11  john
68  * Initial revision
69  * 
70  * 
71  */
72
73 #ifdef HAVE_CONFIG_H
74 #include <conf.h>
75 #endif
76
77 #ifdef RCS
78 static char rcsid[] = "$Id: args.c,v 1.3 2001-01-31 15:18:04 bradleyb Exp $";
79 #endif
80
81 #include <stdio.h>
82 #include <stdlib.h>
83 #include <string.h>
84 #include "u_mem.h"
85 #include "strio.h"
86 //added 6/15/99 - Owen Evans
87 #include "strutil.h"
88 //end added - OE
89
90 int Num_args=0;
91 char * Args[100];
92
93 int FindArg( char * s ) {
94         int i;
95
96         for (i=0; i<Num_args; i++ )
97                 if (! strcasecmp( Args[i], s))
98                         return i;
99
100         return 0;
101 }
102
103 //added 7/11/99 by adb to free arguments (prevent memleak msg)
104 void args_exit(void)
105 {
106    int i;
107    for (i=0; i< Num_args; i++ )
108     d_free(Args[i]);
109 }
110 //end additions - adb
111
112 void args_init( int argc,char **argv )
113 {
114  int i;
115  FILE *f;
116  char *line,*word;
117
118   Num_args=0;
119
120    for (i=0; i<argc; i++ )
121     Args[Num_args++] = d_strdup( argv[i] );
122         
123
124    for (i=0; i< Num_args; i++ )
125     {
126 //killed 02/06/99 Matthew Mueller - interferes with filename args which might start with /
127 //     if ( Args[i][0] == '/' )  
128 //      Args[i][0] = '-';
129 //end kill -MM
130      if ( Args[i][0] == '-' )
131       strlwr( Args[i]  );             // Convert all args to lowercase
132     }
133   if((i=FindArg("-ini")))
134    f=fopen(Args[i+1],"rt");
135   else
136    f=fopen("d1x.ini","rt");
137
138      if(f)
139       {
140        while(!feof(f))
141         {
142          line=fsplitword(f,'\n');
143          word=splitword(line,' ');
144
145          Args[Num_args++] = d_strdup(word);
146
147           if(line)
148            Args[Num_args++] = d_strdup(line);
149
150          d_free(line); d_free(word);
151         }
152        fclose(f);
153       }
154    
155         atexit(args_exit);
156 }