Mercurial > hg > index.cgi
comparison lwasm/main.c @ 7:917b608b8c66
Switched lwasm to lw_cmdline from argp
author | lost@l-w.ca |
---|---|
date | Sat, 22 Jan 2011 09:40:52 -0700 |
parents | 7317fbe024af |
children | ceab04fd2969 |
comparison
equal
deleted
inserted
replaced
6:1e5e8ec406fb | 7:917b608b8c66 |
---|---|
17 | 17 |
18 You should have received a copy of the GNU General Public License along with | 18 You should have received a copy of the GNU General Public License along with |
19 this program. If not, see <http://www.gnu.org/licenses/>. | 19 this program. If not, see <http://www.gnu.org/licenses/>. |
20 */ | 20 */ |
21 | 21 |
22 #include <argp.h> | |
23 #include <stdio.h> | 22 #include <stdio.h> |
24 #include <stdlib.h> | 23 #include <stdlib.h> |
25 #include <string.h> | 24 #include <string.h> |
26 | 25 |
27 #include <lw_alloc.h> | 26 #include <lw_alloc.h> |
28 #include <lw_string.h> | 27 #include <lw_string.h> |
29 #include <lw_stringlist.h> | 28 #include <lw_stringlist.h> |
30 #include <lw_expr.h> | 29 #include <lw_expr.h> |
30 #include <lw_cmdline.h> | |
31 | 31 |
32 #include "lwasm.h" | 32 #include "lwasm.h" |
33 #include "input.h" | 33 #include "input.h" |
34 | 34 |
35 extern int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr); | 35 extern int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr); |
36 | 36 |
37 /* command line option handling */ | 37 /* command line option handling */ |
38 const char *argp_program_version = "lwasm from " PACKAGE_STRING; | 38 #define PROGVER "lwasm from " PACKAGE_STRING |
39 const char *argp_program_bug_address = PACKAGE_BUGREPORT; | |
40 char *program_name; | 39 char *program_name; |
41 | 40 |
42 static struct argp_option options[] = | 41 static struct lw_cmdline_options options[] = |
43 { | 42 { |
44 { "output", 'o', "FILE", 0, "Output to FILE"}, | 43 { "output", 'o', "FILE", 0, "Output to FILE"}, |
45 { "debug", 'd', "LEVEL", OPTION_ARG_OPTIONAL, "Set debug mode"}, | 44 { "debug", 'd', "LEVEL", lw_cmdline_opt_optional, "Set debug mode"}, |
46 { "format", 'f', "TYPE", 0, "Select output format: decb, raw, obj, os9"}, | 45 { "format", 'f', "TYPE", 0, "Select output format: decb, raw, obj, os9"}, |
47 { "list", 'l', "FILE", OPTION_ARG_OPTIONAL, "Generate list [to FILE]"}, | 46 { "list", 'l', "FILE", lw_cmdline_opt_optional, "Generate list [to FILE]"}, |
48 { "symbols", 's', 0, OPTION_ARG_OPTIONAL, "Generate symbol list in listing, no effect without --list"}, | 47 { "symbols", 's', 0, lw_cmdline_opt_optional, "Generate symbol list in listing, no effect without --list"}, |
49 { "decb", 'b', 0, 0, "Generate DECB .bin format output, equivalent of --format=decb"}, | 48 { "decb", 'b', 0, 0, "Generate DECB .bin format output, equivalent of --format=decb"}, |
50 { "raw", 'r', 0, 0, "Generate raw binary format output, equivalent of --format=raw"}, | 49 { "raw", 'r', 0, 0, "Generate raw binary format output, equivalent of --format=raw"}, |
51 { "obj", 0x100, 0, 0, "Generate proprietary object file format for later linking, equivalent of --format=obj" }, | 50 { "obj", 0x100, 0, 0, "Generate proprietary object file format for later linking, equivalent of --format=obj" }, |
52 { "depend", 0x101, 0, 0, "Output a dependency list to stdout; do not do any actual output though assembly is completed as usual" }, | 51 { "depend", 0x101, 0, 0, "Output a dependency list to stdout; do not do any actual output though assembly is completed as usual" }, |
53 { "pragma", 'p', "PRAGMA", 0, "Set an assembler pragma to any value understood by the \"pragma\" pseudo op"}, | 52 { "pragma", 'p', "PRAGMA", 0, "Set an assembler pragma to any value understood by the \"pragma\" pseudo op"}, |
54 { "6809", '9', 0, 0, "Set assembler to 6809 only mode" }, | 53 { "6809", '9', 0, 0, "Set assembler to 6809 only mode" }, |
55 { "6309", '3', 0, 0, "Set assembler to 6309 mode (default)" }, | 54 { "6309", '3', 0, 0, "Set assembler to 6309 mode (default)" }, |
56 { "includedir", 'I', "PATH", 0, "Add entry to include path" }, | 55 { "includedir", 'I', "PATH", 0, "Add entry to include path" }, |
57 { 0 } | 56 { 0 } |
58 }; | 57 }; |
59 | 58 |
60 | 59 |
61 static error_t parse_opts(int key, char *arg, struct argp_state *state) | 60 static int parse_opts(int key, char *arg, void *state) |
62 { | 61 { |
63 asmstate_t *as = state -> input; | 62 asmstate_t *as = state; |
64 | 63 |
65 switch (key) | 64 switch (key) |
66 { | 65 { |
67 case 'I': | 66 case 'I': |
68 lw_stringlist_addstring(as -> include_list, arg); | 67 lw_stringlist_addstring(as -> include_list, arg); |
144 | 143 |
145 case '3': | 144 case '3': |
146 as -> target = TARGET_6309; | 145 as -> target = TARGET_6309; |
147 break; | 146 break; |
148 | 147 |
149 case ARGP_KEY_END: | 148 case lw_cmdline_key_end: |
150 break; | 149 break; |
151 | 150 |
152 case ARGP_KEY_ARG: | 151 case lw_cmdline_key_arg: |
153 lw_stringlist_addstring(as -> input_files, arg); | 152 lw_stringlist_addstring(as -> input_files, arg); |
154 break; | 153 break; |
155 | 154 |
156 default: | 155 default: |
157 return ARGP_ERR_UNKNOWN; | 156 return lw_cmdline_err_unknown; |
158 } | 157 } |
159 return 0; | 158 return 0; |
160 } | 159 } |
161 | 160 |
162 static struct argp argp = | 161 static struct lw_cmdline_parser cmdline_parser = |
163 { | 162 { |
164 options, | 163 options, |
165 parse_opts, | 164 parse_opts, |
166 "<input file>", | 165 "INPUTFILE", |
167 "LWASM, a HD6309 and MC6809 cross-assembler" | 166 "lwasm, a HD6309 and MC6809 cross-assembler\vPlease report bugs to lost@l-w.ca.", |
167 PROGVER | |
168 }; | 168 }; |
169 | 169 |
170 /* | 170 /* |
171 main function; parse command line, set up assembler state, and run the | 171 main function; parse command line, set up assembler state, and run the |
172 assembler on the first file | 172 assembler on the first file |
217 asmstate.include_list = lw_stringlist_create(); | 217 asmstate.include_list = lw_stringlist_create(); |
218 asmstate.input_files = lw_stringlist_create(); | 218 asmstate.input_files = lw_stringlist_create(); |
219 asmstate.nextcontext = 1; | 219 asmstate.nextcontext = 1; |
220 | 220 |
221 /* parse command line arguments */ | 221 /* parse command line arguments */ |
222 argp_parse(&argp, argc, argv, 0, 0, &asmstate); | 222 lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, &asmstate); |
223 | 223 |
224 if (!asmstate.output_file) | 224 if (!asmstate.output_file) |
225 { | 225 { |
226 asmstate.output_file = lw_strdup("a.out"); | 226 asmstate.output_file = lw_strdup("a.out"); |
227 } | 227 } |