1 | |
---|
2 | /* WcPrintf - Replacement for printf |
---|
3 | **************************************************************************** |
---|
4 | Allows the application to easily take control of warning output. |
---|
5 | Wcl provides two resources: wclWarningFileDescriptor, which can be an |
---|
6 | int or "stderr" or "stdout", and wclWarningFileName, defaults to NULL. |
---|
7 | If not null, then the file is opened and dup'd to use the desired |
---|
8 | file descriptior, otherwise the descriptor is used. |
---|
9 | |
---|
10 | The client (and libXmp etc) can provide replacements which send the |
---|
11 | messages to a widget. |
---|
12 | */ |
---|
13 | |
---|
14 | typedef void (*WcPrintfProc) _(( char*, va_list )); |
---|
15 | extern void WcPrintf _(( char*, ... )); |
---|
16 | extern WcPrintfProc WcSetPrintfProc _(( WcPrintfProc )); |
---|
17 | |
---|
18 | static void WcxDefaultPrintf _(( char*, va_list )); |
---|
19 | static WcPrintfProc Printf = WcxDefaultPrintf; |
---|
20 | static FILE* wcxFileDescriptor; |
---|
21 | |
---|
22 | WcPrintfProc WcSetPrintfProc( UserPrintfProc ) |
---|
23 | WcPrintfProc UserPrintfProc; |
---|
24 | { |
---|
25 | WcPrintfProc OldPrintfProc = Printf; |
---|
26 | Printf = UserPrintfProc; |
---|
27 | return OldPrintfProc; |
---|
28 | } |
---|
29 | |
---|
30 | #ifdef _NO_VFPRINTF |
---|
31 | #ifdef _NO_DOPRNT |
---|
32 | |
---|
33 | /* |
---|
34 | * No way to do this reliably and portably. If your machine is like this, |
---|
35 | * you need to fully implement vfprintf according to the ANSI spec so it |
---|
36 | * works on your specific machine. Yuck! |
---|
37 | * |
---|
38 | * Luckily, there are probably no machines on earth still plugged in |
---|
39 | * which are this deficient. |
---|
40 | */ |
---|
41 | |
---|
42 | /*VARARGS1*/ |
---|
43 | static void WcPrintf( format, va_alist ) |
---|
44 | char* format; |
---|
45 | va_dcl |
---|
46 | { |
---|
47 | if ( Printf == WcxDefaultPrintf ) |
---|
48 | fprintf( wcxFileDescriptor, format, va_alist ); |
---|
49 | |
---|
50 | va_list var; |
---|
51 | |
---|
52 | Va_start( var, format ); |
---|
53 | Printf( format, var ); |
---|
54 | va_end( var ); |
---|
55 | } |
---|
56 | |
---|
57 | /*ARGSUSED*/ |
---|
58 | static void WcxDefaultPrintf( format, var ) |
---|
59 | char* format; |
---|
60 | va_list var; |
---|
61 | { |
---|
62 | (void)fprintf( wcxFileDescriptor, |
---|
63 | "No vprintf, no _doprnt: Cannot safely format <%s>\n", |
---|
64 | format ); |
---|
65 | } |
---|
66 | |
---|
67 | #else /* the system does have _doprnt, but no vfprintf() */ |
---|
68 | |
---|
69 | /* |
---|
70 | * Implement vfprintf() using _doprnt |
---|
71 | */ |
---|
72 | |
---|
73 | int vfprintf( fd, format, var ) |
---|
74 | FILE* fd; |
---|
75 | char* format; |
---|
76 | va_list var; |
---|
77 | { |
---|
78 | return _doprnt( format, var, fd ); |
---|
79 | } |
---|
80 | |
---|
81 | #undef _NO_VFPRINTF |
---|
82 | |
---|
83 | #endif /*_NO_DOPRNT*/ |
---|
84 | #endif /*_NO_VFPRINTF*/ |
---|
85 | |
---|
86 | #ifndef _NO_VFPRINTF |
---|
87 | /* |
---|
88 | * All modern systems will end up here. |
---|
89 | */ |
---|
90 | |
---|
91 | static void WcxDefaultPrintf( format, var ) |
---|
92 | char* format; |
---|
93 | va_list var; |
---|
94 | { |
---|
95 | vfprintf( wcxFileDescriptor, format, var ); |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | #if NeedFunctionPrototypes |
---|
100 | void WcPrintf( |
---|
101 | char* format, |
---|
102 | ... ) |
---|
103 | #else |
---|
104 | /*VARARGS1*/ |
---|
105 | void WcPrintf( format, va_alist ) |
---|
106 | char* format; |
---|
107 | va_dcl |
---|
108 | #endif |
---|
109 | { |
---|
110 | va_list var; |
---|
111 | |
---|
112 | Va_start( var, format ); |
---|
113 | Printf( format, var ); |
---|
114 | va_end( var ); |
---|
115 | } |
---|
116 | #endif /*!_NO_VFPRINTF*/ |
---|