Mercurial > hg > dmlib
annotate tools/data2inc.c @ 2416:377e96524145
Added signature for changeset a2c565ae8098
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 14 Jan 2020 02:10:09 +0200 |
parents | bc05bcfc4598 |
children | 1361e3883dd8 |
rev | line source |
---|---|
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * data2inc - Convert binary data to "C"-source or XA-compatible include file |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hamalainen |
2406 | 4 * (C) Copyright 2003,2009-2020 Tecnic Software productions (TNSP) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 */ |
1432
a9516570cc26
Improve build, so that we can build the tools and tests with minimal
Matti Hamalainen <ccr@tnsp.org>
parents:
1429
diff
changeset
|
8 #include "dmtool.h" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include "dmlib.h" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include "dmargs.h" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include "dmmutex.h" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
1433 | 13 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
14 #define SET_DEF_LINELEN 16 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
15 #define SET_MAX_FEXTS 16 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
16 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
18 // |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
19 // Types etc |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
20 // |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
21 typedef struct |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
23 char *name; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
24 char *desc; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
25 char *fexts[SET_MAX_FEXTS]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
26 |
2250
956db0095f82
Change struct member name.
Matti Hamalainen <ccr@tnsp.org>
parents:
2246
diff
changeset
|
27 char *defDataType; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
29 int (*writeHeader) (FILE *fh, const char *name); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
30 int (*writeDecl) (FILE *fh, const size_t len, const char *name); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
31 int (*writeData) (FILE *fh, const Uint8 *buf, const size_t len); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
32 int (*writeFooter) (FILE *fh, const size_t len, const char *name); |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
33 } DMOutputFormat; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
34 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
35 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
36 // |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
37 // Options |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
38 // |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 char *optInFilename = NULL, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 *optOutFilename = NULL, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 *optObjName = "default_object", |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 *optDataType = NULL, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 *optAddLine = NULL; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
45 const DMOutputFormat *setFormat = NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
46 int optIndentation = -1, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
47 optLineLen = SET_DEF_LINELEN; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 BOOL optHexMode = FALSE, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 optQuiet = FALSE, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 optExtraData = FALSE, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 optFormatting = TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
54 static const DMOptArg optList[] = |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 { |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
56 { 0, '?', "help" , "Show this help", OPT_NONE }, |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
57 { 1, 0, "license" , "Print out this program's license agreement", OPT_NONE }, |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
58 |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
59 { 10, 'n', "name" , "Set object name", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
60 { 12, 't', "type" , "Set datatype (unsigned char/byte)", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
61 { 14, 'f', "format" , "Set output format (see list below)", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
62 { 16, 'a', "add-line" , "Add this line to start of file", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
63 { 18, 'l', "line-items" , "Set number of items per line", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
64 { 20, 'x', "hexadecimal" , "Use hexadecimal output", OPT_NONE }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
65 { 22, 'q', "quiet" , "Do not add comments", OPT_NONE }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
66 { 24, 'N', "no-formatting" , "Disable additional output formatting", OPT_NONE }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
67 { 26, 'i', "indentation" , "Set indentation (negative value = tab)", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
68 { 28, 'e', "extra-data" , "Add object end labels and size in asm output", OPT_NONE }, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
72 static const DMOutputFormat dmFormatList[]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
73 static const int ndmFormatList; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 void argShowHelp() |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 dmPrintBanner(stdout, dmProgName, |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
79 "[options] [sourcefile] [destfile]"); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 |
2402
b7cd5dd0b82e
Merge one more change from th-libs args processing.
Matti Hamalainen <ccr@tnsp.org>
parents:
2286
diff
changeset
|
81 dmArgsPrintHelp(stdout, optList, optListN, 0, 80 - 2); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1107
diff
changeset
|
82 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
83 fprintf(stdout, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
84 "\n" |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
85 "Available output formats (-f <frmt>):\n" |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
86 " frmt | Description (filename extensions)\n" |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
87 "------+------------------------------------------\n"); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
88 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
89 for (int i = 0; i < ndmFormatList; i++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
90 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
91 const DMOutputFormat *fmt = &dmFormatList[i]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
92 fprintf(stdout, "%-5s | %s (", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
93 fmt->name, fmt->desc); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
94 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
95 for (int n = 0; n < SET_MAX_FEXTS && fmt->fexts[n] != NULL; n++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
96 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
97 fprintf(stdout, ".%s%s", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
98 fmt->fexts[n], |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
99 (n + 1 < SET_MAX_FEXTS && |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
100 fmt->fexts[n + 1] != NULL) ? " " : ""); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
101 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
102 fprintf(stdout, ")\n"); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
103 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
104 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
105 fprintf(stdout, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 "\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 "To convert a data file to a C structure using 'Uint8' as type:\n" |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
108 "$ data2inc -n variable_name -t Uint8 input.bin output.h\n" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 "\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 ); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 switch (optN) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 case 0: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 argShowHelp(); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 exit(0); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
123 case 1: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
124 dmPrintLicense(stdout); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
125 exit(0); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
126 break; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
127 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
128 case 10: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 optObjName = optArg; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
132 case 12: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 optDataType = optArg; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
136 case 14: |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
137 for (int i = 0; i < ndmFormatList; i++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
138 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
139 const DMOutputFormat *fmt = &dmFormatList[i]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
140 if (strcasecmp(fmt->name, optArg) == 0) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
141 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
142 setFormat = fmt; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
143 return TRUE; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
144 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
145 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
146 dmErrorMsg("Invalid format name '%s'.\n", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
147 optArg); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
148 return FALSE; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
149 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
150 case 16: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 optAddLine = optArg; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
154 case 18: |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
155 optLineLen = atoi(optArg); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
156 if (optLineLen < 1) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
157 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
158 dmErrorMsg("Invalid line length / number of items per line '%s'.\n", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
159 optArg); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
160 return FALSE; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
161 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 break; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
163 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
164 case 20: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 optHexMode = TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 break; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
167 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
168 case 22: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 optQuiet = TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 break; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
171 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
172 case 24: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 optFormatting = FALSE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
176 case 26: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 optIndentation = atoi(optArg); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
180 case 28: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 optExtraData = TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 default: |
2183
e3f0eaf23f4f
Change the error message for unimplemented option argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
1433
diff
changeset
|
185 dmErrorMsg("Unimplemented option argument '%s'.\n", currArg); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 return FALSE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 return TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 BOOL argHandleFile(char * currArg) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
195 if (optInFilename == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 optInFilename = currArg; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 else |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
198 if (optOutFilename == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 optOutFilename = currArg; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 else |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
201 dmErrorMsg("Source and destination filenames already specified, extraneous argument '%s'.\n", currArg); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 return TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 /* Assembler include data output functions |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 */ |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
209 int writeHeader_ASM(FILE *fh, const char *name) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
211 int res = 0; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
212 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 if (name) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
214 res = fprintf(fh, "; '%s'", name); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
216 res = fprintf(fh, "; Generated"); |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
217 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
218 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
219 res = fprintf(fh, " by %s v%s\n", |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 dmProgName, dmProgVersion); |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
221 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
222 return res >= 0 ? DMERR_OK : dmGetErrno(); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
225 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
226 int writeDecl_ASM(FILE *fh, const size_t len, const char *name) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
228 int res = 0; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
229 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 if (optExtraData) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
231 res = fprintf(fh, "%s_size = %" DM_PRIu_SIZE_T "\n", name, len); |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
232 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
233 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
234 res = fprintf(fh, "%s:\n", name); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
235 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
236 return res >= 0 ? DMERR_OK : dmGetErrno(); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
239 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
240 int writeData_ASM(FILE *fh, const Uint8 * buf, const size_t len) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
242 int res = fprintf(fh, "%s ", optDataType); |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
243 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
244 for (size_t i = 0; res >= 0 && i < len; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 if (optFormatting) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
249 res = fprintf(fh, "$%.2x", buf[i]); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
251 res = fprintf(fh, "%3d", buf[i]); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
256 res = fprintf(fh, "$%x", buf[i]); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
258 res = fprintf(fh, "%d", buf[i]); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
261 if (res >= 0 && i + 1 < len) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
262 res = fprintf(fh, optFormatting ? ", " : ","); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 } |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
264 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
265 return res >= 0 ? DMERR_OK : dmGetErrno(); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
268 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
269 int writeFooter_ASM(FILE *fh, const size_t len, const char *name) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
271 int res; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 (void) len; |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
273 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
274 if (optExtraData) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
275 res = fprintf(fh, "%s_end: \n", name); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
277 res = fprintf(fh, "\n"); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
278 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
279 return res >= 0 ? DMERR_OK : dmGetErrno(); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
280 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 /* ANSI-C include data output functions |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 */ |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
285 int writeHeader_C(FILE *fh, const char *name) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
287 int res; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
288 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 if (name) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
290 res = fprintf(fh, "/* '%s' generated", name); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
292 res = fprintf(fh, "/* Generated"); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
294 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
295 res = fprintf(fh, " by %s v%s\n" " */\n", |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 dmProgName, dmProgVersion); |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
297 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
298 return res >= 0 ? DMERR_OK : dmGetErrno(); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
301 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
302 int writeDecl_C(FILE *fh, const size_t len, const char *name) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
304 int res; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
305 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
306 res = fprintf(fh, "%s %s[%" DM_PRIu_SIZE_T "] = {\n", |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
307 optDataType, name, len); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
309 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
310 res = printf("extern %s %s[%" DM_PRIu_SIZE_T "];\n", |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 optDataType, name, len); |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
312 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
313 return res >= 0 ? DMERR_OK : dmGetErrno(); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
316 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
317 int writeData_C(FILE *fh, const Uint8 *buf, const size_t len) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
319 int res = 0; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
320 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
321 for (size_t i = 0; res >= 0 && i < len; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
322 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 if (optFormatting) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
326 res = fprintf(fh, "0x%.2x", buf[i]); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
328 res = fprintf(fh, "%3d", buf[i]); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
333 res = fprintf(fh, "0x%x", buf[i]); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
334 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
335 res = fprintf(fh, "%d", buf[i]); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
338 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
339 res = fprintf(fh, optFormatting ? ", " : ","); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
340 } |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
341 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
342 return res >= 0 ? DMERR_OK : dmGetErrno(); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
345 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
346 int writeFooter_C(FILE *fh, const size_t len, const char *name) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
348 int res; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 (void) len; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 (void) name; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
351 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
352 res = fprintf(fh, "};\n"); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
353 return res >= 0 ? DMERR_OK : dmGetErrno(); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
357 /* |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
358 * List of formats |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
359 */ |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
360 static const DMOutputFormat dmFormatList[] = |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
362 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
363 "asm", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
364 "XA65 compatible assembler", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
365 { "s", "asm", NULL }, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
366 ".byte", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
367 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
368 writeHeader_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
369 writeDecl_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
370 writeData_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
371 writeFooter_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
372 }, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
373 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
374 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
375 "c", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
376 "ANSI C array", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
377 { "c", "h", "cc", "cpp", "hpp", "c++", NULL }, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
378 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
379 "unsigned char", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
380 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
381 writeHeader_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
382 writeDecl_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
383 writeData_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
384 writeFooter_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
385 }, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
386 }; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
387 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
388 static const int ndmFormatList = sizeof(dmFormatList) / sizeof(dmFormatList[0]); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
389 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
390 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
391 off_t dmGetFileSize(FILE *fh) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
392 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
393 off_t len, pos = ftello(fh); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
394 fseeko(fh, 0, SEEK_END); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
395 len = ftello(fh); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
396 fseeko(fh, pos, SEEK_SET); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 return len; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
398 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
399 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
400 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
401 const DMOutputFormat *dmGuessFormatFromName(const char *filename) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
402 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
403 const char *fext; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
404 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
405 if ((fext = strrchr(filename, '.')) == NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
406 return NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
407 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
408 for (int i = 0; i < ndmFormatList; i++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
409 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
410 const DMOutputFormat *fmt = &dmFormatList[i]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
411 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
412 for (int n = 0; n < SET_MAX_FEXTS && fmt->fexts[n] != NULL; n++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
413 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
414 if (strcasecmp(fext + 1, fmt->fexts[n]) == 0) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
415 return fmt; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
416 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
417 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
418 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
419 return NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
420 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
421 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
422 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
423 int main(int argc, char *argv[]) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
424 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
425 FILE *inFile = NULL, *outFile = NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
426 Uint8 *dataBuf = NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
427 size_t dataSize; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
428 off_t totalSize; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
429 int res; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
430 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
431 // Initialize |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
432 dmInitProg("data2inc", "Data to include file converter", "0.7", NULL, NULL); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
433 dmVerbosity = 0; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
434 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
435 // Parse arguments |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
436 if (!dmArgsProcess(argc, argv, optList, optListN, |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
437 argHandleOpt, argHandleFile, OPTH_BAILOUT)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 exit(1); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
439 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
440 // Determine output type, if not specified |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
441 if (setFormat == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
442 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
443 if (optOutFilename == NULL) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
444 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
445 dmErrorMsg("Output format not specified and no output filename given (try --help)\n"); |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
446 goto exit; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
447 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
448 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
449 if ((setFormat = dmGuessFormatFromName(optOutFilename)) == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
450 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
451 dmErrorMsg("Could not guess output format from filename '%s'.\n", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
452 optOutFilename); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
453 goto exit; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
454 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
455 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
456 dmMsg(0, "Guessed output format: %s (%s)\n", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
457 setFormat->desc, setFormat->name); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
458 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
459 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
460 // Set some option defaults |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
461 if (optDataType == NULL) |
2250
956db0095f82
Change struct member name.
Matti Hamalainen <ccr@tnsp.org>
parents:
2246
diff
changeset
|
462 optDataType = setFormat->defDataType; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
463 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
464 // Open the files |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
465 if (optInFilename == NULL) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
466 inFile = stdin; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
467 else |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
468 if ((inFile = fopen(optInFilename, "rb")) == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
469 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
470 res = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
471 dmErrorMsg("Error opening input file '%s'. (%s)\n", |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
472 optInFilename, dmErrorStr(res)); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
473 goto exit; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
474 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
475 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
476 if (optOutFilename == NULL) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
477 outFile = stdout; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
478 else |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
479 if ((outFile = fopen(optOutFilename, "wa")) == NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
480 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
481 res = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
482 dmErrorMsg("Error creating output file '%s'. (%s)\n", |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
483 optOutFilename, dmErrorStr(res)); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
484 goto exit; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
485 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
486 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
487 // Allocate linebuffer |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
488 dataSize = optLineLen * sizeof(Uint8); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
489 if ((dataBuf = dmMalloc(dataSize)) == NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
490 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
491 dmErrorMsg("Could not allocate %" DM_PRIu_SIZE_T " byte buffer.\n", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
492 dataSize); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
493 goto exit; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
494 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
495 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
496 // Get sourcefile size |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
497 totalSize = dmGetFileSize(inFile); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
498 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
499 // Output header |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
500 if (!optQuiet && |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
501 (res = setFormat->writeHeader(outFile, optOutFilename)) != DMERR_OK) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
502 { |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
503 dmErrorMsg("Error writing output header: %s\n", |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
504 dmErrorStr(res)); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
505 goto exit; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
506 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
507 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
508 if (optAddLine) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
509 fprintf(outFile, "%s\n", optAddLine); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
510 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
511 // Output declaration |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
512 setFormat->writeDecl(outFile, totalSize, optObjName); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
513 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
514 // Output data |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
515 while (!feof(inFile)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
516 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
517 res = fread(dataBuf, 1, dataSize, inFile); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
518 if (res > 0) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
519 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
520 if (optIndentation < 0) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
521 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
522 for (int i = 0; i < -optIndentation; i++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
523 fputs("\t", outFile); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
524 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
525 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
526 if (optIndentation > 0) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
527 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
528 for (int i = 0; i < optIndentation; i++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
529 fputs(" ", outFile); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
530 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
531 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
532 if ((res = setFormat->writeData(outFile, dataBuf, res)) != DMERR_OK) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
533 { |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
534 dmErrorMsg("Error writing output data: %s\n", |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
535 dmErrorStr(res)); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
536 goto exit; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
537 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
538 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
539 fprintf(outFile, "\n"); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
540 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
541 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
542 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
543 // Output footer |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
544 if ((res = setFormat->writeFooter(outFile, totalSize, optObjName)) != DMERR_OK) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
545 { |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
546 dmErrorMsg("Error writing output footer: %s\n", |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
547 dmErrorStr(res)); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
548 goto exit; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
549 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
550 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
551 exit: |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
552 // Cleanup |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
553 if (inFile != NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
554 fclose(inFile); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
555 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
556 if (outFile != NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
557 fclose(outFile); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
558 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
559 dmFree(dataBuf); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
560 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
561 return 0; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
562 } |