summaryrefslogtreecommitdiffstats
path: root/patches/p7zip/p7zip_4.57-ds-rusxmms.patch
blob: 0913c1340e89504439437eae162a7352b23cc5d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
diff -dPNur p7zip_4.57/C/rccrecode.c p7zip_4.57-new/C/rccrecode.c
--- p7zip_4.57/C/rccrecode.c	1970-01-01 01:00:00.000000000 +0100
+++ p7zip_4.57-new/C/rccrecode.c	2008-04-11 20:23:42.000000000 +0200
@@ -0,0 +1,71 @@
+#include <pthread.h>
+#include <librcc.h>
+
+static rcc_class_default_charset default_oem[] = {
+    { "ru", "IBM866" },
+    { NULL, NULL }
+};
+
+static rcc_class_default_charset default_iso[] = {
+    { "ru", "CP1251" },
+    { NULL, NULL }
+};
+
+#define ARC_CLASS 0
+#define OUT_CLASS 1
+#define ARCOUT_CLASS 0
+static rcc_class classes[] = {
+    { "oem", RCC_CLASS_STANDARD, NULL, default_oem, "OEM Encoding", 0 },
+    { "out", RCC_CLASS_STANDARD, "LC_CTYPE", NULL, "Output", 0 },
+    { NULL, RCC_CLASS_STANDARD, NULL, NULL, NULL, 0 }
+};
+
+static int initialized = 0;
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void *rcc_init() {
+    rcc_context ctx;
+    
+    pthread_mutex_lock(&mutex);
+    if (!initialized) {
+	rccInit();
+	rccInitDefaultContext(NULL, 0, 0, classes, 0);
+	rccLoad(NULL, "zip");
+	rccInitDb4(NULL, NULL, 0);
+    }
+    initialized++;
+    pthread_mutex_unlock(&mutex);
+    
+    ctx = rccCreateContext(NULL, 0, 0, classes, 0);
+    if (ctx) rccInitDb4(ctx, NULL, 0);
+    if (ctx) rccLoad(ctx, "zip");
+
+    return ctx;
+}
+
+
+void rcc_free(void *ctx) {
+    if (ctx) rccFreeContext((rcc_context)ctx);
+    
+    pthread_mutex_lock(&mutex);
+    if (initialized == 1) rccFree();
+    initialized--;
+    pthread_mutex_unlock(&mutex);
+}
+
+
+char *rcc_read(void *ctx, const char *string, size_t size) {
+    if (!initialized) {
+	rcc_init();
+	if (!initialized) return NULL;
+    }
+    return rccSizedRecode((rcc_context)ctx, ARC_CLASS, OUT_CLASS, string, size, NULL);
+}
+
+char *rcc_write(rcc_context ctx, const char *string, size_t size) {
+    if (!initialized) {
+	rcc_init();
+	if (!initialized) return NULL;
+    }
+    return rccSizedRecode((rcc_context)ctx, OUT_CLASS, ARCOUT_CLASS, string, size, NULL);
+}
diff -dPNur p7zip_4.57/C/rccrecode.h p7zip_4.57-new/C/rccrecode.h
--- p7zip_4.57/C/rccrecode.h	1970-01-01 01:00:00.000000000 +0100
+++ p7zip_4.57-new/C/rccrecode.h	2008-04-11 20:23:42.000000000 +0200
@@ -0,0 +1,17 @@
+#ifndef _RCC_RECODE_H
+#define _RCC_RECODE_H
+
+# ifdef __cplusplus 
+extern "C" { 
+# endif
+
+    void *rcc_init();
+    void rcc_free(void *ctx);
+    char *rcc_read(void *ctx, const char *string, size_t size);
+    char *rcc_write(void *ctx, const char *string, size_t size);
+
+# ifdef __cplusplus 
+}
+# endif
+
+#endif /* _RCC_RECODE_H */
diff -dPNur p7zip_4.57/CPP/7zip/Archive/Zip/ZipIn.cpp p7zip_4.57-new/CPP/7zip/Archive/Zip/ZipIn.cpp
--- p7zip_4.57/CPP/7zip/Archive/Zip/ZipIn.cpp	2007-12-08 11:19:00.000000000 +0100
+++ p7zip_4.57-new/CPP/7zip/Archive/Zip/ZipIn.cpp	2008-04-11 20:23:42.000000000 +0200
@@ -9,11 +9,22 @@
 #include "../../Common/LimitedStreams.h"
 #include "../../Common/StreamUtils.h"
 
+#include "../../../../C/rccrecode.h"
+
 namespace NArchive {
 namespace NZip {
+
+CInArchive::CInArchive() {
+    rccctx = rcc_init();
+}
+
+CInArchive::~CInArchive() {
+    rcc_free(rccctx);
+}
+
  
 // static const char kEndOfString = '\0';
-  
+ 
 bool CInArchive::Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit)
 {
   m_Stream = inStream;
@@ -196,10 +207,18 @@
 
 AString CInArchive::ReadFileName(UInt32 nameSize)
 {
+  char *rccrec;
   if (nameSize == 0)
     return AString();
   SafeReadBytes(m_NameBuffer.GetBuffer(nameSize), nameSize);
   m_NameBuffer.ReleaseBuffer(nameSize);
+
+  rccrec = rcc_read(rccctx, (LPCSTR)m_NameBuffer, 0);
+  if (rccrec) {
+	m_NameBuffer = rccrec;
+	free(rccrec);
+  }
+  
   return m_NameBuffer;
 }
 
diff -dPNur p7zip_4.57/CPP/7zip/Archive/Zip/ZipIn.h p7zip_4.57-new/CPP/7zip/Archive/Zip/ZipIn.h
--- p7zip_4.57/CPP/7zip/Archive/Zip/ZipIn.h	2007-12-08 11:19:00.000000000 +0100
+++ p7zip_4.57-new/CPP/7zip/Archive/Zip/ZipIn.h	2008-04-11 20:23:42.000000000 +0200
@@ -106,6 +106,10 @@
   bool SeekInArchive(UInt64 position);
   ISequentialInStream *CreateLimitedStream(UInt64 position, UInt64 size);
   IInStream* CreateStream();
+
+  void *rccctx;
+  CInArchive();
+  ~CInArchive();
 };
   
 }}
diff -dPNur p7zip_4.57/CPP/7zip/Archive/Zip/ZipOut.cpp p7zip_4.57-new/CPP/7zip/Archive/Zip/ZipOut.cpp
--- p7zip_4.57/CPP/7zip/Archive/Zip/ZipOut.cpp	2007-06-26 20:06:23.000000000 +0200
+++ p7zip_4.57-new/CPP/7zip/Archive/Zip/ZipOut.cpp	2008-04-11 20:23:42.000000000 +0200
@@ -7,9 +7,19 @@
 #include "../../Common/OffsetStream.h"
 #include "../../Common/StreamUtils.h"
 
+#include "../../../../C/rccrecode.h"
+
 namespace NArchive {
 namespace NZip {
 
+COutArchive::COutArchive() {
+    rccctx = rcc_init();
+}
+
+COutArchive::~COutArchive() {
+    rcc_free(rccctx);
+}
+
 void COutArchive::Create(IOutStream *outStream)
 {
   if (!m_OutBuffer.Create(1 << 16))
@@ -112,6 +122,7 @@
 {
   SeekTo(m_BasePosition);
   
+  char *rccrec;
   bool isZip64 = m_IsZip64 || item.PackSize >= 0xFFFFFFFF || item.UnPackSize >= 0xFFFFFFFF;
   
   WriteUInt32(NSignature::kLocalFileHeader);
@@ -130,6 +141,12 @@
       throw CSystemException(E_FAIL);
   }
   WriteUInt16((UInt16)m_ExtraSize); // test it;
+  rccrec = rcc_write(rccctx, (const char *)item.Name, item.Name.Length());
+  if (rccrec) {
+    printf("%u, %s.\n", item.Name.Length(), rccrec);
+    WriteBytes(rccrec, strlen(rccrec));
+    free(rccrec);
+  } else
   WriteBytes((const char *)item.Name, item.Name.Length());
 
   UInt32 extraPos = 0;
@@ -154,6 +171,7 @@
 
 void COutArchive::WriteCentralHeader(const CItem &item)
 {
+  char *rccrec;
   bool isUnPack64 = item.UnPackSize >= 0xFFFFFFFF;
   bool isPack64 = item.PackSize >= 0xFFFFFFFF;
   bool isPosition64 = item.LocalHeaderPosition >= 0xFFFFFFFF;
@@ -180,6 +198,13 @@
   WriteUInt16(item.InternalAttributes);
   WriteUInt32(item.ExternalAttributes);
   WriteUInt32(isPosition64 ? 0xFFFFFFFF: (UInt32)item.LocalHeaderPosition);
+
+  rccrec = rcc_write(rccctx, (const char *)item.Name, item.Name.Length());
+  if (rccrec) {
+    printf("C: %u, %s.\n", item.Name.Length(), rccrec);
+    WriteBytes(rccrec, strlen(rccrec));
+    free(rccrec);
+  } else
   WriteBytes((const char *)item.Name, item.Name.Length());
   if (isZip64)
   {
diff -dPNur p7zip_4.57/CPP/7zip/Archive/Zip/ZipOut.h p7zip_4.57-new/CPP/7zip/Archive/Zip/ZipOut.h
--- p7zip_4.57/CPP/7zip/Archive/Zip/ZipOut.h	2007-06-26 20:06:22.000000000 +0200
+++ p7zip_4.57-new/CPP/7zip/Archive/Zip/ZipOut.h	2008-04-11 20:23:42.000000000 +0200
@@ -49,6 +49,11 @@
   void CreateStreamForCompressing(IOutStream **outStream);
   void CreateStreamForCopying(ISequentialOutStream **outStream);
   void SeekToPackedDataPosition();
+
+  void *rccctx;
+  COutArchive();
+  ~COutArchive();
+
 };
 
 }}
diff -dPNur p7zip_4.57/CPP/7zip/Bundles/Alone/makefile p7zip_4.57-new/CPP/7zip/Bundles/Alone/makefile
--- p7zip_4.57/CPP/7zip/Bundles/Alone/makefile	2007-07-24 20:55:33.000000000 +0200
+++ p7zip_4.57-new/CPP/7zip/Bundles/Alone/makefile	2008-04-11 20:23:42.000000000 +0200
@@ -15,6 +15,7 @@
 LIBS=$(LOCAL_LIBS)
 
 OBJS=\
+rccrecode.o \
 myGetTickCount.o \
 wine_date_and_time.o \
 myAddExeFlag.o \
diff -dPNur p7zip_4.57/CPP/7zip/Bundles/Alone/makefile.list p7zip_4.57-new/CPP/7zip/Bundles/Alone/makefile.list
--- p7zip_4.57/CPP/7zip/Bundles/Alone/makefile.list	2007-07-24 20:56:10.000000000 +0200
+++ p7zip_4.57-new/CPP/7zip/Bundles/Alone/makefile.list	2008-04-11 20:23:42.000000000 +0200
@@ -196,6 +196,7 @@
  ../../../../C/Compress/Branch/BranchPPC.c \
  ../../../../C/Compress/Branch/BranchSPARC.c \
  ../../../../C/Compress/Branch/BranchX86.c \
+ ../../../../C/rccrecode.c \
  ../../../../C/7zCrc.c \
  ../../../../C/Sort.c \
  ../../../../C/Threads.c \
@@ -237,6 +238,8 @@
 	$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp
 ListFileUtils.o : ../../../Common/ListFileUtils.cpp
 	$(CXX) $(CFLAGS) ../../../Common/ListFileUtils.cpp
+rccrecode.o : ../../../../C/rccrecode.c
+	$(CC) $(CFLAGS) ../../../../C/rccrecode.c
 MyWindows.o : ../../../Common/MyWindows.cpp
 	$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp
 Random.o : ../../../Common/Random.cpp
diff -dPNur p7zip_4.57/CPP/7zip/Bundles/Format7zFree/makefile p7zip_4.57-new/CPP/7zip/Bundles/Format7zFree/makefile
--- p7zip_4.57/CPP/7zip/Bundles/Format7zFree/makefile	2007-08-03 20:16:04.000000000 +0200
+++ p7zip_4.57-new/CPP/7zip/Bundles/Format7zFree/makefile	2008-04-11 20:30:53.000000000 +0200
@@ -14,6 +14,7 @@
 LIBS=$(LOCAL_LIBS_DLL)
 
 OBJS = \
+rccrecode.o \
 wine_date_and_time.o \
 myGetTickCount.o \
 CRC.o \
diff -dPNur p7zip_4.57/CPP/7zip/Bundles/Format7zFree/makefile.list p7zip_4.57-new/CPP/7zip/Bundles/Format7zFree/makefile.list
--- p7zip_4.57/CPP/7zip/Bundles/Format7zFree/makefile.list	2007-08-03 20:17:57.000000000 +0200
+++ p7zip_4.57-new/CPP/7zip/Bundles/Format7zFree/makefile.list	2008-04-11 20:32:11.000000000 +0200
@@ -218,6 +218,7 @@
  ../../../../C/Compress/Branch/BranchPPC.c \
  ../../../../C/Compress/Branch/BranchSPARC.c \
  ../../../../C/Compress/Branch/BranchX86.c \
+ ../../../../C/rccrecode.c \
  ../../../../C/7zCrc.c \
  ../../../../C/Sort.c \
  ../../../../C/Threads.c \
@@ -237,6 +238,8 @@
 	$(CXX) $(CC_SHARED) $(CFLAGS) ../../../Common/ListFileUtils.cpp
 MyWindows.o : ../../../Common/MyWindows.cpp
 	$(CXX) $(CC_SHARED) $(CFLAGS) ../../../Common/MyWindows.cpp
+rccrecode.o : ../../../../C/rccrecode.c
+	$(CC) $(CC_SHARED) $(CFLAGS) ../../../../C/rccrecode.c
 Random.o : ../../../Common/Random.cpp
 	$(CXX) $(CC_SHARED) $(CFLAGS) ../../../Common/Random.cpp
 StdInStream.o : ../../../Common/StdInStream.cpp
diff -dPNur p7zip_4.57/makefile.machine p7zip_4.57-new/makefile.machine
--- p7zip_4.57/makefile.machine	2007-12-15 18:19:48.000000000 +0100
+++ p7zip_4.57-new/makefile.machine	2008-04-11 20:23:42.000000000 +0200
@@ -14,7 +14,7 @@
 CC_SHARED=-fPIC
 LINK_SHARED=-fPIC -shared
 
-LOCAL_LIBS=-lpthread
+LOCAL_LIBS=-lpthread -lrcc
 LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl
 
 OBJ_CRC32=$(OBJ_CRC32_C)
diff -dPNur p7zip_4.57/makefile.machine.orig p7zip_4.57-new/makefile.machine.orig
--- p7zip_4.57/makefile.machine.orig	1970-01-01 01:00:00.000000000 +0100
+++ p7zip_4.57-new/makefile.machine.orig	2007-12-15 18:19:48.000000000 +0100
@@ -0,0 +1,21 @@
+#
+# makefile for Linux (x86, PPC, alpha ...)
+#
+
+OPTFLAGS=-O
+
+ALLFLAGS=${OPTFLAGS} -s \
+    	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
+	-DNDEBUG -D_REENTRANT -DENV_UNIX \
+	$(LOCAL_FLAGS)
+
+CXX=g++ $(ALLFLAGS)
+CC=gcc $(ALLFLAGS)
+CC_SHARED=-fPIC
+LINK_SHARED=-fPIC -shared
+
+LOCAL_LIBS=-lpthread
+LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl
+
+OBJ_CRC32=$(OBJ_CRC32_C)
+