123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718 |
- #define __API_C
- #include <malloc.h>
- #ifdef WINDLL
- # include <windows.h>
- # include "windll/windll.h"
- #endif
- #ifdef OS2
- # define INCL_DOSMEMMGR
- # include <os2.h>
- #endif
- #ifdef __BORLANDC__
- #include <dir.h>
- #endif
- #include <direct.h>
- #include <ctype.h>
- #include "api.h"
- #include "crypt.h"
- #include "revision.h"
- #ifdef USE_ZLIB
- # include "zlib.h"
- #endif
- DLLPRNT *lpZipPrint;
- DLLPASSWORD *lpZipPassword;
- extern DLLCOMMENT *lpComment;
- ZIPUSERFUNCTIONS ZipUserFunctions, far * lpZipUserFunctions;
- int ZipRet;
- char szOrigDir[PATH_MAX];
- BOOL fNo_int64 = FALSE;
- extern int zipmain OF((int, char **));
- int AllocMemory(unsigned int, char *, char *, BOOL);
- int ParseString(LPSTR, unsigned int);
- void FreeArgVee(void);
- ZPOPT Options;
- char **argVee;
- unsigned int argCee;
- char szRootDir[PATH_MAX], szExcludeList[PATH_MAX], szIncludeList[PATH_MAX], szTempDir[PATH_MAX];
- int ParseString(LPSTR s, unsigned int ArgC)
- {
- unsigned int i;
- int root_flag, m, j;
- char *str1, *str2, *str3;
- size_t size;
- i = ArgC;
- str1 = (char *) malloc(lstrlen(s)+4);
- lstrcpy(str1, s);
- lstrcat(str1, " @");
- if ((szRootDir != NULL) && (szRootDir[0] != '\0'))
- {
- root_flag = TRUE;
- if (szRootDir[lstrlen(szRootDir)-1] != '\\')
- lstrcat(szRootDir, "\\");
- }
- else
- root_flag = FALSE;
- str2 = strchr(str1, '\"');
- while ((str3 = strchr(str1, '\t')) != NULL)
- {
- str3[0] = ' ';
- }
- while ((str2 = strchr(str1, '\"')) != NULL)
-
- {
- str3 = strchr(str2+1, '\"');
- if (str3 == NULL)
- {
- free(str1);
- return ZE_PARMS;
- }
- str3[0] = '\0';
-
- if (root_flag)
- if ((_strnicmp(szRootDir, str2+1, lstrlen(szRootDir))) == 0)
- {
- m = 0;
- str2++;
- for (j = lstrlen(szRootDir); j < lstrlen(str2); j++)
- str2[m++] = str2[j];
- str2[m] = '\0';
- str2--;
- }
- size = _msize(argVee);
- if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
- {
- fprintf(stdout, "Unable to allocate memory in zip dll\n");
- return ZE_MEM;
- }
-
- if (AllocMemory(i, str2+1, "Creating file list from string", TRUE) != ZE_OK)
- {
- free(str1);
- return ZE_MEM;
- }
- i++;
- str3+=2;
- str2[0] = '\0';
- lstrcat(str1, str3);
- }
- str2 = strchr(str1, ' ');
- while ((str2[0] != '\0') && (str2[0] != '@'))
- {
- while ((str2[0] == ' ') && (str2[1] == ' '))
- {
- str3 = &str2[1];
- str2[0] = '\0';
- lstrcat(str1, str3);
- }
- str2++;
- }
- if (str1[0] == ' ')
- {
- str3 = &str1[1];
- lstrcpy(str1, str3);
- }
- str2 = str3 = str1;
- while ((str2[0] != '\0') && (str3[0] != '@'))
- {
- str3 = strchr(str2+1, ' ');
- str3[0] = '\0';
-
- if (root_flag)
- if ((_strnicmp(szRootDir, str2, lstrlen(szRootDir))) == 0)
- {
- m = 0;
- for (j = lstrlen(Options.szRootDir); j < lstrlen(str2); j++)
- str2[m++] = str2[j];
- str2[m] = '\0';
- }
- size = _msize(argVee);
- if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
- {
- fprintf(stdout, "Unable to allocate memory in zip dll\n");
- return ZE_MEM;
- }
- if (AllocMemory(i, str2, "Creating file list from string", TRUE) != ZE_OK)
- {
- free(str1);
- return ZE_MEM;
- }
- i++;
- str3++;
- str2 = str3;
- }
- free(str1);
- return ZE_OK;
- }
- int AllocMemory(unsigned int i, char *cmd, char *str, BOOL IncrementArgCee)
- {
- if ((argVee[i] = (char *) malloc( sizeof(char) * strlen(cmd)+1 )) == NULL)
- {
- if (IncrementArgCee)
- argCee++;
- FreeArgVee();
- fprintf(stdout, "Unable to allocate memory in zip library at %s\n", str);
- return ZE_MEM;
- }
- strcpy( argVee[i], cmd );
- argCee++;
- return ZE_OK;
- }
- void FreeArgVee(void)
- {
- unsigned i;
- for (i = 0; i < argCee; i++)
- {
- free (argVee[i]);
- argVee[i] = NULL;
- }
- free(argVee);
- chdir(szOrigDir);
- #ifdef __BORLANDC__
- setdisk(toupper(szOrigDir[0]) - 'A');
- #endif
- }
- int EXPENTRY ZpInit(LPZIPUSERFUNCTIONS lpZipUserFunc)
- {
- ZipUserFunctions = *lpZipUserFunc;
- lpZipUserFunctions = &ZipUserFunctions;
- if (!lpZipUserFunctions->print ||
- !lpZipUserFunctions->comment)
- return FALSE;
- return TRUE;
- }
- int EXPENTRY ZpArchive(ZCL C, LPZPOPT Opts)
- {
- int k, j, m;
- size_t size;
- Options = *Opts;
- szRootDir[0] = '\0';
- szExcludeList[0] = '\0';
- szIncludeList[0] = '\0';
- szTempDir[0] = '\0';
- if (Options.szRootDir) lstrcpy(szRootDir, Options.szRootDir);
- if (Options.szExcludeList) lstrcpy(szExcludeList, Options.szExcludeList);
- if (Options.szIncludeList) lstrcpy(szIncludeList, Options.szIncludeList);
- if (Options.szTempDir) lstrcpy(szTempDir, Options.szTempDir);
- getcwd(szOrigDir, PATH_MAX);
- if ((szRootDir != NULL) && (szRootDir[0] != '\0'))
- {
-
- if (szRootDir[lstrlen(szRootDir)-1] == '\\')
- szRootDir[lstrlen(szRootDir)-1] = '\0';
- chdir(szRootDir);
- #ifdef __BORLANDC__
- setdisk(toupper(szRootDir[0]) - 'A');
- #endif
- }
- argCee = 0;
- if ((argVee = (char **)malloc((C.argc+40)*sizeof(char *))) == NULL)
- {
- fprintf(stdout, "Unable to allocate memory in zip dll\n");
- return ZE_MEM;
- }
- if ((argVee[argCee] = (char *) malloc( sizeof(char) * strlen("wiz.exe")+1 )) == NULL)
- {
- free(argVee);
- fprintf(stdout, "Unable to allocate memory in zip dll\n");
- return ZE_MEM;
- }
- strcpy( argVee[argCee], "wiz.exe" );
- argCee++;
- if (AllocMemory(argCee, "-0", "Compression", FALSE) != ZE_OK)
- return ZE_MEM;
- if ((Options.fLevel < '0') || (Options.fLevel > '9'))
- {
- Options.fLevel = '6';
- if (!Options.fDeleteEntries)
- fprintf(stdout, "Compression level set to invalid value. Setting to default\n");
- }
- argVee[argCee-1][1] = Options.fLevel;
- if (Options.fOffsets)
- {
- if (AllocMemory(argCee, "-A", "Offsets", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fDeleteEntries)
- {
- if (AllocMemory(argCee, "-d", "Delete", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fNoDirEntries)
- {
- if (AllocMemory(argCee, "-D", "No Dir Entries", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fFreshen)
- {
- if (AllocMemory(argCee, "-f", "Freshen", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fRepair)
- {
- if (Options.fRepair == 1)
- {
- if (AllocMemory(argCee, "-F", "Repair", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- else
- {
- if (AllocMemory(argCee, "-FF", "Repair", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- }
- if (Options.fGrow)
- {
- if (AllocMemory(argCee, "-g", "Appending", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fJunkDir)
- {
- if (AllocMemory(argCee, "-j", "Junk Dir Names", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fEncrypt)
- {
- if (AllocMemory(argCee, "-e", "Encrypt", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fJunkSFX)
- {
- if (AllocMemory(argCee, "-J", "Junk SFX", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fForce)
- {
- if (AllocMemory(argCee, "-k", "Force DOS", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fLF_CRLF)
- {
- if (AllocMemory(argCee, "-l", "LF-CRLF", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fCRLF_LF)
- {
- if (AllocMemory(argCee, "-ll", "CRLF-LF", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fMove)
- {
- if (AllocMemory(argCee, "-m", "Move", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fLatestTime)
- {
- if (AllocMemory(argCee, "-o", "Time", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fComment)
- {
- if (AllocMemory(argCee, "-z", "Comment", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fQuiet)
- {
- if (AllocMemory(argCee, "-q", "Quiet", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fRecurse == 1)
- {
- if (AllocMemory(argCee, "-r", "Recurse -r", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- else if (Options.fRecurse == 2)
- {
- if (AllocMemory(argCee, "-R", "Recurse -R", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fSystem)
- {
- if (AllocMemory(argCee, "-S", "System", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fExcludeDate)
- {
- if ((Options.Date != NULL) && (Options.Date[0] != '\0'))
- {
- if (AllocMemory(argCee, "-tt", "Date", FALSE) != ZE_OK)
- return ZE_MEM;
- if (AllocMemory(argCee, Options.Date, "Date", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- }
- if (Options.fIncludeDate)
- {
- if ((Options.Date != NULL) && (Options.Date[0] != '\0'))
- {
- if (AllocMemory(argCee, "-t", "Date", FALSE) != ZE_OK)
- return ZE_MEM;
- if (AllocMemory(argCee, Options.Date, "Date", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- }
- if (Options.fUpdate)
- {
- if (AllocMemory(argCee, "-u", "Update", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fVerbose)
- {
- if (AllocMemory(argCee, "-v", "Verbose", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.fVolume)
- {
- if (AllocMemory(argCee, "-$", "Volume", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.szSplitSize != NULL)
- {
- if (AllocMemory(argCee, "-s", "Splitting", FALSE) != ZE_OK)
- return ZE_MEM;
- if (AllocMemory(argCee, Options.szSplitSize, "Split size", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (lpZipUserFunctions->split != NULL)
- {
- if (AllocMemory(argCee, "-sp", "Split Pause Select Destination", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- #ifdef WIN32
- if (Options.fPrivilege)
- {
- if (AllocMemory(argCee, "-!", "Privileges", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- #endif
- if (Options.fExtra)
- {
- if (AllocMemory(argCee, "-X", "Extra", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.IncludeList != NULL)
- {
- if (AllocMemory(argCee, "-i", "Include file list", FALSE) != ZE_OK)
- return ZE_MEM;
- k = 0;
- if (Options.IncludeListCount > 0)
- while ((Options.IncludeList[k] != NULL) && (Options.IncludeListCount != k+1))
- {
- size = _msize(argVee);
- if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
- {
- fprintf(stdout, "Unable to allocate memory in zip dll\n");
- return ZE_MEM;
- }
- if (AllocMemory(argCee, Options.IncludeList[k], "Include file list array", TRUE) != ZE_OK)
- {
- return ZE_MEM;
- }
- k++;
- }
- else
- while (Options.IncludeList[k] != NULL)
- {
- size = _msize(argVee);
- if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
- {
- FreeArgVee();
- fprintf(stdout, "Unable to allocate memory in zip dll\n");
- return ZE_MEM;
- }
- if (AllocMemory(argCee, Options.IncludeList[k], "Include file list array", TRUE) != ZE_OK)
- return ZE_MEM;
- k++;
- }
- if (AllocMemory(argCee, "@", "End of Include List", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (Options.ExcludeList != NULL)
- {
- if (AllocMemory(argCee, "-x", "Exclude file list", FALSE) != ZE_OK)
- return ZE_MEM;
- k = 0;
- if (Options.ExcludeListCount > 0)
- while ((Options.ExcludeList[k] != NULL) && (Options.ExcludeListCount != k+1))
- {
- size = _msize(argVee);
- if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
- {
- fprintf(stdout, "Unable to allocate memory in zip dll\n");
- return ZE_MEM;
- }
- if (AllocMemory(argCee, Options.ExcludeList[k], "Exclude file list array", TRUE) != ZE_OK)
- return ZE_MEM;
- k++;
- }
- else
- while (Options.ExcludeList[k] != NULL)
- {
- size = _msize(argVee);
- if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
- {
- FreeArgVee();
- fprintf(stdout, "Unable to allocate memory in zip dll\n");
- return ZE_MEM;
- }
- if (AllocMemory(argCee, Options.ExcludeList[k], "Exclude file list array", TRUE) != ZE_OK)
- return ZE_MEM;
- k++;
- }
- if (AllocMemory(argCee, "@", "End of Exclude List", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (szIncludeList != NULL && szIncludeList[0] != '\0')
- {
- if (AllocMemory(argCee, "-i", "Include file list", FALSE) != ZE_OK)
- return ZE_MEM;
- if ((k = ParseString(szIncludeList, argCee)) != ZE_OK)
- return k;
- if (AllocMemory(argCee, "@", "End of Include List", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (szExcludeList != NULL && szExcludeList[0] != '\0')
- {
- if (AllocMemory(argCee, "-x", "Exclude file list", FALSE) != ZE_OK)
- return ZE_MEM;
- if ((k = ParseString(szExcludeList, argCee)) != ZE_OK)
- return k;
- if (AllocMemory(argCee, "@", "End of Exclude List", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if ((szTempDir != NULL) && (szTempDir[0] != '\0')
- && Options.fTemp)
- {
- if (AllocMemory(argCee, "-b", "Temp dir switch command", FALSE) != ZE_OK)
- return ZE_MEM;
- if (AllocMemory(argCee, szTempDir, "Temporary directory", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (AllocMemory(argCee, C.lpszZipFN, "Zip file name", FALSE) != ZE_OK)
- return ZE_MEM;
- if ((szRootDir != NULL) && (szRootDir[0] != '\0'))
- {
- if (szRootDir[lstrlen(szRootDir)-1] != '\\')
- lstrcat(szRootDir, "\\");
- if (C.FNV != NULL)
- {
- for (k = 0; k < C.argc; k++)
- {
- if (AllocMemory(argCee, C.FNV[k], "Making argv", FALSE) != ZE_OK)
- return ZE_MEM;
- if ((_strnicmp(szRootDir, C.FNV[k], lstrlen(szRootDir))) == 0)
- {
- m = 0;
- for (j = lstrlen(szRootDir); j < lstrlen(C.FNV[k]); j++)
- argVee[argCee-1][m++] = C.FNV[k][j];
- argVee[argCee-1][m] = '\0';
- }
- }
- }
- }
- else
- if (C.FNV != NULL)
- for (k = 0; k < C.argc; k++)
- {
- if (AllocMemory(argCee, C.FNV[k], "Making argv", FALSE) != ZE_OK)
- return ZE_MEM;
- }
- if (C.lpszAltFNL != NULL)
- {
- if ((k = ParseString(C.lpszAltFNL, argCee)) != ZE_OK)
- return k;
- }
- argVee[argCee] = NULL;
- ZipRet = zipmain(argCee, argVee);
- FreeArgVee();
- return ZipRet;
- }
- #if CRYPT
- int encr_passwd(int modeflag, char *pwbuf, int size, const char *zfn)
- {
- return (*lpZipUserFunctions->password)(pwbuf, size, ((modeflag == ZP_PW_VERIFY) ?
- "Verify password: " : "Enter password: "),
- (char *)zfn);
- }
- #endif
- void EXPENTRY ZpVersion(ZpVer far * p)
- {
- p->structlen = ZPVER_LEN;
- #ifdef BETA
- p->flag = 1;
- #else
- p->flag = 0;
- #endif
- #ifdef CRYPT
- p->fEncryption = TRUE;
- #else
- p->fEncryption = FALSE;
- #endif
- lstrcpy(p->betalevel, Z_BETALEVEL);
- lstrcpy(p->date, REVDATE);
- #ifdef ZLIB_VERSION
- lstrcpy(p->zlib_version, ZLIB_VERSION);
- p->flag |= 2;
- #else
- p->zlib_version[0] = '\0';
- #endif
- #ifdef ZIP64_SUPPORT
- p->flag |= 4;
- #endif
- p->zip.major = Z_MAJORVER;
- p->zip.minor = Z_MINORVER;
- p->zip.patchlevel = Z_PATCHLEVEL;
- #ifdef OS2
- p->os2dll.major = D2_MAJORVER;
- p->os2dll.minor = D2_MINORVER;
- p->os2dll.patchlevel = D2_PATCHLEVEL;
- #endif
- #ifdef WINDLL
- p->windll.major = DW_MAJORVER;
- p->windll.minor = DW_MINORVER;
- p->windll.patchlevel = DW_PATCHLEVEL;
- #endif
- }
|