Mercurial > hg > dmlib
annotate tools/data2inc.c @ 2421:1361e3883dd8
Make things more flexible.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 16 Jan 2020 14:08:48 +0200 |
parents | bc05bcfc4598 |
children | f07e3e66ca58 |
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 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
29 int (*initContext) (void **pctx); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
30 int (*closeContext) (void *pctx); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
31 |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
32 int (*writeHeader) (FILE *fh, void *ctx, const char *name); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
33 int (*writeDecl) (FILE *fh, void *ctx, const size_t len, const char *name); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
34 int (*writeData) (FILE *fh, void *ctx, const Uint8 *buf, const size_t len); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
35 int (*writeFooter) (FILE *fh, void *ctx, const size_t len, const char *name); |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
36 } DMOutputFormat; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
37 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
38 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
39 // |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
40 // Options |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
41 // |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 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
|
43 *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
|
44 *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
|
45 *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
|
46 *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
|
47 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
48 const DMOutputFormat *setFormat = NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
49 int optIndentation = -1, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
57 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
|
58 { |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
59 { 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
|
60 { 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
|
61 |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
62 { 10, 'n', "name" , "Set object name", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
63 { 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
|
64 { 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
|
65 { 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
|
66 { 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
|
67 { 20, 'x', "hexadecimal" , "Use hexadecimal output", OPT_NONE }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
68 { 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
|
69 { 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
|
70 { 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
|
71 { 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
|
72 }; |
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 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
|
75 static const DMOutputFormat dmFormatList[]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
76 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
|
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 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 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
|
80 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 dmPrintBanner(stdout, dmProgName, |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
82 "[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
|
83 |
2402
b7cd5dd0b82e
Merge one more change from th-libs args processing.
Matti Hamalainen <ccr@tnsp.org>
parents:
2286
diff
changeset
|
84 dmArgsPrintHelp(stdout, optList, optListN, 0, 80 - 2); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1107
diff
changeset
|
85 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
86 fprintf(stdout, |
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 "Available output formats (-f <frmt>):\n" |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
89 " frmt | Description (filename extensions)\n" |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
90 "------+------------------------------------------\n"); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
91 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
92 for (int i = 0; i < ndmFormatList; i++) |
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 const DMOutputFormat *fmt = &dmFormatList[i]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
95 fprintf(stdout, "%-5s | %s (", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
96 fmt->name, fmt->desc); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
97 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
98 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
|
99 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
100 fprintf(stdout, ".%s%s", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
101 fmt->fexts[n], |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
102 (n + 1 < SET_MAX_FEXTS && |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
103 fmt->fexts[n + 1] != NULL) ? " " : ""); |
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, ")\n"); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
106 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
107 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
108 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
|
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 "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
|
111 "$ 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
|
112 "\n" |
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 } |
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 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 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
|
118 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 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
|
120 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 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
|
122 argShowHelp(); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 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
|
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 |
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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
131 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
|
132 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
|
133 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
135 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
|
136 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
|
137 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
139 case 14: |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
140 for (int i = 0; i < ndmFormatList; i++) |
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 const DMOutputFormat *fmt = &dmFormatList[i]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
143 if (strcasecmp(fmt->name, optArg) == 0) |
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 setFormat = fmt; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
146 return TRUE; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
147 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
148 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
149 dmErrorMsg("Invalid format name '%s'.\n", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
150 optArg); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
151 return FALSE; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
152 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
153 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
|
154 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
|
155 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
157 case 18: |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
158 optLineLen = atoi(optArg); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
159 if (optLineLen < 1) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
160 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
161 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
|
162 optArg); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
163 return FALSE; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
164 } |
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 break; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
166 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
167 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
|
168 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
|
169 break; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
170 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
171 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
|
172 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
|
173 break; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
174 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
175 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
|
176 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
|
177 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
179 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
|
180 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
|
181 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
183 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
|
184 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
|
185 break; |
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 default: |
2183
e3f0eaf23f4f
Change the error message for unimplemented option argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
1433
diff
changeset
|
188 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
|
189 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
|
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 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
|
193 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 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
|
197 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
198 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
|
199 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
|
200 else |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
201 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
|
202 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
|
203 else |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
204 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
|
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 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
|
207 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
210 static void dmPrintIndentation(FILE *fh) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
211 { |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
212 if (optIndentation < 0) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
213 { |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
214 for (int i = 0; i < -optIndentation; i++) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
215 fputs("\t", fh); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
216 } |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
217 else |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
218 if (optIndentation > 0) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
219 { |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
220 for (int i = 0; i < optIndentation; i++) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
221 fputs(" ", fh); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
222 } |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
223 } |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
224 |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
225 |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
226 static int dmHandleError(const int res) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
227 { |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
228 return res >= 0 ? DMERR_OK : dmGetErrno(); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
229 } |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
230 |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
231 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 /* 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
|
233 */ |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
234 int writeHeader_ASM(FILE *fh, void *ctx, 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
|
235 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
236 int res = 0; |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
237 (void) ctx; |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
238 |
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 if (name) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
240 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
|
241 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
242 res = fprintf(fh, "; Generated"); |
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 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
245 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
|
246 dmProgName, dmProgVersion); |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
247 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
248 return dmHandleError(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
|
249 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
251 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
252 int writeDecl_ASM(FILE *fh, void *ctx, 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
|
253 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
254 int res = 0; |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
255 (void) ctx; |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
256 |
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 if (optExtraData) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
258 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
|
259 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
260 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
261 res = fprintf(fh, "%s:\n", name); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
262 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
263 return dmHandleError(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
|
264 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
266 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
267 int writeData_ASM(FILE *fh, void *ctx, 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
|
268 { |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
269 int res; |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
270 (void) ctx; |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
271 |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
272 dmPrintIndentation(fh); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
273 res = fprintf(fh, "%s ", optDataType); |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
274 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
275 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
|
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 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
|
278 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
280 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
|
281 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
282 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
|
283 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
287 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
|
288 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
289 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
|
290 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
292 if (res >= 0 && i + 1 < len) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
293 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
|
294 } |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
295 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
296 if (res >= 0) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
297 res = fprintf(fh, "\n"); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
298 |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
299 return dmHandleError(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
|
300 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
301 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
302 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
303 int writeFooter_ASM(FILE *fh, void *ctx, 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
|
304 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
305 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
|
306 (void) len; |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
307 (void) ctx; |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
308 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 if (optExtraData) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
310 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
|
311 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
312 res = fprintf(fh, "\n"); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
313 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
314 return dmHandleError(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
|
315 } |
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 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 /* 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
|
319 */ |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
320 int writeHeader_C(FILE *fh, void *ctx, 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
|
321 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
322 int res; |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
323 (void) ctx; |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
324 |
407
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 (name) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
326 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
|
327 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
328 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
|
329 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
330 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
331 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
|
332 dmProgName, dmProgVersion); |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
333 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
334 return dmHandleError(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
|
335 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
337 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
338 int writeDecl_C(FILE *fh, void *ctx, 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
|
339 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
340 int res; |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
341 (void) ctx; |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
342 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
343 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
|
344 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
|
345 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
346 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
347 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
|
348 optDataType, name, len); |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
349 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
350 return dmHandleError(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
|
351 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
352 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
353 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
354 int writeData_C(FILE *fh, void *ctx, 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
|
355 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
356 int res = 0; |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
357 (void) ctx; |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
358 |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
359 dmPrintIndentation(fh); |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
360 |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
361 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
|
362 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 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
|
364 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
366 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
|
367 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
368 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
|
369 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
370 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
372 if (optHexMode) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
373 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
|
374 else |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
375 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
|
376 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
377 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
378 if (res >= 0) |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
379 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
|
380 } |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
381 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
382 if (res >= 0) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
383 res = fprintf(fh, "\n"); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
384 |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
385 return dmHandleError(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
|
386 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
388 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
389 int writeFooter_C(FILE *fh, void *ctx, 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
|
390 { |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
391 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
|
392 (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
|
393 (void) name; |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
394 (void) ctx; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
395 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
396 res = fprintf(fh, "};\n"); |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
397 return dmHandleError(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
|
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 |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
401 /* |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
402 * List of formats |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
403 */ |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
404 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
|
405 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
406 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
407 "asm", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
408 "XA65 compatible assembler", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
409 { "s", "asm", NULL }, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
410 ".byte", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
411 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
412 NULL, |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
413 NULL, |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
414 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
415 writeHeader_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
416 writeDecl_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
417 writeData_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
418 writeFooter_ASM, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
419 }, |
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 "c", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
423 "ANSI C array", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
424 { "c", "h", "cc", "cpp", "hpp", "c++", NULL }, |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
425 "unsigned char", |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
426 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
427 NULL, |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
428 NULL, |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
429 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
430 writeHeader_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
431 writeDecl_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
432 writeData_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
433 writeFooter_C, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
434 }, |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
435 }; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
436 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
437 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
|
438 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
439 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
440 off_t dmGetFileSize(FILE *fh) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
441 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
442 off_t len, pos = ftello(fh); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
443 fseeko(fh, 0, SEEK_END); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
444 len = ftello(fh); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
445 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
|
446 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
|
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 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
450 const DMOutputFormat *dmGuessFormatFromName(const char *filename) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
451 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
452 const char *fext; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
453 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
454 if ((fext = strrchr(filename, '.')) == NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
455 return NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
456 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
457 for (int i = 0; i < ndmFormatList; i++) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
458 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
459 const DMOutputFormat *fmt = &dmFormatList[i]; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
460 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
461 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
|
462 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
463 if (strcasecmp(fext + 1, fmt->fexts[n]) == 0) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
464 return fmt; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
465 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
466 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
467 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
468 return NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
469 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
470 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
471 |
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 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
|
473 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
474 FILE *inFile = NULL, *outFile = NULL; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
475 Uint8 *dataBuf = NULL; |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
476 void *ctx = NULL; |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
477 size_t dataSize; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
478 off_t totalSize; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
479 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
|
480 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
481 // Initialize |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2406
diff
changeset
|
482 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
|
483 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
|
484 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
485 // 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
|
486 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
|
487 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
|
488 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
|
489 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
490 // Determine output type, if not specified |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
491 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
|
492 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
493 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
|
494 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
495 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
|
496 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
|
497 } |
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 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
|
500 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
501 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
|
502 optOutFilename); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
503 goto exit; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
504 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
505 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
506 dmMsg(0, "Guessed output format: %s (%s)\n", |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
507 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
|
508 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
509 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
510 // Set some option defaults |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
511 if (optDataType == NULL) |
2250
956db0095f82
Change struct member name.
Matti Hamalainen <ccr@tnsp.org>
parents:
2246
diff
changeset
|
512 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
|
513 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
514 // 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
|
515 if (optInFilename == NULL) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
516 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
|
517 else |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
518 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
|
519 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
520 res = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
521 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
|
522 optInFilename, dmErrorStr(res)); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
523 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
|
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 |
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 (optOutFilename == NULL) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
527 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
|
528 else |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
529 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
|
530 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
531 res = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
532 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
|
533 optOutFilename, dmErrorStr(res)); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
534 goto exit; |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
535 } |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
536 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
537 // Allocate linebuffer |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
538 dataSize = optLineLen * sizeof(Uint8); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
539 if ((dataBuf = dmMalloc(dataSize)) == NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
540 { |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
541 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
|
542 dataSize); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
543 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
|
544 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
545 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
546 // Get sourcefile size |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
547 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
|
548 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
549 // Call context init |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
550 if (setFormat->initContext != NULL && |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
551 (res = setFormat->initContext(&ctx)) != DMERR_OK) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
552 { |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
553 dmErrorMsg("Error initializing format %s (%s) context: %s\n", |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
554 setFormat->name, setFormat->desc, |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
555 dmErrorStr(res)); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
556 goto exit; |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
557 } |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
558 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
559 // Output header |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
560 if (!optQuiet && |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
561 (res = setFormat->writeHeader(outFile, ctx, optOutFilename)) != DMERR_OK) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
562 { |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
563 dmErrorMsg("Error writing output header: %s\n", |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
564 dmErrorStr(res)); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
565 goto exit; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
566 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
567 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
568 if (optAddLine) |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
569 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
|
570 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
571 // Output declaration |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
572 if (setFormat->writeDecl != NULL && |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
573 (res = setFormat->writeDecl(outFile, ctx, totalSize, optObjName)) != DMERR_OK) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
574 { |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
575 dmErrorMsg("Error writing output declaration: %s\n", |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
576 dmErrorStr(res)); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
577 goto exit; |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
578 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
579 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
580 // Output data |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
581 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
|
582 { |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
583 res = fread(dataBuf, 1, dataSize, inFile); |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
584 if (res > 0 && |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
585 (res = setFormat->writeData(outFile, ctx, dataBuf, res)) != DMERR_OK) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
586 { |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
587 dmErrorMsg("Error writing output data: %s\n", |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
588 dmErrorStr(res)); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
589 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
|
590 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
591 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
592 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
593 // Output footer |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
594 if (setFormat->writeFooter != NULL && |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
595 (res = setFormat->writeFooter(outFile, ctx, totalSize, optObjName)) != DMERR_OK) |
2405
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
596 { |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
597 dmErrorMsg("Error writing output footer: %s\n", |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
598 dmErrorStr(res)); |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
599 goto exit; |
1f74cc842d71
Add some error checking to data2inc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
600 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
601 |
2246
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
602 exit: |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
603 // Cleanup |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
604 if (inFile != NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
605 fclose(inFile); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
606 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
607 if (outFile != NULL) |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
608 fclose(outFile); |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
609 |
d76b0c92769d
Refactor data2inc to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
610 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
|
611 |
2421
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
612 if (setFormat != NULL && |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
613 setFormat->closeContext != NULL && |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
614 (res = setFormat->closeContext(ctx)) != DMERR_OK) |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
615 { |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
616 dmErrorMsg("Error closing format %s (%s) context: %s\n", |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
617 setFormat->name, setFormat->desc, |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
618 dmErrorStr(res)); |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
619 } |
1361e3883dd8
Make things more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
2410
diff
changeset
|
620 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
621 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
|
622 } |