00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 #ifndef CPL_SERV_H_INCLUDED
00030 #define CPL_SERV_H_INCLUDED
00031 
00032 
00033 
00034 
00035 
00036 #include "geo_config.h"
00037 #include <stdio.h>
00038 
00039 #include <math.h>
00040 
00041 #ifdef HAVE_STRING_H
00042 #  include <string.h>
00043 #endif
00044 #if defined(HAVE_STRINGS_H) && !defined(HAVE_STRING_H)
00045 #  include <strings.h>
00046 #endif
00047 #ifdef HAVE_STDLIB_H
00048 #  include <stdlib.h>
00049 #endif
00050 
00051 
00052 
00053 
00054 #if !defined(CPL_DLL)
00055 #  if defined(_WIN32) && defined(BUILD_AS_DLL)
00056 #    define CPL_DLL     __declspec(dllexport)
00057 #  else
00058 #    define CPL_DLL
00059 #  endif
00060 #endif
00061 
00062 
00063 
00064 
00065 #ifdef __cplusplus
00066 #  define CPL_C_START           extern "C" {
00067 #  define CPL_C_END             }
00068 #else
00069 #  define CPL_C_START
00070 #  define CPL_C_END
00071 #endif
00072 
00073 #ifndef NULL
00074 #  define NULL  0
00075 #endif
00076 
00077 #ifndef FALSE
00078 #  define FALSE 0
00079 #endif
00080 
00081 #ifndef TRUE
00082 #  define TRUE  1
00083 #endif
00084 
00085 #ifndef MAX
00086 #  define MIN(a,b)      ((a<b) ? a : b)
00087 #  define MAX(a,b)      ((a>b) ? a : b)
00088 #endif
00089 
00090 #ifndef NULL
00091 #define NULL 0
00092 #endif
00093 
00094 #ifndef ABS
00095 #  define ABS(x)        ((x<0) ? (-1*(x)) : x)
00096 #endif
00097 
00098 #ifndef EQUAL
00099 #if defined(_WIN32) && !defined(__CYGWIN__)
00100 #  define EQUALN(a,b,n)           (strnicmp(a,b,n)==0)
00101 #  define EQUAL(a,b)              (stricmp(a,b)==0)
00102 #else
00103 #  define EQUALN(a,b,n)           (strncasecmp(a,b,n)==0)
00104 #  define EQUAL(a,b)              (strcasecmp(a,b)==0)
00105 #endif
00106 #endif
00107 
00108 
00109 
00110 
00111 
00112 #define VSIFOpen        fopen
00113 #define VSIFClose       fclose
00114 #define VSIFEof         feof
00115 #define VSIFPrintf      fprintf
00116 #define VSIFPuts        fputs
00117 #define VSIFPutc        fputc
00118 #define VSIFGets        fgets
00119 #define VSIRewind       rewind
00120 
00121 #define VSICalloc(x,y)  _GTIFcalloc(x*y)
00122 #define VSIMalloc       _GTIFcalloc
00123 #define VSIFree         _GTIFFree
00124 #define VSIRealloc      _GTIFrealloc
00125 
00126 
00127 
00128 
00129 
00130 CPL_C_START
00131 void  *CPLMalloc( int );
00132 void  *CPLCalloc( int, int );
00133 void  *CPLRealloc( void *, int );
00134 char  *CPLStrdup( const char * );
00135 
00136 #define CPLFree VSIFree
00137 
00138 
00139 
00140 
00141 const char *CPLReadLine( FILE * );
00142 
00143 
00144 
00145 
00146 
00147 typedef enum
00148 {
00149     CE_None = 0,
00150     CE_Log = 1,
00151     CE_Warning = 2,
00152     CE_Failure = 3,
00153     CE_Fatal = 4
00154   
00155 } CPLErr;
00156 
00157 void  CPLError(CPLErr eErrClass, int err_no, const char *fmt, ...);
00158 void  CPLErrorReset();
00159 int  CPLGetLastErrorNo();
00160 const char  * CPLGetLastErrorMsg();
00161 void  CPLSetErrorHandler(void(*pfnErrorHandler)(CPLErr,int,
00162                                                        const char *));
00163 void  _CPLAssert( const char *, const char *, int );
00164 
00165 #ifdef DEBUG
00166 #  define CPLAssert(expr)  ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
00167 #else
00168 #  define CPLAssert(expr)
00169 #endif
00170 
00171 CPL_C_END
00172 
00173 
00174 
00175 
00176 
00177 #define CPLE_AppDefined                 1
00178 #define CPLE_OutOfMemory                2
00179 #define CPLE_FileIO                     3
00180 #define CPLE_OpenFailed                 4
00181 #define CPLE_IllegalArg                 5
00182 #define CPLE_NotSupported               6
00183 #define CPLE_AssertionFailed            7
00184 #define CPLE_NoWriteAccess              8
00185 
00186 
00187 
00188 
00189 CPL_C_START
00190 
00191 char    **CSLAddString(char **papszStrList, const char *pszNewString);
00192 int     CSLCount(char **papszStrList);
00193 const char *CSLGetField( char **, int );
00194 void    CSLDestroy(char **papszStrList);
00195 char    **CSLDuplicate(char **papszStrList);
00196 
00197 char    **CSLTokenizeString(const char *pszString );
00198 char    **CSLTokenizeStringComplex(const char *pszString,
00199                                    const char *pszDelimiter,
00200                                    int bHonourStrings, int bAllowEmptyTokens );
00201 
00202 int     CSLPrint(char **papszStrList, FILE *fpOut);
00203 char    **CSLLoad(const char *pszFname);
00204 int     CSLSave(char **papszStrList, const char *pszFname);
00205 
00206 char  **CSLInsertStrings(char **papszStrList, int nInsertAtLineNo, 
00207                          char **papszNewLines);
00208 char  **CSLInsertString(char **papszStrList, int nInsertAtLineNo, 
00209                         char *pszNewLine);
00210 char  **CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete,
00211                          int nNumToRemove, char ***ppapszRetStrings);
00212 
00213 const char *CPLSPrintf(char *fmt, ...);
00214 char  **CSLAppendPrintf(char **papszStrList, char *fmt, ...);
00215 
00216 const char *CSLFetchNameValue(char **papszStrList, const char *pszName);
00217 char  **CSLFetchNameValueMultiple(char **papszStrList, const char *pszName);
00218 char  **CSLAddNameValue(char **papszStrList, 
00219                         const char *pszName, const char *pszValue);
00220 char  **CSLSetNameValue(char **papszStrList, 
00221                         const char *pszName, const char *pszValue);
00222 
00223 CPL_C_END
00224 
00225 #endif