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

source code of include/nspr/prwin16.h