c62d2810 |
1 | /* FCE Ultra - NES/Famicom Emulator |
2 | * |
3 | * Copyright notice for this file: |
4 | * Copyright (C) 2002 Ben Parnell |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | */ |
20 | |
21 | /****************************************************************/ |
22 | /* FCE Ultra */ |
23 | /* */ |
24 | /* This file contains code for parsing command-line */ |
25 | /* options. */ |
26 | /* */ |
27 | /****************************************************************/ |
28 | |
29 | #include <stdio.h> |
30 | #include <stdlib.h> |
31 | #include <string.h> |
32 | |
33 | #include "../../types.h" |
34 | #include "args.h" |
35 | |
36 | void ParseEA(int x, int argc, char *argv[], ARGPSTRUCT *argsps) |
37 | { |
38 | int y=0; |
39 | |
40 | do |
41 | { |
42 | if(!argsps[y].name) |
43 | { |
44 | ParseEA(x,argc,argv,(void *)argsps[y].var); |
45 | y++; |
46 | continue; |
47 | } |
48 | if(!strcmp(argv[x],argsps[y].name)) // A match. |
49 | { |
50 | if(argsps[y].subs) |
51 | { |
52 | if((x+1)>=argc) |
53 | break; |
54 | if(argsps[y].substype&0x8000) |
55 | { |
56 | *(int *)argsps[y].subs&=~(argsps[y].substype&(~0x8000)); |
57 | *(int *)argsps[y].subs|=atoi(argv[x+1])?(argsps[y].substype&(~0x8000)):0; |
58 | } |
59 | else |
60 | switch(argsps[y].substype&(~0x4000)) |
61 | { |
62 | case 0: // Integer |
63 | *(int *)argsps[y].subs=atoi(argv[x+1]); |
64 | break; |
65 | case 1: // String |
66 | if(argsps[y].substype&0x4000) |
67 | { |
68 | if(*(char **)argsps[y].subs) |
69 | free(*(char **)argsps[y].subs); |
70 | if(!( *(char **)argsps[y].subs=malloc(strlen(argv[x+1])+1) )) |
71 | break; |
72 | } |
73 | strcpy(*(char **)argsps[y].subs,argv[x+1]); |
74 | break; |
75 | } |
76 | } |
77 | if(argsps[y].var) |
78 | *argsps[y].var=1; |
79 | } |
80 | y++; |
81 | } while(argsps[y].var || argsps[y].subs); |
82 | } |
83 | |
84 | void ParseArguments(int argc, char *argv[], ARGPSTRUCT *argsps) |
85 | { |
86 | int x; |
87 | |
88 | for(x=0;x<argc;x++) |
89 | ParseEA(x,argc,argv,argsps); |
90 | } |
91 | |