View | Details | Raw Unified | Return to bug 4871
Collapse All | Expand All

(-)unzip-5.50.orig/unix/unix.c (+89 lines)
Lines 29-34 Link Here
29
#define UNZIP_INTERNAL
29
#define UNZIP_INTERNAL
30
#include "unzip.h"
30
#include "unzip.h"
31
31
32
#include <iconv.h>
33
#include <langinfo.h>
34
32
#ifdef SCO_XENIX
35
#ifdef SCO_XENIX
33
#  define SYSNDIR
36
#  define SYSNDIR
34
#else  /* SCO Unix, AIX, DNIX, TI SysV, Coherent 4.x, ... */
37
#else  /* SCO Unix, AIX, DNIX, TI SysV, Coherent 4.x, ... */
Lines 1524-1526 Link Here
1524
    }
1527
    }
1525
}
1528
}
1526
#endif /* QLZIP */
1529
#endif /* QLZIP */
1530
1531
1532
typedef struct {
1533
    char *local_charset;
1534
    char *archive_charset;
1535
} CHARSET_MAP;
1536
1537
/* A mapping of local <-> archive charsets used by default to convert filenames
1538
 * of DOS/Windows Zip archives. Currently very basic. */
1539
static CHARSET_MAP dos_charset_map[] = {
1540
    { "ANSI_X3.4-1968", "CP850" },
1541
    { "ISO-8859-1", "CP850" },
1542
    { "CP1252", "CP850" },
1543
    { "CP1251", "CP866" },
1544
    { "KOI8-R", "CP866" },
1545
    { "KOI8-U", "CP866" },
1546
    { "ISO-8859-5", "CP866" }
1547
};
1548
1549
char OEM_CP[MAX_CP_NAME] = "";
1550
char ISO_CP[MAX_CP_NAME] = "";
1551
1552
/* Try to guess the default value of OEM_CP based on the current locale.
1553
 * ISO_CP is left alone for now. */
1554
void init_conversion_charsets()
1555
{
1556
    const char *local_charset;
1557
    int i;
1558
1559
    /* Make a guess only if OEM_CP not already set. */ 
1560
    if(*OEM_CP == '\0') {
1561
    	local_charset = nl_langinfo(CODESET);
1562
    	for(i = 0; i < sizeof(dos_charset_map)/sizeof(CHARSET_MAP); i++)
1563
    		if(!strcasecmp(local_charset, dos_charset_map[i].local_charset)) {
1564
    			strncpy(OEM_CP, dos_charset_map[i].archive_charset,
1565
    					sizeof(OEM_CP));
1566
    			break;
1567
    		}
1568
    }
1569
}
1570
1571
/* Convert a string from one encoding to the current locale using iconv().
1572
 * Be as non-intrusive as possible. If error is encountered during covertion
1573
 * just leave the string intact. */
1574
static void charset_to_intern(char *string, char *from_charset)
1575
{
1576
    iconv_t cd;
1577
    char *s, *d, *buf;
1578
    size_t slen, dlen, buflen;
1579
    const char *local_charset;
1580
1581
    if(*from_charset == '\0')
1582
    	return;
1583
1584
    buf = NULL;
1585
    local_charset = nl_langinfo(CODESET);
1586
1587
    if((cd = iconv_open(local_charset, from_charset)) == (iconv_t)-1)
1588
        return;
1589
1590
    slen = dlen = buflen = strlen(string);
1591
    s = string;
1592
    d = buf = malloc(buflen + 1);
1593
    if(!d)
1594
    	goto cleanup;
1595
1596
    if(iconv(cd, &s, &slen, &d, &dlen) == (size_t)-1)
1597
    	goto cleanup;
1598
    strncpy(string, buf, buflen);
1599
    
1600
    cleanup:
1601
    free(buf);
1602
    iconv_close(cd);
1603
}
1604
1605
/* Convert a string from OEM_CP to the current locale charset. */
1606
inline void oem_intern(char *string)
1607
{
1608
    charset_to_intern(string, OEM_CP);
1609
}
1610
1611
/* Convert a string from ISO_CP to the current locale charset. */
1612
inline void iso_intern(char *string)
1613
{
1614
    charset_to_intern(string, ISO_CP);
1615
}
(-)unzip-5.50.orig/unix/unxcfg.h (+26 lines)
Lines 123-126 Link Here
123
/* wild_dir, dirname, wildname, matchname[], dirnamelen, have_dirname, */
123
/* wild_dir, dirname, wildname, matchname[], dirnamelen, have_dirname, */
124
/*    and notfirstcall are used by do_wild().                          */
124
/*    and notfirstcall are used by do_wild().                          */
125
125
126
127
#define MAX_CP_NAME 25 
128
   
129
#ifdef SETLOCALE
130
#  undef SETLOCALE
131
#endif
132
#define SETLOCALE(category, locale) setlocale(category, locale)
133
#include <locale.h>
134
   
135
#ifdef _ISO_INTERN
136
#  undef _ISO_INTERN
137
#endif
138
#define _ISO_INTERN(str1) iso_intern(str1)
139
140
#ifdef _OEM_INTERN
141
#  undef _OEM_INTERN
142
#endif
143
#ifndef IZ_OEM2ISO_ARRAY
144
#  define IZ_OEM2ISO_ARRAY
145
#endif
146
#define _OEM_INTERN(str1) oem_intern(str1)
147
148
void iso_intern(char *);
149
void oem_intern(char *);
150
void init_conversion_charsets(void);
151
   
126
#endif /* !__unxcfg_h */
152
#endif /* !__unxcfg_h */
(-)unzip-5.50.orig/unzip.c (+89 lines)
Lines 304-314 Link Here
304
  -2  just filenames but allow -h/-t/-z  -l  long Unix \"ls -l\" format\n\
304
  -2  just filenames but allow -h/-t/-z  -l  long Unix \"ls -l\" format\n\
305
                                         -v  verbose, multi-page format\n";
305
                                         -v  verbose, multi-page format\n";
306
306
307
#ifndef UNIX
307
static ZCONST char Far ZipInfoUsageLine3[] = "miscellaneous options:\n\
308
static ZCONST char Far ZipInfoUsageLine3[] = "miscellaneous options:\n\
308
  -h  print header line       -t  print totals for listed files or for all\n\
309
  -h  print header line       -t  print totals for listed files or for all\n\
309
  -z  print zipfile comment  %c-T%c print file times in sortable decimal format\
310
  -z  print zipfile comment  %c-T%c print file times in sortable decimal format\
310
\n %c-C%c be case-insensitive   %s\
311
\n %c-C%c be case-insensitive   %s\
311
  -x  exclude filenames that follow from listing\n";
312
  -x  exclude filenames that follow from listing\n";
313
#else /* UNIX */
314
static ZCONST char Far ZipInfoUsageLine3[] = "miscellaneous options:\n\
315
  -h  print header line       -t  print totals for listed files or for all\n\
316
  -z  print zipfile comment  %c-T%c print file times in sortable decimal format\
317
\n %c-C%c be case-insensitive   %s\
318
  -x  exclude filenames that follow from listing\n\
319
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives\n\
320
  -I CHARSET  specify a character encoding for UNIX and other archives\n";
321
#endif /* !UNIX */
312
#ifdef MORE
322
#ifdef MORE
313
#ifdef VMS
323
#ifdef VMS
314
   static ZCONST char Far ZipInfoUsageLine4[] =
324
   static ZCONST char Far ZipInfoUsageLine4[] =
Lines 589-594 Link Here
589
#endif /* ?VM_CMS */
599
#endif /* ?VM_CMS */
590
#endif /* ?MACOS */
600
#endif /* ?MACOS */
591
601
602
#ifndef UNIX
592
static ZCONST char Far UnzipUsageLine4[] = "\
603
static ZCONST char Far UnzipUsageLine4[] = "\
593
modifiers:                                   -q  quiet mode (-qq => quieter)\n\
604
modifiers:                                   -q  quiet mode (-qq => quieter)\n\
594
  -n  never overwrite existing files         -a  auto-convert any text files\n\
605
  -n  never overwrite existing files         -a  auto-convert any text files\n\
Lines 596-601 Link Here
596
 -j  junk paths (do not make directories)   -v  be verbose/print version info\n\
607
 -j  junk paths (do not make directories)   -v  be verbose/print version info\n\
597
 %c-C%c match filenames case-insensitively    %c-L%c make (some) names \
608
 %c-C%c match filenames case-insensitively    %c-L%c make (some) names \
598
lowercase\n %-42s %c-V%c retain VMS version numbers\n%s";
609
lowercase\n %-42s %c-V%c retain VMS version numbers\n%s";
610
#else /* UNIX */
611
static ZCONST char Far UnzipUsageLine4[] = "\
612
modifiers:                                   -q  quiet mode (-qq => quieter)\n\
613
  -n  never overwrite existing files         -a  auto-convert any text files\n\
614
  -o  overwrite files WITHOUT prompting      -aa treat ALL files as text\n \
615
 -j  junk paths (do not make directories)   -v  be verbose/print version info\n\
616
 %c-C%c match filenames case-insensitively    %c-L%c make (some) names \
617
lowercase\n %-42s %c-V%c retain VMS version numbers\n%s\n\
618
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives\n\
619
  -I CHARSET  specify a character encoding for UNIX and other archives\n\n";
620
#endif /* !UNIX */
599
621
600
static ZCONST char Far UnzipUsageLine5[] = "\
622
static ZCONST char Far UnzipUsageLine5[] = "\
601
Examples (see unzip.txt for more info):\n\
623
Examples (see unzip.txt for more info):\n\
Lines 656-661 Link Here
656
678
657
    SETLOCALE(LC_CTYPE,"");
679
    SETLOCALE(LC_CTYPE,"");
658
680
681
#ifdef UNIX
682
    init_conversion_charsets();
683
#endif
684
659
#if (defined(__IBMC__) && defined(__DEBUG_ALLOC__))
685
#if (defined(__IBMC__) && defined(__DEBUG_ALLOC__))
660
    extern void DebugMalloc(void);
686
    extern void DebugMalloc(void);
661
687
Lines 1070-1075 Link Here
1070
    argc = *pargc;
1096
    argc = *pargc;
1071
    argv = *pargv;
1097
    argv = *pargv;
1072
1098
1099
#ifdef UNIX
1100
    extern char OEM_CP[MAX_CP_NAME];
1101
    extern char ISO_CP[MAX_CP_NAME];
1102
#endif
1103
    
1073
    while (++argv, (--argc > 0 && *argv != NULL && **argv == '-')) {
1104
    while (++argv, (--argc > 0 && *argv != NULL && **argv == '-')) {
1074
        s = *argv + 1;
1105
        s = *argv + 1;
1075
        while ((c = *s++) != 0) {    /* "!= 0":  prevent Turbo C warning */
1106
        while ((c = *s++) != 0) {    /* "!= 0":  prevent Turbo C warning */
Lines 1233-1238 Link Here
1233
                    }
1264
                    }
1234
                    break;
1265
                    break;
1235
#endif  /* MACOS */
1266
#endif  /* MACOS */
1267
#ifdef UNIX
1268
    			case ('I'):
1269
                    if (negative) {
1270
                        Info(slide, 0x401, ((char *)slide,
1271
                          "error:  encodings can't be negated"));
1272
                        return(PK_PARAM);
1273
    				} else {
1274
    					if(*s) { /* Handle the -Icharset case */
1275
    						/* Assume that charsets can't start with a dash to spot arguments misuse */
1276
    						if(*s == '-') { 
1277
    	                        Info(slide, 0x401, ((char *)slide,
1278
        		                  "error:  a valid character encoding should follow the -I argument"));
1279
    	                        return(PK_PARAM); 
1280
    						}
1281
    						strncpy(ISO_CP, s, sizeof(ISO_CP));
1282
    					} else { /* -I charset */
1283
    						++argv;
1284
    						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
1285
    	                        Info(slide, 0x401, ((char *)slide,
1286
        		                  "error:  a valid character encoding should follow the -I argument"));
1287
    	                        return(PK_PARAM); 
1288
    						}
1289
    						s = *argv;
1290
    						strncpy(ISO_CP, s, sizeof(ISO_CP));
1291
    					}
1292
    					while(*(++s)); /* No params straight after charset name */
1293
    				}
1294
    				break;
1295
#endif /* ?UNIX */
1236
                case ('j'):    /* junk pathnames/directory structure */
1296
                case ('j'):    /* junk pathnames/directory structure */
1237
                    if (negative)
1297
                    if (negative)
1238
                        uO.jflag = FALSE, negative = 0;
1298
                        uO.jflag = FALSE, negative = 0;
Lines 1299-1304 Link Here
1299
                    } else
1359
                    } else
1300
                        ++uO.overwrite_all;
1360
                        ++uO.overwrite_all;
1301
                    break;
1361
                    break;
1362
#ifdef UNIX
1363
    			case ('O'):
1364
                    if (negative) {
1365
                        Info(slide, 0x401, ((char *)slide,
1366
                          "error:  encodings can't be negated"));
1367
                        return(PK_PARAM);
1368
    				} else {
1369
    					if(*s) { /* Handle the -Ocharset case */
1370
    						/* Assume that charsets can't start with a dash to spot arguments misuse */
1371
    						if(*s == '-') { 
1372
    	                        Info(slide, 0x401, ((char *)slide,
1373
        		                  "error:  a valid character encoding should follow the -I argument"));
1374
    	                        return(PK_PARAM); 
1375
    						}
1376
    						strncpy(OEM_CP, s, sizeof(OEM_CP));
1377
    					} else { /* -O charset */
1378
    						++argv;
1379
    						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
1380
    	                        Info(slide, 0x401, ((char *)slide,
1381
        		                  "error:  a valid character encoding should follow the -O argument"));
1382
    	                        return(PK_PARAM); 
1383
    						}
1384
    						s = *argv;
1385
    						strncpy(OEM_CP, s, sizeof(OEM_CP));
1386
    					}
1387
    					while(*(++s)); /* No params straight after charset name */
1388
    				}
1389
    				break;
1390
#endif /* ?UNIX */
1302
                case ('p'):    /* pipes:  extract to stdout, no messages */
1391
                case ('p'):    /* pipes:  extract to stdout, no messages */
1303
                    if (negative) {
1392
                    if (negative) {
1304
                        uO.cflag = FALSE;
1393
                        uO.cflag = FALSE;
(-)unzip-5.50.orig/unzpriv.h (-2 / +4 lines)
Lines 1103-1109 Link Here
1103
#  define lastchar(ptr, len) (ptr[(len)-1])
1103
#  define lastchar(ptr, len) (ptr[(len)-1])
1104
#  define MBSCHR(str, c) strchr(str, c)
1104
#  define MBSCHR(str, c) strchr(str, c)
1105
#  define MBSRCHR(str, c) strrchr(str, c)
1105
#  define MBSRCHR(str, c) strrchr(str, c)
1106
#  define SETLOCALE(category, locale)
1106
#  ifndef SETLOCALE
1107
#    define SETLOCALE(category, locale)
1108
#  endif
1107
#endif /* ?_MBCS */
1109
#endif /* ?_MBCS */
1108
#define INCSTR(ptr) PREINCSTR(ptr)
1110
#define INCSTR(ptr) PREINCSTR(ptr)
1109
1111
Lines 2424-2430 Link Here
2424
         !(((islochdr) || (isuxatt)) && \
2426
         !(((islochdr) || (isuxatt)) && \
2425
           ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
2427
           ((hostver) == 25 || (hostver) == 26 || (hostver) == 40))) || \
2426
        (hostnum) == FS_HPFS_ || \
2428
        (hostnum) == FS_HPFS_ || \
2427
        ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
2429
        ((hostnum) == FS_NTFS_/* && (hostver) == 50*/)) { \
2428
        _OEM_INTERN((string)); \
2430
        _OEM_INTERN((string)); \
2429
    } else { \
2431
    } else { \
2430
        _ISO_INTERN((string)); \
2432
        _ISO_INTERN((string)); \
(-)unzip-5.50.orig/zipinfo.c (+62 lines)
Lines 440-445 Link Here
440
    int    tflag_slm=TRUE, tflag_2v=FALSE;
440
    int    tflag_slm=TRUE, tflag_2v=FALSE;
441
    int    explicit_h=FALSE, explicit_t=FALSE;
441
    int    explicit_h=FALSE, explicit_t=FALSE;
442
442
443
#ifdef UNIX
444
    extern char OEM_CP[MAX_CP_NAME];
445
    extern char ISO_CP[MAX_CP_NAME];
446
#endif
443
447
444
#ifdef MACOS
448
#ifdef MACOS
445
    uO.lflag = LFLAG;         /* reset default on each call */
449
    uO.lflag = LFLAG;         /* reset default on each call */
Lines 484-489 Link Here
484
                            uO.lflag = 0;
488
                            uO.lflag = 0;
485
                    }
489
                    }
486
                    break;
490
                    break;
491
#ifdef UNIX
492
    			case ('I'):
493
                    if (negative) {
494
                        Info(slide, 0x401, ((char *)slide,
495
                          "error:  encodings can't be negated"));
496
                        return(PK_PARAM);
497
    				} else {
498
    					if(*s) { /* Handle the -Icharset case */
499
    						/* Assume that charsets can't start with a dash to spot arguments misuse */
500
    						if(*s == '-') { 
501
    	                        Info(slide, 0x401, ((char *)slide,
502
        		                  "error:  a valid character encoding should follow the -I argument"));
503
    	                        return(PK_PARAM); 
504
    						}
505
    						strncpy(ISO_CP, s, sizeof(ISO_CP));
506
    					} else { /* -I charset */
507
    						++argv;
508
    						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
509
    	                        Info(slide, 0x401, ((char *)slide,
510
        		                  "error:  a valid character encoding should follow the -I argument"));
511
    	                        return(PK_PARAM); 
512
    						}
513
    						s = *argv;
514
    						strncpy(ISO_CP, s, sizeof(ISO_CP));
515
    					}
516
    					while(*(++s)); /* No params straight after charset name */
517
    				}
518
    				break;
519
#endif /* ?UNIX */
487
                case 'l':      /* longer form of "ls -l" type listing */
520
                case 'l':      /* longer form of "ls -l" type listing */
488
                    if (negative)
521
                    if (negative)
489
                        uO.lflag = -2, negative = 0;
522
                        uO.lflag = -2, negative = 0;
Lines 504-509 Link Here
504
                        G.M_flag = TRUE;
537
                        G.M_flag = TRUE;
505
                    break;
538
                    break;
506
#endif
539
#endif
540
#ifdef UNIX
541
    			case ('O'):
542
                    if (negative) {
543
                        Info(slide, 0x401, ((char *)slide,
544
                          "error:  encodings can't be negated"));
545
                        return(PK_PARAM);
546
    				} else {
547
    					if(*s) { /* Handle the -Ocharset case */
548
    						/* Assume that charsets can't start with a dash to spot arguments misuse */
549
    						if(*s == '-') { 
550
    	                        Info(slide, 0x401, ((char *)slide,
551
        		                  "error:  a valid character encoding should follow the -I argument"));
552
    	                        return(PK_PARAM); 
553
    						}
554
    						strncpy(OEM_CP, s, sizeof(OEM_CP));
555
    					} else { /* -O charset */
556
    						++argv;
557
    						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
558
    	                        Info(slide, 0x401, ((char *)slide,
559
        		                  "error:  a valid character encoding should follow the -O argument"));
560
    	                        return(PK_PARAM); 
561
    						}
562
    						s = *argv;
563
    						strncpy(OEM_CP, s, sizeof(OEM_CP));
564
    					}
565
    					while(*(++s)); /* No params straight after charset name */
566
    				}
567
    				break;
568
#endif /* ?UNIX */
507
                case 's':      /* default:  shorter "ls -l" type listing */
569
                case 's':      /* default:  shorter "ls -l" type listing */
508
                    if (negative)
570
                    if (negative)
509
                        uO.lflag = -2, negative = 0;
571
                        uO.lflag = -2, negative = 0;

Return to bug 4871