Ticket #1735: unzip61_haiku.diff

File unzip61_haiku.diff, 7.4 KB (added by pulkomandy, 13 years ago)

Patch to Unzip 6.1beta for Haiku support

  • beos/beocfg.h

    diff -ur unzip610b/beos/beocfg.h Unzip_Haiku/beos/beocfg.h
    old new  
    5858/* wild_dir, dirname, wildname, matchname[], dirnamelen, have_dirname, */
    5959/*    and notfirstcall are used by do_wild().                          */
    6060
     61#define USE_ICONV_MAPPING /* part of vanilla Haiku distribution */
     62#ifdef USE_ICONV_MAPPING
     63# define MAX_CP_NAME 25
     64   
     65# ifdef SETLOCALE
     66#  undef SETLOCALE
     67# endif
     68# define SETLOCALE(category, locale) setlocale(category, locale)
     69# include <locale.h>
     70   
     71# ifdef _ISO_INTERN
     72#  undef _ISO_INTERN
     73# endif
     74# define _ISO_INTERN(str1) iso_intern(str1)
     75
     76# ifdef _OEM_INTERN
     77#  undef _OEM_INTERN
     78# endif
     79# ifndef IZ_OEM2ISO_ARRAY
     80#  define IZ_OEM2ISO_ARRAY
     81# endif
     82# define _OEM_INTERN(str1) oem_intern(str1)
     83
     84void iso_intern(char *);
     85void oem_intern(char *);
     86void init_conversion_charsets(void);
     87#endif /* USE_ICONV_MAPPING */
     88
    6189#endif /* !__beocfg_h */
  • beos/beos.c

    diff -ur unzip610b/beos/beos.c Unzip_Haiku/beos/beos.c
    old new  
    3434#define UNZIP_INTERNAL
    3535#include "unzip.h"
    3636
     37#ifdef USE_ICONV_MAPPING
     38#include <iconv.h>
     39#include <langinfo.h>
     40#endif /* USE_ICONV_MAPPING */
     41
    3742#include "beos.h"
    3843#include <errno.h>             /* Just make sure we've got a few things... */
    3944#include <sys/types.h>
     
    4449
    4550/* For the new post-DR8 file attributes */
    4651#include <kernel/fs_attr.h>
    47 #include <support/byteorder.h>
     52#include <support/ByteOrder.h>
    4853#include <storage/Mime.h>
    4954
    5055static unsigned filtattr OF((__GPRO__ unsigned perms));
     
    15441549    retval = update_mime_info( fullname, FALSE, TRUE, TRUE );
    15451550}
    15461551#endif
     1552
     1553
     1554#ifdef USE_ICONV_MAPPING
     1555typedef struct {
     1556    char *local_charset;
     1557    char *archive_charset;
     1558} CHARSET_MAP;
     1559
     1560/* A mapping of local <-> archive charsets used by default to convert filenames
     1561 * of DOS/Windows Zip archives. Currently very basic. */
     1562static CHARSET_MAP dos_charset_map[] = {
     1563    { "ANSI_X3.4-1968", "CP850" },
     1564    { "ISO-8859-1", "CP850" },
     1565    { "CP1252", "CP850" },
     1566    { "UTF-8", "CP866" },
     1567    { "KOI8-R", "CP866" },
     1568    { "KOI8-U", "CP866" },
     1569    { "ISO-8859-5", "CP866" }
     1570};
     1571
     1572char OEM_CP[MAX_CP_NAME] = "";
     1573char ISO_CP[MAX_CP_NAME] = "";
     1574
     1575/* Try to guess the default value of OEM_CP based on the current locale.
     1576 * ISO_CP is left alone for now. */
     1577void init_conversion_charsets()
     1578{
     1579    const char *local_charset;
     1580    int i;
     1581
     1582    /* Make a guess only if OEM_CP not already set. */
     1583    if(*OEM_CP == '\0') {
     1584        local_charset = nl_langinfo(CODESET);
     1585        for(i = 0; i < sizeof(dos_charset_map)/sizeof(CHARSET_MAP); i++)
     1586            if(!strcasecmp(local_charset, dos_charset_map[i].local_charset)) {
     1587                strncpy(OEM_CP, dos_charset_map[i].archive_charset,
     1588                        sizeof(OEM_CP));
     1589                break;
     1590            }
     1591    }
     1592}
     1593
     1594/* Convert a string from one encoding to the current locale using iconv().
     1595 * Be as non-intrusive as possible. If error is encountered during
     1596 * convertion just leave the string intact. */
     1597static void charset_to_intern(char *string, char *from_charset)
     1598{
     1599    iconv_t cd;
     1600    char *s,*d, *buf;
     1601    size_t slen, dlen, buflen;
     1602    const char *local_charset;
     1603
     1604    if (*from_charset == '\0')
     1605        return;
     1606
     1607    buf = NULL;
     1608    local_charset = nl_langinfo(CODESET);
     1609
     1610    if ((cd = iconv_open(local_charset, from_charset)) == (iconv_t)-1)
     1611        return;
     1612
     1613    slen = strlen(string);
     1614    s = string;
     1615    dlen = buflen = 2 * slen;
     1616    d = buf = malloc(buflen + 1);
     1617    if (d) {
     1618        bzero(buf, buflen);
     1619        if(iconv(cd, &s, &slen, &d, &dlen) != (size_t)-1)
     1620            strncpy(string, buf, buflen);
     1621        free(buf);
     1622    }
     1623    iconv_close(cd);
     1624}
     1625
     1626/* Convert a string from OEM_CP to the current locale charset. */
     1627inline void oem_intern(char *string)
     1628{
     1629    charset_to_intern(string, OEM_CP);
     1630}
     1631
     1632/* Convert a string from ISO_CP to the current locale charset. */
     1633inline void iso_intern(char *string)
     1634{
     1635    charset_to_intern(string, ISO_CP);
     1636}
     1637#endif /* USE_ICONV_MAPPING */
  • beos/Makefile

    diff -ur unzip610b/beos/Makefile Unzip_Haiku/beos/Makefile
    old new  
    4949SHELL = /bin/sh
    5050
    5151# Punish those of you not running on SMP hardware...
    52 MAKE  = make -j 4 -f beos/Makefile
     52MAKE  = make -f beos/Makefile
    5353
    5454LOC=$(LOCAL_UNZIP) -DPASSWD_FROM_STDIN
    5555AF=$(LOC)
     
    8282LOBJS = $(OBJS)
    8383OBJSDLL = $(OBJS) api$O
    8484OBJX = unzipsfx$O crc32_$O crypt_$O extract_$O fileio_$O globals_$O \
    85     inflate_$O match_$O process_$O ttyio_$O ubz2err_$O $M_$O $(BEOS_MAIN)
     85    inflate_$O process_$O ttyio_$O ubz2err$O $M_$O match$O $(BEOS_MAIN)
    8686LOBJX = $(OBJX)
    8787OBJF = funzip$O crc32f$O cryptf$O globalsf$O inflatef$O ttyiof$O
    8888UNZIP_H = unzip.h unzpriv.h globals.h $(OSDEP_H)
     
    157157ifeq "$(WHAT)" "x86-gcc"
    158158CC=gcc
    159159LD=gcc
    160 CF=-O3 -mpentiumpro \
     160CF=-O3 -mpentiumpro -DUNIX \
    161161   -Wall -Wno-multichar -Wno-trigraphs \
    162    -ansi -I. -I/boot/develop/headers/be/support \
     162   -I. -I/boot/develop/headers/be/support \
    163163   -I/boot/develop/headers/be/storage $(LOC)
    164164LF=-o unzip
    165 LF2=-L/boot/develop/lib/x86 -lbe -lroot
     165LF2=-L/boot/develop/lib/x86 -lbe -lroot -liconv
    166166BEOS_MAIN=beosmain$O
    167167TARGET=$(UNZIPS)
    168168endif
     
    310310
    311311ubz2err$O:  ubz2err.c $(UNZIP_H)
    312312    $(CP) ubz2err.c ubz2err_.c
    313     $(CC) -c $(CF) -DSFX ubz2err_.c
     313    $(CC) -c $(CF) -DSFX ubz2err_.c -o ubz2err$O
    314314    $(RM) ubz2err_.c
    315315
    316316# funzip compilation section
  • unzip.c

    diff -ur unzip610b/unzip.c Unzip_Haiku/unzip.c
    old new  
    836836
    837837
    838838#ifdef USE_ICONV_MAPPING
    839 # ifdef UNIX
     839# ifdef UNIX 
    840840    init_conversion_charsets();
    841841# endif
    842842#endif /* USE_ICONV_MAPPING */
  • unzip.h

    diff -ur unzip610b/unzip.h Unzip_Haiku/unzip.h
    old new  
    500500 * HP C V7.3-009 dislikes "defined" in macro in #if (%CC-I-EXPANDEDDEFINED).
    501501 * It seems safest to avoid any continuation lines in either.
    502502 */
    503 #if defined(__ATHEOS__) || defined(__BEOS__) || defined(MACOS)
     503#if defined(__ATHEOS__) || defined(__BEOS__) || defined(__HAIKU__) || defined(MACOS)
    504504# define J_FLAG 1
    505505#else
    506506# if defined( UNIX) && defined( __APPLE__)
     
    547547    int vflag;          /* -v: (verbosely) list directory */
    548548    int V_flag;         /* -V: don't strip VMS version numbers */
    549549    int W_flag;         /* -W: wildcard '*' won't match '/' dir separator */
    550 #if (defined (__ATHEOS__) || defined(__BEOS__) || defined(UNIX))
     550#if (defined (__ATHEOS__) || defined(__BEOS__) ||defined(UNIX))
    551551    int X_flag;         /* -X: restore owner/protection or UID/GID or ACLs */
    552552#else
    553553#if (defined(TANDEM) || defined(THEOS))
  • unzpriv.h

    Binary files unzip610b/unzip.o and Unzip_Haiku/unzip.o differ
    Only in Unzip_Haiku/: unzipsfx
    Only in Unzip_Haiku/: unzipsfx.o
    diff -ur unzip610b/unzpriv.h Unzip_Haiku/unzpriv.h
    old new  
    301301    BeOS section:
    302302  ---------------------------------------------------------------------------*/
    303303
    304 #ifdef __BEOS__
     304#if defined(__BEOS__) || defined(__HAIKU__)
    305305#  include "beos/beocfg.h"
    306306#endif
    307307