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