| 1 |
/* |
| 2 |
windll/windll.c - Zip 3 |
| 3 |
|
| 4 |
Copyright (c) 1990-2004 Info-ZIP. All rights reserved. |
| 5 |
|
| 6 |
See the accompanying file LICENSE, version 2003-May-08 or later |
| 7 |
(the contents of which are also included in zip.h) for terms of use. |
| 8 |
If, for some reason, all these files are missing, the Info-ZIP license |
| 9 |
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html |
| 10 |
*/ |
| 11 |
/* |
| 12 |
* windll.c by Mike White loosly based on Mark Adler's zip.c |
| 13 |
*/ |
| 14 |
#include <windows.h> |
| 15 |
#include <process.h> |
| 16 |
#include <signal.h> |
| 17 |
#include <stdarg.h> |
| 18 |
#include <ctype.h> |
| 19 |
#include "../zip.h" |
| 20 |
#include "windll.h" |
| 21 |
|
| 22 |
HINSTANCE hCurrentInst; |
| 23 |
#ifdef ZIPLIB |
| 24 |
/* DLL Entry Point */ |
| 25 |
#ifdef __BORLANDC__ |
| 26 |
#pragma argsused |
| 27 |
/* Borland seems to want DllEntryPoint instead of DllMain like MSVC */ |
| 28 |
#define DllMain DllEntryPoint |
| 29 |
#endif |
| 30 |
#ifdef WIN32 |
| 31 |
BOOL WINAPI DllMain( HINSTANCE hInstance, |
| 32 |
DWORD dwReason, |
| 33 |
LPVOID plvReserved) |
| 34 |
#else |
| 35 |
int WINAPI LibMain( HINSTANCE hInstance, |
| 36 |
WORD wDataSegment, |
| 37 |
WORD wHeapSize, |
| 38 |
LPSTR lpszCmdLine ) |
| 39 |
#endif |
| 40 |
{ |
| 41 |
#ifndef WIN32 |
| 42 |
/* The startup code for the DLL initializes the local heap(if there is one) |
| 43 |
with a call to LocalInit which locks the data segment. */ |
| 44 |
|
| 45 |
if ( wHeapSize != 0 ) |
| 46 |
{ |
| 47 |
UnlockData( 0 ); |
| 48 |
} |
| 49 |
hCurrentInst = hInstance; |
| 50 |
return 1; /* Indicate that the DLL was initialized successfully. */ |
| 51 |
#else |
| 52 |
BOOL rc = TRUE; |
| 53 |
switch( dwReason ) |
| 54 |
{ |
| 55 |
case DLL_PROCESS_ATTACH: |
| 56 |
// DLL is loaded. Do your initialization here. |
| 57 |
// If cannot init, set rc to FALSE. |
| 58 |
hCurrentInst = hInstance; |
| 59 |
break; |
| 60 |
|
| 61 |
case DLL_PROCESS_DETACH: |
| 62 |
// DLL is unloaded. Do your cleanup here. |
| 63 |
break; |
| 64 |
default: |
| 65 |
break; |
| 66 |
} |
| 67 |
return rc; |
| 68 |
#endif |
| 69 |
} |
| 70 |
|
| 71 |
#ifdef __BORLANDC__ |
| 72 |
#pragma argsused |
| 73 |
#endif |
| 74 |
int FAR PASCAL WEP ( int bSystemExit ) |
| 75 |
{ |
| 76 |
return 1; |
| 77 |
} |
| 78 |
#endif /* ZIPLIB */ |
| 79 |
|
| 80 |
LPSTR szCommentBuf; |
| 81 |
HANDLE hStr; |
| 82 |
|
| 83 |
void comment(unsigned int comlen) |
| 84 |
{ |
| 85 |
unsigned int i; |
| 86 |
if (comlen > 65534L) |
| 87 |
comlen = (unsigned int) 65534L; |
| 88 |
hStr = GlobalAlloc( GPTR, (DWORD)65535L); |
| 89 |
if ( !hStr ) |
| 90 |
{ |
| 91 |
hStr = GlobalAlloc( GPTR, (DWORD) 2); |
| 92 |
szCommentBuf = GlobalLock(hStr); |
| 93 |
szCommentBuf[0] = '\0'; |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
szCommentBuf = GlobalLock(hStr); |
| 98 |
if (comlen) |
| 99 |
{ |
| 100 |
for (i = 0; i < comlen; i++) |
| 101 |
szCommentBuf[i] = zcomment[i]; |
| 102 |
szCommentBuf[comlen] = '\0'; |
| 103 |
} |
| 104 |
else |
| 105 |
szCommentBuf[0] = '\0'; |
| 106 |
free(zcomment); |
| 107 |
zcomment = malloc(1); |
| 108 |
*zcomment = 0; |
| 109 |
lpZipUserFunctions->comment(szCommentBuf); |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
#define STDIO_BUF_SIZE 16384 |
| 114 |
|
| 115 |
int __far __cdecl printf(const char *format, ...) |
| 116 |
{ |
| 117 |
va_list argptr; |
| 118 |
HANDLE hMemory; |
| 119 |
LPSTR pszBuffer; |
| 120 |
int len; |
| 121 |
|
| 122 |
va_start(argptr, format); |
| 123 |
hMemory = GlobalAlloc(GMEM_MOVEABLE, STDIO_BUF_SIZE); |
| 124 |
WinAssert(hMemory); |
| 125 |
if (!hMemory) |
| 126 |
{ |
| 127 |
return 0; |
| 128 |
} |
| 129 |
pszBuffer = (LPSTR)GlobalLock(hMemory); |
| 130 |
WinAssert(pszBuffer); |
| 131 |
len = wvsprintf(pszBuffer, format, argptr); |
| 132 |
va_end(argptr); |
| 133 |
WinAssert(strlen(pszBuffer) < STDIO_BUF_SIZE); |
| 134 |
len = lpZipUserFunctions->print(pszBuffer, len); |
| 135 |
GlobalUnlock(hMemory); |
| 136 |
GlobalFree(hMemory); |
| 137 |
return len; |
| 138 |
} |
| 139 |
|
| 140 |
/* fprintf clone for code in zip.c, etc. */ |
| 141 |
int __far __cdecl fprintf(FILE *file, const char *format, ...) |
| 142 |
{ |
| 143 |
va_list argptr; |
| 144 |
HANDLE hMemory; |
| 145 |
LPSTR pszBuffer; |
| 146 |
int len; |
| 147 |
|
| 148 |
va_start(argptr, format); |
| 149 |
hMemory = GlobalAlloc(GMEM_MOVEABLE, STDIO_BUF_SIZE); |
| 150 |
WinAssert(hMemory); |
| 151 |
if (!hMemory) |
| 152 |
{ |
| 153 |
return 0; |
| 154 |
} |
| 155 |
pszBuffer = GlobalLock(hMemory); |
| 156 |
WinAssert(pszBuffer); |
| 157 |
len = wvsprintf(pszBuffer, format, argptr); |
| 158 |
va_end(argptr); |
| 159 |
WinAssert(strlen(pszBuffer) < STDIO_BUF_SIZE); |
| 160 |
if ((file == stderr) || (file == stdout)) |
| 161 |
{ |
| 162 |
len = lpZipUserFunctions->print(pszBuffer, len); |
| 163 |
} |
| 164 |
else |
| 165 |
len = write(fileno(file),(char far *)(pszBuffer), len); |
| 166 |
GlobalUnlock(hMemory); |
| 167 |
GlobalFree(hMemory); |
| 168 |
return len; |
| 169 |
} |
| 170 |
|
| 171 |
void __far __cdecl perror(const char *parm1) |
| 172 |
{ |
| 173 |
printf("%s", parm1); |
| 174 |
} |
| 175 |
|
| 176 |
|