]> git.sur5r.net Git - cc65/blobdiff - src/cc65/main.c
Changed names of the pragmas to be identical to the corresponding command line
[cc65] / src / cc65 / main.c
index c058f13de9e65fa7af3827c20e195a346aef7ef9..3785716dfafc1bdaa7e543757df16ec88f24cbfd 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2004 Ullrich von Bassewitz                                       */
-/*               Römerstraße 52                                              */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2000-2009, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -48,6 +48,7 @@
 #include "mmodel.h"
 #include "print.h"
 #include "segnames.h"
+#include "strbuf.h"
 #include "target.h"
 #include "tgttrans.h"
 #include "version.h"
 #include "incpath.h"
 #include "input.h"
 #include "macrotab.h"
+#include "output.h"
 #include "scanner.h"
-#include "standard.h"
 #include "segments.h"
+#include "standard.h"
+#include "svnversion.h"
 
 
 
@@ -175,10 +178,6 @@ static void SetSys (const char* Sys)
            cbmsys ("__C128__");
            break;
 
-       case TGT_ACE:
-           cbmsys ("__ACE__");
-           break;
-
        case TGT_PLUS4:
            cbmsys ("__PLUS4__");
            break;
@@ -665,12 +664,59 @@ static void OptVerbose (const char* Opt attribute ((unused)),
 
 
 static void OptVersion (const char* Opt attribute ((unused)),
-                       const char* Arg attribute ((unused)))
-/* Print the assembler version */
+                       const char* Arg attribute ((unused)))
+/* Print the compiler version */
 {
     fprintf (stderr,
-                    "cc65 V%u.%u.%u\n",
-                    VER_MAJOR, VER_MINOR, VER_PATCH);
+                    "cc65 V%s\nSVN version: %s\n",
+                    GetVersionAsString (), SVNVersion);
+    exit (EXIT_SUCCESS);
+}
+
+
+
+static void OptWarning (const char* Opt attribute ((unused)), const char* Arg)
+/* Handle the -W option */
+{
+    StrBuf W = AUTO_STRBUF_INITIALIZER;
+
+    /* Arg is a list of suboptions, separated by commas */
+    while (Arg) {
+
+        const char* Pos;
+        int         Enabled = 1;
+        IntStack*   S;
+
+        /* The suboption may be prefixed with '-' or '+' */
+        if (*Arg == '-') {
+            Enabled = 0;
+            ++Arg;
+        } else if (*Arg == '+') {
+            /* This is the default */
+            ++Arg;
+        }
+
+        /* Get the next suboption */
+        Pos = strchr (Arg, ',');
+        if (Pos) {
+            SB_CopyBuf (&W, Arg, Pos - Arg);
+            Arg = Pos + 1;
+        } else {
+            SB_CopyStr (&W, Arg);
+            Arg = 0;
+        }
+        SB_Terminate (&W);
+
+        /* Search for the warning */
+        S = FindWarning (SB_GetConstBuf (&W));
+        if (S == 0) {
+            InvArg (Opt, SB_GetConstBuf (&W));
+        }
+        IS_Set (S, Enabled);
+    }
+
+    /* Free allocated memory */
+    SB_Done (&W);
 }
 
 
@@ -720,8 +766,7 @@ int main (int argc, char* argv[])
 
     unsigned I;
 
-    /* Initialize the output file name */
-    const char* OutputFile = 0;
+    /* Initialize the input file name */
     const char* InputFile  = 0;
 
     /* Initialize the cmdline module */
@@ -743,9 +788,9 @@ int main (int argc, char* argv[])
                const char* Arg = ArgVec[I];
 
                /* Check for an option */
-               if (Arg [0] == '-') {
+               if (Arg[0] == '-') {
 
-                   switch (Arg [1]) {
+                   switch (Arg[1]) {
 
                case '-':
                    LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
@@ -769,7 +814,7 @@ int main (int argc, char* argv[])
                    break;
 
                case 'o':
-                   OutputFile = GetArg (&I, 2);
+                   SetOutputName (GetArg (&I, 2));
                    break;
 
                 case 'r':
@@ -798,7 +843,7 @@ int main (int argc, char* argv[])
                            default:
                                UnknownOption (Arg);
                                break;
-                       }
+                       }
                    }
                    break;
 
@@ -841,7 +886,7 @@ int main (int argc, char* argv[])
                            break;
 
                        case 'W':
-                           IS_Set (&WarnDisable, 1);
+                    OptWarning (Arg, GetArg (&I, 2));
                            break;
 
                        default:
@@ -866,9 +911,7 @@ int main (int argc, char* argv[])
     }
 
     /* Create the output file name if it was not explicitly given */
-    if (OutputFile == 0) {
-       OutputFile = MakeFilename (InputFile, ".s");
-    }
+    MakeDefaultOutputName (InputFile);
 
     /* If no CPU given, use the default CPU for the target */
     if (CPU == CPU_UNKNOWN) {
@@ -893,29 +936,21 @@ int main (int argc, char* argv[])
     Compile (InputFile);
 
     /* Create the output file if we didn't had any errors */
-    if (ErrorCount == 0 || Debug) {
+    if (PreprocessOnly == 0 && (ErrorCount == 0 || Debug)) {
 
        /* Open the file */
-       FILE* F = fopen (OutputFile, "w");
-       if (F == 0) {
-           Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno));
-       }
-       Print (stdout, 1, "Opened output file `%s'\n", OutputFile);
+        OpenOutputFile ();
 
        /* Write the output to the file */
-       WriteOutput (F);
-               Print (stdout, 1, "Wrote output to `%s'\n", OutputFile);
+               WriteAsmOutput ();
+               Print (stdout, 1, "Wrote output to `%s'\n", OutputFilename);
 
        /* Close the file, check for errors */
-       if (fclose (F) != 0) {
-           remove (OutputFile);
-           Fatal ("Cannot write to output file (disk full?)");
-       }
-               Print (stdout, 1, "Closed output file `%s'\n", OutputFile);
+        CloseOutputFile ();
 
        /* Create dependencies if requested */
        if (CreateDep) {
-           DoCreateDep (OutputFile);
+           DoCreateDep (OutputFilename);
            Print (stdout, 1, "Creating dependeny file\n");
        }