commit:     f30b488fc9b6821fe541da04652512331ee4012a
Author:     Joe Kappus <joe <AT> wt <DOT> gd>
AuthorDate: Fri Apr 14 11:52:25 2023 +0000
Commit:     Matthew Thode <prometheanfire <AT> gentoo <DOT> org>
CommitDate: Fri Apr 14 15:34:06 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f30b488f

app-arch/p7zip: add natspec support via useflag

Patch is from Arch:
https://aur.archlinux.org/cgit/aur.git/tree/natspec.patch?h=p7zip-natspec

Closes: https://bugs.gentoo.org/574900
Signed-off-by: Joe Kappus <joe <AT> wt.gd>
Signed-off-by: Matthew Thode <prometheanfire <AT> gentoo.org>

 app-arch/p7zip/files/p7zip-17.05-natspec.patch | 130 +++++++++++++++++++++++++
 app-arch/p7zip/metadata.xml                    |   1 +
 app-arch/p7zip/p7zip-17.05-r1.ebuild           |   5 +-
 3 files changed, 135 insertions(+), 1 deletion(-)

diff --git a/app-arch/p7zip/files/p7zip-17.05-natspec.patch 
b/app-arch/p7zip/files/p7zip-17.05-natspec.patch
new file mode 100644
index 000000000000..45f24559a4c8
--- /dev/null
+++ b/app-arch/p7zip/files/p7zip-17.05-natspec.patch
@@ -0,0 +1,130 @@
+commit f25f0b75bbeb485961dc139aed6b5b474552d043 (HEAD -> main)
+Author: Taiki Sugawara <[email protected]>
+Date:   Wed May 12 18:26:11 2021 +0900
+
+    natspec patch for p7zip 17.x
+
+diff --git a/CPP/7zip/Archive/Zip/ZipItem.cpp 
b/CPP/7zip/Archive/Zip/ZipItem.cpp
+index 353e895..44071f3 100644
+--- a/CPP/7zip/Archive/Zip/ZipItem.cpp
++++ b/CPP/7zip/Archive/Zip/ZipItem.cpp
+@@ -1,9 +1,7 @@
+ // Archive/ZipItem.cpp
+ 
+-#if (!defined _WIN32) && (!defined __CYGWIN__) && (!defined __APPLE__)
+ #include <iconv.h>
+-#include <locale.h>
+-#endif
++#include <natspec.h>
+ 
+ #include "StdAfx.h"
+ 
+@@ -355,87 +353,15 @@ void CItem::GetUnicodeString(UString &res, const AString 
&s, bool isComment, boo
+     #endif
+   }
+   
+-  #if (!defined _WIN32) && (!defined __CYGWIN__) && (!defined __APPLE__)
+-  // Convert OEM char set to UTF-8 if needed
+-  // Use system locale to select code page
+-
+-  Byte hostOS = GetHostOS();
+-  if (!isUtf8 && ((hostOS == NFileHeader::NHostOS::kFAT) || (hostOS == 
NFileHeader::NHostOS::kNTFS))) {
+-
+-    const char *oemcp;
+-    oemcp = getenv("OEMCP");
+-    if (!oemcp) {
+-      oemcp = "CP437\0"; // CP name is 6 chars max
+-
+-      const char *lc_to_cp_table[] = {
+-      "af_ZA", "CP850", "ar_SA", "CP720", "ar_LB", "CP720", "ar_EG", "CP720",
+-      "ar_DZ", "CP720", "ar_BH", "CP720", "ar_IQ", "CP720", "ar_JO", "CP720",
+-      "ar_KW", "CP720", "ar_LY", "CP720", "ar_MA", "CP720", "ar_OM", "CP720",
+-      "ar_QA", "CP720", "ar_SY", "CP720", "ar_TN", "CP720", "ar_AE", "CP720",
+-      "ar_YE", "CP720","ast_ES", "CP850", "az_AZ", "CP866", "az_AZ", "CP857",
+-      "be_BY", "CP866", "bg_BG", "CP866", "br_FR", "CP850", "ca_ES", "CP850",
+-      "zh_CN", "CP936", "zh_TW", "CP950", "kw_GB", "CP850", "cs_CZ", "CP852",
+-      "cy_GB", "CP850", "da_DK", "CP850", "de_AT", "CP850", "de_LI", "CP850",
+-      "de_LU", "CP850", "de_CH", "CP850", "de_DE", "CP850", "el_GR", "CP737",
+-      "en_AU", "CP850", "en_CA", "CP850", "en_GB", "CP850", "en_IE", "CP850",
+-      "en_JM", "CP850", "en_BZ", "CP850", "en_PH", "CP437", "en_ZA", "CP437",
+-      "en_TT", "CP850", "en_US", "CP437", "en_ZW", "CP437", "en_NZ", "CP850",
+-      "es_PA", "CP850", "es_BO", "CP850", "es_CR", "CP850", "es_DO", "CP850",
+-      "es_SV", "CP850", "es_EC", "CP850", "es_GT", "CP850", "es_HN", "CP850",
+-      "es_NI", "CP850", "es_CL", "CP850", "es_MX", "CP850", "es_ES", "CP850",
+-      "es_CO", "CP850", "es_ES", "CP850", "es_PE", "CP850", "es_AR", "CP850",
+-      "es_PR", "CP850", "es_VE", "CP850", "es_UY", "CP850", "es_PY", "CP850",
+-      "et_EE", "CP775", "eu_ES", "CP850", "fa_IR", "CP720", "fi_FI", "CP850",
+-      "fo_FO", "CP850", "fr_FR", "CP850", "fr_BE", "CP850", "fr_CA", "CP850",
+-      "fr_LU", "CP850", "fr_MC", "CP850", "fr_CH", "CP850", "ga_IE", "CP437",
+-      "gd_GB", "CP850", "gv_IM", "CP850", "gl_ES", "CP850", "he_IL", "CP862",
+-      "hr_HR", "CP852", "hu_HU", "CP852", "id_ID", "CP850", "is_IS", "CP850",
+-      "it_IT", "CP850", "it_CH", "CP850", "iv_IV", "CP437", "ja_JP", "CP932",
+-      "kk_KZ", "CP866", "ko_KR", "CP949", "ky_KG", "CP866", "lt_LT", "CP775",
+-      "lv_LV", "CP775", "mk_MK", "CP866", "mn_MN", "CP866", "ms_BN", "CP850",
+-      "ms_MY", "CP850", "nl_BE", "CP850", "nl_NL", "CP850", "nl_SR", "CP850",
+-      "nn_NO", "CP850", "nb_NO", "CP850", "pl_PL", "CP852", "pt_BR", "CP850",
+-      "pt_PT", "CP850", "rm_CH", "CP850", "ro_RO", "CP852", "ru_RU", "CP866",
+-      "sk_SK", "CP852", "sl_SI", "CP852", "sq_AL", "CP852", "sr_RS", "CP855",
+-      "sr_RS", "CP852", "sv_SE", "CP850", "sv_FI", "CP850", "sw_KE", "CP437",
+-      "th_TH", "CP874", "tr_TR", "CP857", "tt_RU", "CP866", "uk_UA", "CP866",
+-      "ur_PK", "CP720", "uz_UZ", "CP866", "uz_UZ", "CP857", "vi_VN", "CP1258",
+-      "wa_BE", "CP850", "zh_HK", "CP950", "zh_SG", "CP936"};
+-      int table_len = sizeof(lc_to_cp_table) / sizeof(char *);
+-      int lc_len, i;
+-
+-      char *lc = setlocale(LC_CTYPE, "");
+-
+-      if (lc && lc[0]) {
+-          // Compare up to the dot, if it exists, e.g. en_US.UTF-8
+-          for (lc_len = 0; lc[lc_len] != '.' && lc[lc_len] != '\0'; ++lc_len)
+-              ;
+-          for (i = 0; i < table_len; i += 2)
+-              if (strncmp(lc, lc_to_cp_table[i], lc_len) == 0)
+-                  oemcp = lc_to_cp_table[i + 1];
+-      }
+-    }
+-
+-    iconv_t cd;
+-    if ((cd = iconv_open("UTF-8", oemcp)) != (iconv_t)-1) {
+-
+-      AString s_utf8;
+-      const char* src = s.Ptr();
+-      size_t slen = s.Len();
+-      size_t dlen = slen * 4;
+-      const char* dest = s_utf8.GetBuf_SetEnd(dlen + 1); // (source length * 
4) + null termination
+-
+-      size_t done = iconv(cd, (char**)&src, &slen, (char**)&dest, &dlen);
+-      bzero((size_t*)dest + done, 1);
+-
+-      iconv_close(cd);
+-
+-      if (ConvertUTF8ToUnicode(s_utf8, res) || ignore_Utf8_Errors)
+-        return;
+-    }    
++  if (!isUtf8) {
++    const char *oem_charset = natspec_get_charset_by_locale(NATSPEC_DOSCS, 
"");
++    char *p = natspec_convert(s.Ptr(), NULL, oem_charset, 0);
++    AString utf = p;
++    free(p);
++    if (ConvertUTF8ToUnicode(utf, res))
++      return;
+   }
+-  #endif
+-  
++
+   if (isUtf8)
+     if (ConvertUTF8ToUnicode(s, res) || ignore_Utf8_Errors)
+       return;
+diff --git a/makefile.machine b/makefile.machine
+index a89b568..3e12592 100644
+--- a/makefile.machine
++++ b/makefile.machine
+@@ -16,7 +16,7 @@ CC=gcc
+ CC_SHARED=-fPIC
+ LINK_SHARED=-fPIC -shared
+ 
+-LOCAL_LIBS=-lpthread
++LOCAL_LIBS=-lpthread -lnatspec
+ LOCAL_LIBS_DLL=$(LOCAL_LIBS) -ldl
+ 
+ OBJ_CRC32=$(OBJ_CRC32_C)

diff --git a/app-arch/p7zip/metadata.xml b/app-arch/p7zip/metadata.xml
index b936059d893c..6a21e35bb813 100644
--- a/app-arch/p7zip/metadata.xml
+++ b/app-arch/p7zip/metadata.xml
@@ -5,6 +5,7 @@
     <email>[email protected]</email>
   </maintainer>
   <use>
+    <flag name="natspec">Use <pkg>dev-libs/libnatspec</pkg> to correctly 
decode non-ascii file names archived in Windows.</flag>
     <flag name="rar">Enable support for non-free rar decoder</flag>
   </use>
   <upstream>

diff --git a/app-arch/p7zip/p7zip-17.05-r1.ebuild 
b/app-arch/p7zip/p7zip-17.05-r1.ebuild
index 8b320e470f1f..dbb6ca8a3567 100644
--- a/app-arch/p7zip/p7zip-17.05-r1.ebuild
+++ b/app-arch/p7zip/p7zip-17.05-r1.ebuild
@@ -13,8 +13,9 @@ 
SRC_URI="https://github.com/p7zip-project/p7zip/archive/v${PV}.tar.gz -> ${P}.ta
 LICENSE="LGPL-2.1 rar? ( unRAR )"
 SLOT="0"
 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~ppc ~ppc64 ~riscv ~s390 
~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~sparc-solaris"
-IUSE="abi_x86_x32 doc +pch rar static"
+IUSE="abi_x86_x32 doc natspec +pch rar static"
 
+RDEPEND="natspec? ( dev-libs/libnatspec )"
 DEPEND="${RDEPEND}"
 BDEPEND="
        abi_x86_x32? ( >=dev-lang/yasm-1.2.0-r1 )
@@ -24,6 +25,8 @@ BDEPEND="
 src_prepare() {
        default
 
+       use natspec && eapply "${FILESDIR}"/${P}-natspec.patch
+
        if ! use pch; then
                sed "s:PRE_COMPILED_HEADER=StdAfx.h.gch:PRE_COMPILED_HEADER=:g" 
-i makefile.* || die
        fi

Reply via email to