annotate lwdisasm/main.c @ 408:2a94b2e64621

Started creation of lwdisasm
author lost@l-w.ca
date Mon, 02 Aug 2010 13:24:07 -0600
parents
children cba03436c720
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
408
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
1 /*
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
2 main.c
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
3
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
4 Copyright © 2010 William Astle
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
5
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
6 This file is part of LWTOOLS.
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
7
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
11 version.
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
12
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
16 more details.
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
17
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
20 */
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
21
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
22 #include <config.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
23
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
24 #include <argp.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
25 #include <stdio.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
26 #include <stdlib.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
27
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
28 #include <lw_alloc.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
29 #include <lw_string.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
30
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
31 #include "lwdisasm.h"
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
32
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
33 /* command line option handling */
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
34 const char *argp_program_version = "lwdisasmasm from " PACKAGE_STRING;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
35 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
36 char *program_name;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
37
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
38 static struct argp_option options[] =
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
39 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
40 { "output", 'o', "FILE", 0, "Output to FILE"},
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
41 { "debug", 'd', "LEVEL", OPTION_ARG_OPTIONAL, "Set debug mode"},
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
42 { "format", 'f', "TYPE", 0, "Select input format: decb, raw, obj, os9"},
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
43 { "decb", 'b', 0, 0, "Read DECB .bin format input, equivalent of --format=decb"},
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
44 { "raw", 'r', 0, 0, "Read raw binary format input, equivalent of --format=raw"},
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
45 { "obj", 0x100, 0, 0, "Read proprietary object file format, equivalent of --format=obj" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
46 { "6809", '9', 0, 0, "Set disassembler to 6809 only mode" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
47 { "6309", '3', 0, 0, "Set disassembler to 6309 mode (default)" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
48 { "data", 0x101, "RANGE", 0, "Set an address range as data" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
49 { "code", 0x102, "RANGE", 0, "Set an address range as code" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
50 { "entry", 0x103, "ADDR", 0, "Start disassembling at ADDR" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
51 { "base", 0x104, "ADDR", 0, "Set the base address of a raw file" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
52 { 0 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
53 };
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
54
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
55
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
56 static error_t parse_opts(int key, char *arg, struct argp_state *state)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
57 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
58 disasmstate_t *as = state -> input;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
59 int rangelow, rangehigh;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
60 char *e;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
61
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
62 switch (key)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
63 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
64
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
65 case 0x101: // data range
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
66 rangelow = strtol(arg, &e, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
67 if (*e != ':')
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
68 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
69 fprintf(stderr, "Invalid range: %s\n", arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
70 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
71 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
72 rangehigh = strtol(e + 1, NULL, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
73 if (rangelow < 0 || rangehigh < 0 || rangehigh < rangelow)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
74 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
75 fprintf(stderr, "Invalid range: %s\n", arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
76 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
77 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
78 // register the range as data
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
79 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
80
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
81 case 0x102: // code range
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
82 rangelow = strtol(arg, &e, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
83 if (*e != ':')
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
84 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
85 fprintf(stderr, "Invalid range: %s\n", arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
86 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
87 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
88 rangehigh = strtol(e + 1, NULL, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
89 if (rangelow < 0 || rangehigh < 0 || rangehigh < rangelow)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
90 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
91 fprintf(stderr, "Invalid range: %s\n", arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
92 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
93 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
94 // register the range as code
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
95 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
96
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
97 case 0x103: // entry
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
98 as -> entry = strtol(arg, NULL, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
99 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
100
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
101 case 0x104: // base
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
102 as -> base = strtol(arg, NULL, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
103 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
104
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
105 case 'o':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
106 if (as -> output_file)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
107 lw_free(as -> output_file);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
108 as -> output_file = lw_strdup(arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
109 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
110
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
111 case 'd':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
112 if (!arg)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
113 as -> debug_level = 50;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
114 else
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
115 as -> debug_level = atoi(arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
116 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
117
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
118 case 'b':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
119 as -> input_type = INPUT_DECB;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
120 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
121
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
122 case 'r':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
123 as -> input_type = INPUT_RAW;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
124 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
125
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
126 case 0x100:
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
127 as -> input_type = INPUT_OBJ;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
128 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
129
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
130 case 'f':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
131 if (!strcasecmp(arg, "decb"))
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
132 as -> input_type = INPUT_DECB;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
133 else if (!strcasecmp(arg, "raw"))
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
134 as -> input_type = INPUT_RAW;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
135 else if (!strcasecmp(arg, "obj"))
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
136 as -> input_type = INPUT_OBJ;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
137 else if (!strcasecmp(arg, "os9"))
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
138 as -> input_type = INPUT_OS9;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
139 else
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
140 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
141 fprintf(stderr, "Invalid input format: %s\n", arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
142 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
143 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
144 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
145
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
146 case '9':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
147 as -> target = TARGET_6809;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
148 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
149
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
150 case '3':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
151 as -> target = TARGET_6309;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
152 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
153
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
154 case ARGP_KEY_END:
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
155 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
156
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
157 case ARGP_KEY_ARG:
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
158 if (as -> input_file)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
159 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
160 fprintf(stderr, "Only one input file allowed\n");
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
161 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
162 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
163 as -> input_file = lw_strdup(arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
164 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
165
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
166 default:
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
167 return ARGP_ERR_UNKNOWN;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
168 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
169 return 0;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
170 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
171
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
172 static struct argp argp =
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
173 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
174 options,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
175 parse_opts,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
176 "<input file>",
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
177 "LWDISASM, a HD6309 and MC6809 disassembler"
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
178 };
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
179
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
180 /*
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
181 main function; parse command line, set up disassembler state, and run the
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
182 disassembler on the first file
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
183 */
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
184
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
185 int main(int argc, char **argv)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
186 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
187 disasmstate_t as = { 0 };
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
188 FILE *fp;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
189
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
190 /* assembler state */
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
191 program_name = argv[0];
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
192
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
193 /* parse command line arguments */
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
194 argp_parse(&argp, argc, argv, 0, 0, &as);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
195
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
196 if (as.input_file == NULL)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
197 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
198 fprintf(stderr, "No input files specified.\n");
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
199 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
200 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
201
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
202 fp = fopen(as.input_file, "rb");
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
203 if (!fp)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
204 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
205 perror("Cannot open input file");
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
206 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
207 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
208
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
209 fseek(fp, 0, SEEK_END);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
210 as.filelen = ftell(fp);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
211 rewind(fp);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
212
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
213 as.filedata = lw_alloc(as.filelen);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
214 0 == fread(as.filedata, as.filelen, 1, fp);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
215
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
216 fclose(fp);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
217
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
218 exit(0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
219 }