1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/include/prwin16.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,164 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef prwin16_h___ 1.10 +#define prwin16_h___ 1.11 + 1.12 +/* 1.13 +** Condition use of this header on platform. 1.14 +*/ 1.15 +#if (defined(XP_PC) && !defined(_WIN32) && !defined(XP_OS2) && defined(MOZILLA_CLIENT)) || defined(WIN16) 1.16 +#include <stdio.h> 1.17 + 1.18 +PR_BEGIN_EXTERN_C 1.19 +/* 1.20 +** Win16 stdio special case. 1.21 +** To get stdio to work for Win16, all calls to printf() and related 1.22 +** things must be called from the environment of the .EXE; calls to 1.23 +** printf() from the .DLL send output to the bit-bucket. 1.24 +** 1.25 +** To make sure that PR_fprintf(), and related functions, work correctly, 1.26 +** the actual stream I/O to stdout, stderr, stdin must be done in the 1.27 +** .EXE. To do this, a hack is placed in _MD_Write() such that the 1.28 +** fd for stdio handles results in a call to the .EXE. 1.29 +** 1.30 +** file w16stdio.c contains the functions that get called from NSPR 1.31 +** to do the actual I/O. w16stdio.o must be statically linked with 1.32 +** any application needing stdio for Win16. 1.33 +** 1.34 +** The address of these functions must be made available to the .DLL 1.35 +** so he can call back to the .EXE. To do this, function 1.36 +** PR_MD_RegisterW16StdioCallbacks() is called from the .EXE. 1.37 +** The arguments are the functions defined in w16stdio.c 1.38 +** At runtime, MD_Write() calls the registered functions, if any 1.39 +** were registered. 1.40 +** 1.41 +** prinit.h contains a macro PR_STDIO_INIT() that calls the registration 1.42 +** function for Win16; For other platforms, the macro is a No-Op. 1.43 +** 1.44 +** Note that stdio is not operational at all on Win16 GUI applications. 1.45 +** This special case exists to provide stdio capability from the NSPR 1.46 +** .DLL for command line applications only. NSPR's test cases are 1.47 +** almost exclusively command line applications. 1.48 +** 1.49 +** See also: w16io.c, w16stdio.c 1.50 +*/ 1.51 +typedef PRInt32 (PR_CALLBACK *PRStdinRead)( void *buf, PRInt32 amount); 1.52 +typedef PRInt32 (PR_CALLBACK *PRStdoutWrite)( void *buf, PRInt32 amount); 1.53 +typedef PRInt32 (PR_CALLBACK *PRStderrWrite)( void *buf, PRInt32 amount); 1.54 + 1.55 +NSPR_API(PRStatus) 1.56 +PR_MD_RegisterW16StdioCallbacks( 1.57 + PRStdinRead inReadf, /* i: function pointer for stdin read */ 1.58 + PRStdoutWrite outWritef, /* i: function pointer for stdout write */ 1.59 + PRStderrWrite errWritef /* i: function pointer for stderr write */ 1.60 + ); 1.61 + 1.62 +NSPR_API(PRInt32) 1.63 +_PL_W16StdioWrite( void *buf, PRInt32 amount ); 1.64 + 1.65 +NSPR_API(PRInt32) 1.66 +_PL_W16StdioRead( void *buf, PRInt32 amount ); 1.67 + 1.68 +#define PR_STDIO_INIT() PR_MD_RegisterW16StdioCallbacks( \ 1.69 + _PL_W16StdioRead, _PL_W16StdioWrite, _PL_W16StdioWrite ); \ 1.70 + PR_INIT_CALLBACKS(); 1.71 + 1.72 +/* 1.73 +** Win16 hackery. 1.74 +** 1.75 +*/ 1.76 +struct PRMethodCallbackStr { 1.77 + int (PR_CALLBACK *auxOutput)(const char *outputString); 1.78 + size_t (PR_CALLBACK *strftime)(char *s, size_t len, const char *fmt, const struct tm *p); 1.79 + void * (PR_CALLBACK *malloc)( size_t size ); 1.80 + void * (PR_CALLBACK *calloc)(size_t n, size_t size ); 1.81 + void * (PR_CALLBACK *realloc)( void* old_blk, size_t size ); 1.82 + void (PR_CALLBACK *free)( void *ptr ); 1.83 + void * (PR_CALLBACK *getenv)( const char *name); 1.84 + int (PR_CALLBACK *putenv)( const char *assoc); 1.85 +/* void * (PR_CALLBACK *perror)( const char *prefix ); */ 1.86 +}; 1.87 + 1.88 +NSPR_API(void) PR_MDRegisterCallbacks(struct PRMethodCallbackStr *); 1.89 + 1.90 +int PR_CALLBACK _PL_W16CallBackPuts( const char *outputString ); 1.91 +size_t PR_CALLBACK _PL_W16CallBackStrftime( 1.92 + char *s, 1.93 + size_t len, 1.94 + const char *fmt, 1.95 + const struct tm *p ); 1.96 +void * PR_CALLBACK _PL_W16CallBackMalloc( size_t size ); 1.97 +void * PR_CALLBACK _PL_W16CallBackCalloc( size_t n, size_t size ); 1.98 +void * PR_CALLBACK _PL_W16CallBackRealloc( 1.99 + void *old_blk, 1.100 + size_t size ); 1.101 +void PR_CALLBACK _PL_W16CallBackFree( void *ptr ); 1.102 +void * PR_CALLBACK _PL_W16CallBackGetenv( const char *name ); 1.103 +int PR_CALLBACK _PL_W16CallBackPutenv( const char *assoc ); 1.104 + 1.105 +/* 1.106 +** Hackery! 1.107 +** 1.108 +** These functions are provided as static link points. 1.109 +** This is to satisfy the quick port of Gromit to NSPR 2.0 1.110 +** ... Don't do this! ... alas, It may never go away. 1.111 +** 1.112 +*/ 1.113 +NSPR_API(int) PR_MD_printf(const char *, ...); 1.114 +NSPR_API(void) PR_MD_exit(int); 1.115 +NSPR_API(size_t) PR_MD_strftime(char *, size_t, const char *, const struct tm *); 1.116 +NSPR_API(int) PR_MD_sscanf(const char *, const char *, ...); 1.117 +NSPR_API(void*) PR_MD_malloc( size_t size ); 1.118 +NSPR_API(void*) PR_MD_calloc( size_t n, size_t size ); 1.119 +NSPR_API(void*) PR_MD_realloc( void* old_blk, size_t size ); 1.120 +NSPR_API(void) PR_MD_free( void *ptr ); 1.121 +NSPR_API(char*) PR_MD_getenv( const char *name ); 1.122 +NSPR_API(int) PR_MD_putenv( const char *assoc ); 1.123 +NSPR_API(int) PR_MD_fprintf(FILE *fPtr, const char *fmt, ...); 1.124 + 1.125 +#define PR_INIT_CALLBACKS() \ 1.126 + { \ 1.127 + static struct PRMethodCallbackStr cbf = { \ 1.128 + _PL_W16CallBackPuts, \ 1.129 + _PL_W16CallBackStrftime, \ 1.130 + _PL_W16CallBackMalloc, \ 1.131 + _PL_W16CallBackCalloc, \ 1.132 + _PL_W16CallBackRealloc, \ 1.133 + _PL_W16CallBackFree, \ 1.134 + _PL_W16CallBackGetenv, \ 1.135 + _PL_W16CallBackPutenv, \ 1.136 + }; \ 1.137 + PR_MDRegisterCallbacks( &cbf ); \ 1.138 + } 1.139 + 1.140 + 1.141 +/* 1.142 +** Get the exception context for Win16 MFC applications threads 1.143 +*/ 1.144 +NSPR_API(void *) PR_W16GetExceptionContext(void); 1.145 +/* 1.146 +** Set the exception context for Win16 MFC applications threads 1.147 +*/ 1.148 +NSPR_API(void) PR_W16SetExceptionContext(void *context); 1.149 + 1.150 +PR_END_EXTERN_C 1.151 +#else 1.152 +/* 1.153 +** For platforms other than Win16, define 1.154 +** PR_STDIO_INIT() as a No-Op. 1.155 +*/ 1.156 +#define PR_STDIO_INIT() 1.157 +#endif /* WIN16 || MOZILLA_CLIENT */ 1.158 + 1.159 +#endif /* prwin16_h___ */ 1.160 + 1.161 + 1.162 + 1.163 + 1.164 + 1.165 + 1.166 + 1.167 +