prwin16.h 7.4 KB

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