michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef prwin16_h___ michael@0: #define prwin16_h___ michael@0: michael@0: /* michael@0: ** Condition use of this header on platform. michael@0: */ michael@0: #if (defined(XP_PC) && !defined(_WIN32) && !defined(XP_OS2) && defined(MOZILLA_CLIENT)) || defined(WIN16) michael@0: #include michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: /* michael@0: ** Win16 stdio special case. michael@0: ** To get stdio to work for Win16, all calls to printf() and related michael@0: ** things must be called from the environment of the .EXE; calls to michael@0: ** printf() from the .DLL send output to the bit-bucket. michael@0: ** michael@0: ** To make sure that PR_fprintf(), and related functions, work correctly, michael@0: ** the actual stream I/O to stdout, stderr, stdin must be done in the michael@0: ** .EXE. To do this, a hack is placed in _MD_Write() such that the michael@0: ** fd for stdio handles results in a call to the .EXE. michael@0: ** michael@0: ** file w16stdio.c contains the functions that get called from NSPR michael@0: ** to do the actual I/O. w16stdio.o must be statically linked with michael@0: ** any application needing stdio for Win16. michael@0: ** michael@0: ** The address of these functions must be made available to the .DLL michael@0: ** so he can call back to the .EXE. To do this, function michael@0: ** PR_MD_RegisterW16StdioCallbacks() is called from the .EXE. michael@0: ** The arguments are the functions defined in w16stdio.c michael@0: ** At runtime, MD_Write() calls the registered functions, if any michael@0: ** were registered. michael@0: ** michael@0: ** prinit.h contains a macro PR_STDIO_INIT() that calls the registration michael@0: ** function for Win16; For other platforms, the macro is a No-Op. michael@0: ** michael@0: ** Note that stdio is not operational at all on Win16 GUI applications. michael@0: ** This special case exists to provide stdio capability from the NSPR michael@0: ** .DLL for command line applications only. NSPR's test cases are michael@0: ** almost exclusively command line applications. michael@0: ** michael@0: ** See also: w16io.c, w16stdio.c michael@0: */ michael@0: typedef PRInt32 (PR_CALLBACK *PRStdinRead)( void *buf, PRInt32 amount); michael@0: typedef PRInt32 (PR_CALLBACK *PRStdoutWrite)( void *buf, PRInt32 amount); michael@0: typedef PRInt32 (PR_CALLBACK *PRStderrWrite)( void *buf, PRInt32 amount); michael@0: michael@0: NSPR_API(PRStatus) michael@0: PR_MD_RegisterW16StdioCallbacks( michael@0: PRStdinRead inReadf, /* i: function pointer for stdin read */ michael@0: PRStdoutWrite outWritef, /* i: function pointer for stdout write */ michael@0: PRStderrWrite errWritef /* i: function pointer for stderr write */ michael@0: ); michael@0: michael@0: NSPR_API(PRInt32) michael@0: _PL_W16StdioWrite( void *buf, PRInt32 amount ); michael@0: michael@0: NSPR_API(PRInt32) michael@0: _PL_W16StdioRead( void *buf, PRInt32 amount ); michael@0: michael@0: #define PR_STDIO_INIT() PR_MD_RegisterW16StdioCallbacks( \ michael@0: _PL_W16StdioRead, _PL_W16StdioWrite, _PL_W16StdioWrite ); \ michael@0: PR_INIT_CALLBACKS(); michael@0: michael@0: /* michael@0: ** Win16 hackery. michael@0: ** michael@0: */ michael@0: struct PRMethodCallbackStr { michael@0: int (PR_CALLBACK *auxOutput)(const char *outputString); michael@0: size_t (PR_CALLBACK *strftime)(char *s, size_t len, const char *fmt, const struct tm *p); michael@0: void * (PR_CALLBACK *malloc)( size_t size ); michael@0: void * (PR_CALLBACK *calloc)(size_t n, size_t size ); michael@0: void * (PR_CALLBACK *realloc)( void* old_blk, size_t size ); michael@0: void (PR_CALLBACK *free)( void *ptr ); michael@0: void * (PR_CALLBACK *getenv)( const char *name); michael@0: int (PR_CALLBACK *putenv)( const char *assoc); michael@0: /* void * (PR_CALLBACK *perror)( const char *prefix ); */ michael@0: }; michael@0: michael@0: NSPR_API(void) PR_MDRegisterCallbacks(struct PRMethodCallbackStr *); michael@0: michael@0: int PR_CALLBACK _PL_W16CallBackPuts( const char *outputString ); michael@0: size_t PR_CALLBACK _PL_W16CallBackStrftime( michael@0: char *s, michael@0: size_t len, michael@0: const char *fmt, michael@0: const struct tm *p ); michael@0: void * PR_CALLBACK _PL_W16CallBackMalloc( size_t size ); michael@0: void * PR_CALLBACK _PL_W16CallBackCalloc( size_t n, size_t size ); michael@0: void * PR_CALLBACK _PL_W16CallBackRealloc( michael@0: void *old_blk, michael@0: size_t size ); michael@0: void PR_CALLBACK _PL_W16CallBackFree( void *ptr ); michael@0: void * PR_CALLBACK _PL_W16CallBackGetenv( const char *name ); michael@0: int PR_CALLBACK _PL_W16CallBackPutenv( const char *assoc ); michael@0: michael@0: /* michael@0: ** Hackery! michael@0: ** michael@0: ** These functions are provided as static link points. michael@0: ** This is to satisfy the quick port of Gromit to NSPR 2.0 michael@0: ** ... Don't do this! ... alas, It may never go away. michael@0: ** michael@0: */ michael@0: NSPR_API(int) PR_MD_printf(const char *, ...); michael@0: NSPR_API(void) PR_MD_exit(int); michael@0: NSPR_API(size_t) PR_MD_strftime(char *, size_t, const char *, const struct tm *); michael@0: NSPR_API(int) PR_MD_sscanf(const char *, const char *, ...); michael@0: NSPR_API(void*) PR_MD_malloc( size_t size ); michael@0: NSPR_API(void*) PR_MD_calloc( size_t n, size_t size ); michael@0: NSPR_API(void*) PR_MD_realloc( void* old_blk, size_t size ); michael@0: NSPR_API(void) PR_MD_free( void *ptr ); michael@0: NSPR_API(char*) PR_MD_getenv( const char *name ); michael@0: NSPR_API(int) PR_MD_putenv( const char *assoc ); michael@0: NSPR_API(int) PR_MD_fprintf(FILE *fPtr, const char *fmt, ...); michael@0: michael@0: #define PR_INIT_CALLBACKS() \ michael@0: { \ michael@0: static struct PRMethodCallbackStr cbf = { \ michael@0: _PL_W16CallBackPuts, \ michael@0: _PL_W16CallBackStrftime, \ michael@0: _PL_W16CallBackMalloc, \ michael@0: _PL_W16CallBackCalloc, \ michael@0: _PL_W16CallBackRealloc, \ michael@0: _PL_W16CallBackFree, \ michael@0: _PL_W16CallBackGetenv, \ michael@0: _PL_W16CallBackPutenv, \ michael@0: }; \ michael@0: PR_MDRegisterCallbacks( &cbf ); \ michael@0: } michael@0: michael@0: michael@0: /* michael@0: ** Get the exception context for Win16 MFC applications threads michael@0: */ michael@0: NSPR_API(void *) PR_W16GetExceptionContext(void); michael@0: /* michael@0: ** Set the exception context for Win16 MFC applications threads michael@0: */ michael@0: NSPR_API(void) PR_W16SetExceptionContext(void *context); michael@0: michael@0: PR_END_EXTERN_C michael@0: #else michael@0: /* michael@0: ** For platforms other than Win16, define michael@0: ** PR_STDIO_INIT() as a No-Op. michael@0: */ michael@0: #define PR_STDIO_INIT() michael@0: #endif /* WIN16 || MOZILLA_CLIENT */ michael@0: michael@0: #endif /* prwin16_h___ */ michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: