foam to Tecplot360 converter
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecio / tecsrc / q_msg.cpp
blob6a20cf56041abe9cb11696a33ab6c81d00de9729
1 /*
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.
17 * Tecplot, Inc.
18 * 3535 Factoria Blvd, Ste. 550
19 * Bellevue, WA 98006, USA
20 * Phone: +1 425 653 1200
21 * http://www.tecplot.com/
24 #include "stdafx.h"
25 #include "MASTER.h"
27 #define TECPLOTENGINEMODULE
30 ******************************************************************
31 ******************************************************************
32 ******* ********
33 ****** (C) 1988-2008 Tecplot, Inc. *******
34 ******* ********
35 ******************************************************************
36 ******************************************************************
39 #define Q_MSGMODULE
40 #include "GLOBAL.h"
41 #include "TASSERT.h"
42 #include "Q_UNICODE.h"
43 #include "ALLOC.h"
44 #include "ARRLIST.h"
46 #if defined TECPLOTKERNEL
47 /* CORE SOURCE CODE REMOVED */
48 #if !defined ENGINE
49 #if defined MOTIF
50 #endif
51 #if defined MSWIN
52 #endif
53 #endif
54 #endif
56 #include "STRUTIL.h"
57 #if defined TECPLOTKERNEL
58 /* CORE SOURCE CODE REMOVED */
59 #endif
61 using std::string;
62 using namespace tecplot::strutil;
63 #if defined TECPLOTKERNEL
64 /* CORE SOURCE CODE REMOVED */
65 #endif
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,
74 char **NewString)
76 size_t L;
77 if (OldString == NULL)
78 return (FALSE);
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)
90 return (FALSE);
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'))
101 size_t CurLen;
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))
110 WPtr++;
111 while (*WPtr == '\n')
112 WPtr++;
113 LineStart = WPtr;
115 * Skip over trailing spaces. Special handling to
116 * allow indent after hard newline.
118 while (*WPtr == ' ')
119 WPtr++;
120 LastWord = WPtr;
121 continue;
124 * Find next "word"
126 WPtr = strchr(LastWord, ' ');
127 if (WPtr != NULL)
129 while (*WPtr == ' ')
130 WPtr++;
133 if (WPtr == NULL)
135 CurLen = strlen(LineStart);
137 else
139 CurLen = WPtr - LineStart;
142 if (CurLen > MAXCHARACTERSPERLINE)
145 * Line is too long. Back up to previous
146 * word and replace preceeding space with
147 * a newline.
149 if (LastWord == LineStart)
152 * Bad news, line has very long word.
154 if (WPtr && (*WPtr != '\0'))
156 *(WPtr - 1) = '\n';
157 LastWord = WPtr;
160 else
162 *(LastWord - 1) = '\n';
164 LineStart = LastWord;
166 else
167 LastWord = WPtr;
170 return (TRUE);
174 static void SendWarningToFile(FILE *F,
175 const char *S)
177 char *S2;
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 */
189 #endif
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.
196 * param Format
197 * C Format string or a simple message.
198 * param ...
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 */
208 if (!InWarning)
210 #if defined TECPLOTKERNEL
211 /* CORE SOURCE CODE REMOVED */
212 #endif
214 InWarning = TRUE;
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;
224 va_list Arguments;
225 va_start(Arguments, Format);
226 char* message = vFormatString(Format.c_str(), Arguments);
227 va_end(Arguments);
229 if (message == NULL)
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 */
237 #ifdef MSWIN
238 #endif
239 #if defined UNIXX
240 #endif
241 #if defined MSWIN
242 #endif
243 #else /* !TECPLOTKERNEL */
245 SendWarningToFile(stderr, message);
247 #endif
249 if (cleanUp)
250 FREE_ARRAY(message, "message");
252 InWarning = FALSE;
254 #if defined TECPLOTKERNEL
255 /* CORE SOURCE CODE REMOVED */
256 #endif
261 static void SendErrToFile(FILE *File,
262 const char *Msg)
264 char *FormattedMsg;
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");
272 else
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));
282 #ifdef MSWIN
283 #ifdef TECPLOTKERNEL
284 /* CORE SOURCE CODE REMOVED */
285 #else
286 MessageBox(NULL, Msg, "Error", MB_OK | MB_ICONERROR);
287 #endif
288 #else
289 SendErrToFile(stderr, Msg);
290 #endif
293 static void PostErrorMessage(TranslatedString Format,
294 va_list Arguments)
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 */
314 #ifdef MSWIN
315 #endif
316 #if defined UNIXX
317 #if !defined ENGINE
318 #endif
319 #endif
320 #else /* !TECPLOTKERNEL */
322 DefaultErrMsg(messageString);
324 #endif
326 /* cleanup if we allocated the string */
327 if (cleanUp)
328 FREE_ARRAY(messageString, "messageString");
332 * NOTES:
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
336 * batch log file.
338 void vErrMsg(TranslatedString Format,
339 va_list Arguments)
341 REQUIRE(!Format.isNull());
343 static Boolean_t InErrMsg = FALSE; /* ...used to prevent recursive deadlock */
344 if (!InErrMsg)
346 #if defined TECPLOTKERNEL
347 /* CORE SOURCE CODE REMOVED */
348 #endif
350 InErrMsg = TRUE;
352 PostErrorMessage(Format, Arguments);
354 InErrMsg = FALSE;
356 #if defined TECPLOTKERNEL
357 /* CORE SOURCE CODE REMOVED */
358 #endif
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.
366 * @param Format
367 * C Format string or a simple message.
368 * @param ...
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());
377 va_list Arguments;
378 va_start(Arguments, Format);
379 #if defined TECPLOTKERNEL
380 /* CORE SOURCE CODE REMOVED */
381 #else
382 PostErrorMessage(Format, Arguments);
383 #endif
384 va_end(Arguments);
388 #if defined TECPLOTKERNEL
389 /* CORE SOURCE CODE REMOVED */
390 #if !defined ENGINE
391 #endif
392 #if !defined ENGINE
393 #if defined MOTIF
394 #endif
395 #if defined MSWIN
396 #endif
397 #endif
398 #if !defined ENGINE
399 #if defined MOTIF
400 #endif
401 #if defined MSWIN
402 #endif
403 #endif
404 #if !defined ENGINE
405 #if defined MOTIF
406 #endif /* MOTIF */
407 #if defined MSWIN
408 #endif
409 #if defined MOTIF
410 #endif /* MOTIF */
411 #endif
412 #if !defined ENGINE
413 #endif
414 #endif /* TECPLOTKERNEL */