comparison lwlink/main.c @ 8:fdc11ef4115b

Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
author lost@l-w.ca
date Sat, 22 Jan 2011 09:58:24 -0700
parents 7317fbe024af
children 08fb11004df9
comparison
equal deleted inserted replaced
7:917b608b8c66 8:fdc11ef4115b
20 20
21 Implements the program startup code 21 Implements the program startup code
22 22
23 */ 23 */
24 24
25 #include <argp.h>
26 #include <errno.h> 25 #include <errno.h>
27 #include <stdio.h> 26 #include <stdio.h>
28 #include <stdlib.h> 27 #include <stdlib.h>
29 #include <unistd.h> 28 #include <unistd.h>
30 #include <string.h> 29 #include <string.h>
31 30
31 #include <lw_cmdline.h>
32
32 #include "lwlink.h" 33 #include "lwlink.h"
33 34
34 char *program_name; 35 char *program_name;
35 36
36 // command line option handling 37 // command line option handling
37 const char *argp_program_version = "LWLINK from " PACKAGE_STRING; 38 #define PROGVER "lwlink from " PACKAGE_STRING
38 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
39 39
40 static error_t parse_opts(int key, char *arg, struct argp_state *state) 40 static int parse_opts(int key, char *arg, void *state)
41 { 41 {
42 switch (key) 42 switch (key)
43 { 43 {
44 case 'o': 44 case 'o':
45 // output 45 // output
78 { 78 {
79 fprintf(stderr, "Invalid output format: %s\n", arg); 79 fprintf(stderr, "Invalid output format: %s\n", arg);
80 exit(1); 80 exit(1);
81 } 81 }
82 break; 82 break;
83 case ARGP_KEY_END: 83 case lw_cmdline_key_end:
84 // done; sanity check 84 // done; sanity check
85 if (!outfile) 85 if (!outfile)
86 outfile = "a.out"; 86 outfile = "a.out";
87 break; 87 break;
88 88
100 100
101 case 'm': 101 case 'm':
102 map_file = arg; 102 map_file = arg;
103 break; 103 break;
104 104
105 case ARGP_KEY_ARG: 105 case lw_cmdline_key_arg:
106 add_input_file(arg); 106 add_input_file(arg);
107 break; 107 break;
108 108
109 default: 109 default:
110 return ARGP_ERR_UNKNOWN; 110 return lw_cmdline_err_unknown;
111 } 111 }
112 return 0; 112 return 0;
113 } 113 }
114 114
115 static struct argp_option options[] = 115 static struct lw_cmdline_options options[] =
116 { 116 {
117 { "output", 'o', "FILE", 0, 117 { "output", 'o', "FILE", 0,
118 "Output to FILE"}, 118 "Output to FILE"},
119 { "debug", 'd', 0, 0, 119 { "debug", 'd', 0, 0,
120 "Set debug mode"}, 120 "Set debug mode"},
135 { "map", 'm', "FILE", 0, 135 { "map", 'm', "FILE", 0,
136 "Output informaiton about the link" }, 136 "Output informaiton about the link" },
137 { 0 } 137 { 0 }
138 }; 138 };
139 139
140 static struct argp argp = 140 static struct lw_cmdline_parser cmdline_parser =
141 { 141 {
142 options, 142 options,
143 parse_opts, 143 parse_opts,
144 "<input file> ...", 144 "INPUTFILE ...",
145 "LWLINK, a HD6309 and MC6809 cross-linker" 145 "lwlink, a HD6309 and MC6809 cross-linker",
146 PROGVER
146 }; 147 };
147 148
148 extern void read_files(void); 149 extern void read_files(void);
149 extern void setup_script(void); 150 extern void setup_script(void);
150 extern void resolve_files(void); 151 extern void resolve_files(void);
157 // assembler on the first file 158 // assembler on the first file
158 int main(int argc, char **argv) 159 int main(int argc, char **argv)
159 { 160 {
160 program_name = argv[0]; 161 program_name = argv[0];
161 162
162 argp_parse(&argp, argc, argv, 0, 0, NULL); 163 lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, NULL);
163 if (ninputfiles == 0) 164 if (ninputfiles == 0)
164 { 165 {
165 fprintf(stderr, "No input files\n"); 166 fprintf(stderr, "No input files\n");
166 exit(1); 167 exit(1);
167 } 168 }