prwin16.h 5.9 KB

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