From 60bd665e74cfeeaf70882173a0dd56c883e2014a Mon Sep 17 00:00:00 2001
From: "Suren A. Chilingaryan" <csa@suren.me>
Date: Fri, 12 Mar 2021 03:55:34 +0100
Subject: Added to git tree

---
 patches/unzip/README                       |  30 ++++++
 patches/unzip/unzip-5.52-ds-rusxmms.patch  | 159 +++++++++++++++++++++++++++++
 patches/unzip/unzip-5.52-ds-rusxmms2.patch | 149 +++++++++++++++++++++++++++
 patches/unzip/unzip-ds-unixenc.patch       |   9 ++
 patches/unzip/unzip60-ds-isprint.patch     |  12 +++
 patches/unzip/update_lazy                  |   9 ++
 patches/unzip/update_shared                |   9 ++
 7 files changed, 377 insertions(+)
 create mode 100644 patches/unzip/README
 create mode 100644 patches/unzip/unzip-5.52-ds-rusxmms.patch
 create mode 100644 patches/unzip/unzip-5.52-ds-rusxmms2.patch
 create mode 100644 patches/unzip/unzip-ds-unixenc.patch
 create mode 100644 patches/unzip/unzip60-ds-isprint.patch
 create mode 100755 patches/unzip/update_lazy
 create mode 100755 patches/unzip/update_shared

(limited to 'patches/unzip')

diff --git a/patches/unzip/README b/patches/unzip/README
new file mode 100644
index 0000000..03c08f6
--- /dev/null
+++ b/patches/unzip/README
@@ -0,0 +1,30 @@
+You can use patch in two modes:
+    standard: The unzip will be dynamically linked with librcc (In that case
+    some problems with building OpenOffice from sources may arise)
+    
+    lazy: In this case the librcc will be dynamically loaded (with help of
+    dlopen, dlsym) during execution.
+    
+
+Usage
+=====
+1. Apply patches: unzip-*-ds-rusxmms.patch, unzip-ds-unixenc.patch
+2. In the root of `unzip` source tree run either `update_shared` for standard
+mode or `update_lazy` for lazy mode.
+
+
+Configuration
+=============
+ - The patch uses "zip" configuration of RCC. This means settings could be 
+ altered using "rcc-gtk2-config zip". 
+ - ZIP OEM / ZIP ISO / Output  - encodings are important for patch.
+
+
+Build
+=====
+ On Unix, call following command to get list of possible targets:
+     make -f unix/Makefile list
+ and then just build with:
+    make -f unix/Makefile <target>
+ for example:
+     make -f unix/Makefile linux_noasm
diff --git a/patches/unzip/unzip-5.52-ds-rusxmms.patch b/patches/unzip/unzip-5.52-ds-rusxmms.patch
new file mode 100644
index 0000000..87835f0
--- /dev/null
+++ b/patches/unzip/unzip-5.52-ds-rusxmms.patch
@@ -0,0 +1,159 @@
+diff -dPNur unzip-5.52/dsrecode.h unzip-5.52-ds/dsrecode.h
+--- unzip-5.52/dsrecode.h	1970-01-01 01:00:00.000000000 +0100
++++ unzip-5.52-ds/dsrecode.h	2008-04-11 22:24:24.000000000 +0200
+@@ -0,0 +1,128 @@
++#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 OEM_CLASS 0
++#define ISO_CLASS 1
++#define OUT_CLASS 2
++static rcc_class classes[] = {
++    { "oem", RCC_CLASS_STANDARD, NULL, default_oem, "OEM_INTERN", 0 },
++    { "iso", RCC_CLASS_STANDARD, NULL, default_iso, "ISO_INTERN", 0 },
++    { "out", RCC_CLASS_STANDARD, "LC_CTYPE", NULL, "Output", 0 },
++    { NULL }
++};
++
++int initialized = 0;
++
++#ifdef RCC_LAZY	
++#include <dlfcn.h>
++# define RCC_LIBRARY "librcc.so.0"
++int (*rccInit2)();
++int (*rccFree2)();
++int (*rccInitDefaultContext2)(const char *locale_variable, unsigned int max_languages, unsigned int max_classes, rcc_class_ptr defclasses, rcc_init_flags flags);
++int (*rccInitDb42)(rcc_context ctx, const char *name, rcc_db4_flags flags); 
++char* (*rccSizedRecode2)(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *buf, size_t len, size_t *rlen);
++int (*rccLoad2)(rcc_context ctx, const char *name);
++
++
++static char *rccRecode2(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *buf) {
++    return rccSizedRecode2(ctx, from, to, buf, 0, NULL);
++}
++
++void *rcc_handle;
++#else /* RCC_LAZY */
++#define rccInit2 rccInit
++#define rccFree2 rccFree
++#define rccInitDefaultContext2 rccInitDefaultContext
++#define rccInitDb42 rccInitDb4
++#define rccRecode2 rccRecode 
++#define rccLoad2 rccLoad
++#endif /* RCC_LAZY */
++
++static void rccUnzipFree() {
++    if (initialized > 0) {
++	rccFree2();
++#ifdef RCC_LAZY	
++	dlclose(rcc_handle);
++#endif /* RCC_LAZY */
++	initialized = 0;
++    }
++}
++
++
++static int rccUnzipInit() {
++    if (initialized) return 0;
++    
++#ifdef RCC_LAZY	
++    if (sizeof(size_t) == 8) {
++	rcc_handle = dlopen("/usr/lib64/" RCC_LIBRARY, RTLD_NOW);
++	if (!rcc_handle) rcc_handle = dlopen("/usr/local/lib64/" RCC_LIBRARY, RTLD_NOW);
++    } else {
++	rcc_handle = dlopen("/usr/lib32/" RCC_LIBRARY, RTLD_NOW);
++	if (!rcc_handle) rcc_handle = dlopen("/usr/local/lib32/" RCC_LIBRARY, RTLD_NOW);
++    }
++    if (!rcc_handle) {
++	rcc_handle = dlopen("/usr/lib/" RCC_LIBRARY, RTLD_NOW);
++	if (!rcc_handle) rcc_handle = dlopen("/usr/local/lib/" RCC_LIBRARY, RTLD_NOW);
++    }
++    if (!rcc_handle) {
++	initialized = -1;
++	return 1;
++    }
++    
++    rccInit2 = dlsym(rcc_handle, "rccInit");
++    rccFree2 = dlsym(rcc_handle, "rccFree");
++    rccInitDefaultContext2 = dlsym(rcc_handle, "rccInitDefaultContext");
++    rccInitDb42 = dlsym(rcc_handle, "rccInitDb4");
++    rccSizedRecode2 = dlsym(rcc_handle, "rccSizedRecode");
++    rccLoad2 = dlsym(rcc_handle, "rccLoad");
++    
++    if ((!rccInit2)||(!rccFree2)||(!rccInitDefaultContext2)||(!rccInitDb42)||(!rccSizedRecode2)||(!rccLoad2)) {
++	dlclose(rcc_handle);
++	initialized = -1;
++	return 1;
++    }
++#endif /* RCC_LAZY */
++    
++    rccInit2();
++    rccInitDefaultContext2(NULL, 0, 0, classes, 0);
++    rccLoad2(NULL, "zip");
++    rccInitDb42(NULL, NULL, 0);
++    atexit(rccUnzipFree);
++    initialized = 1;
++    return 0;
++}
++
++
++
++void _DS_OEM_INTERN(char *string) {
++    char *str;
++    rccUnzipInit();
++    if (initialized>0) {
++	str = rccRecode2(NULL, OEM_CLASS, OUT_CLASS, string);
++	if (str) {
++	    strncpy(string,str,FILNAMSIZ);
++	    free(str);
++	}
++    }
++}
++
++void _DS_ISO_INTERN(char *string) {
++    char *str;
++    rccUnzipInit();
++    if (initialized>0) {
++	str = rccRecode2(NULL, ISO_CLASS, OUT_CLASS, string);
++	if (str) {
++	    strncpy(string,str,FILNAMSIZ);
++	    free(str);
++	}
++    }
++}
+diff -dPNur unzip-5.52/fileio.c unzip-5.52-ds/fileio.c
+--- unzip-5.52/fileio.c	2005-02-27 03:10:12.000000000 +0100
++++ unzip-5.52-ds/fileio.c	2008-04-11 22:25:31.000000000 +0200
+@@ -78,7 +78,7 @@
+ #  endif
+ #endif
+ #include "ebcdic.h"   /* definition/initialization of ebcdic[] */
+-
++#include "dsrecode.h"
+ 
+ /*
+    Note: Under Windows, the maximum size of the buffer that can be used
+diff -dPNur unzip-5.52/unzpriv.h unzip-5.52-ds/unzpriv.h
+--- unzip-5.52/unzpriv.h	2005-02-04 00:26:42.000000000 +0100
++++ unzip-5.52-ds/unzpriv.h	2008-04-11 22:25:31.000000000 +0200
+@@ -2564,9 +2564,9 @@
+            ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
+         (hostnum) == FS_HPFS_ || \
+         ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
+-        _OEM_INTERN((string)); \
++        _DS_OEM_INTERN((string)); \
+     } else { \
+-        _ISO_INTERN((string)); \
++        _DS_ISO_INTERN((string)); \
+     }
+ #endif
+ 
diff --git a/patches/unzip/unzip-5.52-ds-rusxmms2.patch b/patches/unzip/unzip-5.52-ds-rusxmms2.patch
new file mode 100644
index 0000000..6670a10
--- /dev/null
+++ b/patches/unzip/unzip-5.52-ds-rusxmms2.patch
@@ -0,0 +1,149 @@
+diff -dPNur unzip-5.52/fileio.c unzip-5.52-ds/fileio.c
+--- unzip-5.52/fileio.c	2005-02-27 03:10:12.000000000 +0100
++++ unzip-5.52-ds/fileio.c	2008-04-11 22:25:31.000000000 +0200
+@@ -78,7 +78,7 @@
+ #  endif
+ #endif
+ #include "ebcdic.h"   /* definition/initialization of ebcdic[] */
+-
++#include "dsrecode.h"
+ 
+ /*
+    Note: Under Windows, the maximum size of the buffer that can be used
+diff -dPNur unzip-5.52/unzpriv.h unzip-5.52-ds/unzpriv.h
+--- unzip-5.52/unzpriv.h	2005-02-04 00:26:42.000000000 +0100
++++ unzip-5.52-ds/unzpriv.h	2008-04-11 22:25:31.000000000 +0200
+@@ -2564,9 +2564,9 @@
+            ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
+         (hostnum) == FS_HPFS_ || \
+         ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
+-        _OEM_INTERN((string)); \
++        _DS_OEM_INTERN((string)); \
+     } else { \
+-        _ISO_INTERN((string)); \
++        _DS_ISO_INTERN((string)); \
+     }
+ #endif
+ 
+diff -dPNur unzip-5.52/dsrecode.h unzip-5.52-ds/dsrecode.h
+--- unzip-5.52/dsrecode.h	1970-01-01 01:00:00.000000000 +0100
++++ unzip-5.52-ds/dsrecode.h	2008-04-11 22:24:24.000000000 +0200
+@@ -0,0 +1,118 @@
++#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 OEM_CLASS 0
++#define ISO_CLASS 1
++#define OUT_CLASS 2
++static rcc_class classes[] = {
++    { "oem", RCC_CLASS_STANDARD, NULL, default_oem, "OEM_INTERN", 0 },
++    { "iso", RCC_CLASS_STANDARD, NULL, default_iso, "ISO_INTERN", 0 },
++    { "out", RCC_CLASS_STANDARD, "LC_CTYPE", NULL, "Output", 0 },
++    { NULL }
++};
++
++int initialized = 0;
++
++#ifdef RCC_LAZY	
++#include <dlfcn.h>
++# define RCC_LIBRARY "librcc.so.0"
++int (*rccInit2)();
++int (*rccFree2)();
++int (*rccInitDefaultContext2)(const char *locale_variable, unsigned int max_languages, unsigned int max_classes, rcc_class_ptr defclasses, rcc_init_flags flags);
++int (*rccInitDb42)(rcc_context ctx, const char *name, rcc_db4_flags flags); 
++char* (*rccSizedRecode2)(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *buf, size_t len, size_t *rlen);
++int (*rccLoad2)(rcc_context ctx, const char *name);
++
++
++static char *rccRecode2(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *buf) {
++    return rccSizedRecode2(ctx, from, to, buf, 0, NULL);
++}
++
++void *rcc_handle;
++#else /* RCC_LAZY */
++#define rccInit2 rccInit
++#define rccFree2 rccFree
++#define rccInitDefaultContext2 rccInitDefaultContext
++#define rccInitDb42 rccInitDb4
++#define rccRecode2 rccRecode 
++#define rccLoad2 rccLoad
++#endif /* RCC_LAZY */
++
++static void rccUnzipFree() {
++    if (initialized > 0) {
++	rccFree2();
++#ifdef RCC_LAZY	
++	dlclose(rcc_handle);
++#endif /* RCC_LAZY */
++	initialized = 0;
++    }
++}
++
++
++static int rccUnzipInit() {
++    if (initialized) return 0;
++    
++#ifdef RCC_LAZY	
++    rcc_handle = dlopen(RCC_LIBRARY, RTLD_NOW);
++    if (!rcc_handle) {
++	initialized = -1;
++	return 1;
++    }
++    
++    rccInit2 = dlsym(rcc_handle, "rccInit");
++    rccFree2 = dlsym(rcc_handle, "rccFree");
++    rccInitDefaultContext2 = dlsym(rcc_handle, "rccInitDefaultContext");
++    rccInitDb42 = dlsym(rcc_handle, "rccInitDb4");
++    rccSizedRecode2 = dlsym(rcc_handle, "rccSizedRecode");
++    rccLoad2 = dlsym(rcc_handle, "rccLoad");
++    
++    if ((!rccInit2)||(!rccFree2)||(!rccInitDefaultContext2)||(!rccInitDb42)||(!rccSizedRecode2)||(!rccLoad2)) {
++	dlclose(rcc_handle);
++	initialized = -1;
++	return 1;
++    }
++#endif /* RCC_LAZY */
++    
++    rccInit2();
++    rccInitDefaultContext2(NULL, 0, 0, classes, 0);
++    rccLoad2(NULL, "zip");
++    rccInitDb42(NULL, NULL, 0);
++    atexit(rccUnzipFree);
++    initialized = 1;
++    return 0;
++}
++
++
++
++void _DS_OEM_INTERN(char *string) {
++    char *str;
++    rccUnzipInit();
++    if (initialized>0) {
++	str = rccRecode2(NULL, OEM_CLASS, OUT_CLASS, string);
++	if (str) {
++	    strncpy(string,str,FILNAMSIZ);
++	    free(str);
++	}
++    }
++}
++
++void _DS_ISO_INTERN(char *string) {
++    char *str;
++    rccUnzipInit();
++    if (initialized>0) {
++	str = rccRecode2(NULL, ISO_CLASS, OUT_CLASS, string);
++	if (str) {
++	    strncpy(string,str,FILNAMSIZ);
++	    free(str);
++	}
++    }
++}
diff --git a/patches/unzip/unzip-ds-unixenc.patch b/patches/unzip/unzip-ds-unixenc.patch
new file mode 100644
index 0000000..e33e6ba
--- /dev/null
+++ b/patches/unzip/unzip-ds-unixenc.patch
@@ -0,0 +1,9 @@
+diff -dPNur unzip-5.50/unzpriv.h unzip-5.50-new/unzpriv.h
+--- unzip-5.50/unzpriv.h	Sun Feb 17 21:01:48 2002
++++ unzip-5.50-new/unzpriv.h	Tue Jun 10 07:16:23 2003
+@@ -2424,4 +2424,5 @@
+          !(((islochdr) || (isuxatt)) && \
+            ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
+         (hostnum) == FS_HPFS_ || \
++	(hostnum) == UNIX_ || \
+         ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
diff --git a/patches/unzip/unzip60-ds-isprint.patch b/patches/unzip/unzip60-ds-isprint.patch
new file mode 100644
index 0000000..64ea1ee
--- /dev/null
+++ b/patches/unzip/unzip60-ds-isprint.patch
@@ -0,0 +1,12 @@
+diff -dPNur unzip60/extract.c unzip60-ds/extract.c
+--- unzip60/extract.c	2009-03-14 02:32:52.000000000 +0100
++++ unzip60-ds/extract.c	2010-07-06 16:34:09.000000000 +0200
+@@ -2596,7 +2596,7 @@
+      */
+ #   define UZ_FNFILTER_REPLACECHAR      '?'
+ # endif
+-        if (!isprint(*r)) {
++        if (*r < 32) { //(!isprint(*r)) {
+             if (*r < 32) {
+                 /* ASCII control codes are escaped as "^{letter}". */
+                 if (se != NULL && (s > (space + (size-4)))) {
diff --git a/patches/unzip/update_lazy b/patches/unzip/update_lazy
new file mode 100755
index 0000000..de1b04a
--- /dev/null
+++ b/patches/unzip/update_lazy
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+	sed -i \
+		-e "s:-O3:\${CFLAGS}:" \
+		-e "s:CC=gcc :CC=\"gcc -DRCC_LAZY=1\":" \
+		-e "s:LD=gcc :LD=\"gcc \${LDFLAGS} -ldl\" :" \
+		-e "s:-O :\${CFLAGS} :" \
+		-e "s:LF2 = -s:LF2 = :" \
+		unix/Makefile \
diff --git a/patches/unzip/update_shared b/patches/unzip/update_shared
new file mode 100755
index 0000000..1dd8b2a
--- /dev/null
+++ b/patches/unzip/update_shared
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+	sed -i \
+		-e "s:-O3:\${CFLAGS}:" \
+		-e "s:CC=gcc :CC=gcc :" \
+		-e "s:LD=gcc :LD=\"gcc \${LDFLAGS} -lrcc\" :" \
+		-e "s:-O :\${CFLAGS} :" \
+		-e "s:LF2 = -s:LF2 = :" \
+		unix/Makefile \
-- 
cgit v1.2.3