]> git.sur5r.net Git - cc65/blobdiff - src/co65/main.c
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / src / co65 / main.c
index adb1766374d39627372e4a286da6b5191cba8fc9..79aca87fa794860868982b1acb456674c3db02bf 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                 main.c                                   */
+/*                                  main.c                                   */
 /*                                                                           */
 /*              Main program for the co65 object file converter              */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2003      Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2003-2009, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -60,7 +60,7 @@
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
 static void Usage (void)
 /* Print usage information and exit */
 {
-    fprintf (stderr,
-            "Usage: %s [options] file\n"
-            "Short options:\n"
-                    "  -V\t\t\tPrint the version number\n"
-                    "  -g\t\t\tAdd debug info to object file\n"
-                    "  -h\t\t\tHelp (this text)\n"
-             "  -m model\t\tOverride the o65 model\n"
-             "  -n\t\t\tDon't generate an output file\n"
-                    "  -o name\t\tName the output file\n"
-                    "  -v\t\t\tIncrease verbosity\n"
-            "\n"
-            "Long options:\n"
-             "  --bss-label name\tDefine and export a BSS segment label\n"
-            "  --bss-name seg\tSet the name of the BSS segment\n"
-             "  --code-label name\tDefine and export a CODE segment label\n"
-                    "  --code-name seg\tSet the name of the CODE segment\n"
-             "  --data-label name\tDefine and export a DATA segment label\n"
-                    "  --data-name seg\tSet the name of the DATA segment\n"
-                    "  --debug-info\t\tAdd debug info to object file\n"
-            "  --help\t\tHelp (this text)\n"
-             "  --no-output\t\tDon't generate an output file\n"
-             "  --o65-model model\tOverride the o65 model\n"
-                    "  --verbose\t\tIncrease verbosity\n"
-                    "  --version\t\tPrint the version number\n"
-             "  --zeropage-label name\tDefine and export a ZEROPAGE segment label\n"
-                    "  --zeropage-name seg\tSet the name of the ZEROPAGE segment\n",
-            ProgName);
+    printf ("Usage: %s [options] file\n"
+            "Short options:\n"
+            "  -V\t\t\tPrint the version number\n"
+            "  -g\t\t\tAdd debug info to object file\n"
+            "  -h\t\t\tHelp (this text)\n"
+            "  -m model\t\tOverride the o65 model\n"
+            "  -n\t\t\tDon't generate an output file\n"
+            "  -o name\t\tName the output file\n"
+            "  -v\t\t\tIncrease verbosity\n"
+            "\n"
+            "Long options:\n"
+            "  --bss-label name\tDefine and export a BSS segment label\n"
+            "  --bss-name seg\tSet the name of the BSS segment\n"
+            "  --code-label name\tDefine and export a CODE segment label\n"
+            "  --code-name seg\tSet the name of the CODE segment\n"
+            "  --data-label name\tDefine and export a DATA segment label\n"
+            "  --data-name seg\tSet the name of the DATA segment\n"
+            "  --debug-info\t\tAdd debug info to object file\n"
+            "  --help\t\tHelp (this text)\n"
+            "  --no-output\t\tDon't generate an output file\n"
+            "  --o65-model model\tOverride the o65 model\n"
+            "  --verbose\t\tIncrease verbosity\n"
+            "  --version\t\tPrint the version number\n"
+            "  --zeropage-label name\tDefine and export a ZEROPAGE segment label\n"
+            "  --zeropage-name seg\tSet the name of the ZEROPAGE segment\n",
+            ProgName);
 }
 
 
@@ -124,7 +123,7 @@ static void CheckSegName (const char* Seg)
 {
     /* Print an error and abort if the name is not ok */
     if (!ValidSegName (Seg)) {
-       Error ("Segment name `%s' is invalid", Seg);
+        Error ("Segment name `%s' is invalid", Seg);
     }
 }
 
@@ -203,7 +202,7 @@ static void OptDataName (const char* Opt attribute ((unused)), const char* Arg)
 
 
 static void OptDebug (const char* Opt attribute ((unused)),
-                     const char* Arg attribute ((unused)))
+                      const char* Arg attribute ((unused)))
 /* Enable debugging code */
 {
     ++Debug;
@@ -212,7 +211,7 @@ static void OptDebug (const char* Opt attribute ((unused)),
 
 
 static void OptDebugInfo (const char* Opt attribute ((unused)),
-                         const char* Arg attribute ((unused)))
+                          const char* Arg attribute ((unused)))
 /* Add debug info to the object file */
 {
     DebugInfo = 1;
@@ -221,7 +220,7 @@ static void OptDebugInfo (const char* Opt attribute ((unused)),
 
 
 static void OptHelp (const char* Opt attribute ((unused)),
-                    const char* Arg attribute ((unused)))
+                     const char* Arg attribute ((unused)))
 /* Print usage information and exit */
 {
     Usage ();
@@ -231,7 +230,7 @@ static void OptHelp (const char* Opt attribute ((unused)),
 
 
 static void OptNoOutput (const char* Opt attribute ((unused)),
-                        const char* Arg attribute ((unused)))
+                         const char* Arg attribute ((unused)))
 /* Handle the --no-output option */
 {
     NoOutput = 1;
@@ -252,7 +251,7 @@ static void OptO65Model (const char* Opt attribute ((unused)), const char* Arg)
 
 
 static void OptVerbose (const char* Opt attribute ((unused)),
-                       const char* Arg attribute ((unused)))
+                        const char* Arg attribute ((unused)))
 /* Increase verbosity */
 {
     ++Verbosity;
@@ -261,12 +260,10 @@ static void OptVerbose (const char* Opt attribute ((unused)),
 
 
 static void OptVersion (const char* Opt attribute ((unused)),
-                       const char* Arg attribute ((unused)))
+                        const char* Arg attribute ((unused)))
 /* Print the assembler version */
 {
-    fprintf (stderr,
-                    "co65 V%u.%u.%u - (C) Copyright 1998-2003 Ullrich von Bassewitz\n",
-                    VER_MAJOR, VER_MINOR, VER_PATCH);
+    fprintf (stderr, "co65 V%s\n", GetVersionAsString ());
 }
 
 
@@ -295,14 +292,14 @@ static void OptZeropageName (const char* Opt attribute ((unused)), const char* A
 
 
 
-static void ConvertOneFile (const char* InputFile, const char* OutputFile)
+static void DoConversion (void)
 /* Do file conversion */
 {
     /* Read the o65 file into memory */
-    O65Data* D = ReadO65File (InputFile);
+    O65Data* D = ReadO65File (InputName);
 
     /* Do the conversion */
-    Convert (D, OutputFile);
+    Convert (D);
 
     /* Free the o65 module data */
     /* ### */
@@ -316,21 +313,21 @@ int main (int argc, char* argv [])
 {
     /* Program long options */
     static const LongOpt OptTab[] = {
-               { "--bss-label",        1,      OptBssLabel             },
-       { "--bss-name",         1,      OptBssName              },
-               { "--code-label",       1,      OptCodeLabel            },
-       { "--code-name",        1,      OptCodeName             },
-               { "--data-label",       1,      OptDataLabel            },
-       { "--data-name",        1,      OptDataName             },
-               { "--debug",            0,      OptDebug                },
-       { "--debug-info",       0,      OptDebugInfo            },
-       { "--help",             0,      OptHelp                 },
-               { "--no-output",        0,      OptNoOutput             },
+        { "--bss-label",        1,      OptBssLabel             },
+        { "--bss-name",         1,      OptBssName              },
+        { "--code-label",       1,      OptCodeLabel            },
+        { "--code-name",        1,      OptCodeName             },
+        { "--data-label",       1,      OptDataLabel            },
+        { "--data-name",        1,      OptDataName             },
+        { "--debug",            0,      OptDebug                },
+        { "--debug-info",       0,      OptDebugInfo            },
+        { "--help",             0,      OptHelp                 },
+        { "--no-output",        0,      OptNoOutput             },
         { "--o65-model",        1,      OptO65Model             },
-       { "--verbose",          0,      OptVerbose              },
-       { "--version",          0,      OptVersion              },
-               { "--zeropage-label",   1,      OptZeropageLabel        },
-               { "--zeropage-name",    1,      OptZeropageName         },
+        { "--verbose",          0,      OptVerbose              },
+        { "--version",          0,      OptVersion              },
+        { "--zeropage-label",   1,      OptZeropageLabel        },
+        { "--zeropage-name",    1,      OptZeropageName         },
     };
 
     unsigned I;
@@ -342,24 +339,24 @@ int main (int argc, char* argv [])
     I = 1;
     while (I < ArgCount) {
 
-               /* Get the argument */
-               const char* Arg = ArgVec [I];
+        /* Get the argument */
+        const char* Arg = ArgVec [I];
 
-               /* Check for an option */
-               if (Arg [0] == '-') {
-                   switch (Arg [1]) {
+        /* Check for an option */
+        if (Arg [0] == '-') {
+            switch (Arg [1]) {
 
-               case '-':
-                   LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
-                   break;
+                case '-':
+                    LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
+                    break;
 
-               case 'g':
-                   OptDebugInfo (Arg, 0);
-                   break;
+                case 'g':
+                    OptDebugInfo (Arg, 0);
+                    break;
 
-               case 'h':
-                   OptHelp (Arg, 0);
-                   break;
+                case 'h':
+                    OptHelp (Arg, 0);
+                    break;
 
                 case 'm':
                     OptO65Model (Arg, GetArg (&I, 2));
@@ -369,39 +366,39 @@ int main (int argc, char* argv [])
                     OptNoOutput (Arg, 0);
                     break;
 
-                       case 'o':
-                           OutputName = GetArg (&I, 2);
-                           break;
-
-                       case 'v':
-                   OptVerbose (Arg, 0);
-                           break;
-
-                       case 'V':
-                   OptVersion (Arg, 0);
-                           break;
-
-                       default:
-                           UnknownOption (Arg);
-                   break;
-
-           }
-               } else {
-           /* Filename. Check if we already had one */
-           if (InputName) {
-               Error ("Don't know what to do with `%s'\n", Arg);
-           } else {
-               InputName = Arg;
-           }
-       }
-
-       /* Next argument */
-       ++I;
+                case 'o':
+                    OutputName = GetArg (&I, 2);
+                    break;
+
+                case 'v':
+                    OptVerbose (Arg, 0);
+                    break;
+
+                case 'V':
+                    OptVersion (Arg, 0);
+                    break;
+
+                default:
+                    UnknownOption (Arg);
+                    break;
+
+            }
+        } else {
+            /* Filename. Check if we already had one */
+            if (InputName) {
+                Error ("Don't know what to do with `%s'", Arg);
+            } else {
+                InputName = Arg;
+            }
+        }
+
+        /* Next argument */
+        ++I;
     }
 
     /* Do we have an input file? */
     if (InputName == 0) {
-               Error ("No input file\n");
+        Error ("No input file");
     }
 
     /* Generate the name of the output file if none was specified */
@@ -410,7 +407,7 @@ int main (int argc, char* argv [])
     }
 
     /* Do the conversion */
-    ConvertOneFile (InputName, OutputName);
+    DoConversion ();
 
     /* Return an apropriate exit code */
     return EXIT_SUCCESS;