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