00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #ifndef __zip_h
00057 #define __zip_h 1
00058
00059 #define ZIP
00060
00061
00062 #include "tailor.h"
00063
00064 #ifdef USE_ZLIB
00065 # include "zlib.h"
00066 #endif
00067
00068 #define MIN_MATCH 3
00069 #define MAX_MATCH 258
00070
00071
00072 #ifndef WSIZE
00073 # define WSIZE (0x8000)
00074 #endif
00075
00076
00077
00078
00079
00080 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
00081
00082
00083
00084
00085 #define MAX_DIST (WSIZE-MIN_LOOKAHEAD)
00086
00087
00088
00089
00090
00091 #ifdef DOS
00092 # define FNMAX 256
00093 #else
00094 # define FNMAX 1024
00095 #endif
00096
00097 #ifndef MATCH
00098 # define MATCH shmatch
00099 #endif
00100
00101
00102 #define local static
00103 typedef unsigned char uch;
00104 typedef unsigned short ush;
00105 typedef unsigned long ulg;
00106
00107
00108
00109 typedef struct iztimes {
00110 time_t atime;
00111 time_t mtime;
00112 time_t ctime;
00113 } iztimes;
00114
00115
00116 #define LOCHEAD 26
00117 #define CENHEAD 42
00118 #define ENDHEAD 18
00119
00120
00121 struct zlist {
00122
00123 ush vem, ver, flg, how;
00124 ulg tim, crc, siz, len;
00125 extent nam, ext, cext, com;
00126 ush dsk, att, lflg;
00127 ulg atx, off;
00128 char *name;
00129 char *extra;
00130 char *cextra;
00131 char *comment;
00132 char *iname;
00133 char *zname;
00134 int mark;
00135 int trash;
00136 int dosflag;
00137 struct zlist far *nxt;
00138 };
00139 struct flist {
00140 char *name;
00141 char *iname;
00142 char *zname;
00143 int dosflag;
00144 struct flist far *far *lst;
00145 struct flist far *nxt;
00146 };
00147 struct plist {
00148 char *zname;
00149 int select;
00150 };
00151
00152
00153 #define UNKNOWN (-1)
00154 #define BINARY 0
00155 #define ASCII 1
00156 #define __EBCDIC 2
00157
00158
00159 #define EF_VMCMS 0x4704
00160 #define EF_MVS 0x470f
00161 #define EF_IZUNIX 0x5855
00162 #define EF_IZUNIX2 0x7855
00163 #define EF_TIME 0x5455
00164 #define EF_OS2EA 0x0009
00165 #define EF_ACL 0x4C41
00166 #define EF_NTSD 0x4453
00167 #define EF_BEOS 0x6542
00168 #define EF_QDOS 0xfb4a
00169 #define EF_AOSVS 0x5356
00170 #define EF_SPARK 0x4341
00171 #define EF_THEOS 0x6854
00172 #define EF_TANDEM 0x4154
00173
00174
00175 #define EF_SIZE_MAX ((unsigned)0xFFFF)
00176 #define EB_HEADSIZE 4
00177 #define EB_ID 0
00178 #define EB_LEN 2
00179
00180 #define EB_UX_MINLEN 8
00181 #define EB_UX_ATIME 0
00182 #define EB_UX_MTIME 4
00183
00184 #define EB_UX_FULLSIZE 12
00185 #define EB_UX_UID 8
00186 #define EB_UX_GID 10
00187
00188 #define EB_UT_MINLEN 1
00189 #define EB_UT_FLAGS 0
00190 #define EB_UT_TIME1 1
00191 #define EB_UT_FL_MTIME (1 << 0)
00192 #define EB_UT_FL_ATIME (1 << 1)
00193 #define EB_UT_FL_CTIME (1 << 2)
00194 #define EB_UT_LEN(n) (EB_UT_MINLEN + 4 * (n))
00195
00196 #define EB_UX2_MINLEN 4
00197 #define EB_UX2_UID 0
00198 #define EB_UX2_GID 2
00199 #define EB_UX2_VALID (1 << 8)
00200
00201
00202 #define LF 10
00203 #define CR 13
00204 #define CTRLZ 26
00205
00206
00207 #define IZ_PW_ENTERED 0
00208 #define IZ_PW_CANCEL -1
00209 #define IZ_PW_CANCELALL -2
00210 #define IZ_PW_ERROR 5
00211 #define IZ_PW_SKIPVERIFY IZ_PW_CANCEL
00212
00213
00214 #define ZP_PW_ENTER 0
00215 #define ZP_PW_VERIFY 1
00216
00217
00218 #include "ziperr.h"
00219
00220 #if 0
00221 # define CRCVAL_INITIAL crc32(0L, (uch *)NULL, 0)
00222 #else
00223 # define CRCVAL_INITIAL 0L
00224 #endif
00225
00226 #define DOSTIME_MINIMUM ((ulg)0x00210000L)
00227 #define DOSTIME_2038_01_18 ((ulg)0x74320000L)
00228
00229
00230
00231 extern uch upper[256];
00232 extern uch lower[256];
00233 #ifdef EBCDIC
00234 extern ZCONST uch ascii[256];
00235 extern ZCONST uch ebcdic[256];
00236 #endif
00237 #ifdef IZ_ISO2OEM_ARRAY
00238 extern ZCONST uch Far iso2oem[128];
00239 #endif
00240 #ifdef IZ_OEM2ISO_ARRAY
00241 extern ZCONST uch Far oem2iso[128];
00242 #endif
00243 extern char errbuf[FNMAX+81];
00244 extern int recurse;
00245 extern int dispose;
00246 extern int pathput;
00247
00248 #ifdef RISCOS
00249 extern int scanimage;
00250 #endif
00251
00252 #define BEST -1
00253 #define STORE 0
00254 #define DEFLATE 8
00255 extern int method;
00256
00257 extern int dosify;
00258 extern char *special;
00259 extern int verbose;
00260 extern int fix;
00261 extern int adjust;
00262 extern int level;
00263 extern int translate_eol;
00264 #ifdef VMS
00265 extern int vmsver;
00266 extern int vms_native;
00267 #endif
00268 #if defined(OS2) || defined(WIN32)
00269 extern int use_longname_ea;
00270 #endif
00271 #if defined (QDOS) || defined(QLZIP)
00272 extern short qlflag;
00273 #endif
00274 extern int hidden_files;
00275 extern int volume_label;
00276 extern int dirnames;
00277 extern int linkput;
00278 extern int noisy;
00279 extern int extra_fields;
00280 #ifdef WIN32
00281 extern int use_privileges;
00282 #endif
00283 extern char *key;
00284 extern char *tempath;
00285 extern FILE *mesg;
00286 extern char *zipfile;
00287 extern ulg zipbeg;
00288 extern ulg cenbeg;
00289 extern struct zlist far *zfiles;
00290 extern extent zcount;
00291 extern extent zcomlen;
00292 extern char *zcomment;
00293 extern struct zlist far **zsort;
00294 extern ulg tempzn;
00295 extern struct flist far *found;
00296 extern struct flist far *far *fnxt;
00297 extern extent fcount;
00298
00299 extern struct plist *patterns;
00300 extern unsigned pcount;
00301 extern unsigned icount;
00302
00303 #ifdef IZ_CHECK_TZ
00304 extern int zp_tz_is_valid;
00305 #endif
00306 #if (defined(MACOS) || defined(WINDLL))
00307 extern int zipstate;
00308 #endif
00309
00310
00311 #ifdef DEBUG
00312 # ifdef MSDOS
00313 # undef stderr
00314 # define stderr stdout
00315 # endif
00316 # define diag(where) fprintf(stderr, "zip diagnostic: %s\n", where)
00317 # define Assert(cond,msg) {if(!(cond)) error(msg);}
00318 # ifdef THEOS
00319 # define Trace(x) _fprintf x
00320 # define Tracev(x) {if (verbose) _fprintf x ;}
00321 # define Tracevv(x) {if (verbose>1) _fprintf x ;}
00322 # define Tracec(c,x) {if (verbose && (c)) _fprintf x ;}
00323 # define Tracecv(c,x) {if (verbose>1 && (c)) _fprintf x ;}
00324 # else
00325 # define Trace(x) fprintf x
00326 # define Tracev(x) {if (verbose) fprintf x ;}
00327 # define Tracevv(x) {if (verbose>1) fprintf x ;}
00328 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
00329 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
00330 # endif
00331 #else
00332 # define diag(where)
00333 # define Assert(cond,msg)
00334 # define Trace(x)
00335 # define Tracev(x)
00336 # define Tracevv(x)
00337 # define Tracec(c,x)
00338 # define Tracecv(c,x)
00339 #endif
00340
00341 #ifdef DEBUGNAMES
00342 # define free(x) { int *v;Free(x); v=x;*v=0xdeadbeef;x=(void *)0xdeadbeef; }
00343 #endif
00344
00345
00346
00347 #ifndef UTIL
00348 #ifdef USE_ZIPMAIN
00349 int zipmain OF((int, char **));
00350 #else
00351 int main OF((int, char **));
00352 #endif
00353 #endif
00354
00355 #ifdef EBCDIC
00356 extern int aflag;
00357 #endif
00358 #ifdef CMS_MVS
00359 extern int bflag;
00360 #endif
00361 void zipwarn OF((char *, char *));
00362 void ziperr OF((int, char *));
00363 #ifdef UTIL
00364 # define error(msg) ziperr(ZE_LOGIC, msg)
00365 #else
00366 void error OF((char *));
00367 # ifdef VMSCLI
00368 void help OF((void));
00369 # endif
00370 int encr_passwd OF((int, char *, int, ZCONST char *));
00371 #endif
00372
00373
00374 #ifndef UTIL
00375 int percent OF((ulg, ulg));
00376 int zipup OF((struct zlist far *, FILE *));
00377 # ifdef USE_ZLIB
00378 void zl_deflate_free OF((void));
00379 # else
00380 void flush_outbuf OF((char *, unsigned *));
00381 int seekable OF((void));
00382 extern unsigned (*read_buf) OF((char *, unsigned int));
00383 # endif
00384 # ifdef ZP_NEED_MEMCOMPR
00385 ulg memcompress OF((char *, ulg, char *, ulg));
00386 # endif
00387 #endif
00388
00389
00390 #ifndef UTIL
00391 struct zlist far *zsearch OF((ZCONST char *));
00392 # ifdef USE_EF_UT_TIME
00393 int get_ef_ut_ztime OF((struct zlist far *, iztimes *));
00394 # endif
00395 int trash OF((void));
00396 #endif
00397 char *ziptyp OF((char *));
00398 int readzipfile OF((void));
00399 int putlocal OF((struct zlist far *, FILE *));
00400 int putextended OF((struct zlist far *, FILE *));
00401 int putcentral OF((struct zlist far *, FILE *));
00402 int putend OF((int, ulg, ulg, extent, char *, FILE *));
00403 int zipcopy OF((struct zlist far *, FILE *, FILE *));
00404
00405
00406 #ifndef UTIL
00407 char *getnam OF((char *, FILE *));
00408 struct flist far *fexpel OF((struct flist far *));
00409 char *last OF((char *, int));
00410 char *msname OF((char *));
00411 int check_dup OF((void));
00412 int filter OF((char *, int));
00413 int newname OF((char *, int, int));
00414 #endif
00415 #if (!defined(UTIL) || defined(W32_STATROOT_FIX))
00416 time_t dos2unixtime OF((ulg));
00417 #endif
00418 #ifndef UTIL
00419 ulg dostime OF((int, int, int, int, int, int));
00420 ulg unix2dostime OF((time_t *));
00421 int issymlnk OF((ulg a));
00422 # ifdef S_IFLNK
00423 # define rdsymlnk(p,b,n) readlink(p,b,n)
00424
00425 # else
00426 # define rdsymlnk(p,b,n) (0)
00427 # endif
00428 #endif
00429
00430 int destroy OF((char *));
00431 int replace OF((char *, char *));
00432 int getfileattr OF((char *));
00433 int setfileattr OF((char *, int));
00434 char *tempname OF((char *));
00435 int fcopy OF((FILE *, FILE *, ulg));
00436
00437 #ifdef ZMEM
00438 char *memset OF((char *, int, unsigned int));
00439 char *memcpy OF((char *, char *, unsigned int));
00440 int memcmp OF((char *, char *, unsigned int));
00441 #endif
00442
00443
00444 #ifndef UTIL
00445 # ifdef PROCNAME
00446 int wild OF((char *));
00447 # endif
00448 char *in2ex OF((char *));
00449 char *ex2in OF((char *, int, int *));
00450 int procname OF((char *, int));
00451 void stamp OF((char *, ulg));
00452 ulg filetime OF((char *, ulg *, long *, iztimes *));
00453 #if !(defined(VMS) && defined(VMS_PK_EXTRA))
00454 int set_extra_field OF((struct zlist far *, iztimes *));
00455 #endif
00456 int deletedir OF((char *));
00457 #ifdef MY_ZCALLOC
00458 zvoid far *zcalloc OF((unsigned int, unsigned int));
00459 zvoid zcfree OF((zvoid far *));
00460 #endif
00461 #endif
00462 void version_local OF((void));
00463
00464
00465 #ifndef UTIL
00466 int fseekable OF((FILE *));
00467 char *isshexp OF((char *));
00468 int shmatch OF((ZCONST char *, ZCONST char *, int));
00469 #if defined(DOS) || defined(WIN32)
00470 int dosmatch OF((ZCONST char *, ZCONST char *, int));
00471 #endif
00472 #endif
00473 void init_upper OF((void));
00474 int namecmp OF((ZCONST char *string1, ZCONST char *string2));
00475
00476 #ifdef EBCDIC
00477 char *strtoasc OF((char *str1, ZCONST char *str2));
00478 char *strtoebc OF((char *str1, ZCONST char *str2));
00479 char *memtoasc OF((char *mem1, ZCONST char *mem2, unsigned len));
00480 char *memtoebc OF((char *mem1, ZCONST char *mem2, unsigned len));
00481 #endif
00482 #ifdef IZ_ISO2OEM_ARRAY
00483 char *str_iso_to_oem OF((char *dst, ZCONST char *src));
00484 #endif
00485 #ifdef IZ_OEM2ISO_ARRAY
00486 char *str_oem_to_iso OF((char *dst, ZCONST char *src));
00487 #endif
00488
00489 zvoid far **search OF((ZCONST zvoid *, ZCONST zvoid far **, extent,
00490 int (*)(ZCONST zvoid *, ZCONST zvoid far *)));
00491 void envargs OF((int *, char ***, char *, char *));
00492 void expand_args OF((int *, char ***));
00493
00494 #ifndef USE_ZLIB
00495 #ifndef UTIL
00496
00497 ulg crc32 OF((ulg, ZCONST uch *, extent));
00498 #endif
00499
00500
00501 ZCONST ulg near *get_crc_table OF((void));
00502 #ifdef DYNALLOC_CRCTAB
00503 void free_crc_table OF((void));
00504 #endif
00505 #endif
00506
00507 #ifndef UTIL
00508 #ifndef USE_ZLIB
00509
00510 void lm_init OF((int, ush *));
00511 void lm_free OF((void));
00512 ulg deflate OF((void));
00513
00514
00515 void ct_init OF((ush *, int *));
00516 int ct_tally OF((int, int));
00517 ulg flush_block OF((char far *, ulg, int));
00518 void bi_init OF((char *, unsigned int, int));
00519 #endif
00520 #endif
00521
00522
00523 #if defined(ASMV) && defined(RISCOS)
00524 void send_bits OF((int, int));
00525 unsigned bi_reverse OF((unsigned int, int));
00526 #endif
00527
00528
00529
00530
00531 #ifdef VMS
00532 int vms_stat OF((char *, stat_t *));
00533 void vms_exit OF((int));
00534 #ifndef UTIL
00535 #ifdef VMSCLI
00536 ulg vms_zip_cmdline OF((int *, char ***));
00537 void VMSCLI_help OF((void));
00538 #endif
00539 #endif
00540 #endif
00541
00542
00543
00544
00545
00546 #ifdef WIN32
00547 int ZipIsWinNT OF((void));
00548 #endif
00549
00550 #if (defined(WINDLL) || defined(DLL_ZIPAPI))
00551
00552
00553
00554 #include "api.h"
00555 #endif
00556
00557 #endif
00558