]> git.sur5r.net Git - cc65/blobdiff - src/ca65/options.c
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / src / ca65 / options.c
index 0af381818b0a76c734cd2efcc7584956fa804019..c71296a57ab6be6954bcf2cd8e28461d794273cb 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                options.c                                 */
+/*                                 options.c                                 */
 /*                                                                           */
-/*             Object file options for the ca65 macroassembler              */
+/*              Object file options for the ca65 macroassembler              */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 1998-2008, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 
 
-#include "../common/optdefs.h"
-#include "../common/xmalloc.h"
+#include <string.h>
 
+/* common */
+#include "optdefs.h"
+#include "xmalloc.h"
+
+/* ca65 */
 #include "error.h"
 #include "objfile.h"
 #include "options.h"
+#include "spool.h"
 
 
 
 /*****************************************************************************/
-/*                                          Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
 
 /* Option list */
-static Option*         OptRoot = 0;
-static Option*         OptLast = 0;
-static unsigned                OptCount = 0;
+static Option*          OptRoot = 0;
+static Option*          OptLast = 0;
+static unsigned         OptCount = 0;
 
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
 
-static Option* NewOption (unsigned char Type)
+static Option* NewOption (unsigned char Type, unsigned long Val)
 /* Create a new option, insert it into the list and return it */
 {
     Option* Opt;
@@ -72,13 +77,13 @@ static Option* NewOption (unsigned char Type)
     /* Initialize fields */
     Opt->Next  = 0;
     Opt->Type  = Type;
-    Opt->V.Str = 0;
+    Opt->Val   = Val;
 
     /* Insert it into the list */
     if (OptRoot == 0) {
-       OptRoot = Opt;
+        OptRoot = Opt;
     } else {
-               OptLast->Next = Opt;
+        OptLast->Next = Opt;
     }
     OptLast = Opt;
 
@@ -91,57 +96,50 @@ static Option* NewOption (unsigned char Type)
 
 
 
-void OptStr (unsigned char Type, const char* Text)
+void OptStr (unsigned char Type, const StrBuf* Text)
 /* Add a string option */
 {
-    Option* O;
-
-    /* String must have less than 255 bytes */
-    if (strlen (Text) > 255) {
-       Fatal (FAT_STRING_TOO_LONG);
-    }
-    O        = NewOption (Type);
-    O->V.Str = xstrdup (Text);
+    NewOption (Type, GetStrBufId (Text));
 }
 
 
 
-void OptComment (const char* Comment)
+void OptComment (const StrBuf* Comment)
 /* Add a comment */
 {
-    OptStr (OPT_COMMENT, Comment);
+    NewOption (OPT_COMMENT, GetStrBufId (Comment));
 }
 
 
 
-void OptAuthor (const char* Author)
+void OptAuthor (const StrBuf* Author)
 /* Add an author statement */
 {
-    OptStr (OPT_AUTHOR, Author);
+    NewOption (OPT_AUTHOR, GetStrBufId (Author));
 }
 
 
 
-void OptTranslator (const char* Translator)
+void OptTranslator (const StrBuf* Translator)
 /* Add a translator option */
 {
-    OptStr (OPT_TRANSLATOR, Translator);
+    NewOption (OPT_TRANSLATOR, GetStrBufId (Translator));
 }
 
 
 
-void OptCompiler (const char* Compiler)
+void OptCompiler (const StrBuf* Compiler)
 /* Add a compiler option */
 {
-    OptStr (OPT_COMPILER, Compiler);
+    NewOption (OPT_COMPILER, GetStrBufId (Compiler));
 }
 
 
 
-void OptOS (const char* OS)
+void OptOS (const StrBuf* OS)
 /* Add an operating system option */
 {
-    OptStr (OPT_OS, OS);
+    NewOption (OPT_OS, GetStrBufId (OS));
 }
 
 
@@ -149,8 +147,7 @@ void OptOS (const char* OS)
 void OptDateTime (unsigned long DateTime)
 /* Add a date/time option */
 {
-    Option* O = NewOption (OPT_DATETIME);
-    O->V.Val = DateTime;
+    NewOption (OPT_DATETIME, DateTime);
 }
 
 
@@ -164,33 +161,18 @@ void WriteOptions (void)
     ObjStartOptions ();
 
     /* Write the option count */
-    ObjWrite16 (OptCount);
+    ObjWriteVar (OptCount);
 
     /* Walk through the list and write the options */
     O = OptRoot;
     while (O) {
 
-       /* Write the type of the option */
-       ObjWrite8 (O->Type);
-
-       /* Write the argument */
-       switch (O->Type & OPT_ARGMASK) {
-
-           case OPT_ARGSTR:
-               ObjWriteStr (O->V.Str);
-               break;
-
-           case OPT_ARGNUM:
-               ObjWrite32 (O->V.Val);
-               break;
-
-           default:
-               Internal ("Invalid option type: $%02X", O->Type & 0xFF);
-
-       }
+        /* Write the type of the option, then the value */
+        ObjWrite8 (O->Type);
+        ObjWriteVar (O->Val);
 
-       /* Next option */
-       O = O->Next;
+        /* Next option */
+        O = O->Next;
 
     }
 
@@ -200,3 +182,4 @@ void WriteOptions (void)
 
 
 
+