]> git.sur5r.net Git - cc65/commitdiff
Added the write routine.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 9 Mar 2012 11:46:16 +0000 (11:46 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 9 Mar 2012 11:46:16 +0000 (11:46 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5584 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/sp65/input.c
src/sp65/main.c
src/sp65/output.c
src/sp65/output.h

index a34e527e7977cfe536d12671bdac63d0dad05b15..6e3073f802ea13bfa97c7e72cf1922151272bed7 100644 (file)
@@ -80,14 +80,6 @@ static const FileId FormatTable[] = {
 
 
 
-static int Compare (const void* Key, const void* Id)
-/* Compare function for bsearch */
-{
-    return strcmp (Key, ((const FileId*) Id)->Ext);
-}
-
-
-
 int FindInputFormat (const char* Name)
 /* Find an input format by name. The function returns a value less than zero
  * if Name is not a known input format.
@@ -98,7 +90,7 @@ int FindInputFormat (const char* Name)
                                FormatTable,
                                sizeof (FormatTable) / sizeof (FormatTable[0]),
                                sizeof (FormatTable[0]),
-                               Compare);
+                               CompareFileId);
 
     /* Return the id or an error code */
     return (F == 0)? -1 : F->Id;
index 7a72f5a5ef612f40f152bac16ad87c006fd9dd08..db77b71095ccb24401a70fae244a1d67e7a4a21d 100644 (file)
@@ -48,6 +48,7 @@
 #include "attr.h"
 #include "error.h"
 #include "input.h"
+#include "output.h"
 
 
 
@@ -77,16 +78,18 @@ static void Usage (void)
     printf (
            "Usage: %s [options] file [options] [file]\n"
            "Short options:\n"
-                   "  -V\t\t\tPrint the version number and exit\n"
-                   "  -h\t\t\tHelp (this text)\n"
-            "  -v\t\t\tIncrease verbosity\n"
+                   "  -V\t\t\t\tPrint the version number and exit\n"
+                   "  -h\t\t\t\tHelp (this text)\n"
+            "  -v\t\t\t\tIncrease verbosity\n"
            "\n"
            "Long options:\n"
-           "  --help\t\tHelp (this text)\n"
-            "  --pop\t\t\tRestore the original loaded image\n"
-            "  --slice x,y,w,h\tGenerate a slice from the loaded bitmap\n"
-            "  --verbose\t\tIncrease verbosity\n"
-                   "  --version\t\tPrint the version number and exit\n",
+           "  --help\t\t\tHelp (this text)\n"
+            "  --pop\t\t\t\tRestore the original loaded image\n"
+            "  --read file[,attrlist]\tRead an input file\n"
+            "  --slice x,y,w,h\t\tGenerate a slice from the loaded bitmap\n"
+            "  --verbose\t\t\tIncrease verbosity\n"
+                   "  --version\t\t\tPrint the version number and exit\n"
+            "  --write file[,attrlist]\tWrite an output file\n",
            ProgName);
 }
 
@@ -221,6 +224,36 @@ static void OptVersion (const char* Opt attribute ((unused)),
 
 
 
+static void OptWrite (const char* Opt, const char* Arg)
+/* Write an output file */
+{
+    static const char* NameList[] = {
+        "name", "format"
+    };
+
+
+    /* Parse the argument */
+    Collection* A = ParseAttrList (Arg, NameList, 2);
+
+    /* Must have a file name given */
+    const char* FileName = NeedAttrVal (A, "name", Opt);
+
+    /* Determine the format of the input file */
+    int OF = ofAuto;
+    const char* Format = GetAttrVal (A, "format");
+    if (Format != 0) {
+        OF = FindOutputFormat (Format);
+        if (OF < 0) {
+            Error ("Unknown output format `%s'", Format);
+        }
+    }
+
+    /* Write the file */
+    WriteOutputFile (FileName, 0, OF);
+}
+
+
+
 int main (int argc, char* argv [])
 /* sp65 main program */
 {
@@ -232,6 +265,7 @@ int main (int argc, char* argv [])
         { "--slice",            1,      OptSlice                },
                { "--verbose",          0,      OptVerbose              },
        { "--version",          0,      OptVersion              },
+               { "--write",            1,      OptWrite                },
     };
 
     unsigned I;
index 102e4c35543017a1d8b16280fe00765d311a40ab..0dbe5282507f06d2c29bffd149e43dba238f8e8f 100644 (file)
@@ -33,6 +33,8 @@
 
 
 
+#include <stdlib.h>
+
 /* common */
 #include "fileid.h"
 
@@ -88,6 +90,24 @@ static const FileId FormatTable[] = {
 
 
 
+int FindOutputFormat (const char* Name)
+/* Find an output format by name. The function returns a value less than zero
+ * if Name is not a known output format.
+ */
+{
+    /* Search for the entry in the table. */
+    const FileId* F = bsearch (Name,
+                               FormatTable,
+                               sizeof (FormatTable) / sizeof (FormatTable[0]),
+                               sizeof (FormatTable[0]),
+                               CompareFileId);
+
+    /* Return the id or an error code */
+    return (F == 0)? -1 : F->Id;
+}
+
+
+
 void WriteOutputFile (const char* Name, const StrBuf* Data, OutputFormat Format)
 /* Write the contents of Data to the given file in the format specified. If
  * the format is ofAuto, it is determined by the file extension.
index 2f83993d8c18149dd46d67838cc54e3e669acadb..9b564b59dbd76e8f15817ad93ec5c0852685c42b 100644 (file)
@@ -67,6 +67,11 @@ typedef enum OutputFormat OutputFormat;
 
 
 
+int FindOutputFormat (const char* Name);
+/* Find an output format by name. The function returns a value less than zero
+ * if Name is not a known output format.
+ */
+
 void WriteOutputFile (const char* Name, const StrBuf* Data, OutputFormat Format);
 /* Write the contents of Data to the given file in the format specified. If
  * the format is ofAuto, it is determined by the file extension.