Back to index

lightning-sunbird  0.9+nobinonly
prwin16.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef prwin16_h___
00039 #define prwin16_h___
00040 
00041 /*
00042 ** Condition use of this header on platform.
00043 */
00044 #if (defined(XP_PC) && !defined(_WIN32) && !defined(XP_OS2) && defined(MOZILLA_CLIENT)) || defined(WIN16)
00045 #include <stdio.h>
00046 
00047 PR_BEGIN_EXTERN_C
00048 /* 
00049 ** Win16 stdio special case.
00050 ** To get stdio to work for Win16, all calls to printf() and related
00051 ** things must be called from the environment of the .EXE; calls to
00052 ** printf() from the .DLL send output to the bit-bucket.
00053 **
00054 ** To make sure that PR_fprintf(), and related functions, work correctly,
00055 ** the actual stream I/O to stdout, stderr, stdin must be done in the
00056 ** .EXE. To do this, a hack is placed in _MD_Write() such that the
00057 ** fd for stdio handles results in a call to the .EXE.
00058 **
00059 ** file w16stdio.c contains the functions that get called from NSPR
00060 ** to do the actual I/O. w16stdio.o must be statically linked with
00061 ** any application needing stdio for Win16.
00062 **
00063 ** The address of these functions must be made available to the .DLL
00064 ** so he can call back to the .EXE. To do this, function 
00065 ** PR_MD_RegisterW16StdioCallbacks() is called from the .EXE.
00066 ** The arguments are the functions defined in w16stdio.c
00067 ** At runtime, MD_Write() calls the registered functions, if any
00068 ** were registered.
00069 **
00070 ** prinit.h contains a macro PR_STDIO_INIT() that calls the registration
00071 ** function for Win16; For other platforms, the macro is a No-Op.
00072 **
00073 ** Note that stdio is not operational at all on Win16 GUI applications.
00074 ** This special case exists to provide stdio capability from the NSPR
00075 ** .DLL for command line applications only. NSPR's test cases are
00076 ** almost exclusively command line applications.
00077 **
00078 ** See also: w16io.c, w16stdio.c
00079 */
00080 typedef PRInt32 (PR_CALLBACK *PRStdinRead)( void *buf, PRInt32 amount);
00081 typedef PRInt32 (PR_CALLBACK *PRStdoutWrite)( void *buf, PRInt32 amount);
00082 typedef PRInt32 (PR_CALLBACK *PRStderrWrite)( void *buf, PRInt32 amount);
00083 
00084 NSPR_API(PRStatus)
00085 PR_MD_RegisterW16StdioCallbacks( 
00086     PRStdinRead inReadf,            /* i: function pointer for stdin read       */
00087     PRStdoutWrite outWritef,        /* i: function pointer for stdout write     */
00088     PRStderrWrite errWritef         /* i: function pointer for stderr write     */
00089     );
00090 
00091 NSPR_API(PRInt32)
00092 _PL_W16StdioWrite( void *buf, PRInt32 amount );
00093 
00094 NSPR_API(PRInt32)
00095 _PL_W16StdioRead( void *buf, PRInt32 amount );
00096 
00097 #define PR_STDIO_INIT() PR_MD_RegisterW16StdioCallbacks( \
00098     _PL_W16StdioRead, _PL_W16StdioWrite, _PL_W16StdioWrite ); \
00099     PR_INIT_CALLBACKS();
00100 
00101 /*
00102 ** Win16 hackery.
00103 **
00104 */
00105 struct PRMethodCallbackStr {
00106     int     (PR_CALLBACK *auxOutput)(const char *outputString);
00107     size_t  (PR_CALLBACK *strftime)(char *s, size_t len, const char *fmt, const struct tm *p);
00108     void *  (PR_CALLBACK *malloc)( size_t size );
00109     void *  (PR_CALLBACK *calloc)(size_t n, size_t size );
00110     void *  (PR_CALLBACK *realloc)( void* old_blk, size_t size );
00111     void    (PR_CALLBACK *free)( void *ptr );
00112     void *  (PR_CALLBACK *getenv)( const char *name);
00113     int     (PR_CALLBACK *putenv)( const char *assoc);
00114 /*    void *  (PR_CALLBACK *perror)( const char *prefix ); */
00115 };
00116 
00117 NSPR_API(void) PR_MDRegisterCallbacks(struct PRMethodCallbackStr *);
00118 
00119 int PR_CALLBACK _PL_W16CallBackPuts( const char *outputString );
00120 size_t PR_CALLBACK _PL_W16CallBackStrftime( 
00121     char *s, 
00122     size_t len, 
00123     const char *fmt,
00124     const struct tm *p );
00125 void * PR_CALLBACK _PL_W16CallBackMalloc( size_t size );
00126 void * PR_CALLBACK _PL_W16CallBackCalloc( size_t n, size_t size );
00127 void * PR_CALLBACK _PL_W16CallBackRealloc( 
00128     void *old_blk, 
00129     size_t size );
00130 void   PR_CALLBACK _PL_W16CallBackFree( void *ptr );
00131 void * PR_CALLBACK _PL_W16CallBackGetenv( const char *name );
00132 int PR_CALLBACK _PL_W16CallBackPutenv( const char *assoc );
00133 
00134 /*
00135 ** Hackery! 
00136 **
00137 ** These functions are provided as static link points.
00138 ** This is to satisfy the quick port of Gromit to NSPR 2.0
00139 ** ... Don't do this! ... alas, It may never go away.
00140 ** 
00141 */
00142 NSPR_API(int)     PR_MD_printf(const char *, ...);
00143 NSPR_API(void)    PR_MD_exit(int);
00144 NSPR_API(size_t)  PR_MD_strftime(char *, size_t, const char *, const struct tm *); 
00145 NSPR_API(int)     PR_MD_sscanf(const char *, const char *, ...);
00146 NSPR_API(void*)   PR_MD_malloc( size_t size );
00147 NSPR_API(void*)   PR_MD_calloc( size_t n, size_t size );
00148 NSPR_API(void*)   PR_MD_realloc( void* old_blk, size_t size );
00149 NSPR_API(void)    PR_MD_free( void *ptr );
00150 NSPR_API(char*)   PR_MD_getenv( const char *name );
00151 NSPR_API(int)     PR_MD_putenv( const char *assoc );
00152 NSPR_API(int)     PR_MD_fprintf(FILE *fPtr, const char *fmt, ...);
00153 
00154 #define PR_INIT_CALLBACKS()                         \
00155     {                                               \
00156         static struct PRMethodCallbackStr cbf = {   \
00157             _PL_W16CallBackPuts,                    \
00158             _PL_W16CallBackStrftime,                \
00159             _PL_W16CallBackMalloc,                  \
00160             _PL_W16CallBackCalloc,                  \
00161             _PL_W16CallBackRealloc,                 \
00162             _PL_W16CallBackFree,                    \
00163             _PL_W16CallBackGetenv,                  \
00164             _PL_W16CallBackPutenv,                  \
00165         };                                          \
00166         PR_MDRegisterCallbacks( &cbf );             \
00167     }
00168 
00169 
00170 /*
00171 ** Get the exception context for Win16 MFC applications threads
00172 */
00173 NSPR_API(void *) PR_W16GetExceptionContext(void);
00174 /*
00175 ** Set the exception context for Win16 MFC applications threads
00176 */
00177 NSPR_API(void) PR_W16SetExceptionContext(void *context);
00178 
00179 PR_END_EXTERN_C
00180 #else
00181 /*
00182 ** For platforms other than Win16, define
00183 ** PR_STDIO_INIT() as a No-Op.
00184 */
00185 #define PR_STDIO_INIT()
00186 #endif /* WIN16 || MOZILLA_CLIENT */
00187 
00188 #endif /* prwin16_h___ */
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196