1 /*****************************************************************************/
5 /* Main program of the od65 object file dump utility */
9 /* (C) 2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
54 /*****************************************************************************/
56 /*****************************************************************************/
60 static unsigned FilesProcessed = 0;
64 /*****************************************************************************/
66 /*****************************************************************************/
70 static void Usage (void)
71 /* Print usage information and exit */
74 "Usage: %s [options] file [options] [file]\n"
76 " -h\t\t\tHelp (this text)\n"
77 " -V\t\t\tPrint the version number and exit\n"
80 " --dump-all\t\tDump all object file information\n"
81 " --dump-dbgsyms\tDump debug symbols\n"
82 " --dump-exports\tDump exported symbols\n"
83 " --dump-files\t\tDump the source files\n"
84 " --dump-header\t\tDump the object file header\n"
85 " --dump-imports\tDump imported symbols\n"
86 " --dump-options\tDump object file options\n"
87 " --dump-segments\tDump the segments in the file\n"
88 " --help\t\tHelp (this text)\n"
89 " --version\t\tPrint the version number and exit\n",
95 static void OptDumpAll (const char* Opt, const char* Arg)
96 /* Dump all object file information */
103 static void OptDumpDbgSyms (const char* Opt, const char* Arg)
104 /* Dump debug symbols contained in the object file */
111 static void OptDumpExports (const char* Opt, const char* Arg)
112 /* Dump the exported symbols */
119 static void OptDumpFiles (const char* Opt, const char* Arg)
120 /* Dump the source files */
127 static void OptDumpHeader (const char* Opt, const char* Arg)
128 /* Dump the object file header */
135 static void OptDumpImports (const char* Opt, const char* Arg)
136 /* Dump the imported symbols */
143 static void OptDumpOptions (const char* Opt, const char* Arg)
144 /* Dump the object file options */
151 static void OptDumpSegments (const char* Opt, const char* Arg)
152 /* Dump the segments in the object file */
159 static void OptHelp (const char* Opt, const char* Arg)
160 /* Print usage information and exit */
168 static void OptVersion (const char* Opt, const char* Arg)
169 /* Print the assembler version */
172 "%s V%u.%u.%u - (C) Copyright 2000 Ullrich von Bassewitz\n",
173 ProgName, VER_MAJOR, VER_MINOR, VER_PATCH);
178 static void DumpFile (const char* Name)
179 /* Dump information from the named file */
183 /* Try to open the file */
184 FILE* F = fopen (Name, "rb");
186 Warning ("Cannot open `%s': %s", Name, strerror (errno));
189 /* Read the magic word */
192 /* Do we know this type of file? */
193 if (Magic != OBJ_MAGIC) {
196 printf ("%s: (no xo65 object file)\n", Name);
198 } else if (What == 0) {
200 /* Special handling if no info was requested */
201 printf ("%s: (no information requested)\n", Name);
205 /* Print the filename */
206 printf ("%s:\n", Name);
208 /* Check what to dump */
209 if (What & D_HEADER) {
210 DumpObjHeader (F, 0);
212 if (What & D_OPTIONS) {
213 DumpObjOptions (F, 0);
215 if (What & D_FILES) {
218 if (What & D_SEGMENTS) {
219 DumpObjSegments (F, 0);
221 if (What & D_IMPORTS) {
222 DumpObjImports (F, 0);
224 if (What & D_EXPORTS) {
225 DumpObjExports (F, 0);
227 if (What & D_DBGSYMS) {
228 DumpObjDbgSyms (F, 0);
238 int main (int argc, char* argv [])
239 /* Assembler main program */
241 /* Program long options */
242 static const LongOpt OptTab[] = {
243 { "--dump-all", 0, OptDumpAll },
244 { "--dump-dbgsyms", 0, OptDumpDbgSyms },
245 { "--dump-exports", 0, OptDumpExports },
246 { "--dump-files", 0, OptDumpFiles },
247 { "--dump-header", 0, OptDumpHeader },
248 { "--dump-imports", 0, OptDumpImports },
249 { "--dump-options", 0, OptDumpOptions },
250 { "--dump-segments", 0, OptDumpSegments },
251 { "--help", 0, OptHelp },
252 { "--version", 0, OptVersion },
257 /* Initialize the cmdline module */
258 InitCmdLine (argc, argv, "od65");
260 /* Check the parameters */
264 /* Get the argument */
265 const char* Arg = argv [I];
267 /* Check for an option */
268 if (Arg [0] == '-') {
272 LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
280 OptDumpHeader (Arg, 0);
293 /* Filename. Dump it. */
302 /* Print a message if we did not process any files */
303 if (FilesProcessed == 0) {
304 fprintf (stderr, "%s: No input files\n", ProgName);