api.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*
  2. api.c - Zip 3
  3. Copyright (c) 1990-2007 Info-ZIP. All rights reserved.
  4. See the accompanying file LICENSE, version 2007-Mar-4 or later
  5. (the contents of which are also included in zip.h) for terms of use.
  6. If, for some reason, all these files are missing, the Info-ZIP license
  7. also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
  8. */
  9. /*---------------------------------------------------------------------------
  10. api.c
  11. This module supplies a Zip dll engine for use directly from C/C++
  12. programs.
  13. The entry points are:
  14. ZpVer *ZpVersion(void);
  15. int EXPENTRY ZpInit(LPZIPUSERFUNCTIONS lpZipUserFunc);
  16. int EXPENTRY ZpArchive(ZCL C, LPZPOPT Opts);
  17. This module is currently only used by the Windows dll, and is not used at
  18. all by any of the other platforms, although it should be easy enough to
  19. implement this on most platforms.
  20. ---------------------------------------------------------------------------*/
  21. #define __API_C
  22. #include <malloc.h>
  23. #ifdef WINDLL
  24. # include <windows.h>
  25. # include "windll/windll.h"
  26. #endif
  27. #ifdef OS2
  28. # define INCL_DOSMEMMGR
  29. # include <os2.h>
  30. #endif
  31. #ifdef __BORLANDC__
  32. #include <dir.h>
  33. #endif
  34. #include <direct.h>
  35. #include <ctype.h>
  36. #include "api.h" /* this includes zip.h */
  37. #include "crypt.h"
  38. #include "revision.h"
  39. #ifdef USE_ZLIB
  40. # include "zlib.h"
  41. #endif
  42. DLLPRNT *lpZipPrint;
  43. DLLPASSWORD *lpZipPassword;
  44. extern DLLCOMMENT *lpComment;
  45. ZIPUSERFUNCTIONS ZipUserFunctions, far * lpZipUserFunctions;
  46. int ZipRet;
  47. char szOrigDir[PATH_MAX];
  48. BOOL fNo_int64 = FALSE; /* flag for DLLSERVICE_NO_INT64 */
  49. /* Local forward declarations */
  50. extern int zipmain OF((int, char **));
  51. int AllocMemory(unsigned int, char *, char *, BOOL);
  52. int ParseString(LPSTR, unsigned int);
  53. void FreeArgVee(void);
  54. ZPOPT Options;
  55. char **argVee;
  56. unsigned int argCee;
  57. /*---------------------------------------------------------------------------
  58. Local functions
  59. ---------------------------------------------------------------------------*/
  60. char szRootDir[PATH_MAX], szExcludeList[PATH_MAX], szIncludeList[PATH_MAX], szTempDir[PATH_MAX];
  61. int ParseString(LPSTR s, unsigned int ArgC)
  62. {
  63. unsigned int i;
  64. int root_flag, m, j;
  65. char *str1, *str2, *str3;
  66. size_t size;
  67. i = ArgC;
  68. str1 = (char *) malloc(lstrlen(s)+4);
  69. lstrcpy(str1, s);
  70. lstrcat(str1, " @");
  71. if ((szRootDir != NULL) && (szRootDir[0] != '\0'))
  72. {
  73. root_flag = TRUE;
  74. if (szRootDir[lstrlen(szRootDir)-1] != '\\')
  75. lstrcat(szRootDir, "\\");
  76. }
  77. else
  78. root_flag = FALSE;
  79. str2 = strchr(str1, '\"'); /* get first occurance of double quote */
  80. while ((str3 = strchr(str1, '\t')) != NULL)
  81. {
  82. str3[0] = ' '; /* Change tabs into a single space */
  83. }
  84. /* Note that if a quoted string contains multiple adjacent spaces, they
  85. will not be removed, because they could well point to a valid
  86. folder/file name.
  87. */
  88. while ((str2 = strchr(str1, '\"')) != NULL)
  89. /* Found a double quote if not NULL */
  90. {
  91. str3 = strchr(str2+1, '\"'); /* Get the second quote */
  92. if (str3 == NULL)
  93. {
  94. free(str1);
  95. return ZE_PARMS; /* Something is screwy with the
  96. string, bail out */
  97. }
  98. str3[0] = '\0'; /* terminate str2 with a NULL */
  99. /* strip unwanted fully qualified path from entry */
  100. if (root_flag)
  101. if ((_strnicmp(szRootDir, str2+1, lstrlen(szRootDir))) == 0)
  102. {
  103. m = 0;
  104. str2++;
  105. for (j = lstrlen(szRootDir); j < lstrlen(str2); j++)
  106. str2[m++] = str2[j];
  107. str2[m] = '\0';
  108. str2--;
  109. }
  110. size = _msize(argVee);
  111. if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
  112. {
  113. fprintf(stdout, "Unable to allocate memory in zip dll\n");
  114. return ZE_MEM;
  115. }
  116. /* argCee is incremented in AllocMemory */
  117. if (AllocMemory(i, str2+1, "Creating file list from string", TRUE) != ZE_OK)
  118. {
  119. free(str1);
  120. return ZE_MEM;
  121. }
  122. i++;
  123. str3+=2; /* Point past the whitespace character */
  124. str2[0] = '\0'; /* Terminate str1 */
  125. lstrcat(str1, str3);
  126. } /* end while */
  127. /* points to first occurance of a space */
  128. str2 = strchr(str1, ' ');
  129. /* Go through the string character by character, looking for instances
  130. of two spaces together. Terminate when you find the trailing @
  131. */
  132. while ((str2[0] != '\0') && (str2[0] != '@'))
  133. {
  134. while ((str2[0] == ' ') && (str2[1] == ' '))
  135. {
  136. str3 = &str2[1];
  137. str2[0] = '\0';
  138. lstrcat(str1, str3);
  139. }
  140. str2++;
  141. }
  142. /* Do we still have a leading space? */
  143. if (str1[0] == ' ')
  144. {
  145. str3 = &str1[1];
  146. lstrcpy(str1, str3); /* Dump the leading space */
  147. }
  148. /* Okay, now we have gotten rid of any tabs and replaced them with
  149. spaces, and have replaced multiple spaces with a single space. We
  150. couldn't do this before because the folder names could have actually
  151. contained these characters.
  152. */
  153. str2 = str3 = str1;
  154. while ((str2[0] != '\0') && (str3[0] != '@'))
  155. {
  156. str3 = strchr(str2+1, ' ');
  157. str3[0] = '\0';
  158. /* strip unwanted fully qualified path from entry */
  159. if (root_flag)
  160. if ((_strnicmp(szRootDir, str2, lstrlen(szRootDir))) == 0)
  161. {
  162. m = 0;
  163. for (j = lstrlen(Options.szRootDir); j < lstrlen(str2); j++)
  164. str2[m++] = str2[j];
  165. str2[m] = '\0';
  166. }
  167. size = _msize(argVee);
  168. if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
  169. {
  170. fprintf(stdout, "Unable to allocate memory in zip dll\n");
  171. return ZE_MEM;
  172. }
  173. if (AllocMemory(i, str2, "Creating file list from string", TRUE) != ZE_OK)
  174. {
  175. free(str1);
  176. return ZE_MEM;
  177. }
  178. i++;
  179. str3++;
  180. str2 = str3;
  181. }
  182. free(str1);
  183. return ZE_OK;
  184. }
  185. int AllocMemory(unsigned int i, char *cmd, char *str, BOOL IncrementArgCee)
  186. {
  187. if ((argVee[i] = (char *) malloc( sizeof(char) * strlen(cmd)+1 )) == NULL)
  188. {
  189. if (IncrementArgCee)
  190. argCee++;
  191. FreeArgVee();
  192. fprintf(stdout, "Unable to allocate memory in zip library at %s\n", str);
  193. return ZE_MEM;
  194. }
  195. strcpy( argVee[i], cmd );
  196. argCee++;
  197. return ZE_OK;
  198. }
  199. void FreeArgVee(void)
  200. {
  201. unsigned i;
  202. /* Free the arguments in the array */
  203. for (i = 0; i < argCee; i++)
  204. {
  205. free (argVee[i]);
  206. argVee[i] = NULL;
  207. }
  208. /* Then free the array itself */
  209. free(argVee);
  210. /* Restore the original working directory */
  211. chdir(szOrigDir);
  212. #ifdef __BORLANDC__
  213. setdisk(toupper(szOrigDir[0]) - 'A');
  214. #endif
  215. }
  216. /*---------------------------------------------------------------------------
  217. Documented API entry points
  218. ---------------------------------------------------------------------------*/
  219. int EXPENTRY ZpInit(LPZIPUSERFUNCTIONS lpZipUserFunc)
  220. {
  221. ZipUserFunctions = *lpZipUserFunc;
  222. lpZipUserFunctions = &ZipUserFunctions;
  223. if (!lpZipUserFunctions->print ||
  224. !lpZipUserFunctions->comment)
  225. return FALSE;
  226. return TRUE;
  227. }
  228. int EXPENTRY ZpArchive(ZCL C, LPZPOPT Opts)
  229. /* Add, update, freshen, or delete zip entries in a zip file. See the
  230. command help in help() zip.c */
  231. {
  232. int k, j, m;
  233. size_t size;
  234. Options = *Opts; /* Save off options, and make them available locally */
  235. szRootDir[0] = '\0';
  236. szExcludeList[0] = '\0';
  237. szIncludeList[0] = '\0';
  238. szTempDir[0] = '\0';
  239. if (Options.szRootDir) lstrcpy(szRootDir, Options.szRootDir);
  240. if (Options.szExcludeList) lstrcpy(szExcludeList, Options.szExcludeList);
  241. if (Options.szIncludeList) lstrcpy(szIncludeList, Options.szIncludeList);
  242. if (Options.szTempDir) lstrcpy(szTempDir, Options.szTempDir);
  243. getcwd(szOrigDir, PATH_MAX); /* Save current drive and directory */
  244. if ((szRootDir != NULL) && (szRootDir[0] != '\0'))
  245. {
  246. /* Make sure there isn't a trailing slash */
  247. if (szRootDir[lstrlen(szRootDir)-1] == '\\')
  248. szRootDir[lstrlen(szRootDir)-1] = '\0';
  249. chdir(szRootDir);
  250. #ifdef __BORLANDC__
  251. setdisk(toupper(szRootDir[0]) - 'A');
  252. #endif
  253. }
  254. argCee = 0;
  255. /* malloc additional 40 to allow for additional command line arguments. Note
  256. that we are also adding in the count for the include lists as well as the
  257. exclude list. */
  258. if ((argVee = (char **)malloc((C.argc+40)*sizeof(char *))) == NULL)
  259. {
  260. fprintf(stdout, "Unable to allocate memory in zip dll\n");
  261. return ZE_MEM;
  262. }
  263. if ((argVee[argCee] = (char *) malloc( sizeof(char) * strlen("wiz.exe")+1 )) == NULL)
  264. {
  265. free(argVee);
  266. fprintf(stdout, "Unable to allocate memory in zip dll\n");
  267. return ZE_MEM;
  268. }
  269. strcpy( argVee[argCee], "wiz.exe" );
  270. argCee++;
  271. /* Set compression level efficacy -0...-9 */
  272. if (AllocMemory(argCee, "-0", "Compression", FALSE) != ZE_OK)
  273. return ZE_MEM;
  274. /* Check to see if the compression level is set to a valid value. If
  275. not, then set it to the default.
  276. */
  277. if ((Options.fLevel < '0') || (Options.fLevel > '9'))
  278. {
  279. Options.fLevel = '6';
  280. if (!Options.fDeleteEntries)
  281. fprintf(stdout, "Compression level set to invalid value. Setting to default\n");
  282. }
  283. argVee[argCee-1][1] = Options.fLevel;
  284. if (Options.fOffsets) /* Update offsets for SFX prefix */
  285. {
  286. if (AllocMemory(argCee, "-A", "Offsets", FALSE) != ZE_OK)
  287. return ZE_MEM;
  288. }
  289. if (Options.fDeleteEntries) /* Delete files from zip file -d */
  290. {
  291. if (AllocMemory(argCee, "-d", "Delete", FALSE) != ZE_OK)
  292. return ZE_MEM;
  293. }
  294. if (Options.fNoDirEntries) /* Do not add directory entries -D */
  295. {
  296. if (AllocMemory(argCee, "-D", "No Dir Entries", FALSE) != ZE_OK)
  297. return ZE_MEM;
  298. }
  299. if (Options.fFreshen) /* Freshen zip file--overwrite only -f */
  300. {
  301. if (AllocMemory(argCee, "-f", "Freshen", FALSE) != ZE_OK)
  302. return ZE_MEM;
  303. }
  304. if (Options.fRepair) /* Fix archive -F or -FF */
  305. {
  306. if (Options.fRepair == 1)
  307. {
  308. if (AllocMemory(argCee, "-F", "Repair", FALSE) != ZE_OK)
  309. return ZE_MEM;
  310. }
  311. else
  312. {
  313. if (AllocMemory(argCee, "-FF", "Repair", FALSE) != ZE_OK)
  314. return ZE_MEM;
  315. }
  316. }
  317. if (Options.fGrow) /* Allow appending to a zip file -g */
  318. {
  319. if (AllocMemory(argCee, "-g", "Appending", FALSE) != ZE_OK)
  320. return ZE_MEM;
  321. }
  322. if (Options.fJunkDir) /* Junk directory names -j */
  323. {
  324. if (AllocMemory(argCee, "-j", "Junk Dir Names", FALSE) != ZE_OK)
  325. return ZE_MEM;
  326. }
  327. if (Options.fEncrypt) /* encrypt -e */
  328. {
  329. if (AllocMemory(argCee, "-e", "Encrypt", FALSE) != ZE_OK)
  330. return ZE_MEM;
  331. }
  332. if (Options.fJunkSFX) /* Junk sfx prefix */
  333. {
  334. if (AllocMemory(argCee, "-J", "Junk SFX", FALSE) != ZE_OK)
  335. return ZE_MEM;
  336. }
  337. if (Options.fForce) /* Make entries using DOS names (k for Katz) -k */
  338. {
  339. if (AllocMemory(argCee, "-k", "Force DOS", FALSE) != ZE_OK)
  340. return ZE_MEM;
  341. }
  342. if (Options.fLF_CRLF) /* Translate LF_CRLF -l */
  343. {
  344. if (AllocMemory(argCee, "-l", "LF-CRLF", FALSE) != ZE_OK)
  345. return ZE_MEM;
  346. }
  347. if (Options.fCRLF_LF) /* Translate CR/LF to LF -ll */
  348. {
  349. if (AllocMemory(argCee, "-ll", "CRLF-LF", FALSE) != ZE_OK)
  350. return ZE_MEM;
  351. }
  352. if (Options.fMove) /* Delete files added to or updated in zip file -m */
  353. {
  354. if (AllocMemory(argCee, "-m", "Move", FALSE) != ZE_OK)
  355. return ZE_MEM;
  356. }
  357. if (Options.fLatestTime) /* Set zip file time to time of latest file in it -o */
  358. {
  359. if (AllocMemory(argCee, "-o", "Time", FALSE) != ZE_OK)
  360. return ZE_MEM;
  361. }
  362. if (Options.fComment) /* Add archive comment "-z" */
  363. {
  364. if (AllocMemory(argCee, "-z", "Comment", FALSE) != ZE_OK)
  365. return ZE_MEM;
  366. }
  367. if (Options.fQuiet) /* quiet operation -q */
  368. {
  369. if (AllocMemory(argCee, "-q", "Quiet", FALSE) != ZE_OK)
  370. return ZE_MEM;
  371. }
  372. if (Options.fRecurse == 1) /* recurse into subdirectories -r */
  373. {
  374. if (AllocMemory(argCee, "-r", "Recurse -r", FALSE) != ZE_OK)
  375. return ZE_MEM;
  376. }
  377. else if (Options.fRecurse == 2) /* recurse into subdirectories -R */
  378. {
  379. if (AllocMemory(argCee, "-R", "Recurse -R", FALSE) != ZE_OK)
  380. return ZE_MEM;
  381. }
  382. if (Options.fSystem) /* include system and hidden files -S */
  383. {
  384. if (AllocMemory(argCee, "-S", "System", FALSE) != ZE_OK)
  385. return ZE_MEM;
  386. }
  387. if (Options.fExcludeDate) /* Exclude files newer than specified date -tt */
  388. {
  389. if ((Options.Date != NULL) && (Options.Date[0] != '\0'))
  390. {
  391. if (AllocMemory(argCee, "-tt", "Date", FALSE) != ZE_OK)
  392. return ZE_MEM;
  393. if (AllocMemory(argCee, Options.Date, "Date", FALSE) != ZE_OK)
  394. return ZE_MEM;
  395. }
  396. }
  397. if (Options.fIncludeDate) /* include files newer than specified date -t */
  398. {
  399. if ((Options.Date != NULL) && (Options.Date[0] != '\0'))
  400. {
  401. if (AllocMemory(argCee, "-t", "Date", FALSE) != ZE_OK)
  402. return ZE_MEM;
  403. if (AllocMemory(argCee, Options.Date, "Date", FALSE) != ZE_OK)
  404. return ZE_MEM;
  405. }
  406. }
  407. if (Options.fUpdate) /* Update zip file--overwrite only if newer -u */
  408. {
  409. if (AllocMemory(argCee, "-u", "Update", FALSE) != ZE_OK)
  410. return ZE_MEM;
  411. }
  412. if (Options.fVerbose) /* Mention oddities in zip file structure -v */
  413. {
  414. if (AllocMemory(argCee, "-v", "Verbose", FALSE) != ZE_OK)
  415. return ZE_MEM;
  416. }
  417. if (Options.fVolume) /* Include volume label -$ */
  418. {
  419. if (AllocMemory(argCee, "-$", "Volume", FALSE) != ZE_OK)
  420. return ZE_MEM;
  421. }
  422. if (Options.szSplitSize != NULL) /* Turn on archive splitting */
  423. {
  424. if (AllocMemory(argCee, "-s", "Splitting", FALSE) != ZE_OK)
  425. return ZE_MEM;
  426. if (AllocMemory(argCee, Options.szSplitSize, "Split size", FALSE) != ZE_OK)
  427. return ZE_MEM;
  428. }
  429. if (lpZipUserFunctions->split != NULL) /* Turn on archive split destinations select */
  430. {
  431. if (AllocMemory(argCee, "-sp", "Split Pause Select Destination", FALSE) != ZE_OK)
  432. return ZE_MEM;
  433. }
  434. #ifdef WIN32
  435. if (Options.fPrivilege) /* Use privileges -! */
  436. {
  437. if (AllocMemory(argCee, "-!", "Privileges", FALSE) != ZE_OK)
  438. return ZE_MEM;
  439. }
  440. #endif
  441. if (Options.fExtra) /* Exclude extra attributes -X */
  442. {
  443. if (AllocMemory(argCee, "-X", "Extra", FALSE) != ZE_OK)
  444. return ZE_MEM;
  445. }
  446. if (Options.IncludeList != NULL) /* Include file list -i */
  447. {
  448. if (AllocMemory(argCee, "-i", "Include file list", FALSE) != ZE_OK)
  449. return ZE_MEM;
  450. k = 0;
  451. if (Options.IncludeListCount > 0)
  452. while ((Options.IncludeList[k] != NULL) && (Options.IncludeListCount != k+1))
  453. {
  454. size = _msize(argVee);
  455. if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
  456. {
  457. fprintf(stdout, "Unable to allocate memory in zip dll\n");
  458. return ZE_MEM;
  459. }
  460. if (AllocMemory(argCee, Options.IncludeList[k], "Include file list array", TRUE) != ZE_OK)
  461. {
  462. return ZE_MEM;
  463. }
  464. k++;
  465. }
  466. else
  467. while (Options.IncludeList[k] != NULL)
  468. {
  469. size = _msize(argVee);
  470. if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
  471. {
  472. FreeArgVee();
  473. fprintf(stdout, "Unable to allocate memory in zip dll\n");
  474. return ZE_MEM;
  475. }
  476. if (AllocMemory(argCee, Options.IncludeList[k], "Include file list array", TRUE) != ZE_OK)
  477. return ZE_MEM;
  478. k++;
  479. }
  480. if (AllocMemory(argCee, "@", "End of Include List", FALSE) != ZE_OK)
  481. return ZE_MEM;
  482. }
  483. if (Options.ExcludeList != NULL) /* Exclude file list -x */
  484. {
  485. if (AllocMemory(argCee, "-x", "Exclude file list", FALSE) != ZE_OK)
  486. return ZE_MEM;
  487. k = 0;
  488. if (Options.ExcludeListCount > 0)
  489. while ((Options.ExcludeList[k] != NULL) && (Options.ExcludeListCount != k+1))
  490. {
  491. size = _msize(argVee);
  492. if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
  493. {
  494. fprintf(stdout, "Unable to allocate memory in zip dll\n");
  495. return ZE_MEM;
  496. }
  497. if (AllocMemory(argCee, Options.ExcludeList[k], "Exclude file list array", TRUE) != ZE_OK)
  498. return ZE_MEM;
  499. k++;
  500. }
  501. else
  502. while (Options.ExcludeList[k] != NULL)
  503. {
  504. size = _msize(argVee);
  505. if ((argVee = (char **)realloc(argVee, size + sizeof(char *))) == NULL)
  506. {
  507. FreeArgVee();
  508. fprintf(stdout, "Unable to allocate memory in zip dll\n");
  509. return ZE_MEM;
  510. }
  511. if (AllocMemory(argCee, Options.ExcludeList[k], "Exclude file list array", TRUE) != ZE_OK)
  512. return ZE_MEM;
  513. k++;
  514. }
  515. if (AllocMemory(argCee, "@", "End of Exclude List", FALSE) != ZE_OK)
  516. return ZE_MEM;
  517. }
  518. if (szIncludeList != NULL && szIncludeList[0] != '\0') /* Include file list -i */
  519. {
  520. if (AllocMemory(argCee, "-i", "Include file list", FALSE) != ZE_OK)
  521. return ZE_MEM;
  522. if ((k = ParseString(szIncludeList, argCee)) != ZE_OK)
  523. return k; /* Something was screwy with the parsed string
  524. bail out */
  525. if (AllocMemory(argCee, "@", "End of Include List", FALSE) != ZE_OK)
  526. return ZE_MEM;
  527. }
  528. if (szExcludeList != NULL && szExcludeList[0] != '\0') /* Exclude file list -x */
  529. {
  530. if (AllocMemory(argCee, "-x", "Exclude file list", FALSE) != ZE_OK)
  531. return ZE_MEM;
  532. if ((k = ParseString(szExcludeList, argCee)) != ZE_OK)
  533. return k; /* Something was screwy with the parsed string
  534. bail out */
  535. if (AllocMemory(argCee, "@", "End of Exclude List", FALSE) != ZE_OK)
  536. return ZE_MEM;
  537. }
  538. if ((szTempDir != NULL) && (szTempDir[0] != '\0')
  539. && Options.fTemp) /* Use temporary directory -b */
  540. {
  541. if (AllocMemory(argCee, "-b", "Temp dir switch command", FALSE) != ZE_OK)
  542. return ZE_MEM;
  543. if (AllocMemory(argCee, szTempDir, "Temporary directory", FALSE) != ZE_OK)
  544. return ZE_MEM;
  545. }
  546. if (AllocMemory(argCee, C.lpszZipFN, "Zip file name", FALSE) != ZE_OK)
  547. return ZE_MEM;
  548. if ((szRootDir != NULL) && (szRootDir[0] != '\0'))
  549. {
  550. if (szRootDir[lstrlen(szRootDir)-1] != '\\')
  551. lstrcat(szRootDir, "\\"); /* append trailing \\ */
  552. if (C.FNV != NULL)
  553. {
  554. for (k = 0; k < C.argc; k++)
  555. {
  556. if (AllocMemory(argCee, C.FNV[k], "Making argv", FALSE) != ZE_OK)
  557. return ZE_MEM;
  558. if ((_strnicmp(szRootDir, C.FNV[k], lstrlen(szRootDir))) == 0)
  559. {
  560. m = 0;
  561. for (j = lstrlen(szRootDir); j < lstrlen(C.FNV[k]); j++)
  562. argVee[argCee-1][m++] = C.FNV[k][j];
  563. argVee[argCee-1][m] = '\0';
  564. }
  565. }
  566. }
  567. }
  568. else
  569. if (C.FNV != NULL)
  570. for (k = 0; k < C.argc; k++)
  571. {
  572. if (AllocMemory(argCee, C.FNV[k], "Making argv", FALSE) != ZE_OK)
  573. return ZE_MEM;
  574. }
  575. if (C.lpszAltFNL != NULL)
  576. {
  577. if ((k = ParseString(C.lpszAltFNL, argCee)) != ZE_OK)
  578. return k; /* Something was screwy with the parsed string
  579. bail out
  580. */
  581. }
  582. argVee[argCee] = NULL;
  583. ZipRet = zipmain(argCee, argVee);
  584. /* Free the arguments in the array. Note this also restores the
  585. current directory
  586. */
  587. FreeArgVee();
  588. return ZipRet;
  589. }
  590. #if CRYPT
  591. int encr_passwd(int modeflag, char *pwbuf, int size, const char *zfn)
  592. {
  593. return (*lpZipUserFunctions->password)(pwbuf, size, ((modeflag == ZP_PW_VERIFY) ?
  594. "Verify password: " : "Enter password: "),
  595. (char *)zfn);
  596. }
  597. #endif /* CRYPT */
  598. void EXPENTRY ZpVersion(ZpVer far * p) /* should be pointer to const struct */
  599. {
  600. p->structlen = ZPVER_LEN;
  601. #ifdef BETA
  602. p->flag = 1;
  603. #else
  604. p->flag = 0;
  605. #endif
  606. #ifdef CRYPT
  607. p->fEncryption = TRUE;
  608. #else
  609. p->fEncryption = FALSE;
  610. #endif
  611. lstrcpy(p->betalevel, Z_BETALEVEL);
  612. lstrcpy(p->date, REVDATE);
  613. #ifdef ZLIB_VERSION
  614. lstrcpy(p->zlib_version, ZLIB_VERSION);
  615. p->flag |= 2;
  616. #else
  617. p->zlib_version[0] = '\0';
  618. #endif
  619. #ifdef ZIP64_SUPPORT
  620. p->flag |= 4; /* Flag that ZIP64 was compiled in. */
  621. #endif
  622. p->zip.major = Z_MAJORVER;
  623. p->zip.minor = Z_MINORVER;
  624. p->zip.patchlevel = Z_PATCHLEVEL;
  625. #ifdef OS2
  626. p->os2dll.major = D2_MAJORVER;
  627. p->os2dll.minor = D2_MINORVER;
  628. p->os2dll.patchlevel = D2_PATCHLEVEL;
  629. #endif
  630. #ifdef WINDLL
  631. p->windll.major = DW_MAJORVER;
  632. p->windll.minor = DW_MINORVER;
  633. p->windll.patchlevel = DW_PATCHLEVEL;
  634. #endif
  635. }