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