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\n"
76 " -h\t\t\tHelp (this text)\n"
77 " -V\t\t\tPrint the version number and exit\n"
80 " --dump-header\t\tDump the object file header\n"
81 " --help\t\tHelp (this text)\n"
82 " --version\t\tPrint the version number and exit\n",
88 static void OptDumpHeader (const char* Opt, const char* Arg)
89 /* Dump the object file header */
96 static void OptHelp (const char* Opt, const char* Arg)
97 /* Print usage information and exit */
105 static void OptVersion (const char* Opt, const char* Arg)
106 /* Print the assembler version */
109 "%s V%u.%u.%u - (C) Copyright 2000 Ullrich von Bassewitz\n",
110 ProgName, VER_MAJOR, VER_MINOR, VER_PATCH);
115 static void DumpFile (const char* Name)
116 /* Dump information from the named file */
120 /* Try to open the file */
121 FILE* F = fopen (Name, "rb");
123 Warning ("Cannot open `%s': %s", Name, strerror (errno));
126 /* Read the magic word */
129 /* Do we know this type of file? */
130 if (Magic != OBJ_MAGIC) {
133 printf ("%s: (no xo65 object file)\n", Name);
135 } else if (What == 0) {
137 /* Special handling if no info was requested */
138 printf ("%s: (no information requested)\n", Name);
142 /* Print the filename */
143 printf ("%s:\n", Name);
145 /* Check what to dump */
146 if (What & D_HEADER) {
158 int main (int argc, char* argv [])
159 /* Assembler main program */
161 /* Program long options */
162 static const LongOpt OptTab[] = {
163 { "--dump-header", 0, OptDumpHeader },
164 { "--help", 0, OptHelp },
165 { "--version", 0, OptVersion },
170 /* Initialize the cmdline module */
171 InitCmdLine (argc, argv, "od65");
173 /* Check the parameters */
177 /* Get the argument */
178 const char* Arg = argv [I];
180 /* Check for an option */
181 if (Arg [0] == '-') {
185 LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
193 OptDumpHeader (Arg, 0);
206 /* Filename. Dump it. */
215 /* Print a message if we did not process any files */
216 if (FilesProcessed == 0) {
217 fprintf (stderr, "%s: No input files\n", ProgName);