home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip531.zip / windll / dllsetup.c < prev    next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  121 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. /* MS Windows Setup  and Take-Down functions bracket calls to
  9.  * process_zipfiles().
  10.  * These functions allocate and free the necessary buffers, set and clear
  11.  * any global variables so that  process_zipfiles()  can be called multiple
  12.  * times in the same session of WiZ.
  13.  *
  14.  * Based on Robert Heath's code in a module I no longer remember
  15.  * the name of.
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <windows.h>
  20. #ifdef __RSXNT__
  21. #  include "win32/rsxntwin.h"
  22. #endif
  23. #include "version.h"
  24. #define UNZIP_INTERNAL
  25. #include "unzip.h"
  26. #include "windll.h"
  27. #include "consts.h"
  28.  
  29. /* Added typecasts to prevent potential "type mismatch" error messages. */
  30. #ifdef REENTRANT
  31. #  undef G
  32. #  undef __G
  33. #  undef __G__
  34. #  define G                   (*(struct Globals *)pG)
  35. #  define __G                 (struct Globals *)pG
  36. #  define __G__               (struct Globals *)pG,
  37. #endif
  38.  
  39. extern HANDLE hwildZipFN;
  40. /*
  41.     ncflag    = write to stdout if true
  42.     ntflag    = test zip file
  43.     nvflag    = verbose listing
  44.     nUflag    = "update" (extract only newer/new files
  45.     nzflag    = display zip file comment
  46.     ndflag    = all args are files/dir to be extracted
  47.     noflag    = overwrite all files
  48.     naflag    = do ASCII-EBCDIC and/or end of line translation
  49.     nZIflag   = get Zip Info if true
  50.     fPrivilege = restore ACL's if 1, use privileges if 2
  51.     lpszZipFN = zip file name
  52. */
  53.  
  54. BOOL WINAPI Unz_SetOpts(pG, C)
  55. zvoid * pG;
  56. LPDCL C;
  57. {
  58.     G.qflag=C->fQuiet;  /* Quiet flag */
  59.     G.pfnames = &fnames[0];       /* assign default file name vector */
  60.  
  61.     G.jflag = !C->ndflag;
  62.     G.cflag = C->ncflag;
  63.     G.overwrite_all = C->noflag;
  64.     G.tflag = C->ntflag ;
  65.     G.vflag = C->nvflag;
  66.     G.zflag = C->nzflag;
  67.     G.uflag = C->nUflag;
  68.     G.aflag = C->naflag;
  69.     G.uflag = C->ExtractOnlyNewer;
  70. #ifdef WIN32
  71.     G.X_flag = C->fPrivilege;
  72. #endif
  73.     G.overwrite_all = C->Overwrite;
  74.     G.overwrite_none = !G.overwrite_all;
  75.     G.sflag = C->SpaceToUnderscore; /* Translate spaces to underscores? */
  76.     if (C->nZIflag)
  77.       {
  78.       G.zipinfo_mode = TRUE;
  79.       G.hflag = TRUE;
  80.       G.lflag = 10;
  81.       G.qflag = 2;
  82.       }
  83.     else
  84.       {
  85.       G.zipinfo_mode = FALSE;
  86.       }
  87.  
  88.     G.extract_flag = (!G.zipinfo_mode &&
  89.                       !G.cflag && !G.tflag && !G.vflag && !G.zflag
  90. #ifdef TIMESTAMP
  91.                       && !G.T_flag
  92. #endif
  93.                      );
  94.  
  95.     G.xfilespecs = 0;
  96.  
  97. /* G.wildzipfn needs to be initialized so that do_wild does not wind
  98.    up clearing out the zip file name when it returns in process.c
  99. */
  100.     if ((hwildZipFN = GlobalAlloc(GMEM_MOVEABLE, FILNAMSIZ))== (HGLOBAL)NULL)
  101.         return FALSE;
  102.  
  103.     G.wildzipfn = GlobalLock(hwildZipFN);
  104.     lstrcpy(G.wildzipfn, C->lpszZipFN);
  105.     _ISO_INTERN(G.wildzipfn);
  106.  
  107.     return TRUE;    /* set up was OK */
  108. }
  109.  
  110. void FreeDllMem(__GPRO)
  111. {
  112.     if (G.wildzipfn) {
  113.         GlobalUnlock(hwildZipFN);
  114.         G.wildzipfn = NULL;
  115.     }
  116.     if (hwildZipFN)
  117.         hwildZipFN = GlobalFree(hwildZipFN);
  118.  
  119.     G.zipinfo_mode = FALSE;
  120. }
  121.