]> icculus.org git repositories - btb/d2x.git/blob - misc/args.c
use the orientation parameter of g3_draw_bitmap
[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 /*
15  *
16  * Functions for accessing arguments.
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <conf.h>
22 #endif
23
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "physfsx.h"
28 #include "args.h"
29 #include "u_mem.h"
30 #include "strio.h"
31 #include "strutil.h"
32
33 #define MAX_ARGS 100
34
35 int Num_args=0;
36 char * Args[MAX_ARGS];
37
38 int FindArg(char *s)
39 {
40         int i;
41
42         for (i=0; i<Num_args; i++ )
43                 if (! stricmp( Args[i], s))
44                         return i;
45
46         return 0;
47 }
48
49 int FindResArg(char *prefix, int *sw, int *sh)
50 {
51         int i;
52         int w, h;
53         char *endptr;
54         int prefixlen = (int)strlen(prefix);
55
56         for (i = 0; i < Num_args; ++i)
57                 if (Args[i][0] == '-' && !strnicmp(Args[i] + 1, prefix, prefixlen))
58                 {
59                         w = (int)strtol(Args[i] + 1 + prefixlen, &endptr, 10);
60                         if (w > 0 && endptr && endptr[0] == 'x')
61                         {
62                                 h = (int)strtol(endptr + 1, &endptr, 10);
63                                 if (h > 0 && endptr[0] == '\0')
64                                 {
65                                         *sw = w;
66                                         *sh = h;
67                                         return i;
68                                 }
69                         }
70                 }
71
72         return 0;
73
74 }
75
76 void args_exit(void)
77 {
78         int i;
79         for (i=0; i< Num_args; i++ )
80                 d_free(Args[i]);
81 }
82
83 void InitArgs( int argc,char **argv )
84 {
85         int i;
86         
87         Num_args=0;
88         
89         for (i=0; i<argc; i++ )
90                 Args[Num_args++] = d_strdup( argv[i] );
91         
92         
93         for (i=0; i< Num_args; i++ ) {
94                 if ( Args[i][0] == '-' )
95                         strlwr( Args[i]  );  // Convert all args to lowercase
96         }
97         AppendArgs();
98
99         atexit(args_exit);
100 }
101
102 void AppendArgs(void)
103 {
104         PHYSFS_file *f;
105         char *line,*word;
106         int i;
107         
108         if((i=FindArg("-ini")))
109                 f = PHYSFSX_openReadBuffered(Args[i+1]);
110         else
111                 f = PHYSFSX_openReadBuffered("d2x.ini");
112         
113         if(f) {
114                 while(!PHYSFS_eof(f) && Num_args < MAX_ARGS)
115                 {
116                         line=fgets_unlimited(f);
117                         word=splitword(line,' ');
118                         
119                         Args[Num_args++] = d_strdup(word);
120                         
121                         if(line)
122                                 Args[Num_args++] = d_strdup(line);
123                         
124                         d_free(line); d_free(word);
125                 }
126                 PHYSFS_close(f);
127         }
128 }