annotate tools/packed.c @ 2414:69a5af2eb1ea

Remove useless dmMemset().
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 13 Jan 2020 23:27:01 +0200
parents bc05bcfc4598
children 0b18f597351a
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
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
4 * (C) Copyright 2011, 2018 Tecnic Software productions (TNSP)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
1432
a9516570cc26 Improve build, so that we can build the tools and tests with minimal
Matti Hamalainen <ccr@tnsp.org>
parents: 1407
diff changeset
6 #include "dmtool.h"
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "dmargs.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "dmpack.h"
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
10 #include "dmfile.h"
115
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
11 #include "dmres.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)
1977
33c29e7d1861 Increase the zlib compression buffer size to 1MB to improve the efficiency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1742
diff changeset
16 #define SET_TMPBUF_SIZE (1024 * 1024)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
17
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 CMD_NONE = 0,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 CMD_CREATE,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 CMD_ADD,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 CMD_LIST,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 CMD_EXTRACT
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 } DCOMMAND;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 PACK_EXTRACTED = 0x0001,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
32 int nsrcFilenames = 0, nexcFilenames = 0;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 char * srcFilenames[SET_MAX_FILES];
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
34 char * excFilenames[SET_MAX_FILES];
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
35
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 char * optPackFilename = NULL;
1120
c1583a2278ec Fix '-n' option handling for packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
37 BOOL optDoCompress = TRUE;
1027
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
38 int optCompressLevel = Z_BEST_COMPRESSION;
0
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
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
43 static const DMOptArg cmdList[] =
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
44 {
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
45 { CMD_CREATE , 'c', "create", "Create and add files to PACK", OPT_NONE },
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
46 { CMD_ADD , 'a', "add", "Add files to PACK", OPT_NONE },
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
47 { CMD_LIST , 'l', "list", "List files in PACK", OPT_NONE },
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
48 { CMD_EXTRACT , 'e', "extract", "Extract files from PACK", OPT_NONE },
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
49 };
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
50
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
51 static const int cmdListN = sizeof(cmdList) / sizeof(cmdList[0]);
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
52
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
53
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 752
diff changeset
54 static const DMOptArg optList[] =
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 {
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
56 { 0, '?', "help" , "Show this help", OPT_NONE },
2410
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
57 { 1, 0, "license" , "Print out this program's license agreement", OPT_NONE },
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
58 { 2, 'v', "verbose" , "Be more verbose", OPT_NONE },
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
59
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
60 { 3, 'n', "nocompress" , "No compression / decompression", OPT_NONE },
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
61 { 4, 'C', "level" , "Set zlib compression level 1-9", OPT_ARGREQ },
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
62 { 5, 'f', "resflags" , "Set default resource flags (-f 0xff)", OPT_ARGREQ },
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
63 { 6, 'x', "exclude" , "Exclude name/glob pattern", OPT_ARGREQ },
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 };
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 static const int optListN = sizeof(optList) / sizeof(optList[0]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
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 void argShowHelp()
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 {
2036
0fe1bce4e8a5 Fix 'packed' help.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
71 dmPrintBanner(stdout, dmProgName, "<command> [options] <packfile> [<filename(s)>]");
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
72
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
73 for (int i = 0; i < cmdListN; i++)
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
74 {
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
75 const DMOptArg *cmd = &cmdList[i];
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
76 char tmpStr[128];
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
77 snprintf(tmpStr, sizeof(tmpStr), "%c / %s",
1742
ddec147d1f90 Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
78 cmd->o_short, cmd->o_long);
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
79
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
80 fprintf(stdout, " %-15s %s\n", tmpStr, cmd->desc);
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
81 }
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
82
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
83 fprintf(stdout, "\n");
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
84
2402
b7cd5dd0b82e Merge one more change from th-libs args processing.
Matti Hamalainen <ccr@tnsp.org>
parents: 2391
diff changeset
85 dmArgsPrintHelp(stdout, optList, optListN, 0, 80 - 2);
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
86
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 fprintf(stdout,
1406
cb9865a49134 Indentation cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1267
diff changeset
88 "\n"
cb9865a49134 Indentation cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1267
diff changeset
89 "Examples:\n"
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
90 "$ %s l test.pak -- list files in test.pak\n"
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
91 "$ %s c test.pak foobar.jpg -- create test.pak and add foobar.jpg in it\n"
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
92 "$ %s e test.pak foobar.jpg -- extract foobar.jpg from test.pak\n",
1406
cb9865a49134 Indentation cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1267
diff changeset
93 dmProgName, dmProgName, dmProgName);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 {
1267
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
99 (void) currArg;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 switch (optN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 {
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
102 case 0:
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
103 argShowHelp();
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
104 exit(0);
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
105 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
2410
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
107 case 1:
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
108 dmPrintLicense(stdout);
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
109 exit(0);
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
110 break;
bc05bcfc4598 Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents: 2408
diff changeset
111
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
112 case 2:
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
113 dmVerbosity++;
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
114 break;
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
115
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
116 case 3:
1120
c1583a2278ec Fix '-n' option handling for packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
117 optDoCompress = FALSE;
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
118 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
120 case 4:
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
121 optCompressLevel = atoi(optArg);
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
122 if (optCompressLevel < 1 || optCompressLevel > 9)
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
123 {
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
124 dmErrorMsg("Invalid compression level argument '%s', must be 1 .. 9.\n", optArg);
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
125 return FALSE;
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
126 }
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
127 break;
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
128
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
129 case 5:
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 {
2004
161e731eb152 Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents: 1977
diff changeset
131 unsigned int tmpUI;
161e731eb152 Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents: 1977
diff changeset
132 if (!dmGetIntVal(optArg, &tmpUI, NULL))
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
133 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
134 dmErrorMsg("Invalid flags value '%s'.\n", optArg);
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
135 return FALSE;
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
136 }
2004
161e731eb152 Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents: 1977
diff changeset
137 optDefResFlags = tmpUI;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 }
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
139 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
140
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
141 case 6:
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
142 if (nexcFilenames < SET_MAX_FILES)
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
143 {
1267
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
144 excFilenames[nexcFilenames++] = optArg;
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
145 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
146 else
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
147 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
148 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
149 SET_MAX_FILES);
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
150 return FALSE;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
151 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
152 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
154 default:
2183
e3f0eaf23f4f Change the error message for unimplemented option argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 2105
diff changeset
155 dmErrorMsg("Unimplemented option argument '%s'.\n", currArg);
211
3dc35ce354f7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
156 return FALSE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
163 BOOL argHandleNonOpt(char *currArg)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 {
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
165 if (optCommand == CMD_NONE)
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
166 {
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
167 for (int n = 0; n < cmdListN; n++)
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
168 {
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
169 const DMOptArg *cmd = &cmdList[n];
1742
ddec147d1f90 Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
170 if ((currArg[0] == cmd->o_short && currArg[1] == 0) ||
ddec147d1f90 Bring in changes from the th-libs version of commandline argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
171 strcmp(currArg, cmd->o_long) == 0)
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
172 {
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
173 optCommand = cmd->id;
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
174 break;
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
175 }
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
176 }
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
177 if (optCommand == CMD_NONE)
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
178 {
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
179 dmErrorMsg("Invalid command '%s'.\n", currArg);
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
180 return FALSE;
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
181 }
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
182 }
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
183 else
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
184 if (optPackFilename == NULL)
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
185 {
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
186 optPackFilename = currArg;
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
187 }
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
188 else
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 if (nsrcFilenames < SET_MAX_FILES)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 {
1022
0020c192c8dd Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1021
diff changeset
191 srcFilenames[nsrcFilenames++] = currArg;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
195 dmErrorMsg("Maximum number of input files (%d) exceeded!\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 SET_MAX_FILES);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
203 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
204 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
205 DMPackEntry *node = dmPackEntryNew();
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
206 if (node == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
207 return NULL;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
208
1033
c353e6bcb733 Change handling of filename field in PACKs.
Matti Hamalainen <ccr@tnsp.org>
parents: 1032
diff changeset
209 strncpy(node->filename, src->filename, DMRES_NAME_LEN);
c353e6bcb733 Change handling of filename field in PACKs.
Matti Hamalainen <ccr@tnsp.org>
parents: 1032
diff changeset
210 node->filename[DMRES_NAME_LEN] = 0;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
211
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
212 node->size = src->size;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
213 node->offset = src->offset;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
214 node->length = src->length;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
215 node->flags = src->flags;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
216
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
217 return node;
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
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
220
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
221 int dmPackWrite(DMPackFile * pack)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
222 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
223 DMPackEntry *node;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
224 DMPackFileHeader hdr;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
225
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
226 if (pack == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
227 return DMERR_OK;
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 if (pack->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
230 return DMERR_FOPEN;
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 // 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
233 memcpy(&hdr.ident, DPACK_IDENT, sizeof(hdr.ident));
2321
9360a693d8af Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2183
diff changeset
234 hdr.version = DPACK_VERSION;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
235 hdr.dirEntries = 0;
2321
9360a693d8af Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2183
diff changeset
236 hdr.dirOffset =
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
237 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
238 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
239
2105
eebe338b3c39 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2037
diff changeset
240 for (node = pack->entries; node != NULL; node = node->next)
952
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 hdr.dirEntries++;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
243 hdr.dirOffset += node->length;
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
2391
d1992206765a Fix some format specifiers, was erraneously using DM_PRI*_SIZE_T instead of DM_PRI*64.
Matti Hamalainen <ccr@tnsp.org>
parents: 2384
diff changeset
246 dmMsg(1, "%d entries in PACK, dir at offset 0x%08" DM_PRIx64 ".\n",
1128
0194c8a26aa8 Add informative message to packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1120
diff changeset
247 hdr.dirEntries, hdr.dirOffset);
0194c8a26aa8 Add informative message to packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1120
diff changeset
248
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
249 // Write PACK header
1108
5a8d29b88431 More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1041
diff changeset
250 if (fseeko(pack->file, 0, SEEK_SET) != 0)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
251 return DMERR_FSEEK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
252
2321
9360a693d8af Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 2183
diff changeset
253 if (!dm_fwrite_str(pack->file, (Uint8 *) &hdr.ident, sizeof(hdr.ident)) ||
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
254 !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
255 !dm_fwrite_le32(pack->file, hdr.dirEntries) ||
1037
d674ddc0fc82 Change PACK file format to use 64 bit fileoffsets. Also switch some
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
256 !dm_fwrite_le64(pack->file, hdr.dirOffset))
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
257 return DMERR_FWRITE;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
258
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
259 // Write the directory
1108
5a8d29b88431 More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1041
diff changeset
260 if (fseeko(pack->file, hdr.dirOffset, SEEK_SET) != 0)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
261 return DMERR_FSEEK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
262
2105
eebe338b3c39 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2037
diff changeset
263 for (node = pack->entries; node != NULL; node = node->next)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
264 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
265 // Write one entry
1033
c353e6bcb733 Change handling of filename field in PACKs.
Matti Hamalainen <ccr@tnsp.org>
parents: 1032
diff changeset
266 if (!dm_fwrite_str(pack->file, node->filename, DMRES_NAME_LEN) ||
1037
d674ddc0fc82 Change PACK file format to use 64 bit fileoffsets. Also switch some
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
267 !dm_fwrite_le64(pack->file, node->offset) ||
d674ddc0fc82 Change PACK file format to use 64 bit fileoffsets. Also switch some
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
268 !dm_fwrite_le32(pack->file, node->length) ||
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
269 !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
270 !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
271 return DMERR_FWRITE;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
272 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
273
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
274 return DMERR_OK;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
275 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
276
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
277
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
278 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
279 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
280 // Allocate packfile-structure
1024
66b01739e5d3 Use dmMalloc0() instead of dmCalloc(1, ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 1023
diff changeset
281 *pack = (DMPackFile *) dmMalloc0(sizeof(DMPackFile));
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
282 if (*pack == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
283 return DMERR_MALLOC;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
284
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
285 // Open the file
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
286 (*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
287 if ((*pack)->file == NULL)
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 dmFree(*pack);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
290 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
291 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
292
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
293 (*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
294
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
295 // Set the result
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
296 return DMERR_OK;
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
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
299
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
300 int dmPackAddFile(DMPackFile * pack, const char *filename,
1041
d0f80f6a0c65 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1039
diff changeset
301 const Uint32 flags, const BOOL compress, int level,
d0f80f6a0c65 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1039
diff changeset
302 DMPackEntry ** ppEntry)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
303 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
304 Uint64 startOffs, outSize;
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
305 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
306 DMPackEntry entry, *node;
1031
f7863608d84c Cleanup, remove debug code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
307 FILE *inFile = NULL;
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
308 int ret = DMERR_OK;
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
309 BOOL zinit = FALSE;
1031
f7863608d84c Cleanup, remove debug code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1029
diff changeset
310 z_stream zstr;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
311
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
312 *ppEntry = NULL;
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 if (pack == NULL)
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
315 return DMERR_NULLPTR;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
316
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
317 if (pack->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
318 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
319
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
320 // Compute starting offset
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
321 outSize = 0;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
322 startOffs = sizeof(DMPackFileHeader);
2105
eebe338b3c39 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2037
diff changeset
323 for (node = pack->entries; node != NULL; node = node->next)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
324 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
325 startOffs += node->length;
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
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
328 // Seek to the position
1108
5a8d29b88431 More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1041
diff changeset
329 if (fseeko(pack->file, startOffs, SEEK_SET) != 0)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
330 return DMERR_INVALID;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
331
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
332 // Read file data
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
333 if ((inFile = fopen(filename, "rb")) == NULL)
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
334 return DMERR_FOPEN;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
335
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
336 // Allocate temporary buffer
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
337 if ((inBuffer = (Uint8 *) dmMalloc(SET_TMPBUF_SIZE)) == NULL ||
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
338 (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
339 {
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
340 ret = DMERR_MALLOC;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
341 goto out;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
342 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
343
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
344 // Read (and possibly compress) the data
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
345 if (compress)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
346 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
347 int zret;
2414
69a5af2eb1ea Remove useless dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 2410
diff changeset
348 memset(&zstr, 0, sizeof(zstr));
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
349 if (deflateInit(&zstr, level) != Z_OK)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
350 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
351 ret = DMERR_COMPRESSION;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
352 goto out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
353 }
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
354 zinit = TRUE;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
355
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
356 // Initialize compression streams
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
357 zret = Z_OK;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
358 while (!feof(inFile) && zret == Z_OK)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
359 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
360 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
361
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
362 zstr.next_in = inBuffer;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
363 zstr.next_out = outBuffer;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
364 zstr.avail_out = SET_TMPBUF_SIZE;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
365 zstr.total_out = 0;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
366 zret = deflate(&zstr, Z_FULL_FLUSH);
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
367
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
368 if (zret == Z_OK && zstr.total_out > 0)
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
369 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
370 outSize += zstr.total_out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
371 if (fwrite(outBuffer, sizeof(Uint8), zstr.total_out, pack->file) != zstr.total_out)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
372 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
373 ret = DMERR_FWRITE;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
374 goto out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
375 }
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
376 }
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 }
1032
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
379 else
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
380 {
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
381 while (!feof(inFile))
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
382 {
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
383 size_t read = fread(inBuffer, sizeof(Uint8), SET_TMPBUF_SIZE, inFile);
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
384 if (read > 0)
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
385 {
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
386 outSize += read;
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
387 if (fwrite(inBuffer, sizeof(Uint8), read, pack->file) != read)
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
388 {
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
389 ret = DMERR_FWRITE;
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
390 goto out;
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
391 }
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
392 }
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
393 }
1039
54970cd5acf0 Remember to set the "compressed" size field for raw nodes too, as we check
Matti Hamalainen <ccr@tnsp.org>
parents: 1037
diff changeset
394 zstr.total_in = outSize;
1032
f8d75a51de2c Implement raw uncompressed data copy.
Matti Hamalainen <ccr@tnsp.org>
parents: 1031
diff changeset
395 }
952
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 // Create directory entry
1035
d2fa4f6d6117 Oops, add a missing semicolon.
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
398 strncpy(entry.filename, filename, DMRES_NAME_LEN);
1033
c353e6bcb733 Change handling of filename field in PACKs.
Matti Hamalainen <ccr@tnsp.org>
parents: 1032
diff changeset
399 entry.filename[DMRES_NAME_LEN] = 0;
1018
782a2a3a3707 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1011
diff changeset
400 entry.offset = startOffs;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
401 entry.size = zstr.total_in;
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
402 entry.length = outSize;
1029
c88b879c735c Add DMF_COMPRESSED flag to compressed entry node flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1028
diff changeset
403 entry.flags = flags | (compress ? DMF_COMPRESSED : 0);
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
404
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
405 // Add directory entry
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
406 if ((*ppEntry = dmPackEntryCopy(&entry)) == NULL)
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
407 {
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
408 ret = DMERR_MALLOC;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
409 goto out;
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
410 }
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
411
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
412 dmPackEntryInsert(&pack->entries, *ppEntry);
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
413
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
414 out:
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
415 // Cleanup
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
416 if (zinit)
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
417 deflateEnd(&zstr);
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
418
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
419 dmFree(inBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
420 dmFree(outBuffer);
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
421 if (inFile != NULL)
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
422 fclose(inFile);
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
423
994
e8de4fbc03b6 Clean up packed a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
424 return ret;
952
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
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
427
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
428 /*
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
429 * 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
430 */
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
431 int dmPackExtractFile(DMPackFile *pack, DMPackEntry * entry, BOOL decompress)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
432 {
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
433 z_stream zstr;
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
434 FILE *outFile = NULL;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
435 Uint8 *inBuffer = NULL, *outBuffer = NULL;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
436 size_t remaining;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
437 int zret, ret = DMERR_OK;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
438 BOOL zinit = FALSE;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
439
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
440 if (pack == NULL)
1018
782a2a3a3707 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1011
diff changeset
441 return DMERR_NULLPTR;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
442
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
443 if (pack->file == NULL)
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
444 return DMERR_FOPEN;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
445
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
446 // Seek to the position
1108
5a8d29b88431 More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1041
diff changeset
447 if (fseeko(pack->file, entry->offset, SEEK_SET) != 0)
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
448 return DMERR_FSEEK;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
449
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
450 // Open destination file
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
451 if ((outFile = fopen(entry->filename, "wb")) == NULL)
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
452 return DMERR_FOPEN;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
453
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
454 // Allocate temporary buffer
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
455 if ((inBuffer = (Uint8 *) dmMalloc(SET_TMPBUF_SIZE)) == NULL ||
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
456 (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
457 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
458 ret = DMERR_MALLOC;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
459 goto out;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
460 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
461
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
462 // Read and uncompress the data, if needed
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
463 if (decompress || (entry->flags & DMF_COMPRESSED) == 0)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
464 {
2414
69a5af2eb1ea Remove useless dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 2410
diff changeset
465 memset(&zstr, 0, sizeof(zstr));
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
466 if (inflateInit(&zstr) != Z_OK)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
467 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
468 ret = DMERR_COMPRESSION;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
469 goto out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
470 }
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
471 zinit = TRUE;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
472 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
473
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
474 // Initialize compression streams
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
475 remaining = entry->length;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
476 zret = Z_OK;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
477 while (remaining > 0 && zret == Z_OK)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
478 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
479 size_t needed = remaining > SET_TMPBUF_SIZE ? SET_TMPBUF_SIZE : remaining;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
480 zstr.avail_in = fread(inBuffer, sizeof(Uint8), needed, pack->file);
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
481 if (zstr.avail_in < needed)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
482 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
483 ret = DMERR_FREAD;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
484 goto out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
485 }
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
486
1018
782a2a3a3707 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1011
diff changeset
487 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
488 zstr.next_in = inBuffer;
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
489
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
490 if (!decompress)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
491 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
492 if (fwrite(inBuffer, sizeof(Uint8), zstr.avail_in, outFile) != zstr.avail_in)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
493 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
494 ret = DMERR_FWRITE;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
495 goto out;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
496 }
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
497 }
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
498 else
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
499 while (zstr.avail_in > 0 && zret == Z_OK)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
500 {
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
501 zstr.next_out = outBuffer;
996
acda8cfc9119 Also here.
Matti Hamalainen <ccr@tnsp.org>
parents: 994
diff changeset
502 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
503 zstr.total_out = 0;
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
504 zret = inflate(&zstr, Z_FULL_FLUSH);
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
505 if (zstr.total_out > 0 &&
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
506 fwrite(outBuffer, sizeof(Uint8), zstr.total_out, outFile) != zstr.total_out)
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
507 {
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
508 ret = DMERR_FWRITE;
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
509 goto out;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
510 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
511 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
512 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
513
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
514 out:
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
515 // Cleanup
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
516 if (zinit)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
517 inflateEnd(&zstr);
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
518
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
519 dmFree(inBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
520 dmFree(outBuffer);
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
521
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
522 if (outFile != NULL)
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
523 fclose(outFile);
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
524
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
525 return ret;
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
526 }
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
527
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
528
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 /* Compare a string to a pattern. Case-SENSITIVE version.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 * The matching pattern can consist of any normal characters plus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 * wildcards ? and *. "?" matches any character and "*" matches
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 * any number of characters.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 */
1407
4bca92dd7280 Rename dm_strmatch() to dmStrMatch().
Matti Hamalainen <ccr@tnsp.org>
parents: 1406
diff changeset
534 BOOL dmStrMatch(const char *str, const char *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
536 BOOL matched = TRUE, any = FALSE, end = FALSE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
537 const char *tmp = NULL;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 // Check given pattern and string
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 if (str == NULL || pattern == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 // Start comparision
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544 do {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
545 matched = FALSE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 switch (*pattern)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 case '?':
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 // Any single character matches
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
552 matched = TRUE;
0
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 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558 case '*':
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
559 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560 pattern++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561 if (!*pattern)
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
562 end = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
563 any = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
564 tmp = pattern;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 break;
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 case 0:
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
568 if (any)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 else
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
573 end = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
576 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
579 if (tmp)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
581 any = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
582 pattern = tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 else
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
585 matched = FALSE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587 else
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
588 end = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 default:
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
592 if (any)
0
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 if (*pattern == *str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
596 any = FALSE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
597 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
598 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 else
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 (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
603 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
605 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 if (*pattern == *str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
612 matched = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
613 if (*pattern)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614 pattern++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 if (*str)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
616 str++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
620 if (tmp)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 {
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
622 matched = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
623 any = TRUE;
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
624 pattern = tmp;
0
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 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
627 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 if (!*str && !*pattern)
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
630 end = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 } // switch
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
635 } while (matched && !end);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636
1019
8cf8a8035438 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1018
diff changeset
637 return matched;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
639
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
640
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
641 BOOL dmCheckExcluded(const char *filename)
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
642 {
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
643 for (int i = 0; i < nexcFilenames; i++)
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
644 {
1407
4bca92dd7280 Rename dm_strmatch() to dmStrMatch().
Matti Hamalainen <ccr@tnsp.org>
parents: 1406
diff changeset
645 if (dmStrMatch(filename, excFilenames[i]))
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
646 return TRUE;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
647 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
648 return FALSE;
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
649 }
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
650
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
651
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 int main(int argc, char *argv[])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
653 {
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
654 int res = 0;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
655 DMPackFile *pack = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
656
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 // Parse arguments
2408
60e119262c67 Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents: 2402
diff changeset
658 dmInitProg("packed", "TNSP Pack File Editor", "0.7", NULL, NULL);
1011
aa745d31612e Set default verbosity of 'packed' to none.
Matti Hamalainen <ccr@tnsp.org>
parents: 1008
diff changeset
659 dmVerbosity = 0;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
660
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
661 if (!dmArgsProcess(argc, argv, optList, optListN,
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
662 argHandleOpt, argHandleNonOpt, OPTH_BAILOUT))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 exit(1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665 if (optCommand == CMD_NONE)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
666 {
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
667 dmErrorMsg("Nothing to do. Perhaps try \"%s --help\"?\n",
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
668 dmProgName);
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
669 goto error;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
670 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
671
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
672 if (optPackFilename == NULL)
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
673 {
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
674 dmErrorMsg("No PACK file specified.\n");
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
675 goto error;
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
676 }
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
677
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
678 dmMsg(1, "Processing PACK '%s' ...\n", optPackFilename);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
680 // Execute command
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
681 switch (optCommand)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
682 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
683 case CMD_CREATE:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684 case CMD_ADD:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 switch (optCommand)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687 case CMD_CREATE:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
688 dmMsg(1, "Creating new PACK\n");
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
689 res = dmPackCreate(optPackFilename, &pack);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
690 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
692 case CMD_ADD:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
693 dmMsg(1, "Opening existing PACK\n");
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
694 res = dmPackOpen(optPackFilename, &pack, FALSE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695 break;
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698 // Add files into PACK
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
699 if (res == DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700 {
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
701 dmMsg(1, "Adding files...\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
703 for (int i = 0; i < nsrcFilenames; i++)
752
2b9dd22f01e9 Improve packed by adding file exclusion option.
Matti Hamalainen <ccr@tnsp.org>
parents: 721
diff changeset
704 if (!dmCheckExcluded(srcFilenames[i]))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
706 DMPackEntry *node = NULL;
1026
16e63811d0c2 Clean up the pack file node adding/extracting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1025
diff changeset
707 int res = dmPackAddFile(pack, srcFilenames[i],
1120
c1583a2278ec Fix '-n' option handling for packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
708 optDefResFlags, optDoCompress,
1027
d29058e93799 Add option for setting the zlib compression level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1026
diff changeset
709 optCompressLevel, &node);
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
710
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
711 if (res != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 {
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
713 dmPrint(1, "%-32s [ERROR:%d]\n",
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
714 srcFilenames[i], res);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
716 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
717 {
2391
d1992206765a Fix some format specifiers, was erraneously using DM_PRI*_SIZE_T instead of DM_PRI*64.
Matti Hamalainen <ccr@tnsp.org>
parents: 2384
diff changeset
718 dmPrint(1, "%-32s ['%s', s=%d, c=%d, o=%" DM_PRId64 ", f=0x%04x]\n",
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
719 srcFilenames[i], node->filename,
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
720 node->size, node->length, node->offset, node->flags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
721 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
724 dmMsg(2, "w=%d\n", dmPackWrite(pack));
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
725 dmMsg(2, "c=%d\n", dmPackClose(pack));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
729 dmErrorMsg("Could not open packfile, error #%d: %s\n", res,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
730 dmErrorStr(res));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
731 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
733
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
734 case CMD_LIST:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
735 // List files in PACK
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
736 res = dmPackOpen(optPackFilename, &pack, TRUE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
737 if (res == DMERR_OK)
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 DMPackEntry *node;
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
740 int i;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741 for (i = 0, node = pack->entries; node; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742 node = node->next;
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
743
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744 dmMsg(1, "%d files total\n", i);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
745
115
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
746 dmPrint(0, "%-32s | %8s | %8s | %8s | %s\n",
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
747 "Name", "Size", "CSize", "Offset", "ResFlags");
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
748
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 for (node = pack->entries; node != NULL; node = node->next)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
751 BOOL match;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
752
1025
b43885dd3d1a Comments, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1024
diff changeset
753 // Check for matches in specified filenames/patterns
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 if (nsrcFilenames > 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 match = FALSE;
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
757 for (int i = 0; i < nsrcFilenames && !match; i++)
1407
4bca92dd7280 Rename dm_strmatch() to dmStrMatch().
Matti Hamalainen <ccr@tnsp.org>
parents: 1406
diff changeset
758 match = dmStrMatch(node->filename, srcFilenames[i]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
759 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 else
1025
b43885dd3d1a Comments, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1024
diff changeset
761 // No filenames specified, everything shown
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762 match = TRUE;
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 if (match)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
765 {
2391
d1992206765a Fix some format specifiers, was erraneously using DM_PRI*_SIZE_T instead of DM_PRI*64.
Matti Hamalainen <ccr@tnsp.org>
parents: 2384
diff changeset
766 dmPrint(0, "%-32s | %8d | %8d | %08" DM_PRIx64 " | %04x\n",
115
23e03defa759 Prettify pack content listing output.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
767 node->filename, node->size, node->length,
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
768 node->offset, node->flags);
0
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
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
772 dmMsg(2, "c=%d\n", dmPackClose(pack));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
773 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
774 else
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
775 dmErrorMsg("Could not open packfile, error #%d: %s\n", res,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776 dmErrorStr(res));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779 case CMD_EXTRACT:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
780 // Extract files from PACK
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
781 res = dmPackOpen(optPackFilename, &pack, TRUE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
782 if (res == DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
784 DMPackEntry *node;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
785 FILE *resFile = fopen(DMRES_RES_FILE, "w");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
786 if (resFile == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
787 {
952
ffdae9cd81de Remove the dmpackutil module, move the code to packed utility
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
788 int err = dmGetErrno();
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
789 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
790 DMRES_RES_FILE, err, dmErrorStr(err));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 for (node = pack->entries; node != NULL; node = node->next)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 BOOL match;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
796
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 // Check for matches
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
798 if (nsrcFilenames > 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
800 match = FALSE;
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
801 for (int i = 0; i < nsrcFilenames && !match; i++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802 {
1407
4bca92dd7280 Rename dm_strmatch() to dmStrMatch().
Matti Hamalainen <ccr@tnsp.org>
parents: 1406
diff changeset
803 if (dmStrMatch(node->filename, srcFilenames[i]) &&
1267
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
804 !dmCheckExcluded(node->filename))
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
805 match = TRUE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808 else
1267
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
809 {
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
810 match = !dmCheckExcluded(node->filename);
ad13510c8e41 Fix handling of -x option in packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
811 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813 if (match && (node->privFlags & PACK_EXTRACTED) == 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 // Mark as done
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816 node->privFlags |= PACK_EXTRACTED;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818 // Print one entry
2391
d1992206765a Fix some format specifiers, was erraneously using DM_PRI*_SIZE_T instead of DM_PRI*64.
Matti Hamalainen <ccr@tnsp.org>
parents: 2384
diff changeset
819 dmPrint(0, "Extracting: %-32s [siz=%d, cmp=%d, offs=0x%08" DM_PRIx64 ", flags=0x%04x]\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
820 node->filename, node->size, node->length,
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
821 node->offset, node->flags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
822
1120
c1583a2278ec Fix '-n' option handling for packed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
823 dmPackExtractFile(pack, node, optDoCompress);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
824 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
825 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
826
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
827 dmMsg(2, "c=%d\n", dmPackClose(pack));
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
828
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
829 if (resFile != NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
830 fclose(resFile);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
831 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
832 else
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 952
diff changeset
833 dmErrorMsg("Could not open packfile, error #%d: %s\n", res,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
834 dmErrorStr(res));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
835 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
836 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
837
1642
8fb4e8c825d6 Refactor "packed" utility. This breaks commandline backwards compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
838 error:
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
839 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
840 }