summaryrefslogtreecommitdiffstats
path: root/app-arch/p7zip/files/p7zip-ds-rcc.patch
blob: 98e7855fb609802a6f86ac3c83fc08702edeb08f (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
diff -dPNur p7zip_4.44-old/C/rccrecode.c p7zip_4.44/C/rccrecode.c
--- p7zip_4.44-old/C/rccrecode.c	1970-01-01 01:00:00.000000000 +0100
+++ p7zip_4.44/C/rccrecode.c	2007-04-14 19:47:03.000000000 +0200
@@ -0,0 +1,69 @@
+#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 }
+};
+
+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);
+	rccInitDb4(NULL, NULL, 0);
+    }
+    initialized++;
+    pthread_mutex_unlock(&mutex);
+    
+    ctx = rccCreateContext(NULL, 0, 0, classes, 0);
+    if (ctx) rccInitDb4(ctx, NULL, 0);
+
+    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.44-old/C/rccrecode.h p7zip_4.44/C/rccrecode.h
--- p7zip_4.44-old/C/rccrecode.h	1970-01-01 01:00:00.000000000 +0100
+++ p7zip_4.44/C/rccrecode.h	2007-04-14 19:34:20.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.44-old/CPP/7zip/Archive/Zip/makefile p7zip_4.44/CPP/7zip/Archive/Zip/makefile
--- p7zip_4.44-old/CPP/7zip/Archive/Zip/makefile	2007-01-23 21:29:41.000000000 +0100
+++ p7zip_4.44/CPP/7zip/Archive/Zip/makefile	2007-04-14 18:36:44.000000000 +0200
@@ -13,6 +13,7 @@
 LIBS=$(LOCAL_LIBS_DLL)
 
 OBJS = \
+../../../../C/rccrecode.o \
 ../../../Common/MyWindows.o \
 ../../../Common/Vector.o\
 ../../../Common/Alloc.o\
diff -dPNur p7zip_4.44-old/CPP/7zip/Archive/Zip/ZipIn.cpp p7zip_4.44/CPP/7zip/Archive/Zip/ZipIn.cpp
--- p7zip_4.44-old/CPP/7zip/Archive/Zip/ZipIn.cpp	2007-01-20 18:06:58.000000000 +0100
+++ p7zip_4.44/CPP/7zip/Archive/Zip/ZipIn.cpp	2007-04-14 19:34:59.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;
@@ -179,10 +190,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.44-old/CPP/7zip/Archive/Zip/ZipIn.h p7zip_4.44/CPP/7zip/Archive/Zip/ZipIn.h
--- p7zip_4.44-old/CPP/7zip/Archive/Zip/ZipIn.h	2007-01-20 18:06:28.000000000 +0100
+++ p7zip_4.44/CPP/7zip/Archive/Zip/ZipIn.h	2007-04-14 19:05:31.000000000 +0200
@@ -104,6 +104,10 @@
   bool SeekInArchive(UInt64 position);
   ISequentialInStream *CreateLimitedStream(UInt64 position, UInt64 size);
   IInStream* CreateStream();
+
+  void *rccctx;
+  CInArchive();
+  ~CInArchive();
 };
   
 }}
diff -dPNur p7zip_4.44-old/CPP/7zip/Archive/Zip/ZipOut.cpp p7zip_4.44/CPP/7zip/Archive/Zip/ZipOut.cpp
--- p7zip_4.44-old/CPP/7zip/Archive/Zip/ZipOut.cpp	2007-01-20 18:06:57.000000000 +0100
+++ p7zip_4.44/CPP/7zip/Archive/Zip/ZipOut.cpp	2007-04-14 19:44:44.000000000 +0200
@@ -8,9 +8,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)
 {
   m_Stream = outStream;
@@ -104,6 +114,8 @@
 
 HRESULT COutArchive::WriteLocalHeader(const CLocalItem &item)
 {
+  char *rccrec;
+  
   m_Stream->Seek(m_BasePosition, STREAM_SEEK_SET, NULL);
   
   bool isZip64 = m_IsZip64 || item.PackSize >= 0xFFFFFFFF || item.UnPackSize >= 0xFFFFFFFF;
@@ -124,6 +136,12 @@
       return 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;
@@ -147,6 +165,8 @@
 
 void COutArchive::WriteCentralHeader(const CItem &item)
 {
+  char *rccrec;
+  
   m_Stream->Seek(m_BasePosition, STREAM_SEEK_SET, NULL);
 
   bool isUnPack64 = item.UnPackSize >= 0xFFFFFFFF;
@@ -175,6 +195,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.44-old/CPP/7zip/Archive/Zip/ZipOut.h p7zip_4.44/CPP/7zip/Archive/Zip/ZipOut.h
--- p7zip_4.44-old/CPP/7zip/Archive/Zip/ZipOut.h	2007-01-20 18:06:29.000000000 +0100
+++ p7zip_4.44/CPP/7zip/Archive/Zip/ZipOut.h	2007-04-14 19:10:12.000000000 +0200
@@ -44,6 +44,11 @@
   void CreateStreamForCompressing(IOutStream **outStream);
   void CreateStreamForCopying(ISequentialOutStream **outStream);
   void SeekToPackedDataPosition();
+
+  void *rccctx;
+  COutArchive();
+  ~COutArchive();
+
 };
 
 }}
diff -dPNur p7zip_4.44-old/CPP/7zip/Bundles/Alone/makefile p7zip_4.44/CPP/7zip/Bundles/Alone/makefile
--- p7zip_4.44-old/CPP/7zip/Bundles/Alone/makefile	2007-01-23 21:29:43.000000000 +0100
+++ p7zip_4.44/CPP/7zip/Bundles/Alone/makefile	2007-04-14 18:52:31.000000000 +0200
@@ -41,6 +41,7 @@
 	$(MY_HOME)/mySplitCommandLine.o
 
 OBJS=\
+../../../../C/rccrecode.o \
 ../../../Common/MyWindows.o \
 7zAES.o \
 7zCompressionMode.o \
diff -dPNur p7zip_4.44-old/makefile.linux_amd64 p7zip_4.44/makefile.linux_amd64
--- p7zip_4.44-old/makefile.linux_amd64	2007-04-14 15:37:39.000000000 +0200
+++ p7zip_4.44/makefile.linux_amd64	2007-04-14 18:50:13.000000000 +0200
@@ -11,6 +11,6 @@
 CC=x86_64-pc-linux-gnu-gcc $(ALLFLAGS)
 LINK_SHARED=-shared
 
-LOCAL_LIBS=-lpthread
+LOCAL_LIBS=-lpthread -lrcc
 LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl
 
diff -dPNur p7zip_4.44-old/makefile.linux_gcc_2.95_no_need_for_libstdc p7zip_4.44/makefile.linux_gcc_2.95_no_need_for_libstdc
--- p7zip_4.44-old/makefile.linux_gcc_2.95_no_need_for_libstdc	2007-04-14 15:37:39.000000000 +0200
+++ p7zip_4.44/makefile.linux_gcc_2.95_no_need_for_libstdc	2007-04-14 18:51:02.000000000 +0200
@@ -10,6 +10,6 @@
 CC=x86_64-pc-linux-gnu-gcc $(ALLFLAGS)
 LINK_SHARED=-shared
 
-LOCAL_LIBS=-lpthread
+LOCAL_LIBS=-lpthread -lrcc
 LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl
 
diff -dPNur p7zip_4.44-old/makefile.linux_x86_ppc_alpha p7zip_4.44/makefile.linux_x86_ppc_alpha
--- p7zip_4.44-old/makefile.linux_x86_ppc_alpha	2007-04-14 15:37:39.000000000 +0200
+++ p7zip_4.44/makefile.linux_x86_ppc_alpha	2007-04-14 18:51:15.000000000 +0200
@@ -14,6 +14,6 @@
 CC=x86_64-pc-linux-gnu-gcc $(ALLFLAGS)
 LINK_SHARED=-shared
 
-LOCAL_LIBS=-lpthread
+LOCAL_LIBS=-lpthread -lrcc
 LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl
 
diff -dPNur p7zip_4.44-old/makefile.linux_x86_ppc_alpha__gcc_4.X p7zip_4.44/makefile.linux_x86_ppc_alpha__gcc_4.X
--- p7zip_4.44-old/makefile.linux_x86_ppc_alpha__gcc_4.X	2007-04-14 15:37:39.000000000 +0200
+++ p7zip_4.44/makefile.linux_x86_ppc_alpha__gcc_4.X	2007-04-14 18:51:19.000000000 +0200
@@ -14,6 +14,6 @@
 CC=x86_64-pc-linux-gnu-gcc $(ALLFLAGS)
 LINK_SHARED=-shared
 
-LOCAL_LIBS=-lpthread
+LOCAL_LIBS=-lpthread -lrcc
 LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl
 
diff -dPNur p7zip_4.44-old/makefile.machine p7zip_4.44/makefile.machine
--- p7zip_4.44-old/makefile.machine	2007-04-14 15:37:39.000000000 +0200
+++ p7zip_4.44/makefile.machine	2007-04-14 18:49:24.000000000 +0200
@@ -11,6 +11,6 @@
 CC=x86_64-pc-linux-gnu-gcc $(ALLFLAGS)
 LINK_SHARED=-shared
 
-LOCAL_LIBS=-lpthread
+LOCAL_LIBS=-lpthread -lrcc
 LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl