File Coverage

lib/Archive/Unzip/Burst.xs
Criterion Covered Total %
statement 7 7 100.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 7 7 100.0


line stmt bran cond sub pod time code
1             #include "EXTERN.h"
2             #include "perl.h"
3             #include "XSUB.h"
4              
5             #include "ppport.h"
6              
7             # if (defined(_WIN32))
8              
9             #include "windll/structs.h"
10             #include "windll/decs.h"
11              
12             LPUSERFUNCTIONS lpUserFunctions;
13             HANDLE hUF = (HANDLE)NULL;
14             LPDCL lpDCL = NULL;
15             HANDLE hDCL = (HANDLE)NULL;
16             HANDLE hZCL = (HANDLE)NULL;
17             DWORD dwPlatformId = 0xFFFFFFFF;
18             int WINAPI DisplayBuf(LPSTR, unsigned long);
19             int WINAPI GetReplaceDlgRetVal(LPSTR, unsigned);
20             int WINAPI password(LPSTR, int, LPCSTR, LPCSTR);
21             void WINAPI ReceiveDllMessage(z_uint8, z_uint8, unsigned,
22             unsigned, unsigned, unsigned, unsigned, unsigned,
23             char, LPCSTR, LPCSTR, unsigned long, char);
24              
25             static void FreeUpMemory(void);
26              
27             int
28             UzpMain(int argc, char **argv)
29             {
30             int r;
31             int exfc, infc;
32             char **exfv, **infv;
33              
34             hDCL = GlobalAlloc( GPTR, (DWORD)sizeof(DCL));
35             if (!hDCL)
36             {
37             return 0;
38             }
39             lpDCL = (LPDCL)GlobalLock(hDCL);
40             if (!lpDCL)
41             {
42             GlobalFree(hDCL);
43             return 0;
44             }
45              
46             hUF = GlobalAlloc( GPTR, (DWORD)sizeof(USERFUNCTIONS));
47             if (!hUF)
48             {
49             GlobalUnlock(hDCL);
50             GlobalFree(hDCL);
51             return 0;
52             }
53             lpUserFunctions = (LPUSERFUNCTIONS)GlobalLock(hUF);
54              
55             if (!lpUserFunctions)
56             {
57             GlobalUnlock(hDCL);
58             GlobalFree(hDCL);
59             GlobalFree(hUF);
60             return 0;
61             }
62              
63             lpUserFunctions->password = password;
64             lpUserFunctions->print = DisplayBuf;
65             lpUserFunctions->sound = NULL;
66             lpUserFunctions->replace = GetReplaceDlgRetVal;
67             lpUserFunctions->SendApplicationMessage = ReceiveDllMessage;
68              
69             lpDCL->StructVersID = UZ_DCL_STRUCTVER; /* version of this structure */
70             lpDCL->ncflag = 0; /* Write to stdout if true */
71             lpDCL->fQuiet = 2; /* 0 = We want all messages.
72             1 = fewer messages,
73             2 = no messages */
74             lpDCL->ntflag = 0; /* test zip file if true */
75             lpDCL->nvflag = 0; /* give a verbose listing if true */
76             lpDCL->nzflag = 0; /* display a zip file comment if true */
77             lpDCL->ndflag = 1; /* Recreate directories != 0, skip "../" if < 2 */
78             lpDCL->naflag = 0; /* Do not convert CR to CRLF */
79             lpDCL->nfflag = 0; /* Do not freshen existing files only */
80             lpDCL->noflag = 1; /* Over-write all files if true */
81             lpDCL->ExtractOnlyNewer = 0; /* Do not extract only newer */
82             lpDCL->PromptToOverwrite = 0; /* "Overwrite all" selected -> no query mode */
83             lpDCL->lpszZipFN = argv[3]; /* The archive name */
84             lpDCL->lpszExtractDir = NULL; /* The directory to extract to. This is set
85             to NULL if you are extracting to the
86             current directory.
87             */
88              
89             infc = exfc = 0;
90             infv = exfv = NULL;
91              
92             r = Wiz_SingleEntryUnzip(infc, infv, exfc, exfv, lpDCL, lpUserFunctions);
93             FreeUpMemory();
94             return r;
95             }
96              
97             int WINAPI GetReplaceDlgRetVal(LPSTR filename, unsigned efbufsiz)
98             {
99             /* This is where you will decide if you want to replace, rename etc existing
100             files.
101             */
102             return 1;
103             }
104              
105             static void FreeUpMemory(void)
106             {
107             if (hDCL)
108             {
109             GlobalUnlock(hDCL);
110             GlobalFree(hDCL);
111             }
112             if (hUF)
113             {
114             GlobalUnlock(hUF);
115             GlobalFree(hUF);
116             }
117             }
118              
119             /* This is a very stripped down version of what is done in Wiz. Essentially
120             what this function is for is to do a listing of an archive contents. It
121             is actually never called in this example, but a dummy procedure had to
122             be put in, so this was used.
123             */
124             void WINAPI ReceiveDllMessage(z_uint8 ucsize, z_uint8 csize,
125             unsigned cfactor,
126             unsigned mo, unsigned dy, unsigned yr, unsigned hh, unsigned mm,
127             char c, LPCSTR filename, LPCSTR methbuf, unsigned long crc, char fCrypt)
128             {
129             char psLBEntry[_MAX_PATH];
130             char LongHdrStats[] =
131             "%7lu %7lu %4s %02u-%02u-%02u %02u:%02u %c%s";
132             char CompFactorStr[] = "%c%d%%";
133             char CompFactor100[] = "100%%";
134             char szCompFactor[10];
135             char sgn;
136              
137             if (csize > ucsize)
138             sgn = '-';
139             else
140             sgn = ' ';
141             if (cfactor == 100)
142             lstrcpy(szCompFactor, CompFactor100);
143             else
144             sprintf(szCompFactor, CompFactorStr, sgn, cfactor);
145             wsprintf(psLBEntry, LongHdrStats,
146             ucsize, csize, szCompFactor, mo, dy, yr, hh, mm, c, filename);
147              
148             printf("%s\n", psLBEntry);
149             }
150              
151             /* Password entry routine - see password.c in the wiz directory for how
152             this is actually implemented in WiZ. If you have an encrypted file,
153             this will probably give you great pain.
154             */
155             int WINAPI password(LPSTR p, int n, LPCSTR m, LPCSTR name)
156             {
157             return 1;
158             }
159              
160             /* Dummy "print" routine that simply outputs what is sent from the dll */
161             int WINAPI DisplayBuf(LPSTR buf, unsigned long size)
162             {
163             printf("%s", (char *)buf);
164             return (int)(unsigned int) size;
165             }
166              
167             #else
168              
169             int UzpMain(int, char**);
170              
171             #endif
172              
173             MODULE = Archive::Unzip::Burst PACKAGE = Archive::Unzip::Burst
174              
175             int
176             _unzip(filename)
177             char * filename
178             INIT:
179             int r;
180             CODE:
181 2           int argno = 4;
182             char* args[4];
183 2           args[0] = "unzip";
184 2           args[1] = "-qq";
185 2           args[2] = "-o";
186 2           args[3] = filename;
187 2           r = UzpMain(argno, args);
188 2           RETVAL = r;
189             OUTPUT:
190             RETVAL