annotate src/patchmap.c @ 2835:9405a18756c8 default tip

Add entry for Caz.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 18 Jun 2024 11:21:06 +0300
parents 0fda0c7e7f1c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
1826
79dd960610cb Change copyright blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents: 1771
diff changeset
2 * Patch a map with given diff file
79dd960610cb Change copyright blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents: 1771
diff changeset
3 * Programmed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
2417
eba783bef2ee Bump copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 2346
diff changeset
4 * (C) Copyright 2008-2022 Tecnic Software productions (TNSP)
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
1308
d11f9751e299 Renamed maputils.[ch] -> libmaputils.[ch], adjusted other code accordingly;
Matti Hamalainen <ccr@tnsp.org>
parents: 1249
diff changeset
6 #include "libmaputils.h"
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "th_util.h"
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "th_args.h"
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "th_string.h"
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
1827
75ad82af5c66 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1826
diff changeset
11
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
12 char *mapFilename = NULL,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
13 *patchFilename = NULL,
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
14 *destFilename = NULL;
2470
d0aad04c3e61 th-libs now uses stdbool.h if possible, so we need to rename all
Matti Hamalainen <ccr@tnsp.org>
parents: 2417
diff changeset
15 bool optCheck = false;
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 /* Arguments
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 */
1615
582675ccc3e6 Match th_args API change.
Matti Hamalainen <ccr@tnsp.org>
parents: 1543
diff changeset
20 static const th_optarg optList[] =
1484
2350cd3a6feb Update to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 1317
diff changeset
21 {
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
22 { 0, '?', "help", "Show this help", OPT_NONE },
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
23 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
24 { 2, 'q', "quiet", "Be quiet", OPT_NONE },
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
25 { 3, 'c', "check", "Check non-patched blocks", OPT_NONE },
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
26 { 4, 'o', "output", "Output filename", OPT_ARGREQ },
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 };
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
1484
2350cd3a6feb Update to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 1317
diff changeset
29 static const int optListN = sizeof(optList) / sizeof(optList[0]);
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 void argShowHelp(void)
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
1249
0dad7911e251 Sync th-lib changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1162
diff changeset
34 th_print_banner(stdout, th_prog_name,
0dad7911e251 Sync th-lib changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1162
diff changeset
35 "[options] <mapfile> <patchfile>");
0dad7911e251 Sync th-lib changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1162
diff changeset
36
2240
0799192a29ff Adjust to th-libs th_args_help() API change.
Matti Hamalainen <ccr@tnsp.org>
parents: 2236
diff changeset
37 th_args_help(stdout, optList, optListN, 0, 80 - 2);
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 }
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
2470
d0aad04c3e61 th-libs now uses stdbool.h if possible, so we need to rename all
Matti Hamalainen <ccr@tnsp.org>
parents: 2417
diff changeset
41 bool argHandleOpt(const int optN, char *optArg, char *currArg)
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 {
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
43 switch (optN)
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
44 {
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
45 case 0:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
46 argShowHelp();
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
47 exit(0);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
48 break;
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
50 case 1:
2007
0dc8668abbbc Fix to match changes in th-libs API.
Matti Hamalainen <ccr@tnsp.org>
parents: 1827
diff changeset
51 th_verbosity++;
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
52 break;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
53
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
54 case 2:
2007
0dc8668abbbc Fix to match changes in th-libs API.
Matti Hamalainen <ccr@tnsp.org>
parents: 1827
diff changeset
55 th_verbosity = -1;
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
56 break;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
57
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
58 case 3:
2470
d0aad04c3e61 th-libs now uses stdbool.h if possible, so we need to rename all
Matti Hamalainen <ccr@tnsp.org>
parents: 2417
diff changeset
59 optCheck = true;
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
60 THMSG(2, "Checking non-patched blocks for match.\n");
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
61 break;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
62
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
63 case 4:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
64 destFilename = optArg;
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
65 THMSG(2, "Output file set to '%s'.\n", destFilename);
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
66 break;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
67
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
68 default:
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
69 THERR("Unknown option '%s'.\n", currArg);
2470
d0aad04c3e61 th-libs now uses stdbool.h if possible, so we need to rename all
Matti Hamalainen <ccr@tnsp.org>
parents: 2417
diff changeset
70 return false;
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
71 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
72
2470
d0aad04c3e61 th-libs now uses stdbool.h if possible, so we need to rename all
Matti Hamalainen <ccr@tnsp.org>
parents: 2417
diff changeset
73 return true;
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 }
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
2470
d0aad04c3e61 th-libs now uses stdbool.h if possible, so we need to rename all
Matti Hamalainen <ccr@tnsp.org>
parents: 2417
diff changeset
77 bool argHandleFile(char *currArg)
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 {
2177
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
79 if (mapFilename == NULL)
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
80 mapFilename = currArg;
1692
f5d432ccc9d6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1615
diff changeset
81 else
2177
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
82 if (patchFilename == NULL)
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
83 patchFilename = currArg;
1317
bdecb935b4cb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1314
diff changeset
84 else
bdecb935b4cb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1314
diff changeset
85 {
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
86 THERR("Too many input map files specified!\n");
2470
d0aad04c3e61 th-libs now uses stdbool.h if possible, so we need to rename all
Matti Hamalainen <ccr@tnsp.org>
parents: 2417
diff changeset
87 return false;
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
88 }
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
2470
d0aad04c3e61 th-libs now uses stdbool.h if possible, so we need to rename all
Matti Hamalainen <ccr@tnsp.org>
parents: 2417
diff changeset
90 return true;
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 }
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 int main(int argc, char *argv[])
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 {
2537
e96e757ab01e Make program return values handling a bit more consistent.
Matti Hamalainen <ccr@tnsp.org>
parents: 2534
diff changeset
96 int res = 0;
2177
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
97 MapBlock *map = NULL, *patch = NULL;
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
98 FILE *outFile = NULL;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
99
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
100 // Initialize
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
101 th_init("patchmap", "Patch a mapfile with a diff", "0.1", NULL, NULL);
2007
0dc8668abbbc Fix to match changes in th-libs API.
Matti Hamalainen <ccr@tnsp.org>
parents: 1827
diff changeset
102 th_verbosity = 1;
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
104 // Parse arguments
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
105 if (!th_args_process(argc, argv, optList, optListN,
1484
2350cd3a6feb Update to match the changes in th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 1317
diff changeset
106 argHandleOpt, argHandleFile, OPTH_BAILOUT))
2177
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
107 {
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
108 res = 1;
2534
76b67c40fbf5 Rename "exit" label to "out".
Matti Hamalainen <ccr@tnsp.org>
parents: 2470
diff changeset
109 goto out;
2177
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
110 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
111
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
112 if (mapFilename == NULL || patchFilename == NULL)
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
113 {
2539
0fda0c7e7f1c Show help when there's an argument error or nothing to do.
Matti Hamalainen <ccr@tnsp.org>
parents: 2537
diff changeset
114 argShowHelp();
0fda0c7e7f1c Show help when there's an argument error or nothing to do.
Matti Hamalainen <ccr@tnsp.org>
parents: 2537
diff changeset
115 THERR("Nothing to do.\n");
2177
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
116 res = 1;
2534
76b67c40fbf5 Rename "exit" label to "out".
Matti Hamalainen <ccr@tnsp.org>
parents: 2470
diff changeset
117 goto out;
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
118 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
119
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
120 // Read map and patch file
2470
d0aad04c3e61 th-libs now uses stdbool.h if possible, so we need to rename all
Matti Hamalainen <ccr@tnsp.org>
parents: 2417
diff changeset
121 if ((map = mapBlockParseFile(mapFilename, false)) == NULL ||
d0aad04c3e61 th-libs now uses stdbool.h if possible, so we need to rename all
Matti Hamalainen <ccr@tnsp.org>
parents: 2417
diff changeset
122 (patch = mapBlockParseFile(patchFilename, true)) == NULL)
2177
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
123 {
2537
e96e757ab01e Make program return values handling a bit more consistent.
Matti Hamalainen <ccr@tnsp.org>
parents: 2534
diff changeset
124 res = -2;
2534
76b67c40fbf5 Rename "exit" label to "out".
Matti Hamalainen <ccr@tnsp.org>
parents: 2470
diff changeset
125 goto out;
2177
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
126 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
127
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
128 // Check map and diff sizes
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
129 if (optCheck && (map->width != patch->width || map->height != patch->height))
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
130 {
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
131 THERR("Map and patch dimensions do not match (%d x %d [map] <-> %d x %d [patch])\n",
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
132 map->width, map->height,
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
133 patch->width, patch->height);
2177
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
134
2537
e96e757ab01e Make program return values handling a bit more consistent.
Matti Hamalainen <ccr@tnsp.org>
parents: 2534
diff changeset
135 res = -2;
2534
76b67c40fbf5 Rename "exit" label to "out".
Matti Hamalainen <ccr@tnsp.org>
parents: 2470
diff changeset
136 goto out;
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
137 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
138
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
139 // Generate
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
140 for (int yc = 0; yc < map->height; yc++)
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
141 {
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
142 unsigned char
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
143 *dp = map->data + (map->scansize * yc),
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
144 *sp = patch->data + (patch->scansize * yc);
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
145
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
146 for (int xc = 0; xc < map->width; xc++, sp++, dp++)
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
147 {
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
148 const int i = (*sp & 63);
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
149 unsigned char ch;
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
150
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
151 if (*sp == 0xfd)
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
152 ch = ' ';
1692
f5d432ccc9d6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1615
diff changeset
153 else
f5d432ccc9d6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1615
diff changeset
154 if (i < nmapPieces)
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
155 ch = mapPieces[i].symbol;
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
156 else
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
157 {
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
158 THERR("[%d,%d] invalid symbol index %d (%d) in patch\n",
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
159 xc+1, yc+1, *sp, i);
2537
e96e757ab01e Make program return values handling a bit more consistent.
Matti Hamalainen <ccr@tnsp.org>
parents: 2534
diff changeset
160 res = -7;
2534
76b67c40fbf5 Rename "exit" label to "out".
Matti Hamalainen <ccr@tnsp.org>
parents: 2470
diff changeset
161 goto out;
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
162 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
163
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
164 if (*sp < 64)
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
165 {
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
166 if (optCheck && *sp != *dp)
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
167 {
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
168 THERR("[%d,%d] mismatch %d != %d\n",
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
169 xc+1, yc+1, *sp, *dp);
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
170 }
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
171 }
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
172 else
2232
6a187ef753a4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
173 *dp = ch;
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
174 }
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
175 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
176
1770
cc59f80b0e78 Various cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1692
diff changeset
177 // Open output file
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
178 if (destFilename == NULL)
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
179 outFile = stdout;
1692
f5d432ccc9d6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1615
diff changeset
180 else
f5d432ccc9d6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1615
diff changeset
181 if ((outFile = fopen(destFilename, "wb")) == NULL)
1314
5d6ddd4d6781 Import more changes from Map Mask Designer, and do a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
182 {
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
183 THERR("Error opening output file '%s'!\n",
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
184 destFilename);
2537
e96e757ab01e Make program return values handling a bit more consistent.
Matti Hamalainen <ccr@tnsp.org>
parents: 2534
diff changeset
185 res = -6;
2534
76b67c40fbf5 Rename "exit" label to "out".
Matti Hamalainen <ccr@tnsp.org>
parents: 2470
diff changeset
186 goto out;
714
304a50a9d51f Indentation fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 711
diff changeset
187 }
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
188
1310
a6be5a68032f Rename map block handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1309
diff changeset
189 mapBlockPrint(outFile, map);
1543
0da2d8e74583 Cosmetics pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
190
2534
76b67c40fbf5 Rename "exit" label to "out".
Matti Hamalainen <ccr@tnsp.org>
parents: 2470
diff changeset
191 out:
2208
784ff0c54a7d Some code cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2177
diff changeset
192 if (outFile != NULL)
784ff0c54a7d Some code cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2177
diff changeset
193 fclose(outFile);
2177
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
194
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
195 mapBlockFree(map);
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
196 mapBlockFree(patch);
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
197
a4c03b6155c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2007
diff changeset
198 return res;
549
bbe1f5e4195d Added a new utility, patchmap.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 }