Mercurial > hg-old > index.cgi
comparison src/main.c @ 294:0f488febdc2b
command line options
author | lost |
---|---|
date | Sat, 17 Jan 2009 16:55:53 +0000 |
parents | f14e82afdac7 |
children | 14d835cf02d9 |
comparison
equal
deleted
inserted
replaced
293:f14e82afdac7 | 294:0f488febdc2b |
---|---|
1 /* | |
2 main.c | |
3 Copyright © 2008 William Astle | |
4 | |
5 This file is part of LWLINK. | |
6 | |
7 LWLINK is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 Implements the program startup code | |
22 | |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include "config.h" | |
27 #endif | |
28 | |
29 #include <argp.h> | |
30 #include <errno.h> | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
33 | |
34 #include "lwlink.h" | |
35 | |
36 // command line option handling | |
37 const char *argp_program_version = PACKAGE_STRING; | |
38 const char *argp_program_bug_address = PACKAGE_BUGREPORT; | |
39 | |
40 static error_t parse_opts(int key, char *arg, struct argp_state *state) | |
41 { | |
42 switch (key) | |
43 { | |
44 case 'o': | |
45 // output | |
46 if (outfile) | |
47 { | |
48 } | |
49 outfile = arg; | |
50 break; | |
51 | |
52 case 'd': | |
53 // debug | |
54 debug_level++; | |
55 break; | |
56 | |
57 case 'b': | |
58 // decb output | |
59 outformat = OUTPUT_DECB; | |
60 break; | |
61 | |
62 case 'r': | |
63 // raw binary output | |
64 outformat = OUTPUT_RAW; | |
65 break; | |
66 | |
67 case 'f': | |
68 // output format | |
69 if (!strcasecmp(arg, "decb")) | |
70 outformat = OUTPUT_DECB; | |
71 else if (!strcasecmp(arg, "raw")) | |
72 outformat = OUTPUT_RAW; | |
73 else | |
74 { | |
75 fprintf(stderr, "Invalid output format: %s\n", arg); | |
76 exit(1); | |
77 } | |
78 break; | |
79 case ARGP_KEY_END: | |
80 // done; sanity check | |
81 if (!outfile) | |
82 outfile = "a.out"; | |
83 break; | |
84 | |
85 case ARGP_KEY_ARG: | |
86 // FIXME: input files! | |
87 break; | |
88 | |
89 default: | |
90 return ARGP_ERR_UNKNOWN; | |
91 } | |
92 return 0; | |
93 } | |
94 | |
95 static struct argp_option options[] = | |
96 { | |
97 { "output", 'o', "FILE", 0, | |
98 "Output to FILE"}, | |
99 { "debug", 'd', 0, 0, | |
100 "Set debug mode"}, | |
101 { "format", 'f', "TYPE", 0, | |
102 "Select output format: decb, raw, obj"}, | |
103 { "decb", 'b', 0, 0, | |
104 "Generate DECB .bin format output, equivalent of --format=decb"}, | |
105 { "raw", 'r', 0, 0, | |
106 "Generate raw binary format output, equivalent of --format=raw"}, | |
107 { 0 } | |
108 }; | |
109 | |
110 static struct argp argp = | |
111 { | |
112 options, | |
113 parse_opts, | |
114 "<input file> ...", | |
115 "LWLINK, a HD6309 and MC6809 cross-linker" | |
116 }; | |
117 | |
118 // main function; parse command line, set up assembler state, and run the | |
119 // assembler on the first file | |
120 int main(int argc, char **argv) | |
121 { | |
122 argp_parse(&argp, argc, argv, 0, 0, NULL); | |
123 | |
124 exit(0); | |
125 } |