0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / InterfaceGraphic / InterfaceGraphic_cPrintf.cxx
CommitLineData
b311480e 1// Copyright (c) 1991-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19
20#if defined (__osf__ ) || defined ( DECOSF1 )
21int DECOSF1_a_horreur_du_vide_a_la_compilation;
22#endif
23#if defined ( __hpux ) || defined ( HPUX )
24int HPUX_a_horreur_du_vide_a_la_compilation;
25#endif
26
27#ifdef WNT
28
29#define STRICT
30#include <windows.h>
31
32#include <stdio.h>
33#include <string.h>
34
35#include <InterfaceGraphic_wntio.hxx>
36
37typedef struct _env {
38
39 DWORD len;
40 char* ptr;
41
42} ENV, *PENV;
43
44static DWORD tlsIndex;
45
46class Init_ {
47
48public:
49
50 Init_ () { tlsIndex = TlsAlloc (); }
51
52}; // end Init_
53
54static Init_ init;
55
56int cPrintf ( char* fmt, ... ) {
57
58 static BOOL first = TRUE;
59 static HANDLE hConsole = NULL;
60
61 char buffer[ 256 ];
62 va_list argptr;
63 int cnt;
64 DWORD lpcchWritten;
65
66 if ( first ) {
67 hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
68 if ( hConsole == NULL ) {
69 AllocConsole ();
70 hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
71 } /* end if */
72
73 first = FALSE;
74
75 } /* end if */
76
77 va_start( argptr, fmt );
78 cnt = vsprintf ( buffer, fmt, argptr );
79 va_end ( argptr );
80 WriteConsole ( hConsole, buffer, strlen ( buffer ), &lpcchWritten, NULL );
81 return cnt;
82
83} /* end cPrintf */
84
35e08fe8 85int fcPrintf ( int /*dummy*/, char* fmt, ... ) {
7fd59977 86
87 static BOOL first = TRUE;
88 static HANDLE hConsole = NULL;
89
90 char buffer[ 256 ];
91 va_list argptr;
92 int cnt;
93 DWORD lpcchWritten;
94
95 if ( first ) {
96 hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
97 if ( hConsole == NULL ) {
98 AllocConsole ();
99 hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
100 } /* end if */
101
102 first = FALSE;
103 } /* end if */
104
105 va_start( argptr, fmt );
106 cnt = vsprintf ( buffer, fmt, argptr );
107 va_end ( argptr );
108 WriteConsole ( hConsole, buffer, strlen ( buffer ), &lpcchWritten, NULL );
109
110 return cnt;
111
112} /* end fcPrintf */
113
114char* GetEnv ( char* name ) {
115
116 DWORD dwLen;
117 PENV env = ( PENV )TlsGetValue ( tlsIndex );
118
119 if ( env == NULL ) {
120 env = ( PENV )HeapAlloc (
121 GetProcessHeap (), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY,
122 ( DWORD )sizeof ( ENV )
123 );
124 TlsSetValue ( tlsIndex, ( LPVOID )env );
125 } /* end if */
126
127 SetLastError ( ERROR_SUCCESS );
128 dwLen = GetEnvironmentVariable ( name, NULL, 0 );
129
130 if ( dwLen == 0 && GetLastError () != ERROR_SUCCESS ) return NULL;
131
132 ++dwLen;
133
134 if ( env -> len < dwLen ) {
135 if ( env -> ptr != NULL )
136 env -> ptr = ( char* )HeapReAlloc (
137 GetProcessHeap (), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY,
138 env -> ptr, dwLen
139 );
140 else
141 env -> ptr = ( char* )HeapAlloc (
142 GetProcessHeap (), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY,
143 dwLen
144 );
145 env -> len = dwLen;
146 } /* end if */
147
148 GetEnvironmentVariable ( name, env -> ptr, dwLen );
149 return env -> ptr;
150
151} /* end GetEnv */
152#endif /* WNT */