Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / postProcessing / dataConversion / foamToTecplot360 / tecio / tecsrc / tassert.cpp
blobf74a2d30e645b6a12c77fc27351e2aa58d53c547
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"
26 #define TECPLOTENGINEMODULE
29 *****************************************************************
30 *****************************************************************
31 ******* ********
32 ****** Copyright (C) 1988-2008 Tecplot, Inc. *******
33 ******* ********
34 *****************************************************************
35 *****************************************************************
38 #define TASSERTMODULE
39 #include "GLOBAL.h"
40 #include "TASSERT.h"
41 #include "Q_UNICODE.h"
42 #if defined TECPLOTKERNEL
43 /* CORE SOURCE CODE REMOVED */
44 #if defined (MSWIN)
45 #endif
46 #endif
48 #include "STRUTIL.h"
50 using namespace tecplot::strutil;
51 using namespace std;
53 #define MAX_ERRMSG_LENGTH 2096
55 /* the mopup from assert and the writing out of crash.lay are */
56 /* used by TUASSERT and thus are needed even if NO_ASSERTS */
57 /* is set */
58 #if !defined NO_TU_ASSERTS || !defined NO_ASSERTS
60 #if defined TECPLOTKERNEL
61 /* CORE SOURCE CODE REMOVED */
62 #if defined MSWIN /* ...Unix/Linux calls this via signal handlers */
63 #endif
64 #endif /* TECPLOTKERNEL */
66 #endif /* Mopup function needed ... */
70 #if !defined STD_ASSERTS
72 * Define the final assertion notification function.
74 #if defined UNIXX && !defined NO_ASSERTS
75 /*******************************************************************
76 * *
77 * UNIX *
78 * *
79 *******************************************************************/
82 # if defined NDEBUG
84 * if NDEBUG is defined __assert is NOT defined so we must supply
85 * our own assertion notification function.....
87 # define ASSERT assert
88 static void UnixAssert(const char *expression,
89 const char *file_name,
90 int line)
92 fprintf(stderr, "Assertion: %s\n"
93 "Tecplot version: %s\n"
94 "File Name: %s\n"
95 "Line Number: %d\n",
96 expression, TecVersionId, file_name, line);
97 exit(ExitCode_AssertionFailure);
99 static TAssertFailureNotifyFunc assert_failure_notify = UnixAssert;
100 # else
102 * NDEBUG is not defined so __assert is available....
104 # if defined LINUX
105 # define LOWLEVELASSERTFUNCTION __linuxassertproxy
107 * In linux, __assert does not exist but rather
108 * __assert_fail which has a differnt API. Thus
109 * a proxy is provided
111 static void __linuxassertproxy(const char *__assertion,
112 const char *__file,
113 int __line)
115 __assert_fail(__assertion, __file, __line, __ASSERT_FUNCTION);
117 # elif defined DARWIN
118 # define LOWLEVELASSERTFUNCTION __darwinassertproxy
120 * In Darwin (Mac OS X), __assert is #defined to a call to __eprintf,
121 * which also has a different API. Another proxy...
123 static void __darwinassertproxy(const char *__assertion,
124 const char *__file,
125 int __line)
127 __eprintf("Assertion: %s\n"
128 "Tecplot version: %s\n"
129 "File Name: %s\n"
130 "Line Number: %d\n",
131 __assertion, TecVersionId, __file, (unsigned)__line);
133 # else
134 # define LOWLEVELASSERTFUNCTION __assert
135 # endif
137 static TAssertFailureNotifyFunc assert_failure_notify = (TAssertFailureNotifyFunc) LOWLEVELASSERTFUNCTION;
139 # endif
140 #endif /* UNIXX */
142 #if defined UNIXX && !defined NO_ASSERTS
144 * Replace the current assert failure notification function and
145 * return the current one.
147 * Assumptions:
148 * new function points to valid function (not null) that
149 * conforms to the specified prototype
151 * Guarantees:
152 * result is a pointer to the previously installed
153 * function (not null)
155 TAssertFailureNotifyFunc InstallTAssertFailureNotify(
156 TAssertFailureNotifyFunc new_function) /* new notification function */
158 TAssertFailureNotifyFunc result = 0; /* old function address */
160 ASSERT(new_function != 0);
162 result = assert_failure_notify;
163 assert_failure_notify = new_function;
165 ASSERT(result != 0);
166 return result;
175 * Perform the installed assert failure notification action.
177 void TAssert(const char *expression, /* text representation of the assertion */
178 const char *file_name, /* name of the file containing the assertion */
179 int line) /* line number in the file of the assertion */
181 static Boolean_t InTAssert = FALSE;
182 #if defined TECPLOTKERNEL
183 /* CORE SOURCE CODE REMOVED */
184 #endif
185 char Message[MAX_ERRMSG_LENGTH+1];
186 ASSERT(expression != 0 && strlen(expression) != 0);
187 ASSERT(file_name != 0 && strlen(file_name) != 0);
188 ASSERT(line >= 1);
190 /* check for recursion */
191 if (InTAssert)
193 fprintf(stderr, "Already in assert!\n");
194 fprintf(stderr, "Assertion: %s\n"
195 "Tecplot version: %s\n"
196 "File Name: %s\n"
197 "Line Number: %d\n",
198 expression, TecVersionId, file_name, line);
199 PrintCurBacktrace(stderr, 100);
200 ASSERT(FALSE); /*... really exit */
203 InTAssert = TRUE;
205 sprintf(Message, "Assertion: %s\n"
206 "Tecplot version: %s\n"
207 "File Name: %s\n"
208 "Line Number: %d\n",
209 expression, TecVersionId, file_name, line);
211 #if defined TECPLOTKERNEL
212 /* CORE SOURCE CODE REMOVED */
213 #endif
215 # if defined TECPLOTKERNEL
216 /* CORE SOURCE CODE REMOVED */
217 # else
218 fprintf(stderr, "%s", Message);
219 # endif
221 #if defined TECPLOTKERNEL
222 /* CORE SOURCE CODE REMOVED */
223 #endif
225 (*assert_failure_notify)(expression, file_name, line);
226 #if defined TECPLOTKERNEL
227 /* CORE SOURCE CODE REMOVED */
228 #endif
230 #if defined TECPLOTKERNEL
231 /* CORE SOURCE CODE REMOVED */
232 #endif
234 InTAssert = FALSE; /* just in case assert_failure_notify has an ignore */
236 #endif /* defined UNIXX && !defined NO_ASSERTS */
237 #endif /* STD_ASSERTS */
240 #if defined MSWIN && defined TECPLOTKERNEL
241 /* CORE SOURCE CODE REMOVED */
242 #if defined CHECKED_BUILD
243 #endif
244 #if !defined ENGINE
245 # if defined CHECKED_BUILD
246 # endif // CHECKED_BUILD
247 #endif //!ENGINE
248 #endif /* MSWIN */
251 #if defined NICE_NOT_IMPLEMENTED
252 static Boolean_t NotImplementedCalled = FALSE;
253 void NiceNotImplemented(void)
255 if (!NotImplementedCalled)
257 Warning("Not Implemented!");
258 NotImplementedCalled = TRUE;
261 #endif