Mercurial > hg-old > index.cgi
annotate src/main.c @ 296:14d835cf02d9
Handle input files on command line and add some memory management utility functions
author | lost |
---|---|
date | Sat, 17 Jan 2009 20:54:58 +0000 |
parents | 0f488febdc2b |
children | c52ad3135bd3 |
rev | line source |
---|---|
294 | 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 outfile = arg; | |
47 break; | |
48 | |
49 case 'd': | |
50 // debug | |
51 debug_level++; | |
52 break; | |
53 | |
54 case 'b': | |
55 // decb output | |
56 outformat = OUTPUT_DECB; | |
57 break; | |
58 | |
59 case 'r': | |
60 // raw binary output | |
61 outformat = OUTPUT_RAW; | |
62 break; | |
63 | |
64 case 'f': | |
65 // output format | |
66 if (!strcasecmp(arg, "decb")) | |
67 outformat = OUTPUT_DECB; | |
68 else if (!strcasecmp(arg, "raw")) | |
69 outformat = OUTPUT_RAW; | |
70 else | |
71 { | |
72 fprintf(stderr, "Invalid output format: %s\n", arg); | |
73 exit(1); | |
74 } | |
75 break; | |
76 case ARGP_KEY_END: | |
77 // done; sanity check | |
78 if (!outfile) | |
79 outfile = "a.out"; | |
80 break; | |
81 | |
82 case ARGP_KEY_ARG: | |
296
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
83 add_input_file(arg); |
294 | 84 break; |
85 | |
86 default: | |
87 return ARGP_ERR_UNKNOWN; | |
88 } | |
89 return 0; | |
90 } | |
91 | |
92 static struct argp_option options[] = | |
93 { | |
94 { "output", 'o', "FILE", 0, | |
95 "Output to FILE"}, | |
96 { "debug", 'd', 0, 0, | |
97 "Set debug mode"}, | |
98 { "format", 'f', "TYPE", 0, | |
99 "Select output format: decb, raw, obj"}, | |
100 { "decb", 'b', 0, 0, | |
101 "Generate DECB .bin format output, equivalent of --format=decb"}, | |
102 { "raw", 'r', 0, 0, | |
103 "Generate raw binary format output, equivalent of --format=raw"}, | |
104 { 0 } | |
105 }; | |
106 | |
107 static struct argp argp = | |
108 { | |
109 options, | |
110 parse_opts, | |
111 "<input file> ...", | |
112 "LWLINK, a HD6309 and MC6809 cross-linker" | |
113 }; | |
114 | |
115 // main function; parse command line, set up assembler state, and run the | |
116 // assembler on the first file | |
117 int main(int argc, char **argv) | |
118 { | |
119 argp_parse(&argp, argc, argv, 0, 0, NULL); | |
296
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
120 if (ninputfiles == 0) |
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
121 { |
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
122 fprintf(stderr, "No input files\n"); |
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
123 exit(1); |
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
124 } |
14d835cf02d9
Handle input files on command line and add some memory management utility functions
lost
parents:
294
diff
changeset
|
125 |
294 | 126 exit(0); |
127 } |