Sophie

Sophie

distrib > Mandriva > 9.0 > i586 > by-pkgid > d67485fb8ce60f8952179bbde3b5d022 > files > 47

libgdal0-devel-1.1.7-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>cpl_error.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.3-20001105 on Thu Mar 28 09:47:27 2002 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; </center>
<hr><h1>cpl_error.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/**********************************************************************</font>
00002 <font class="comment"> * $Id: cpl_error_cpp-source.html,v 1.10 2002/04/16 13:11:47 warmerda Exp $</font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * Name:     cpl_error.cpp</font>
00005 <font class="comment"> * Project:  CPL - Common Portability Library</font>
00006 <font class="comment"> * Purpose:  Error handling functions.</font>
00007 <font class="comment"> * Author:   Daniel Morissette, danmo@videotron.ca</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> **********************************************************************</font>
00010 <font class="comment"> * Copyright (c) 1998, Daniel Morissette</font>
00011 <font class="comment"> *</font>
00012 <font class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</font>
00013 <font class="comment"> * copy of this software and associated documentation files (the "Software"),</font>
00014 <font class="comment"> * to deal in the Software without restriction, including without limitation</font>
00015 <font class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</font>
00016 <font class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</font>
00017 <font class="comment"> * Software is furnished to do so, subject to the following conditions:</font>
00018 <font class="comment"> * </font>
00019 <font class="comment"> * The above copyright notice and this permission notice shall be included</font>
00020 <font class="comment"> * in all copies or substantial portions of the Software.</font>
00021 <font class="comment"> * </font>
00022 <font class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</font>
00023 <font class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</font>
00024 <font class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL</font>
00025 <font class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</font>
00026 <font class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</font>
00027 <font class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER </font>
00028 <font class="comment"> * DEALINGS IN THE SOFTWARE.</font>
00029 <font class="comment"> **********************************************************************</font>
00030 <font class="comment"> *</font>
00031 <font class="comment"> * $Log: cpl_error_cpp-source.html,v $
00031 <font class="comment"> * Revision 1.10  2002/04/16 13:11:47  warmerda
00031 <font class="comment"> * updated
00031 <font class="comment"> *</font>
00032 <font class="comment"> * Revision 1.21  2001/12/14 19:45:17  warmerda</font>
00033 <font class="comment"> * Avoid use of errno in prototype.</font>
00034 <font class="comment"> *</font>
00035 <font class="comment"> * Revision 1.20  2001/11/27 17:01:06  warmerda</font>
00036 <font class="comment"> * added timestamp to debug messages</font>
00037 <font class="comment"> *</font>
00038 <font class="comment"> * Revision 1.19  2001/11/15 16:11:08  warmerda</font>
00039 <font class="comment"> * use vsnprintf() for debug calls if it is available</font>
00040 <font class="comment"> *</font>
00041 <font class="comment"> * Revision 1.18  2001/11/02 22:07:58  warmerda</font>
00042 <font class="comment"> * added logging error handler</font>
00043 <font class="comment"> *</font>
00044 <font class="comment"> * Revision 1.17  2001/07/18 04:00:49  warmerda</font>
00045 <font class="comment"> * added CPL_CVSID</font>
00046 <font class="comment"> *</font>
00047 <font class="comment"> * Revision 1.16  2001/02/15 16:30:57  warmerda</font>
00048 <font class="comment"> * fixed initialization of fpLog</font>
00049 <font class="comment"> *</font>
00050 <font class="comment"> * Revision 1.15  2001/01/19 21:16:41  warmerda</font>
00051 <font class="comment"> * expanded tabs</font>
00052 <font class="comment"> *</font>
00053 <font class="comment"> * Revision 1.14  2000/11/30 17:30:10  warmerda</font>
00054 <font class="comment"> * added CPLGetLastErrorType</font>
00055 <font class="comment"> *</font>
00056 <font class="comment"> * Revision 1.13  2000/03/31 14:37:48  warmerda</font>
00057 <font class="comment"> * only use vsnprintf where available</font>
00058 <font class="comment"> *</font>
00059 <font class="comment"> * Revision 1.12  2000/03/31 14:11:55  warmerda</font>
00060 <font class="comment"> * added CPLErrorV</font>
00061 <font class="comment"> *</font>
00062 <font class="comment"> * Revision 1.11  2000/01/10 17:35:45  warmerda</font>
00063 <font class="comment"> * added push down stack of error handlers</font>
00064 <font class="comment"> *</font>
00065 <font class="comment"> * Revision 1.10  1999/11/23 04:16:56  danmo</font>
00066 <font class="comment"> * Fixed var. initialization that failed to compile as C</font>
00067 <font class="comment"> *</font>
00068 <font class="comment"> * Revision 1.9  1999/09/03 17:03:45  warmerda</font>
00069 <font class="comment"> * Completed partial help line.</font>
00070 <font class="comment"> *</font>
00071 <font class="comment"> * Revision 1.8  1999/07/23 14:27:47  warmerda</font>
00072 <font class="comment"> * CPLSetErrorHandler returns old handler</font>
00073 <font class="comment"> *</font>
00074 <font class="comment"> * Revision 1.7  1999/06/27 16:50:52  warmerda</font>
00075 <font class="comment"> * added support for CPL_DEBUG and CPL_LOG variables</font>
00076 <font class="comment"> *</font>
00077 <font class="comment"> * Revision 1.6  1999/06/26 02:46:11  warmerda</font>
00078 <font class="comment"> * Fixed initialization of debug messages.</font>
00079 <font class="comment"> *</font>
00080 <font class="comment"> * Revision 1.5  1999/05/20 14:59:05  warmerda</font>
00081 <font class="comment"> * added CPLDebug()</font>
00082 <font class="comment"> *</font>
00083 <font class="comment"> * Revision 1.4  1999/05/20 02:54:38  warmerda</font>
00084 <font class="comment"> * Added API documentation</font>
00085 <font class="comment"> *</font>
00086 <font class="comment"> * Revision 1.3  1998/12/15 19:02:27  warmerda</font>
00087 <font class="comment"> * Avoid use of errno as a variable</font>
00088 <font class="comment"> *</font>
00089 <font class="comment"> * Revision 1.2  1998/12/06 02:52:52  warmerda</font>
00090 <font class="comment"> * Implement assert support</font>
00091 <font class="comment"> *</font>
00092 <font class="comment"> * Revision 1.1  1998/12/03 18:26:02  warmerda</font>
00093 <font class="comment"> * New</font>
00094 <font class="comment"> *</font>
00095 <font class="comment"> **********************************************************************/</font>
00096 
00097 <font class="preprocessor">#include "<a class="code" href="cpl_error_h.html">cpl_error.h</a>"</font>
00098 <font class="preprocessor">#include "<a class="code" href="cpl_vsi_h.html">cpl_vsi.h</a>"</font>
00099 
00100 <font class="preprocessor">#define TIMESTAMP_DEBUG</font>
00101 <font class="preprocessor"></font><font class="preprocessor">#ifdef TIMESTAMP_DEBUG</font>
00102 <font class="preprocessor"></font><font class="preprocessor">#include &lt;time.h&gt;</font>
00103 <font class="preprocessor">#endif</font>
00104 <font class="preprocessor"></font>
00105 CPL_CVSID(<font class="stringliteral">"$Id: cpl_error_cpp-source.html,v 1.10 2002/04/16 13:11:47 warmerda Exp $"</font>);
00106 
00107 <font class="comment">/* static buffer to store the last error message.  We'll assume that error</font>
00108 <font class="comment"> * messages cannot be longer than 2000 chars... which is quite reasonable</font>
00109 <font class="comment"> * (that's 25 lines of 80 chars!!!)</font>
00110 <font class="comment"> */</font>
00111 <font class="keyword">static</font> <font class="keywordtype">char</font> gszCPLLastErrMsg[2000] = <font class="stringliteral">""</font>;
00112 <font class="keyword">static</font> <font class="keywordtype">int</font>  gnCPLLastErrNo = 0;
00113 <font class="keyword">static</font> CPLErr geCPLLastErrType = CE_None;
00114 
00115 <font class="keyword">static</font> CPLErrorHandler gpfnCPLErrorHandler = CPLDefaultErrorHandler;
00116 
00117 <font class="keyword">typedef</font> <font class="keyword">struct </font>errHandler
00118 {
00119     <font class="keyword">struct </font>errHandler   *psNext;
00120     CPLErrorHandler     pfnHandler;
00121 } CPLErrorHandlerNode;
00122 
00123 <font class="keyword">static</font> CPLErrorHandlerNode * psHandlerStack = NULL;
00124 
00125 <font class="comment">/**********************************************************************</font>
00126 <font class="comment"> *                          CPLError()</font>
00127 <font class="comment"> **********************************************************************/</font>
00128 
00161 <font class="keywordtype">void</font>    <a class="code" href="cpl_error_h.html#a17">CPLError</a>(CPLErr eErrClass, <font class="keywordtype">int</font> err_no, <font class="keyword">const</font> <font class="keywordtype">char</font> *fmt, ...)<font class="keyword"></font>
00162 <font class="keyword"></font>{
00163     va_list args;
00164 
00165     <font class="comment">/* Expand the error message </font>
00166 <font class="comment">     */</font>
00167     va_start(args, fmt);
00168     CPLErrorV( eErrClass, err_no, fmt, args );
00169     va_end(args);
00170 }
00171 
00172 <font class="comment">/************************************************************************/</font>
00173 <font class="comment">/*                             CPLErrorV()                              */</font>
00174 <font class="comment">/************************************************************************/</font>
00175 
00176 <font class="keywordtype">void</font>    CPLErrorV(CPLErr eErrClass, <font class="keywordtype">int</font> err_no, <font class="keyword">const</font> <font class="keywordtype">char</font> *fmt, va_list args )<font class="keyword"></font>
00177 <font class="keyword"></font>{
00178     <font class="comment">/* Expand the error message </font>
00179 <font class="comment">     */</font>
00180 <font class="preprocessor">#if defined(HAVE_VSNPRINTF)</font>
00181 <font class="preprocessor"></font>    vsnprintf(gszCPLLastErrMsg, <font class="keyword">sizeof</font>(gszCPLLastErrMsg), fmt, args);
00182 <font class="preprocessor">#else</font>
00183 <font class="preprocessor"></font>    vsprintf(gszCPLLastErrMsg, fmt, args);
00184 <font class="preprocessor">#endif</font>
00185 <font class="preprocessor"></font>
00186     <font class="comment">/* If the user provided his own error handling function, then call</font>
00187 <font class="comment">     * it, otherwise print the error to stderr and return.</font>
00188 <font class="comment">     */</font>
00189     gnCPLLastErrNo = err_no;
00190     geCPLLastErrType = eErrClass;
00191 
00192     <font class="keywordflow">if</font>( gpfnCPLErrorHandler )
00193         gpfnCPLErrorHandler(eErrClass, err_no, gszCPLLastErrMsg);
00194 
00195     <font class="keywordflow">if</font>( eErrClass == CE_Fatal )
00196         abort();
00197 }
00198 
00199 <font class="comment">/************************************************************************/</font>
00200 <font class="comment">/*                              CPLDebug()                              */</font>
00201 <font class="comment">/************************************************************************/</font>
00202 
00224 <font class="keywordtype">void</font> <a class="code" href="cpl_error_h.html#a29">CPLDebug</a>( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszCategory, <font class="keyword">const</font> <font class="keywordtype">char</font> * pszFormat, ... )<font class="keyword"></font>
00225 <font class="keyword"></font>
00226 <font class="keyword"></font>{
00227     <font class="keywordtype">char</font>        *pszMessage;
00228     va_list args;
00229     <font class="keyword">const</font> <font class="keywordtype">char</font>      *pszDebug = getenv(<font class="stringliteral">"CPL_DEBUG"</font>);
00230 
00231 <font class="preprocessor">#define ERROR_MAX 25000</font>
00232 <font class="preprocessor"></font>
00233 <font class="comment">/* -------------------------------------------------------------------- */</font>
00234 <font class="comment">/*      Does this message pass our current criteria?                    */</font>
00235 <font class="comment">/* -------------------------------------------------------------------- */</font>
00236     <font class="keywordflow">if</font>( pszDebug == NULL )
00237         <font class="keywordflow">return</font>;
00238 
00239     <font class="keywordflow">if</font>( !EQUAL(pszDebug,<font class="stringliteral">"ON"</font>) &amp;&amp; !EQUAL(pszDebug,<font class="stringliteral">""</font>) )
00240     {
00241         <font class="keywordtype">int</font>            i, nLen = strlen(pszCategory);
00242 
00243         <font class="keywordflow">for</font>( i = 0; pszDebug[i] != <font class="charliteral">'\0'</font>; i++ )
00244         {
00245             <font class="keywordflow">if</font>( EQUALN(pszCategory,pszDebug+i,nLen) )
00246                 <font class="keywordflow">break</font>;
00247         }
00248 
00249         <font class="keywordflow">if</font>( pszDebug[i] == <font class="charliteral">'\0'</font> )
00250             <font class="keywordflow">return</font>;
00251     }
00252 
00253 <font class="comment">/* -------------------------------------------------------------------- */</font>
00254 <font class="comment">/*    Allocate a block for the error.                                   */</font>
00255 <font class="comment">/* -------------------------------------------------------------------- */</font>
00256     pszMessage = (<font class="keywordtype">char</font> *) VSIMalloc(ERROR_MAX);
00257     <font class="keywordflow">if</font>( pszMessage == NULL )
00258         <font class="keywordflow">return</font>;
00259         
00260 <font class="comment">/* -------------------------------------------------------------------- */</font>
00261 <font class="comment">/*      Dal -- always log a timestamp as the first part of the line     */</font>
00262 <font class="comment">/*      to ensure one is looking at what one should be looking at!      */</font>
00263 <font class="comment">/* -------------------------------------------------------------------- */</font>
00264 
00265 <font class="preprocessor">#ifdef TIMESTAMP_DEBUG</font>
00266 <font class="preprocessor"></font>    {
00267         time_t ltime;
00268     
00269         time( &amp;ltime );
00270         strcpy( pszMessage, ctime( &amp;ltime ) );
00271         
00272         <font class="comment">// On windows anyway, ctime puts a \n at the end, but I'm not </font>
00273         <font class="comment">// convinced this is standard behaviour, so we'll get rid of it</font>
00274         <font class="comment">// carefully</font>
00275 
00276         <font class="keywordflow">if</font> (pszMessage[strlen(pszMessage) -1 ] == <font class="charliteral">'\n'</font>)
00277         {
00278             pszMessage[strlen(pszMessage) - 1] = 0; <font class="comment">// blow it out</font>
00279         }
00280         strcat( pszMessage, <font class="stringliteral">": "</font> );
00281     }
00282 <font class="preprocessor">#else</font>
00283 <font class="preprocessor"></font>    pszMessage[0] = <font class="charliteral">'\0'</font>;
00284 <font class="preprocessor">#endif</font>
00285 <font class="preprocessor"></font>
00286 <font class="comment">/* -------------------------------------------------------------------- */</font>
00287 <font class="comment">/*      Add the category.                                               */</font>
00288 <font class="comment">/* -------------------------------------------------------------------- */</font>
00289     strcat( pszMessage, pszCategory );
00290     strcat( pszMessage, <font class="stringliteral">": "</font> );
00291     
00292 <font class="comment">/* -------------------------------------------------------------------- */</font>
00293 <font class="comment">/*      Format the application provided portion of the debug message.   */</font>
00294 <font class="comment">/* -------------------------------------------------------------------- */</font>
00295     va_start(args, pszFormat);
00296 <font class="preprocessor">#if defined(HAVE_VSNPRINTF)</font>
00297 <font class="preprocessor"></font>    vsnprintf(pszMessage+strlen(pszMessage), ERROR_MAX - strlen(pszMessage), 
00298               pszFormat, args);
00299 <font class="preprocessor">#else</font>
00300 <font class="preprocessor"></font>    vsprintf(pszMessage+strlen(pszMessage), pszFormat, args);
00301 <font class="preprocessor">#endif</font>
00302 <font class="preprocessor"></font>    va_end(args);
00303 
00304 <font class="comment">/* -------------------------------------------------------------------- */</font>
00305 <font class="comment">/*      If the user provided his own error handling function, then call */</font>
00306 <font class="comment">/*      it, otherwise print the error to stderr and return.             */</font>
00307 <font class="comment">/* -------------------------------------------------------------------- */</font>
00308     <font class="keywordflow">if</font>( gpfnCPLErrorHandler )
00309         gpfnCPLErrorHandler(CE_Debug, CPLE_None, pszMessage);
00310 
00311     VSIFree( pszMessage );
00312 }
00313 
00314 <font class="comment">/**********************************************************************</font>
00315 <font class="comment"> *                          CPLErrorReset()</font>
00316 <font class="comment"> **********************************************************************/</font>
00317 
00325 <font class="keywordtype">void</font>    <a class="code" href="cpl_error_h.html#a19">CPLErrorReset</a>()<font class="keyword"></font>
00326 <font class="keyword"></font>{
00327     gnCPLLastErrNo = CPLE_None;
00328     gszCPLLastErrMsg[0] = <font class="charliteral">'\0'</font>;
00329     geCPLLastErrType = CE_None;
00330 }
00331 
00332 
00333 <font class="comment">/**********************************************************************</font>
00334 <font class="comment"> *                          CPLGetLastErrorNo()</font>
00335 <font class="comment"> **********************************************************************/</font>
00336 
00346 <font class="keywordtype">int</font>     <a class="code" href="cpl_error_h.html#a20">CPLGetLastErrorNo</a>()<font class="keyword"></font>
00347 <font class="keyword"></font>{
00348     <font class="keywordflow">return</font> gnCPLLastErrNo;
00349 }
00350 
00351 <font class="comment">/**********************************************************************</font>
00352 <font class="comment"> *                          CPLGetLastErrorType()</font>
00353 <font class="comment"> **********************************************************************/</font>
00354 
00364 CPLErr <a class="code" href="cpl_error_h.html#a21">CPLGetLastErrorType</a>()<font class="keyword"></font>
00365 <font class="keyword"></font>{
00366     <font class="keywordflow">return</font> geCPLLastErrType;
00367 }
00368 
00369 <font class="comment">/**********************************************************************</font>
00370 <font class="comment"> *                          CPLGetLastErrorMsg()</font>
00371 <font class="comment"> **********************************************************************/</font>
00372 
00384 <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="cpl_error_h.html#a22">CPLGetLastErrorMsg</a>()<font class="keyword"></font>
00385 <font class="keyword"></font>{
00386     <font class="keywordflow">return</font> gszCPLLastErrMsg;
00387 }
00388 
00389 <font class="comment">/************************************************************************/</font>
00390 <font class="comment">/*                       CPLDefaultErrorHandler()                       */</font>
00391 <font class="comment">/************************************************************************/</font>
00392 
00393 <font class="keywordtype">void</font> CPLDefaultErrorHandler( CPLErr eErrClass, <font class="keywordtype">int</font> nError, 
00394                              <font class="keyword">const</font> <font class="keywordtype">char</font> * pszErrorMsg )<font class="keyword"></font>
00395 <font class="keyword"></font>
00396 <font class="keyword"></font>{
00397     <font class="keyword">static</font> <font class="keywordtype">int</font>       bLogInit = FALSE;
00398     <font class="keyword">static</font> FILE *    fpLog = stderr;
00399 
00400     <font class="keywordflow">if</font>( !bLogInit )
00401     {
00402         bLogInit = TRUE;
00403 
00404         fpLog = stderr;
00405         <font class="keywordflow">if</font>( getenv( <font class="stringliteral">"CPL_LOG"</font> ) != NULL )
00406         {
00407             fpLog = fopen( getenv(<font class="stringliteral">"CPL_LOG"</font>), <font class="stringliteral">"wt"</font> );
00408             <font class="keywordflow">if</font>( fpLog == NULL )
00409                 fpLog = stderr;
00410         }
00411     }
00412 
00413     <font class="keywordflow">if</font>( eErrClass == CE_Debug )
00414         fprintf( fpLog, <font class="stringliteral">"%s\n"</font>, pszErrorMsg );
00415     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( eErrClass == CE_Warning )
00416         fprintf( fpLog, <font class="stringliteral">"Warning %d: %s\n"</font>, nError, pszErrorMsg );
00417     <font class="keywordflow">else</font>
00418         fprintf( fpLog, <font class="stringliteral">"ERROR %d: %s\n"</font>, nError, pszErrorMsg );
00419 
00420     fflush( fpLog );
00421 }
00422 
00423 <font class="comment">/************************************************************************/</font>
00424 <font class="comment">/*                        CPLQuietErrorHandler()                        */</font>
00425 <font class="comment">/************************************************************************/</font>
00426 
00427 <font class="keywordtype">void</font> CPLQuietErrorHandler( CPLErr eErrClass , <font class="keywordtype">int</font> nError, 
00428                            <font class="keyword">const</font> <font class="keywordtype">char</font> * pszErrorMsg )<font class="keyword"></font>
00429 <font class="keyword"></font>
00430 <font class="keyword"></font>{
00431     <font class="keywordflow">if</font>( eErrClass == CE_Debug )
00432         CPLDefaultErrorHandler( eErrClass, nError, pszErrorMsg );
00433 }
00434 
00435 <font class="comment">/************************************************************************/</font>
00436 <font class="comment">/*                       CPLLoggingErrorHandler()                       */</font>
00437 <font class="comment">/************************************************************************/</font>
00438 
00439 <font class="keywordtype">void</font> CPLLoggingErrorHandler( CPLErr eErrClass, <font class="keywordtype">int</font> nError, 
00440                              <font class="keyword">const</font> <font class="keywordtype">char</font> * pszErrorMsg )<font class="keyword"></font>
00441 <font class="keyword"></font>
00442 <font class="keyword"></font>{
00443     <font class="keyword">static</font> <font class="keywordtype">int</font>       bLogInit = FALSE;
00444     <font class="keyword">static</font> FILE *    fpLog = stderr;
00445 
00446     <font class="keywordflow">if</font>( !bLogInit )
00447     {
00448         <font class="keyword">const</font> <font class="keywordtype">char</font> *cpl_log = NULL;
00449 
00450         bLogInit = TRUE;
00451 
00452         <font class="keywordflow">if</font>( getenv(<font class="stringliteral">"CPL_LOG"</font>) != NULL )
00453             cpl_log = getenv(<font class="stringliteral">"CPL_LOG"</font>);
00454 
00455         fpLog = stderr;
00456         <font class="keywordflow">if</font>( cpl_log != NULL &amp;&amp; EQUAL(cpl_log,<font class="stringliteral">"OFF"</font>) )
00457         {
00458             fpLog = NULL;
00459         }
00460         <font class="keywordflow">else</font> <font class="keywordflow">if</font>( cpl_log != NULL )
00461         {
00462             <font class="keywordtype">char</font>      path[5000];
00463             <font class="keywordtype">int</font>       i = 0;
00464 
00465             strcpy( path, cpl_log );
00466 
00467             <font class="keywordflow">while</font>( (fpLog = fopen( path, <font class="stringliteral">"rt"</font> )) != NULL ) 
00468             {
00469                 fclose( fpLog );
00470 
00471                 sprintf( path, <font class="stringliteral">"%s_%d"</font>, cpl_log, i++ );
00472             }
00473 
00474             fpLog = fopen( path, <font class="stringliteral">"wt"</font> );
00475         }
00476     }
00477 
00478     <font class="keywordflow">if</font>( fpLog == NULL )
00479         <font class="keywordflow">return</font>;
00480 
00481     <font class="keywordflow">if</font>( eErrClass == CE_Debug )
00482         fprintf( fpLog, <font class="stringliteral">"%s\n"</font>, pszErrorMsg );
00483     <font class="keywordflow">else</font> <font class="keywordflow">if</font>( eErrClass == CE_Warning )
00484         fprintf( fpLog, <font class="stringliteral">"Warning %d: %s\n"</font>, nError, pszErrorMsg );
00485     <font class="keywordflow">else</font>
00486         fprintf( fpLog, <font class="stringliteral">"ERROR %d: %s\n"</font>, nError, pszErrorMsg );
00487 
00488     fflush( fpLog );
00489 }
00490 
00491 <font class="comment">/**********************************************************************</font>
00492 <font class="comment"> *                          CPLSetErrorHandler()</font>
00493 <font class="comment"> **********************************************************************/</font>
00494 
00524 CPLErrorHandler <a class="code" href="cpl_error_h.html#a23">CPLSetErrorHandler</a>( CPLErrorHandler pfnErrorHandler )<font class="keyword"></font>
00525 <font class="keyword"></font>{
00526     CPLErrorHandler     pfnOldHandler = gpfnCPLErrorHandler;
00527     
00528     gpfnCPLErrorHandler = pfnErrorHandler;
00529 
00530     <font class="keywordflow">return</font> pfnOldHandler;
00531 }
00532 
00533 
00534 
00535 <font class="comment">/************************************************************************/</font>
00536 <font class="comment">/*                        CPLPushErrorHandler()                         */</font>
00537 <font class="comment">/************************************************************************/</font>
00538 
00550 <font class="keywordtype">void</font> <a class="code" href="cpl_error_h.html#a24">CPLPushErrorHandler</a>( CPLErrorHandler pfnErrorHandler )<font class="keyword"></font>
00551 <font class="keyword"></font>
00552 <font class="keyword"></font>{
00553     CPLErrorHandlerNode         *psNode;
00554 
00555     psNode = (CPLErrorHandlerNode *) VSIMalloc(<font class="keyword">sizeof</font>(CPLErrorHandlerNode));
00556     psNode-&gt;psNext = psHandlerStack;
00557     psNode-&gt;pfnHandler = gpfnCPLErrorHandler;
00558 
00559     psHandlerStack = psNode;
00560 
00561     <a class="code" href="cpl_error_h.html#a23">CPLSetErrorHandler</a>( pfnErrorHandler );
00562 }
00563 
00564 <font class="comment">/************************************************************************/</font>
00565 <font class="comment">/*                         CPLPopErrorHandler()                         */</font>
00566 <font class="comment">/************************************************************************/</font>
00567 
00575 <font class="keywordtype">void</font> <a class="code" href="cpl_error_h.html#a25">CPLPopErrorHandler</a>()<font class="keyword"></font>
00576 <font class="keyword"></font>
00577 <font class="keyword"></font>{
00578     <font class="keywordflow">if</font>( psHandlerStack != NULL )
00579     {
00580         CPLErrorHandlerNode     *psNode = psHandlerStack;
00581 
00582         psHandlerStack = psNode-&gt;psNext;
00583         <a class="code" href="cpl_error_h.html#a23">CPLSetErrorHandler</a>( psNode-&gt;pfnHandler );
00584         VSIFree( psNode );
00585     }
00586 }
00587 
00588 <font class="comment">/************************************************************************/</font>
00589 <font class="comment">/*                             _CPLAssert()                             */</font>
00590 <font class="comment">/*                                                                      */</font>
00591 <font class="comment">/*      This function is called only when an assertion fails.           */</font>
00592 <font class="comment">/************************************************************************/</font>
00593 
00606 <font class="keywordtype">void</font> <a class="code" href="cpl_error_h.html#a30">_CPLAssert</a>( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszExpression, <font class="keyword">const</font> <font class="keywordtype">char</font> * pszFile,
00607                  <font class="keywordtype">int</font> iLine )<font class="keyword"></font>
00608 <font class="keyword"></font>
00609 <font class="keyword"></font>{
00610     <a class="code" href="cpl_error_h.html#a17">CPLError</a>( CE_Fatal, CPLE_AssertionFailed,
00611               <font class="stringliteral">"Assertion `%s' failed\n"</font>
00612               <font class="stringliteral">"in file `%s', line %d\n"</font>,
00613               pszExpression, pszFile, iLine );
00614 }
00615 
</div></pre><hr><address><small>Generated at Thu Mar 28 09:47:27 2002 for GDAL by
<a href="http://www.stack.nl/~dimitri/doxygen/index.html">
<img src="doxygen.gif" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.3-20001105 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2000</small></address>
</body>
</html>