1 /*****************************************************************************/
5 /* Output format/file definitions for the sp65 sprite and bitmap utility */
9 /* (C) 2012, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
50 /*****************************************************************************/
52 /*****************************************************************************/
56 typedef struct OutputFormatDesc OutputFormatDesc;
57 struct OutputFormatDesc {
60 void (*Write) (const StrBuf*, const Collection*);
64 /* Table with Output formats */
65 static OutputFormatDesc OutputFormatTable[ofCount] = {
70 /* Table that maps extensions to Output formats. Must be sorted alphabetically */
71 static const FileId FormatTable[] = {
72 /* Upper case stuff for obsolete operating systems */
88 /*****************************************************************************/
90 /*****************************************************************************/
94 void WriteOutputFile (const StrBuf* Data, const Collection* A)
95 /* Write the contents of Data to a file. Format, file name etc. must be given
96 * as attributes in A. If no format is given, the function tries to autodetect
97 * it by using the extension of the file name.
102 /* Get the file format from the command line */
103 const char* Format = GetAttrVal (A, "format");
105 /* Format is given, search for it in the table. */
108 sizeof (FormatTable) / sizeof (FormatTable[0]),
109 sizeof (FormatTable[0]),
112 Error ("Unknown output format `%s'", Format);
115 /* No format given, use file name extension */
116 const char* Name = NeedAttrVal (A, "name", "write");
117 F = GetFileId (Name, FormatTable,
118 sizeof (FormatTable) / sizeof (FormatTable[0]));
121 Error ("Cannot determine file format of output file `%s'", Name);
125 /* Call the format specific write */
126 OutputFormatTable[F->Id].Write (Data, A);