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