home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / zip21.zip / wizdll / wizmain.c < prev    next >
C/C++ Source or Header  |  1996-04-19  |  9KB  |  349 lines

  1. /*
  2.  Copyright (C) 1996 Mike White
  3.  Permission is granted to any individual or institution to use, copy, or
  4.  redistribute this software so long as all of the original files are included,
  5.  that it is not sold for profit, and that this copyright notice is retained.
  6.  
  7. */
  8.  
  9. /*
  10.  *  wizmain.c by Mike White based on Mark Adler's zip.c
  11.  */
  12. #include <windows.h>
  13. #include "zip.h"
  14. #include "crypt.h"
  15. #include <process.h>
  16. #include <signal.h>
  17. #include <stdarg.h>
  18. #include "wizdll/wizzip.h"
  19.  
  20. /*
  21. This structure is passed to the DLL when it is called.
  22.  
  23. typedef struct {
  24. DLLPRNT print;
  25. DLLSND sound;
  26. FILE *Stdout;
  27. HWND hInst;
  28. * Zip flag section *
  29. BOOL fEncryptVerify;
  30. BOOL fSuffix;
  31. BOOL fEncrypt;
  32. BOOL fSystem;           = include system and hidden files
  33. BOOL fVolume;           = Include volume label
  34. BOOL fExtra;            = Include extra attributes
  35. BOOL fNoDirEntries;     = Do not add directory entries
  36. BOOL fDate;             = Exclude files earlier than specified date
  37. BOOL fVerbose;          = Mention oddities in zip file structure
  38. BOOL fQuiet;            = Quiet operation
  39. char fLevel;            = Compression level (0 - 9)
  40. BOOL fCRLF_LF;
  41. BOOL fLF_CRLF;          = Translate end-of-line
  42. BOOL fJunkDir;          = Junk directory names
  43. BOOL fRecurse;          = Recurse into subdirectories
  44. BOOL fGrow;             = Allow appending to a zip file
  45. BOOL fForce;            = Make entries using DOS names (k for Katz)
  46. BOOL fMove;             = Delete files added or updated in zip file
  47. BOOL fDeleteEntries;    = Delete files from zip file
  48. BOOL fUpdate;           = Update zip file--overwrite only if newer
  49. BOOL fFreshen;          = Freshen zip file--overwrite only
  50. BOOL fJunkSFX;          = Junk SFX prefix
  51. BOOL fLatestTime;       = Set zip file time to time of latest file in it 
  52. * End Zip Flag section *
  53. char Date[7];           = Date to include files after
  54. int  argc;              = Count of files to zip
  55. LPSTR lpszZipFN;
  56. char **FNV;
  57. } ZCL, _far *LPZCL;
  58. */
  59.  
  60. DLLPRNT lpPrint;
  61. DLLSND lpSound;
  62.  
  63. FILE *orig_stdout;
  64.  
  65. /*  DLL Entry Point */
  66. #ifdef __BORLANDC__
  67. #pragma warn -par
  68. #endif
  69. #if defined WIN32
  70. BOOL WINAPI DllEntryPoint( HINSTANCE hinstDll,
  71.                                     DWORD fdwRreason,
  72.                                     LPVOID plvReserved)
  73. #else
  74. int FAR PASCAL LibMain( HINSTANCE hInstance,
  75.                                 WORD wDataSegment,
  76.                                 WORD wHeapSize,
  77.                                 LPSTR lpszCmdLine )
  78. #endif
  79. {
  80. #ifndef WIN32
  81. /* The startup code for the DLL initializes the local heap(if there is one)
  82.  with a call to LocalInit which locks the data segment. */
  83.  
  84. if ( wHeapSize != 0 )
  85.    {
  86.    UnlockData( 0 );
  87.    }
  88. #endif
  89. return 1;   /* Indicate that the DLL was initialized successfully. */
  90. }
  91.  
  92. int FAR PASCAL WEP ( int bSystemExit )
  93. {
  94. return 1;
  95. }
  96. #ifdef __BORLANDC__
  97. #pragma warn .par
  98. #endif
  99.  
  100.  
  101. /* Local functions */
  102.  
  103. extern int  zipmain OF((int, char **));
  104.  
  105. WINAPI DllZipUpFiles(ZCL far *C)
  106. /* Add, update, freshen, or delete zip entries in a zip file.  See the
  107.    command help in help() zip.c */
  108. {
  109. int argCee, i=0, k;
  110. char **argVee;
  111.  
  112. lpPrint = C->print;
  113. lpSound = C->sound;
  114. orig_stdout = C->Stdout;
  115.  
  116. argCee = C->argc+3; /* Allow for argv[0], compression level, and the zip file name */
  117. /* malloc'd additional 26 to allow for additional command line arguements */
  118. argVee = (char **)malloc((C->argc+26)*sizeof(char *));
  119.  
  120. argVee[i] = (char *) malloc( sizeof(char) * strlen("wizzip.exe")+1 );
  121. strcpy( argVee[i++], "wizzip.exe" );
  122.  
  123. /* Set compression level efficacy -0...-9 */
  124. argVee[i] = (char *) malloc( sizeof(char) * strlen("-0")+1 );
  125. strcpy(argVee[i], "-0");
  126. argVee[i++][1] = C->fLevel;
  127.  
  128. if (C->fDeleteEntries)    /* Delete files from zip file -d */
  129.    {
  130.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-d")+1 );
  131.    strcpy( argVee[i++], "-d" );
  132.    argCee++;
  133.    }
  134. if (C->fNoDirEntries) /* Do not add directory entries -D */
  135.    {
  136.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-D")+1 );
  137.    strcpy( argVee[i++], "-D" );
  138.    argCee++;
  139.    }
  140. if (C->fFreshen) /* Freshen zip file--overwrite only -f */
  141.    {
  142.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-f")+1 );
  143.    strcpy( argVee[i++], "-f" );
  144.    argCee++;
  145.    }
  146. if (C->fGrow) /* Allow appending to a zip file -g */
  147.    {
  148.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-g")+1 );
  149.    strcpy( argVee[i++], "-g" );
  150.    argCee++;
  151.    }
  152. if (C->fJunkDir) /* Junk directory names -j */
  153.    {
  154.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-j")+1 );
  155.    strcpy( argVee[i++], "-j" );
  156.    argCee++;
  157.    }
  158. if (C->fJunkSFX) /* Junk sfx prefix */
  159.    {
  160.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-J")+1 );
  161.    strcpy( argVee[i++], "-J" );
  162.    argCee++;
  163.    }
  164.  
  165. if (C->fForce) /* Make entries using DOS names (k for Katz) -k */
  166.    {
  167.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-k")+1 );
  168.    strcpy( argVee[i++], "-k" );
  169.    argCee++;
  170.    }
  171.  
  172. if (C->fLF_CRLF) /* Translate end-of-line -l */
  173.    {
  174.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-l")+1 );
  175.    strcpy( argVee[i++], "-l" );
  176.    argCee++;
  177.    }
  178. if (C->fMove) /* Delete files added or updated in zip file -m */
  179.    {
  180.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-m")+1 );
  181.    strcpy( argVee[i++], "-m" );
  182.    argCee++;
  183.    }
  184.  
  185. if (C->fLatestTime) /* Set zip file time to time of latest file in it -o */
  186.    {
  187.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-o")+1 );
  188.    strcpy( argVee[i++], "-o" );
  189.    argCee++;
  190.    }
  191.  
  192. if (C->fQuiet) /* quiet operation -q */
  193.    {
  194.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-q")+1 );
  195.    strcpy( argVee[i++], "-q" );
  196.    argCee++;
  197.    }
  198. if (C->fRecurse) /* recurse into subdirectories -r */
  199.    {
  200.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-r")+1 );
  201.    strcpy( argVee[i++], "-r" );
  202.    argCee++;
  203.    }
  204. if (C->fSystem)  /* include system and hidden files -S */
  205.    {
  206.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-S")+1 );
  207.    strcpy( argVee[i++], "-S" );
  208.    argCee++;
  209.    }
  210. if (C->fDate)    /* Exclude files earlier than specified date -t */
  211.    {
  212.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-t")+1 );
  213.    strcpy( argVee[i++], "-t" );
  214.    argCee++;
  215.    argVee[i] = (char *) malloc( sizeof(char) * strlen(C->Date)+1);
  216.    strcpy( argVee[i++], C->Date);
  217.    argCee++;
  218.    }
  219.  
  220. if (C->fUpdate) /* Update zip file--overwrite only if newer -u */
  221.    {
  222.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-u")+1 );
  223.    strcpy( argVee[i++], "-u" );
  224.    argCee++;
  225.    }
  226. if (C->fVerbose)  /* Mention oddities in zip file structure -v */
  227.    {
  228.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-v")+1 );
  229.    strcpy( argVee[i++], "-v" );
  230.    argCee++;
  231.    }
  232. //if (C->
  233. //   {
  234. //            case 'z':   /* Edit zip file comment */
  235. //   }
  236. if (C->fVolume)  /* Include volume label -$ */
  237.    {
  238.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-$")+1 );
  239.    strcpy( argVee[i++], "-$" );
  240.    argCee++;
  241.    }
  242. if (C->fExtra)  /* Include extra attributes -X */
  243.    {
  244.    argVee[i] = (char *) malloc( sizeof(char) * strlen("-X")+1 );
  245.    strcpy( argVee[i++], "-X" );
  246.    argCee++;
  247.    }
  248.  
  249. argVee[i] = (char *) malloc( sizeof(char) * strlen(C->lpszZipFN)+1 );
  250. strcpy( argVee[i++], C->lpszZipFN );
  251.  
  252. for (k = 0; k < C->argc; k++)
  253.    {
  254.    argVee[i] = (char *) malloc( sizeof(char) * strlen(C->FNV[k])+1 );
  255.    strcpy( argVee[i++], C->FNV[k] );
  256.    }
  257.  
  258. argVee[i] = NULL;
  259.  
  260. zipmain(argCee, argVee);
  261.  
  262. /* Free the arguments in the array */
  263. for (i = 0; i < argCee; i++)
  264.    {
  265.       free (argVee[i]);
  266.       argVee[i] = NULL;
  267.    }
  268.  
  269. /* Then free the array itself */
  270. free(argVee);
  271.  
  272.  
  273. return;
  274. }
  275.  
  276. #define STDIO_BUF_SIZE 16384
  277.  
  278. /* printf buffers the current output and counts the number of lines
  279.  * within it.  It makes sure there is enough space in the global
  280.  * buffer, then copies the buffered data to the global buffer.
  281.  * It then triggers a repaint of the status buffer.
  282.  */
  283. int __far __cdecl printf(const char *format, ...)
  284. {
  285. va_list argptr;
  286. HANDLE hMemory;
  287. PSTR pszBuffer;
  288. int len;
  289.  
  290. va_start(argptr, format);
  291. hMemory = GlobalAlloc(GMEM_MOVEABLE, STDIO_BUF_SIZE);
  292. WinAssert(hMemory);
  293. if (!hMemory)
  294.    {
  295.    return 0;
  296.    }
  297. pszBuffer = (PSTR)GlobalLock(hMemory);
  298. WinAssert(pszBuffer);
  299. len = wvsprintf(pszBuffer, format, argptr);
  300. va_end(argptr);
  301. WinAssert(strlen(pszBuffer) < STDIO_BUF_SIZE);
  302. len = lpPrint(orig_stdout, len, pszBuffer);
  303. GlobalUnlock(hMemory);
  304. GlobalFree(hMemory);
  305. return len;
  306. }
  307.  
  308. #ifdef __BORLANDC__
  309. #pragma argsused
  310. #endif
  311. /* fprintf clone for code in zip.c, etc. */
  312. int __far __cdecl fprintf(FILE *file, const char *format, ...)
  313. {
  314. va_list argptr;
  315. HANDLE hMemory;
  316. LPSTR pszBuffer;
  317. int len;
  318.  
  319. va_start(argptr, format);
  320. hMemory = GlobalAlloc(GMEM_MOVEABLE, STDIO_BUF_SIZE);
  321. WinAssert(hMemory);
  322. if (!hMemory)
  323.    {
  324.    return 0;
  325.    }
  326. pszBuffer = GlobalLock(hMemory);
  327. WinAssert(pszBuffer);
  328. len = wvsprintf(pszBuffer, format, argptr);
  329. va_end(argptr);
  330. WinAssert(strlen(pszBuffer) < STDIO_BUF_SIZE);
  331. if ((file != stderr) && (file != stdout))
  332.    {
  333.    len = write(fileno(file),(char *)(pszBuffer), len);
  334.    }
  335. else
  336.    {
  337.    len = lpPrint(orig_stdout, len, pszBuffer);
  338.    }
  339. GlobalUnlock(hMemory);
  340. GlobalFree(hMemory);
  341. return len;
  342. }
  343.  
  344. void __far __cdecl perror(const char *parm1)
  345. {
  346. printf(parm1);
  347. }
  348.  
  349.