2 * NOTICE and LICENSE for Tecplot Input/Output Library (TecIO) - OpenFOAM
4 * Copyright (C) 1988-2009 Tecplot, Inc. All rights reserved worldwide.
6 * Tecplot hereby grants OpenCFD limited authority to distribute without
7 * alteration the source code to the Tecplot Input/Output library, known
8 * as TecIO, as part of its distribution of OpenFOAM and the
9 * OpenFOAM_to_Tecplot converter. Users of this converter are also hereby
10 * granted access to the TecIO source code, and may redistribute it for the
11 * purpose of maintaining the converter. However, no authority is granted
12 * to alter the TecIO source code in any form or manner.
14 * This limited grant of distribution does not supersede Tecplot, Inc.'s
15 * copyright in TecIO. Contact Tecplot, Inc. for further information.
18 * 3535 Factoria Blvd, Ste. 550
19 * Bellevue, WA 98006, USA
20 * Phone: +1 425 653 1200
21 * http://www.tecplot.com/
27 #define TECPLOTENGINEMODULE
30 ******************************************************************
31 ******************************************************************
33 ****** (C) 1988-2008 Tecplot, Inc. *******
35 ******************************************************************
36 ******************************************************************
42 #include "Q_UNICODE.h"
46 #if defined TECPLOTKERNEL
47 /* CORE SOURCE CODE REMOVED */
57 #if defined TECPLOTKERNEL
58 /* CORE SOURCE CODE REMOVED */
62 using namespace tecplot::strutil
;
63 #if defined TECPLOTKERNEL
64 /* CORE SOURCE CODE REMOVED */
67 #define MAXCHARACTERSPERLINE 60
69 * Wrap a string so it contains at most CharactersPerLine
70 * characters. Embedded newlines are left alone. Spaces
71 * following newlines are also left alone.
73 Boolean_t
WrapString(const char *OldString
,
77 if (OldString
== NULL
)
81 * Assume Old string has ample spaces. Will only be
82 * replacing some spaces with newlines and removing
83 * other spaces. New string can be allocated to be
84 * same length as old string.
87 L
= strlen(OldString
);
88 *NewString
= ALLOC_ARRAY(L
+ 1, char, "new error message string");
89 if (*NewString
== NULL
)
92 strcpy(*NewString
, OldString
);
94 if (L
> MAXCHARACTERSPERLINE
)
96 char *LineStart
= *NewString
;
97 char *LastWord
= *NewString
;
98 char *WPtr
= *NewString
;
99 while (WPtr
&& (*WPtr
!= '\0'))
103 * Find next hard newline. If there is one befor the
104 * line should be chopped then reset the Last Word to
105 * be at the first word after the newline.
107 WPtr
= strchr(LineStart
, '\n');
108 if (WPtr
&& ((WPtr
- LineStart
) < MAXCHARACTERSPERLINE
))
111 while (*WPtr
== '\n')
115 * Skip over trailing spaces. Special handling to
116 * allow indent after hard newline.
126 WPtr
= strchr(LastWord
, ' ');
135 CurLen
= strlen(LineStart
);
139 CurLen
= WPtr
- LineStart
;
142 if (CurLen
> MAXCHARACTERSPERLINE
)
145 * Line is too long. Back up to previous
146 * word and replace preceeding space with
149 if (LastWord
== LineStart
)
152 * Bad news, line has very long word.
154 if (WPtr
&& (*WPtr
!= '\0'))
162 *(LastWord
- 1) = '\n';
164 LineStart
= LastWord
;
174 static void SendWarningToFile(FILE *F
,
178 REQUIRE(VALID_REF(F
));
179 REQUIRE(VALID_REF(S
));
180 if (WrapString(S
, &S2
))
182 fprintf(F
, "Warning: %s\n", S2
);
183 FREE_ARRAY(S2
, "temp warning string");
187 #if defined TECPLOTKERNEL
188 /* CORE SOURCE CODE REMOVED */
193 * Show the warning message. Note that the Format string can be the only
194 * argument, in which case it is essentially the warning message itself.
197 * C Format string or a simple message.
199 * Zero or more variable arguments. The number of arguments must correspond
200 * to the placeholders in the format string.
202 void Warning(TranslatedString Format
,
203 ...) /* zero or more arguments */
205 REQUIRE(!Format
.isNull());
207 static Boolean_t InWarning
= FALSE
; /* ...used to prevent recursive deadlock */
210 #if defined TECPLOTKERNEL
211 /* CORE SOURCE CODE REMOVED */
217 * Attempt to format the string. Failing that simply use the original format
218 * string argument which, if we ran out of memory while formatting, is
219 * probably just an warning message saying that we ran out of memory in some
220 * previous operation anyway.
222 Boolean_t cleanUp
= TRUE
;
225 va_start(Arguments
, Format
);
226 char* message
= vFormatString(Format
.c_str(), Arguments
);
231 cleanUp
= FALSE
; // ...this boolean allows us to "carefully" cast away the const'ness
232 message
= (char*)Format
.c_str();
235 #if defined TECPLOTKERNEL
236 /* CORE SOURCE CODE REMOVED */
243 #else /* !TECPLOTKERNEL */
245 SendWarningToFile(stderr
, message
);
250 FREE_ARRAY(message
, "message");
254 #if defined TECPLOTKERNEL
255 /* CORE SOURCE CODE REMOVED */
261 static void SendErrToFile(FILE *File
,
265 REQUIRE(VALID_REF(File
));
266 REQUIRE(VALID_REF(Msg
));
267 if (WrapString(Msg
, &FormattedMsg
))
269 fprintf(File
, "Err: %s\n", FormattedMsg
);
270 FREE_ARRAY(FormattedMsg
, "temp error string");
273 fprintf(File
, "Err: %s\n", Msg
);
277 /* Fall-back ErrMsg procedure when nothing else works */
278 static void DefaultErrMsg(const char *Msg
)
280 REQUIRE(VALID_REF(Msg
));
284 /* CORE SOURCE CODE REMOVED */
286 MessageBox(NULL
, Msg
, "Error", MB_OK
| MB_ICONERROR
);
289 SendErrToFile(stderr
, Msg
);
293 static void PostErrorMessage(TranslatedString Format
,
296 REQUIRE(!Format
.isNull());
299 * Attempt to format the string. Failing that simply use the original format
300 * string argument which, if we ran out of memory while formatting, is
301 * probably just an error message saying that we ran out of memory in some
302 * previous operation anyway.
304 Boolean_t cleanUp
= TRUE
;
305 char* messageString
= vFormatString(Format
.c_str(), Arguments
);
306 if (messageString
== NULL
)
308 cleanUp
= FALSE
; // ...this boolean allows us to "carefully" cast away the const'ness
309 messageString
= (char*)Format
.c_str();
312 #if defined TECPLOTKERNEL
313 /* CORE SOURCE CODE REMOVED */
320 #else /* !TECPLOTKERNEL */
322 DefaultErrMsg(messageString
);
326 /* cleanup if we allocated the string */
328 FREE_ARRAY(messageString
, "messageString");
333 * This function is thread safe in that it may be safely called by multiple
334 * threads however when running interactively only the first error message is
335 * queued for display on idle. In batch mode all messages are sent to the
338 void vErrMsg(TranslatedString Format
,
341 REQUIRE(!Format
.isNull());
343 static Boolean_t InErrMsg
= FALSE
; /* ...used to prevent recursive deadlock */
346 #if defined TECPLOTKERNEL
347 /* CORE SOURCE CODE REMOVED */
352 PostErrorMessage(Format
, Arguments
);
356 #if defined TECPLOTKERNEL
357 /* CORE SOURCE CODE REMOVED */
363 * Show the error message. Note that the Format string can be the only
364 * argument, in which case it is essentially the error message itself.
367 * C Format string or a simple message.
369 * Zero or more variable arguments. The number of arguments must correspond
370 * to the placeholders in the format string.
372 void ErrMsg(TranslatedString Format
,
373 ...) /* zero or more arguments */
375 REQUIRE(!Format
.isNull());
378 va_start(Arguments
, Format
);
379 #if defined TECPLOTKERNEL
380 /* CORE SOURCE CODE REMOVED */
382 PostErrorMessage(Format
, Arguments
);
388 #if defined TECPLOTKERNEL
389 /* CORE SOURCE CODE REMOVED */
414 #endif /* TECPLOTKERNEL */