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 " --dump-options\t\tDump object file options\n"
82 " --help\t\tHelp (this text)\n"
83 " --version\t\tPrint the version number and exit\n",
89 static void OptDumpHeader (const char* Opt, const char* Arg)
90 /* Dump the object file header */
97 static void OptDumpOptions (const char* Opt, const char* Arg)
98 /* Dump the object file options */
105 static void OptHelp (const char* Opt, const char* Arg)
106 /* Print usage information and exit */
114 static void OptVersion (const char* Opt, const char* Arg)
115 /* Print the assembler version */
118 "%s V%u.%u.%u - (C) Copyright 2000 Ullrich von Bassewitz\n",
119 ProgName, VER_MAJOR, VER_MINOR, VER_PATCH);
124 static void DumpFile (const char* Name)
125 /* Dump information from the named file */
129 /* Try to open the file */
130 FILE* F = fopen (Name, "rb");
132 Warning ("Cannot open `%s': %s", Name, strerror (errno));
135 /* Read the magic word */
138 /* Do we know this type of file? */
139 if (Magic != OBJ_MAGIC) {
142 printf ("%s: (no x65 object file)\n", Name);
144 } else if (What == 0) {
146 /* Special handling if no info was requested */
147 printf ("%s: (no information requested)\n", Name);
151 /* Print the filename */
152 printf ("%s:\n", Name);
154 /* Check what to dump */
155 if (What & D_HEADER) {
156 DumpObjHeader (F, 0);
158 if (What & D_OPTIONS) {
159 DumpObjOptions (F, 0);
169 int main (int argc, char* argv [])
170 /* Assembler main program */
172 /* Program long options */
173 static const LongOpt OptTab[] = {
174 { "--dump-header", 0, OptDumpHeader },
175 { "--dump-options", 0, OptDumpOptions },
176 { "--help", 0, OptHelp },
177 { "--version", 0, OptVersion },
182 /* Initialize the cmdline module */
183 InitCmdLine (argc, argv, "od65");
185 /* Check the parameters */
189 /* Get the argument */
190 const char* Arg = argv [I];
192 /* Check for an option */
193 if (Arg [0] == '-') {
197 LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
205 OptDumpHeader (Arg, 0);
218 /* Filename. Dump it. */
227 /* Print a message if we did not process any files */
228 if (FilesProcessed == 0) {
229 fprintf (stderr, "%s: No input files\n", ProgName);