Mercurial > hg > dmlib
annotate tools/data2inc.c @ 2408:60e119262c67
Option index re-ordering cleanup work.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 13 Jan 2020 21:21:25 +0200 |
parents | b153bc46241d |
children | bc05bcfc4598 |
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 }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
57 |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
58 { 10, 'n', "name" , "Set object name", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
59 { 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
|
60 { 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
|
61 { 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
|
62 { 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
|
63 { 20, 'x', "hexadecimal" , "Use hexadecimal output", OPT_NONE }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
64 { 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
|
65 { 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
|
66 { 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
|
67 { 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
|
68 }; |
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 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
|
71 static const DMOutputFormat dmFormatList[]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
72 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
|
73 |
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 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
|
76 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 dmPrintBanner(stdout, dmProgName, |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
78 "[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
|
79 |
2402
b7cd5dd0b82e
Merge one more change from th-libs args processing.
Matti Hamalainen <ccr@tnsp.org>
parents:
2286
diff
changeset
|
80 dmArgsPrintHelp(stdout, optList, optListN, 0, 80 - 2); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1107
diff
changeset
|
81 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
82 fprintf(stdout, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
83 "\n" |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
84 "Available output formats (-f <frmt>):\n" |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
85 " frmt | Description (filename extensions)\n" |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
86 "------+------------------------------------------\n"); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
87 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
88 for (int i = 0; i < ndmFormatList; i++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
89 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
90 const DMOutputFormat *fmt = &dmFormatList[i]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
91 fprintf(stdout, "%-5s | %s (", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
92 fmt->name, fmt->desc); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
93 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
94 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
|
95 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
96 fprintf(stdout, ".%s%s", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
97 fmt->fexts[n], |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
98 (n + 1 < SET_MAX_FEXTS && |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
99 fmt->fexts[n + 1] != NULL) ? " " : ""); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
100 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
101 fprintf(stdout, ")\n"); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
102 } |
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 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
|
105 "\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 "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
|
107 "$ 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
|
108 "\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 ); |
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 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
|
114 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 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
|
116 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 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
|
118 argShowHelp(); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 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
|
120 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
122 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
|
123 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
|
124 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
126 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
|
127 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
|
128 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
130 case 14: |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
131 for (int i = 0; i < ndmFormatList; i++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
132 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
133 const DMOutputFormat *fmt = &dmFormatList[i]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
134 if (strcasecmp(fmt->name, optArg) == 0) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
135 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
136 setFormat = fmt; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
137 return TRUE; |
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 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
140 dmErrorMsg("Invalid format name '%s'.\n", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
141 optArg); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
142 return FALSE; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
143 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
144 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
|
145 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
|
146 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
148 case 18: |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
149 optLineLen = atoi(optArg); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
150 if (optLineLen < 1) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
151 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
152 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
|
153 optArg); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
154 return FALSE; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
155 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 break; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
157 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
158 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
|
159 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
|
160 break; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
161 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
162 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
|
163 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
|
164 break; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
165 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
166 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
|
167 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
|
168 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
170 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
|
171 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
|
172 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
174 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
|
175 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
|
176 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 default: |
2183
e3f0eaf23f4f
Change the error message for unimplemented option argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
1433
diff
changeset
|
179 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
|
180 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
|
181 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 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
|
184 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 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
|
188 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
189 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
|
190 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
|
191 else |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
192 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
|
193 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
|
194 else |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
195 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
|
196 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 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
|
198 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 /* 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
|
202 */ |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
203 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
|
204 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
205 int res = 0; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
206 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 if (name) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
208 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
|
209 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
210 res = fprintf(fh, "; Generated"); |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
211 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
212 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
213 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
|
214 dmProgName, dmProgVersion); |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
215 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
216 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
|
217 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
219 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
220 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
|
221 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
222 int res = 0; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
223 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 if (optExtraData) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
225 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
|
226 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
227 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
228 res = fprintf(fh, "%s:\n", name); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
229 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
230 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
|
231 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
233 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
234 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
|
235 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
236 int res = fprintf(fh, "%s ", optDataType); |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
237 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
238 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
|
239 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 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
|
241 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
243 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
|
244 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
245 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
|
246 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
250 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
|
251 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
252 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
|
253 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
255 if (res >= 0 && i + 1 < len) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
256 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
|
257 } |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
258 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
259 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
|
260 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
262 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
263 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
|
264 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
265 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
|
266 (void) len; |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
267 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 if (optExtraData) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
269 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
|
270 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
271 res = fprintf(fh, "\n"); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
272 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
273 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
|
274 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 /* 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
|
278 */ |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
279 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
|
280 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
281 int res; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
282 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 if (name) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
284 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
|
285 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
286 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
|
287 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
288 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
289 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
|
290 dmProgName, dmProgVersion); |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
291 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
292 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
|
293 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
295 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
296 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
|
297 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
298 int res; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
299 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
300 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
|
301 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
|
302 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
303 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
304 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
|
305 optDataType, name, len); |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
306 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
307 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
|
308 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
310 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
311 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
|
312 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
313 int res = 0; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
314 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
315 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
|
316 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
317 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
|
318 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
319 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
320 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
|
321 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
322 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
|
323 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
326 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
327 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
|
328 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
329 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
|
330 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
332 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
333 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
|
334 } |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
335 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
336 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
|
337 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
339 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
340 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
|
341 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
342 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
|
343 (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
|
344 (void) name; |
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 res = fprintf(fh, "};\n"); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
347 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
|
348 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
351 /* |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
352 * List of formats |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
353 */ |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
354 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
|
355 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
356 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
357 "asm", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
358 "XA65 compatible assembler", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
359 { "s", "asm", NULL }, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
360 ".byte", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
361 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
362 writeHeader_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
363 writeDecl_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
364 writeData_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
365 writeFooter_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
366 }, |
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 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
369 "c", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
370 "ANSI C array", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
371 { "c", "h", "cc", "cpp", "hpp", "c++", NULL }, |
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 "unsigned char", |
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 writeHeader_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
376 writeDecl_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
377 writeData_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
378 writeFooter_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
379 }, |
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 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
382 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
|
383 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
384 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
385 off_t dmGetFileSize(FILE *fh) |
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 off_t len, pos = ftello(fh); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
388 fseeko(fh, 0, SEEK_END); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
389 len = ftello(fh); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
390 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
|
391 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
|
392 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
393 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
395 const DMOutputFormat *dmGuessFormatFromName(const char *filename) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
396 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
397 const char *fext; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
398 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
399 if ((fext = strrchr(filename, '.')) == NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
400 return NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
401 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
402 for (int i = 0; i < ndmFormatList; i++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
403 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
404 const DMOutputFormat *fmt = &dmFormatList[i]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
405 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
406 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
|
407 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
408 if (strcasecmp(fext + 1, fmt->fexts[n]) == 0) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
409 return fmt; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
410 } |
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 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
413 return NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
414 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
415 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
416 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
417 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
|
418 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
419 FILE *inFile = NULL, *outFile = NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
420 Uint8 *dataBuf = NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
421 size_t dataSize; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
422 off_t totalSize; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
423 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
|
424 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
425 // Initialize |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
426 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
|
427 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
|
428 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
429 // 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
|
430 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
|
431 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
|
432 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
|
433 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
434 // Determine output type, if not specified |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
435 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
|
436 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
437 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
|
438 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
439 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
|
440 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
|
441 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
442 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
443 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
|
444 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
445 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
|
446 optOutFilename); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
447 goto exit; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
448 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
449 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
450 dmMsg(0, "Guessed output format: %s (%s)\n", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
451 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
|
452 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
453 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
454 // Set some option defaults |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
455 if (optDataType == NULL) |
2250
956db0095f82
Change struct member name.
Matti Hamalainen <ccr@tnsp.org>
parents:
2246
diff
changeset
|
456 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
|
457 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
458 // 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
|
459 if (optInFilename == NULL) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
460 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
|
461 else |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
462 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
|
463 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
464 res = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
465 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
|
466 optInFilename, dmErrorStr(res)); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
467 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
|
468 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
469 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
470 if (optOutFilename == NULL) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
471 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
|
472 else |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
473 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
|
474 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
475 res = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
476 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
|
477 optOutFilename, dmErrorStr(res)); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
478 goto exit; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
479 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
480 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
481 // Allocate linebuffer |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
482 dataSize = optLineLen * sizeof(Uint8); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
483 if ((dataBuf = dmMalloc(dataSize)) == NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
484 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
485 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
|
486 dataSize); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
487 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
|
488 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
489 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
490 // Get sourcefile size |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
491 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
|
492 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
493 // Output header |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
494 if (!optQuiet && |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
495 (res = setFormat->writeHeader(outFile, optOutFilename)) != DMERR_OK) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
496 { |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
497 dmErrorMsg("Error writing output header: %s\n", |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
498 dmErrorStr(res)); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
499 goto exit; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
500 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
501 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
502 if (optAddLine) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
503 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
|
504 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
505 // Output declaration |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
506 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
|
507 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
508 // Output data |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
509 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
|
510 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
511 res = fread(dataBuf, 1, dataSize, inFile); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
512 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
|
513 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
514 if (optIndentation < 0) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
515 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
516 for (int i = 0; i < -optIndentation; i++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
517 fputs("\t", outFile); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
518 } |
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 else |
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) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
521 { |
2246
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(" ", 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
|
524 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
525 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
526 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
|
527 { |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
528 dmErrorMsg("Error writing output data: %s\n", |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
529 dmErrorStr(res)); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
530 goto exit; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
531 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
532 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
533 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
|
534 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
535 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
536 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
537 // Output footer |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
538 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
|
539 { |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
540 dmErrorMsg("Error writing output footer: %s\n", |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
541 dmErrorStr(res)); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
542 goto exit; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
543 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
544 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
545 exit: |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
546 // Cleanup |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
547 if (inFile != NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
548 fclose(inFile); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
549 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
550 if (outFile != NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
551 fclose(outFile); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
552 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
553 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
|
554 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
555 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
|
556 } |