Mercurial > hg-old > index.cgi
comparison lwasm/main.c @ 325:619fd6ad4ab9
Completed command line parsing
author | lost |
---|---|
date | Sat, 13 Feb 2010 05:20:55 +0000 |
parents | 473ed9b353eb |
children | 591d01b343b9 |
comparison
equal
deleted
inserted
replaced
324:be63116281b0 | 325:619fd6ad4ab9 |
---|---|
23 | 23 |
24 #include <argp.h> | 24 #include <argp.h> |
25 #include <stdio.h> | 25 #include <stdio.h> |
26 #include <stdlib.h> | 26 #include <stdlib.h> |
27 | 27 |
28 #include <lw_string.h> | |
29 #include <lw_stringlist.h> | |
30 | |
28 #include "lwasm.h" | 31 #include "lwasm.h" |
32 | |
33 extern int parse_pragma_string(asmstate_t *as, char *str); | |
29 | 34 |
30 /* command line option handling */ | 35 /* command line option handling */ |
31 const char *argp_program_version = "lwasm from " PACKAGE_STRING; | 36 const char *argp_program_version = "lwasm from " PACKAGE_STRING; |
32 const char *argp_program_bug_address = PACKAGE_BUGREPORT; | 37 const char *argp_program_bug_address = PACKAGE_BUGREPORT; |
33 char *program_name; | 38 char *program_name; |
55 asmstate_t *as = state -> input; | 60 asmstate_t *as = state -> input; |
56 | 61 |
57 switch (key) | 62 switch (key) |
58 { | 63 { |
59 case 'I': | 64 case 'I': |
65 lw_stringlist_addstring(as -> include_list, arg); | |
66 break; | |
67 | |
60 case 'o': | 68 case 'o': |
69 if (as -> output_file) | |
70 lw_free(as -> output_file); | |
71 as -> output_file = lw_strdup(arg); | |
72 break; | |
73 | |
61 case 'd': | 74 case 'd': |
62 as -> debug_level++; | 75 as -> debug_level++; |
63 break; | 76 break; |
64 | 77 |
65 case 'l': | 78 case 'l': |
66 | 79 if (as -> list_file) |
80 lw_free(as -> list_file); | |
81 if (!arg) | |
82 as -> list_file = NULL; | |
83 else | |
84 as -> list_file = lw_strdup(arg); | |
85 as -> flags |= FLAG_LIST; | |
86 break; | |
87 | |
67 case 'b': | 88 case 'b': |
68 as -> output_format = OUTPUT_DECB; | 89 as -> output_format = OUTPUT_DECB; |
69 break; | 90 break; |
70 | 91 |
71 case 'r': | 92 case 'r': |
75 case 0x100: | 96 case 0x100: |
76 as -> output_format = OUTPUT_OBJ; | 97 as -> output_format = OUTPUT_OBJ; |
77 break; | 98 break; |
78 | 99 |
79 case 0x101: | 100 case 0x101: |
101 as -> flags |= FLAG_DEPEND; | |
102 break; | |
103 | |
80 case 'f': | 104 case 'f': |
81 if (!strcasecmp(arg, "decb")) | 105 if (!strcasecmp(arg, "decb")) |
82 as -> output_format = OUTPUT_DECB; | 106 as -> output_format = OUTPUT_DECB; |
83 else if (!strcasecmp(arg, "raw")) | 107 else if (!strcasecmp(arg, "raw")) |
84 as -> output_format = OUTPUT_RAW; | 108 as -> output_format = OUTPUT_RAW; |
85 else if (!strcasecmp(arg, "obj")) | 109 else if (!strcasecmp(arg, "obj")) |
86 as -> output_format = OUTPUT_OBJ; | 110 as -> output_format = OUTPUT_OBJ; |
87 else if (!strcasecmp(arg, "os9")) | 111 else if (!strcasecmp(arg, "os9")) |
88 { | 112 { |
89 //as -> pragmas |= PRAGMA_DOLLARNOTLOCAL; | 113 as -> pragmas |= PRAGMA_DOLLARNOTLOCAL; |
90 as -> output_format = OUTPUT_OS9; | 114 as -> output_format = OUTPUT_OS9; |
91 } | 115 } |
92 else | 116 else |
93 { | 117 { |
94 fprintf(stderr, "Invalid output format: %s\n", arg); | 118 fprintf(stderr, "Invalid output format: %s\n", arg); |
95 exit(1); | 119 exit(1); |
96 } | 120 } |
97 break; | 121 break; |
98 | 122 |
99 case 'p': | 123 case 'p': |
124 if (parse_pragma_string(as, arg) == 0) | |
125 { | |
126 fprintf(stderr, "Unrecognized pragma string: %s\n", arg); | |
127 exit(1); | |
128 } | |
129 break; | |
130 | |
100 case '9': | 131 case '9': |
101 as -> target = TARGET_6809; | 132 as -> target = TARGET_6809; |
102 break; | 133 break; |
103 | 134 |
104 case '3': | 135 case '3': |
107 | 138 |
108 case ARGP_KEY_END: | 139 case ARGP_KEY_END: |
109 break; | 140 break; |
110 | 141 |
111 case ARGP_KEY_ARG: | 142 case ARGP_KEY_ARG: |
143 lw_stringlist_addstring(as -> input_files, arg); | |
112 break; | 144 break; |
113 | 145 |
114 default: | 146 default: |
115 return ARGP_ERR_UNKNOWN; | 147 return ARGP_ERR_UNKNOWN; |
116 } | 148 } |
131 */ | 163 */ |
132 int main(int argc, char **argv) | 164 int main(int argc, char **argv) |
133 { | 165 { |
134 /* assembler state */ | 166 /* assembler state */ |
135 asmstate_t asmstate = { 0 }; | 167 asmstate_t asmstate = { 0 }; |
168 program_name = argv[0]; | |
136 | 169 |
137 program_name = argv[0]; | 170 /* initialize assembler state */ |
138 | 171 asmstate.input_files = lw_stringlist_create(); |
172 asmstate.include_list = lw_stringlist_create(); | |
173 | |
174 /* parse command line arguments */ | |
139 argp_parse(&argp, argc, argv, 0, 0, &asmstate); | 175 argp_parse(&argp, argc, argv, 0, 0, &asmstate); |
140 | 176 |
141 exit(0); | 177 exit(0); |
142 } | 178 } |