home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / prwin16.h < prev   
C/C++ Source or Header  |  1998-07-21  |  7KB  |  178 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef prwin16_h___
  20. #define prwin16_h___
  21.  
  22. /*
  23. ** Condition use of this header on platform.
  24. */
  25. #if (defined(XP_PC) && !defined(_WIN32) && !defined(XP_OS2) && defined(MOZILLA_CLIENT)) || defined(WIN16)
  26. #include <stdio.h>
  27.  
  28. PR_BEGIN_EXTERN_C
  29. /* 
  30. ** Win16 stdio special case.
  31. ** To get stdio to work for Win16, all calls to printf() and related
  32. ** things must be called from the environment of the .EXE; calls to
  33. ** printf() from the .DLL send output to the bit-bucket.
  34. **
  35. ** To make sure that PR_fprintf(), and related functions, work correctly,
  36. ** the actual stream I/O to stdout, stderr, stdin must be done in the
  37. ** .EXE. To do this, a hack is placed in _MD_Write() such that the
  38. ** fd for stdio handles results in a call to the .EXE.
  39. **
  40. ** file w16stdio.c contains the functions that get called from NSPR
  41. ** to do the actual I/O. w16stdio.o must be statically linked with
  42. ** any application needing stdio for Win16.
  43. **
  44. ** The address of these functions must be made available to the .DLL
  45. ** so he can call back to the .EXE. To do this, function 
  46. ** PR_MD_RegisterW16StdioCallbacks() is called from the .EXE.
  47. ** The arguments are the functions defined in w16stdio.c
  48. ** At runtime, MD_Write() calls the registered functions, if any
  49. ** were registered.
  50. **
  51. ** prinit.h contains a macro PR_STDIO_INIT() that calls the registration
  52. ** function for Win16; For other platforms, the macro is a No-Op.
  53. **
  54. ** Note that stdio is not operational at all on Win16 GUI applications.
  55. ** This special case exists to provide stdio capability from the NSPR
  56. ** .DLL for command line applications only. NSPR's test cases are
  57. ** almost exclusively command line applications.
  58. **
  59. ** See also: w16io.c, w16stdio.c
  60. */
  61. typedef PRInt32 (PR_CALLBACK *PRStdinRead)( void *buf, PRInt32 amount);
  62. typedef PRInt32 (PR_CALLBACK *PRStdoutWrite)( void *buf, PRInt32 amount);
  63. typedef PRInt32 (PR_CALLBACK *PRStderrWrite)( void *buf, PRInt32 amount);
  64.  
  65. PR_EXTERN(PRStatus)
  66. PR_MD_RegisterW16StdioCallbacks( 
  67.     PRStdinRead inReadf,            /* i: function pointer for stdin read       */
  68.     PRStdoutWrite outWritef,        /* i: function pointer for stdout write     */
  69.     PRStderrWrite errWritef         /* i: function pointer for stderr write     */
  70.     );
  71.  
  72. PR_EXTERN(PRInt32)
  73. _PL_W16StdioWrite( void *buf, PRInt32 amount );
  74.  
  75. PR_EXTERN(PRInt32)
  76. _PL_W16StdioRead( void *buf, PRInt32 amount );
  77.  
  78. #define PR_STDIO_INIT() PR_MD_RegisterW16StdioCallbacks( \
  79.     _PL_W16StdioRead, _PL_W16StdioWrite, _PL_W16StdioWrite ); \
  80.     PR_INIT_CALLBACKS();
  81.  
  82. /*
  83. ** Win16 hackery.
  84. **
  85. */
  86. struct PRMethodCallbackStr {
  87.     int     (PR_CALLBACK *auxOutput)(const char *outputString);
  88.     size_t  (PR_CALLBACK *strftime)(char *s, size_t len, const char *fmt, const struct tm *p);
  89.     void *  (PR_CALLBACK *malloc)( size_t size );
  90.     void *  (PR_CALLBACK *calloc)(size_t n, size_t size );
  91.     void *  (PR_CALLBACK *realloc)( void* old_blk, size_t size );
  92.     void    (PR_CALLBACK *free)( void *ptr );
  93.     void *  (PR_CALLBACK *getenv)( const char *name);
  94.     int     (PR_CALLBACK *putenv)( const char *assoc);
  95. //    void *  (PR_CALLBACK *perror)( const char *prefix );
  96. };
  97.  
  98. PR_EXTERN(void) PR_MDRegisterCallbacks(struct PRMethodCallbackStr *);
  99.  
  100. int PR_CALLBACK _PL_W16CallBackPuts( const char *outputString );
  101. size_t PR_CALLBACK _PL_W16CallBackStrftime( 
  102.     char *s, 
  103.     size_t len, 
  104.     const char *fmt,
  105.     const struct tm *p );
  106. void * PR_CALLBACK _PL_W16CallBackMalloc( size_t size );
  107. void * PR_CALLBACK _PL_W16CallBackCalloc( size_t n, size_t size );
  108. void * PR_CALLBACK _PL_W16CallBackRealloc( 
  109.     void *old_blk, 
  110.     size_t size );
  111. void   PR_CALLBACK _PL_W16CallBackFree( void *ptr );
  112. void * PR_CALLBACK _PL_W16CallBackGetenv( const char *name );
  113. int PR_CALLBACK _PL_W16CallBackPutenv( const char *assoc );
  114.  
  115. /*
  116. ** Hackery! 
  117. **
  118. ** These functions are provided as static link points.
  119. ** This is to satisfy the quick port of Gromit to NSPR 2.0
  120. ** ... Don't do this! ... alas, It may never go away.
  121. ** 
  122. */
  123. PR_EXTERN(int)     PR_MD_printf(const char *, ...);
  124. PR_EXTERN(void)    PR_MD_exit(int);
  125. PR_EXTERN(size_t)  PR_MD_strftime(char *, size_t, const char *, const struct tm *); 
  126. PR_EXTERN(int)     PR_MD_sscanf(const char *, const char *, ...);
  127. PR_EXTERN(void*)   PR_MD_malloc( size_t size );
  128. PR_EXTERN(void*)   PR_MD_calloc( size_t n, size_t size );
  129. PR_EXTERN(void*)   PR_MD_realloc( void* old_blk, size_t size );
  130. PR_EXTERN(void)    PR_MD_free( void *ptr );
  131. PR_EXTERN(char*)   PR_MD_getenv( const char *name );
  132. PR_EXTERN(int)     PR_MD_putenv( const char *assoc );
  133. PR_EXTERN(int)     PR_MD_fprintf(FILE *fPtr, const char *fmt, ...);
  134.  
  135. #define PR_INIT_CALLBACKS()                         \
  136.     {                                               \
  137.         static struct PRMethodCallbackStr cbf = {   \
  138.             _PL_W16CallBackPuts,                    \
  139.             _PL_W16CallBackStrftime,                \
  140.             _PL_W16CallBackMalloc,                  \
  141.             _PL_W16CallBackCalloc,                  \
  142.             _PL_W16CallBackRealloc,                 \
  143.             _PL_W16CallBackFree,                    \
  144.             _PL_W16CallBackGetenv,                  \
  145.             _PL_W16CallBackPutenv,                  \
  146.         };                                          \
  147.         PR_MDRegisterCallbacks( &cbf );             \
  148.     }
  149.  
  150.  
  151. /*
  152. ** Get the exception context for Win16 MFC applications threads
  153. */
  154. PR_EXTERN(void *) PR_W16GetExceptionContext(void);
  155. /*
  156. ** Set the exception context for Win16 MFC applications threads
  157. */
  158. PR_EXTERN(void) PR_W16SetExceptionContext(void *context);
  159.  
  160. PR_END_EXTERN_C
  161. #else
  162. /*
  163. ** For platforms other than Win16, define
  164. ** PR_STDIO_INIT() as a No-Op.
  165. */
  166. #define PR_STDIO_INIT()
  167. #endif /* WIN16 || MOZILLA_CLIENT */
  168.  
  169. #endif /* prwin16_h___ */
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.