-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.
FormatTable,
sizeof (FormatTable) / sizeof (FormatTable[0]),
sizeof (FormatTable[0]),
- Compare);
+ CompareFileId);
/* Return the id or an error code */
return (F == 0)? -1 : F->Id;
#include "attr.h"
#include "error.h"
#include "input.h"
+#include "output.h"
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);
}
+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 */
{
{ "--slice", 1, OptSlice },
{ "--verbose", 0, OptVerbose },
{ "--version", 0, OptVersion },
+ { "--write", 1, OptWrite },
};
unsigned I;
+#include <stdlib.h>
+
/* common */
#include "fileid.h"
+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.