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 Mozilla Public 4 * License Version 1.1 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of 6 * the License at http://www.mozilla.org/MPL/ 7 * 8 * Software distributed under the License is distributed on an "AS 9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 10 * implied. See the License for the specific language governing 11 * rights and limitations under the License. 12 * 13 * The Original Code is the Netscape Portable Runtime (NSPR). 14 * 15 * The Initial Developer of the Original Code is Netscape 16 * Communications Corporation. Portions created by Netscape are 17 * Copyright (C) 1998-2000 Netscape Communications Corporation. All 18 * Rights Reserved. 19 * 20 * Contributor(s): 21 * 22 * Alternatively, the contents of this file may be used under the 23 * terms of the GNU General Public License Version 2 or later (the 24 * "GPL"), in which case the provisions of the GPL are applicable 25 * instead of those above. If you wish to allow use of your 26 * version of this file only under the terms of the GPL and not to 27 * allow others to use your version of this file under the MPL, 28 * indicate your decision by deleting the provisions above and 29 * replace them with the notice and other provisions required by 30 * the GPL. If you do not delete the provisions above, a recipient 31 * may use your version of this file under either the MPL or the 32 * GPL. 33 */ 34 35 #ifndef prwin16_h___ 36 #define prwin16_h___ 37 38 /* 39 ** Condition use of this header on platform. 40 */ 41 #if (defined(XP_PC) && !defined(_WIN32) && !defined(XP_OS2) && defined(MOZILLA_CLIENT)) || defined(WIN16) 42 #include <stdio.h> 43 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 81 NSPR_API(PRStatus) 82 PR_MD_RegisterW16StdioCallbacks( 83 PRStdinRead inReadf, /* i: function pointer for stdin read */ 84 PRStdoutWrite outWritef, /* i: function pointer for stdout write */ 85 PRStderrWrite errWritef /* i: function pointer for stderr write */ 86 ); 87 88 NSPR_API(PRInt32) 89 _PL_W16StdioWrite( void *buf, PRInt32 amount ); 90 91 NSPR_API(PRInt32) 92 _PL_W16StdioRead( void *buf, PRInt32 amount ); 93 94 #define PR_STDIO_INIT() PR_MD_RegisterW16StdioCallbacks( \ 95 _PL_W16StdioRead, _PL_W16StdioWrite, _PL_W16StdioWrite ); \ 96 PR_INIT_CALLBACKS(); 97 98 /* 99 ** Win16 hackery. 100 ** 101 */ 102 struct PRMethodCallbackStr { 103 int (PR_CALLBACK *auxOutput)(const char *outputString); 104 size_t (PR_CALLBACK *strftime)(char *s, size_t len, const char *fmt, const struct tm *p); 105 void * (PR_CALLBACK *malloc)( size_t size ); 106 void * (PR_CALLBACK *calloc)(size_t n, size_t size ); 107 void * (PR_CALLBACK *realloc)( void* old_blk, size_t size ); 108 void (PR_CALLBACK *free)( void *ptr ); 109 void * (PR_CALLBACK *getenv)( const char *name); 110 int (PR_CALLBACK *putenv)( const char *assoc); 111 /* void * (PR_CALLBACK *perror)( const char *prefix ); */ 112 }; 113 114 NSPR_API(void) PR_MDRegisterCallbacks(struct PRMethodCallbackStr *); 115 116 int PR_CALLBACK _PL_W16CallBackPuts( const char *outputString ); 117 size_t PR_CALLBACK _PL_W16CallBackStrftime( 118 char *s, 119 size_t len, 120 const char *fmt, 121 const struct tm *p ); 122 void * PR_CALLBACK _PL_W16CallBackMalloc( size_t size ); 123 void * PR_CALLBACK _PL_W16CallBackCalloc( size_t n, size_t size ); 124 void * PR_CALLBACK _PL_W16CallBackRealloc( 125 void *old_blk, 126 size_t size ); 127 void PR_CALLBACK _PL_W16CallBackFree( void *ptr ); 128 void * PR_CALLBACK _PL_W16CallBackGetenv( const char *name ); 129 int PR_CALLBACK _PL_W16CallBackPutenv( const char *assoc ); 130 131 /* 132 ** Hackery! 133 ** 134 ** These functions are provided as static link points. 135 ** This is to satisfy the quick port of Gromit to NSPR 2.0 136 ** ... Don't do this! ... alas, It may never go away. 137 ** 138 */ 139 NSPR_API(int) PR_MD_printf(const char *, ...); 140 NSPR_API(void) PR_MD_exit(int); 141 NSPR_API(size_t) PR_MD_strftime(char *, size_t, const char *, const struct tm *); 142 NSPR_API(int) PR_MD_sscanf(const char *, const char *, ...); 143 NSPR_API(void*) PR_MD_malloc( size_t size ); 144 NSPR_API(void*) PR_MD_calloc( size_t n, size_t size ); 145 NSPR_API(void*) PR_MD_realloc( void* old_blk, size_t size ); 146 NSPR_API(void) PR_MD_free( void *ptr ); 147 NSPR_API(char*) PR_MD_getenv( const char *name ); 148 NSPR_API(int) PR_MD_putenv( const char *assoc ); 149 NSPR_API(int) PR_MD_fprintf(FILE *fPtr, const char *fmt, ...); 150 151 #define PR_INIT_CALLBACKS() \ 152 { \ 153 static struct PRMethodCallbackStr cbf = { \ 154 _PL_W16CallBackPuts, \ 155 _PL_W16CallBackStrftime, \ 156 _PL_W16CallBackMalloc, \ 157 _PL_W16CallBackCalloc, \ 158 _PL_W16CallBackRealloc, \ 159 _PL_W16CallBackFree, \ 160 _PL_W16CallBackGetenv, \ 161 _PL_W16CallBackPutenv, \ 162 }; \ 163 PR_MDRegisterCallbacks( &cbf ); \ 164 } 165 166 167 /* 168 ** Get the exception context for Win16 MFC applications threads 169 */ 170 NSPR_API(void *) PR_W16GetExceptionContext(void); 171 /* 172 ** Set the exception context for Win16 MFC applications threads 173 */ 174 NSPR_API(void) PR_W16SetExceptionContext(void *context); 175 176 PR_END_EXTERN_C 177 #else 178 /* 179 ** For platforms other than Win16, define 180 ** PR_STDIO_INIT() as a No-Op. 181 */ 182 #define PR_STDIO_INIT() 183 #endif /* WIN16 || MOZILLA_CLIENT */ 184 185 #endif /* prwin16_h___ */ 186 187 188 189 190 191 192 193 194