annotate tools/packed.c @ 1020:021e76f94dcb

Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 01 Mar 2015 15:53:14 +0200
parents 8cf8a8035438
children f530690b75ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * PACKed - PACKfile EDitor
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2011 Tecnic Software productions (TNSP)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmargs.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "dmpack.h"
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
9 #include "dmfile.h"
115
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
10 #include "dmres.h"
285
245b15cd1919 Don't link libSDL uselessly to utilities that do not actually use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 211
diff changeset
11 #include "dmmutex.h"
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
12 #include <zlib.h>
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
13
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #define SET_MAX_FILES (4096)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #define SET_DEFAULT_PACK "data.pak"
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
17 #define SET_TMPBUF_SIZE (128 * 1024)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
18
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 CMD_NONE = 0,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 CMD_CREATE,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 CMD_ADD,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 CMD_LIST,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 CMD_EXTRACT
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 } DCOMMAND;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 PACK_EXTRACTED = 0x0001,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
33 int nsrcFilenames = 0, nexcFilenames = 0;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 char * srcFilenames[SET_MAX_FILES];
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
35 char * excFilenames[SET_MAX_FILES];
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
36
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 char * optPackFilename = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 BOOL optCompress = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 int optCommand = CMD_NONE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 int optDefResFlags = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
43 static const DMOptArg optList[] =
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 { 0, '?', "help", "Show this help", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 { 1, 'p', "pack", "Set pack filename (default: " SET_DEFAULT_PACK ")", OPT_ARGREQ },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 { 2, 'c', "create", "Create and add files to PACK", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 { 3, 'a', "add", "Add files to PACK", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 { 4, 'l', "list", "List files in PACK", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 { 5, 'e', "extract", "Extract files from PACK", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 { 6, 'n', "nocompress", "No compression", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 { 7, 'v', "verbose", "Increase verbosity", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 { 8, 'f', "resflags", "Set default resource flags (-f 0xff)", OPT_ARGREQ },
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
54 { 9, 'x', "exclude", "Exclude name/glob pattern from add", OPT_ARGREQ },
1020
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
55 { 0, '?', "help", "Show this help", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
56 { 1, 'p', "pack", "Set pack filename (default: " SET_DEFAULT_PACK ")", OPT_ARGREQ },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
57 { 2, 'c', "create", "Create and add files to PACK", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
58 { 3, 'a', "add", "Add files to PACK", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
59 { 4, 'l', "list", "List files in PACK", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
60 { 5, 'e', "extract", "Extract files from PACK", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
61 { 6, 'n', "nocompress", "No compression / decompression", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
62 { 7, 'v', "verbose", "Increase verbosity", OPT_NONE },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
63 { 8, 'f', "resflags", "Set default resource flags (-f 0xff)", OPT_ARGREQ },
021e76f94dcb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
64 { 9, 'x', "exclude", "Exclude name/glob pattern from add", OPT_ARGREQ },
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 static const int optListN = sizeof(optList) / sizeof(optList[0]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 void argShowHelp()
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 {
117
b56ce9981d79 Correct help of 'packed' utility.
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
72 dmPrintBanner(stdout, dmProgName, "[options] [-p <packfilename>] [filename[s]]");
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
73 dmArgsPrintHelp(stdout, optList, optListN, 0);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 fprintf(stdout,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 "\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 "Examples:\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 "$ %s -p test.pak -l -- list files in test.pak\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 "$ %s -a foobar.jpg -- add foobar.jpg in " SET_DEFAULT_PACK "\n"
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
79 "$ %s -e foobar.jpg -- extract foobar.jpg from " SET_DEFAULT_PACK "\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 dmProgName, dmProgName, dmProgName);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 (void) optArg;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 switch (optN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
89 case 0:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
90 argShowHelp();
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
91 exit(0);
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
92 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
94 case 1:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
95 optPackFilename = optArg;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
96 break;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
97 case 2:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
98 optCommand = CMD_CREATE;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
99 break;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
100 case 3:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
101 optCommand = CMD_ADD;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
102 break;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
103 case 4:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
104 optCommand = CMD_LIST;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
105 break;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
106 case 5:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
107 optCommand = CMD_EXTRACT;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
108 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
110 case 6:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
111 optCompress = FALSE;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
112 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
114 case 7:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
115 dmVerbosity++;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
116 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
118 case 8:
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 {
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
120 unsigned int i;
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
121 if (!dmGetIntVal(optArg, &i))
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
122 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
123 dmErrorMsg("Invalid flags value '%s'.\n", optArg);
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
124 return FALSE;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
125 }
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
126 optDefResFlags = i;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 }
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
128 break;
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
129
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
130 case 9:
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
131 if (nexcFilenames < SET_MAX_FILES)
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
132 {
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
133 excFilenames[nsrcFilenames] = currArg;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
134 nexcFilenames++;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
135 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
136 else
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
137 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
138 dmErrorMsg("Maximum number of exclusion patterns (%d) exceeded!\n",
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
139 SET_MAX_FILES);
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
140 return FALSE;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
141 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
142 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
144 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
145 dmErrorMsg("Unknown argument '%s'.\n", currArg);
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
146 return FALSE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 BOOL argHandleFile(char *currArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 if (nsrcFilenames < SET_MAX_FILES)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 srcFilenames[nsrcFilenames] = currArg;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 nsrcFilenames++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
162 dmErrorMsg("Maximum number of input files (%d) exceeded!\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 SET_MAX_FILES);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
170 DMPackEntry *dmPackEntryCopy(const DMPackEntry *src)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
171 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
172 DMPackEntry *node = dmPackEntryNew();
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
173 if (node == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
174 return NULL;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
175
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
176 strncpy(node->filename, src->filename, sizeof(node->filename));
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
177 node->filename[sizeof(node->filename) - 1] = 0;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
178
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
179 node->size = src->size;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
180 node->offset = src->offset;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
181 node->length = src->length;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
182 node->flags = src->flags;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
183
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
184 return node;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
185 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
186
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
187
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
188 int dmPackWrite(DMPackFile * pack)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
189 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
190 DMPackEntry *node;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
191 DMPackFileHeader hdr;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
192
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
193 if (pack == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
194 return DMERR_OK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
195
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
196 if (pack->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
197 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
198
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
199 // Compute directory offset and number of entries
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
200 memcpy(&hdr.ident, DPACK_IDENT, sizeof(hdr.ident));
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
201 hdr.version = DPACK_VERSION;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
202 hdr.dirEntries = 0;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
203 hdr.dirOffset =
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
204 sizeof(hdr.ident) + sizeof(hdr.version) +
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
205 sizeof(hdr.dirEntries) + sizeof(hdr.dirOffset);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
206
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
207 node = pack->entries;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
208 while (node != NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
209 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
210 hdr.dirEntries++;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
211 hdr.dirOffset += node->length;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
212 node = node->next;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
213 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
214
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
215 // Write PACK header
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
216 if (fseek(pack->file, 0L, SEEK_SET) != 0)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
217 return DMERR_FSEEK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
218
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
219 if (!dm_fwrite_str(pack->file, (Uint8 *) & hdr.ident, sizeof(hdr.ident)) ||
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
220 !dm_fwrite_le16(pack->file, hdr.version) ||
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
221 !dm_fwrite_le32(pack->file, hdr.dirEntries) ||
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
222 !dm_fwrite_le32(pack->file, hdr.dirOffset))
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
223 return DMERR_FWRITE;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
224
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
225 // Write the directory
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
226 if (fseek(pack->file, hdr.dirOffset, SEEK_SET) != 0)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
227 return DMERR_FSEEK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
228
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
229 node = pack->entries;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
230 while (node != NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
231 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
232 // Write one entry
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
233 if (!dm_fwrite_str(pack->file, node->filename, sizeof(node->filename)) ||
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
234 !dm_fwrite_le32(pack->file, node->size) ||
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
235 !dm_fwrite_le32(pack->file, node->offset) ||
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
236 !dm_fwrite_le32(pack->file, node->length) ||
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
237 !dm_fwrite_le32(pack->file, node->flags))
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
238 return DMERR_FWRITE;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
239
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
240 node = node->next;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
241 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
242
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
243 return DMERR_OK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
244 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
245
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
246
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
247 int dmPackCreate(const char *filename, DMPackFile ** pack)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
248 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
249 // Allocate packfile-structure
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
250 *pack = (DMPackFile *) dmCalloc(1, sizeof(DMPackFile));
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
251 if (*pack == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
252 return DMERR_MALLOC;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
253
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
254 // Open the file
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
255 (*pack)->file = fopen(filename, "wb");
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
256 if ((*pack)->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
257 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
258 dmFree(*pack);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
259 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
260 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
261
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
262 (*pack)->filename = dm_strdup(filename);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
263
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
264 // Set the result
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
265 return DMERR_OK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
266 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
267
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
268
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
269 int dmPackAddFile(DMPackFile * pack, const char *filename,
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
270 BOOL doCompress, const Uint32 flags, DMPackEntry ** ppEntry)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
271 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
272 z_stream zstr;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
273 off_t startOffs;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
274 unsigned int zstrSize;
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
275 FILE *inFile = NULL;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
276 Uint8 *inBuffer = NULL, *outBuffer = NULL;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
277 DMPackEntry entry, *node;
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
278 int zres, ret = DMERR_OK;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
279 BOOL zinit = FALSE;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
280
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
281 *ppEntry = NULL;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
282
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
283 if (pack == NULL)
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
284 return DMERR_NULLPTR;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
285
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
286 if (pack->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
287 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
288
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
289 // Compute starting offset
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
290 startOffs = sizeof(DMPackFileHeader);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
291 node = pack->entries;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
292 while (node != NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
293 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
294 startOffs += node->length;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
295 node = node->next;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
296 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
297
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
298 // Seek to the position
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
299 if (fseek(pack->file, startOffs, SEEK_SET) != 0)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
300 return DMERR_INVALID;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
301
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
302 // Read file data
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
303 if ((inFile = fopen(filename, "rb")) == NULL)
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
304 return DMERR_FOPEN;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
305
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
306 // Allocate temporary buffer
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
307 if ((inBuffer = (Uint8 *) dmMalloc(SET_TMPBUF_SIZE)) == NULL ||
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
308 (outBuffer = (Uint8 *) dmMalloc(SET_TMPBUF_SIZE)) == NULL)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
309 {
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
310 ret = DMERR_MALLOC;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
311 goto out;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
312 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
313
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
314 // Read (and possibly compress) the data
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
315 zstrSize = 0;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
316 zstr.zalloc = (alloc_func) Z_NULL;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
317 zstr.zfree = (free_func) Z_NULL;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
318 zstr.opaque = (voidpf) Z_NULL;
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
319 zres = deflateInit(&zstr, doCompress ? Z_DEFAULT_COMPRESSION : 0);
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
320 if (zres != Z_OK)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
321 {
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
322 ret = DMERR_COMPRESSION;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
323 goto out;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
324 }
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
325 zinit = TRUE;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
326
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
327 // Initialize compression streams
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
328 zres = Z_OK;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
329 while (!feof(inFile) && zres == Z_OK)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
330 {
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
331 zstr.avail_in = fread(inBuffer, sizeof(Uint8), SET_TMPBUF_SIZE, inFile);
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
332 zstr.next_in = inBuffer;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
333 zstr.next_out = outBuffer;
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
334 zstr.avail_out = SET_TMPBUF_SIZE;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
335 zstr.total_out = 0;
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
336 zres = deflate(&zstr, Z_FULL_FLUSH);
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
337
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
338 if (zres == Z_OK && zstr.total_out > 0)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
339 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
340 zstrSize += zstr.total_out;
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
341 if (fwrite(outBuffer, sizeof(Uint8), zstr.total_out, pack->file) != zstr.total_out)
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
342 {
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
343 ret = DMERR_FWRITE;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
344 goto out;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
345 }
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
346 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
347 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
348
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
349 // Create directory entry
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
350 strncpy(entry.filename, filename, sizeof(entry.filename));
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
351 entry.filename[sizeof(entry.filename) - 1] = 0;
1018
782a2a3a3707 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1011
diff changeset
352 entry.offset = startOffs;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
353 entry.size = zstr.total_in;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
354 entry.length = zstrSize;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
355 entry.flags = flags;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
356
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
357 // Add directory entry
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
358 if ((*ppEntry = dmPackEntryCopy(&entry)) == NULL)
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
359 {
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
360 ret = DMERR_MALLOC;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
361 goto out;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
362 }
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
363
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
364 dmPackEntryInsert(&pack->entries, *ppEntry);
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
365
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
366 out:
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
367 // Cleanup
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
368 if (zinit)
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
369 deflateEnd(&zstr);
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
370
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
371 dmFree(inBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
372 dmFree(outBuffer);
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
373 if (inFile != NULL)
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
374 fclose(inFile);
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
375
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
376 return ret;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
377 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
378
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
379
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
380 /*
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
381 * EXTRACT a file from the PACK
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
382 */
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
383 int dmPackExtractFile(DMPackFile *pack, DMPackEntry * entry)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
384 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
385 z_stream zstr;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
386 FILE *outFile;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
387 Uint8 *inBuffer, *outBuffer;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
388 size_t inDataLeft;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
389 int ret;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
390
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
391 if (pack == NULL)
1018
782a2a3a3707 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1011
diff changeset
392 return DMERR_NULLPTR;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
393
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
394 if (pack->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
395 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
396
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
397 // Seek to the position
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
398 if (fseek(pack->file, entry->offset, SEEK_SET) != 0)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
399 return DMERR_INVALID;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
400
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
401 // Open destination file
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
402 if ((outFile = fopen(entry->filename, "wb")) == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
403 return -1;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
404
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
405 // Allocate temporary buffer
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
406 if ((inBuffer = (Uint8 *) dmMalloc(SET_TMPBUF_SIZE)) == NULL)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
407 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
408 fclose(outFile);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
409 return DMERR_MALLOC;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
410 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
411
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
412 if ((outBuffer = (Uint8 *) dmMalloc(SET_TMPBUF_SIZE)) == NULL)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
413 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
414 dmFree(inBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
415 fclose(outFile);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
416 return DMERR_MALLOC;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
417 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
418
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
419 // Read and uncompress the data
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
420 zstr.zalloc = (alloc_func) Z_NULL;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
421 zstr.zfree = (free_func) Z_NULL;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
422 zstr.opaque = (voidpf) Z_NULL;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
423 ret = inflateInit(&zstr);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
424 if (ret != Z_OK)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
425 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
426 dmFree(inBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
427 dmFree(outBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
428 fclose(outFile);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
429 return DMERR_COMPRESSION;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
430 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
431
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
432 // Initialize compression streams
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
433 inDataLeft = entry->length;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
434 ret = Z_OK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
435 while (inDataLeft > 0 && ret == Z_OK)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
436 {
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
437 if (inDataLeft >= SET_TMPBUF_SIZE)
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
438 zstr.avail_in = fread(inBuffer, sizeof(Uint8), SET_TMPBUF_SIZE, pack->file);
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
439 else
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
440 zstr.avail_in = fread(inBuffer, sizeof(Uint8), inDataLeft, pack->file);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
441
1018
782a2a3a3707 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1011
diff changeset
442 remaining -= zstr.avail_in;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
443 zstr.next_in = inBuffer;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
444
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
445 while (zstr.avail_in > 0 && ret == Z_OK)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
446 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
447 zstr.next_out = outBuffer;
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
448 zstr.avail_out = SET_TMPBUF_SIZE;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
449 zstr.total_out = 0;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
450 ret = inflate(&zstr, Z_FULL_FLUSH);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
451 if (zstr.total_out > 0)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
452 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
453 fwrite(outBuffer, sizeof(Uint8), zstr.total_out, outFile);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
454 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
455 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
456 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
457
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
458 // Cleanup
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
459 inflateEnd(&zstr);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
460 dmFree(inBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
461 dmFree(outBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
462 fclose(outFile);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
463
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
464 return DMERR_OK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
465 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
466
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
467
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 /* Compare a string to a pattern. Case-SENSITIVE version.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 * The matching pattern can consist of any normal characters plus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 * wildcards ? and *. "?" matches any character and "*" matches
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 * any number of characters.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 BOOL dm_strmatch(const char *str, const char *pattern)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
475 BOOL matched = TRUE, any = FALSE, end = FALSE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
476 const char *tmp = NULL;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 // Check given pattern and string
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 if (str == NULL || pattern == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 // Start comparision
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 do {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
484 matched = FALSE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 switch (*pattern)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 case '?':
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 // Any single character matches
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
491 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 pattern++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 case '*':
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
498 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 pattern++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 if (!*pattern)
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
501 end = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
502 any = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
503 tmp = pattern;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 case 0:
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
507 if (any)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 else
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
512 end = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
518 if (tmp)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
520 any = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
521 pattern = tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 else
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
524 matched = FALSE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526 else
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
527 end = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 default:
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
531 if (any)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 if (*pattern == *str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
535 any = FALSE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
536 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
542 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 if (*pattern == *str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
551 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 if (*pattern)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553 pattern++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
559 if (tmp)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
561 matched = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
562 any = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
563 pattern = tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 if (!*str && !*pattern)
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
569 end = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 } // switch
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
574 } while (matched && !end);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
576 return matched;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
580 BOOL dmCheckExcluded(const char *filename)
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
581 {
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
582 int i;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
583 for (i = 0; i < nexcFilenames; i++)
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
584 {
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
585 if (dm_strmatch(filename, excFilenames[i]))
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
586 return TRUE;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
587 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
588 return FALSE;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
589 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
590
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
591
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592 int main(int argc, char *argv[])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594 int i, res = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595 DMPackFile *pack = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 // Parse arguments
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
598 dmInitProg("packed", "Pack File Editor", "0.5", NULL, NULL);
1011
aa745d31612e Set default verbosity of 'packed' to none.
Matti Hamalainen <ccr@tnsp.org>
parents: 1008
diff changeset
599 dmVerbosity = 0;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
601 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: 752
diff changeset
602 argHandleOpt, argHandleFile, OPTH_BAILOUT))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
603 exit(1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
605 // Check PACK filename
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606 if (optPackFilename == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607 optPackFilename = SET_DEFAULT_PACK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 if (optCommand == CMD_NONE)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611 argShowHelp();
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
612 dmErrorMsg("Nothing to do.\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
613 exit(0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
616
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617 dmMsg(1, "Processing %s ...\n", optPackFilename);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619 // Execute command
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620 switch (optCommand)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 case CMD_CREATE:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 case CMD_ADD:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
624 switch (optCommand)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
625 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626 case CMD_CREATE:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
627 dmMsg(1, "Creating new PACK\n");
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
628 res = dmPackCreate(optPackFilename, &pack);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631 case CMD_ADD:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632 dmMsg(1, "Opening existing PACK\n");
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
633 res = dmPackOpen(optPackFilename, &pack, FALSE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
635 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637 // Add files into PACK
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 if (res == DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
639 {
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
640 dmMsg(1, "Adding files...\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 for (i = 0; i < nsrcFilenames; i++)
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
643 if (!dmCheckExcluded(srcFilenames[i]))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
645 DMPackEntry *node = NULL;
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
646 int res = dmPackAddFile(pack, srcFilenames[i], optCompress, optDefResFlags, &node);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
647
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
648 if (res != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
650 dmPrint(1, "%-32s [ERROR:%d]\n",
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
651 srcFilenames[i], res);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
653 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
654 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
655 dmPrint(1, "%-32s ['%s', s=%d, c=%d, o=%ld, f=0x%04x]\n",
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
656 srcFilenames[i], node->filename,
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
657 node->size, node->length, node->offset, node->flags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
660
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
661 dmMsg(1, "w=%d\n", dmPackWrite(pack));
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
662 dmMsg(1, "c=%d\n", dmPackClose(pack));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
666 dmErrorMsg("Could not open packfile, error #%d: %s\n", res,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
667 dmErrorStr(res));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
668 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
669 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
670
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 case CMD_LIST:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672 // List files in PACK
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
673 res = dmPackOpen(optPackFilename, &pack, TRUE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 if (res == DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676 DMPackEntry *node;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
677 for (i = 0, node = pack->entries; node; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 node = node->next;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679 dmMsg(1, "%d files total\n", i);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
680
115
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
681 dmPrint(0, "%-32s | %8s | %8s | %8s | %s\n",
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
682 "Name", "Size", "CSize", "Offset", "ResFlags");
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
683
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684 for (node = pack->entries; node != NULL; node = node->next)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686 BOOL match;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
688 // Check for matches
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689 if (nsrcFilenames > 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
690 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691 match = FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
692 for (i = 0; i < nsrcFilenames && !match; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
693 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694 match = dm_strmatch(node->filename, srcFilenames[i]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
696 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698 match = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
699
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700 if (match)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
701 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
702 dmPrint(0, "%-32s | %8d | %8d | %08x | %04x\n",
115
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
703 node->filename, node->size, node->length,
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
704 node->offset, node->flags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
706 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
707
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
708 dmMsg(1, "c=%d\n", dmPackClose(pack));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
710 else
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
711 dmErrorMsg("Could not open packfile, error #%d: %s\n", res,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 dmErrorStr(res));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 case CMD_EXTRACT:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
716 // Extract files from PACK
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
717 res = dmPackOpen(optPackFilename, &pack, TRUE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
718 if (res == DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
719 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720 DMPackEntry *node;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
721 FILE *resFile = fopen(DMRES_RES_FILE, "w");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722 if (resFile == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723 {
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
724 int err = dmGetErrno();
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
725 dmErrorMsg("Could not create resource output file '%s' #%d: %s\n",
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
726 DMRES_RES_FILE, err, dmErrorStr(err));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 for (node = pack->entries; node != NULL; node = node->next)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
730 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
731 BOOL match;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
733 // Check for matches
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
734 if (nsrcFilenames > 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
735 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 match = FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
737 for (i = 0; (i < nsrcFilenames) && !match; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
738 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739 match = dm_strmatch(node->filename, srcFilenames[i]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
743 match = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
745 if (match && (node->privFlags & PACK_EXTRACTED) == 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
746 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747 // Mark as done
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748 node->privFlags |= PACK_EXTRACTED;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750 // Print one entry
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
751 dmPrint(0, "Extracting: %-32s [siz=%d, cmp=%d, offs=0x%08x, flags=0x%04x]\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 node->filename, node->size, node->length,
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
753 node->offset, node->flags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
755 dmPackExtractFile(pack, node);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
759 dmMsg(1, "c=%d\n", dmPackClose(pack));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761 if (resFile != NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762 fclose(resFile);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
764 else
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
765 dmErrorMsg("Could not open packfile, error #%d: %s\n", res,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
766 dmErrorStr(res));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
767 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772 }