00001 /****************************************************************************** 00002 * $Id: cpl_conv.h,v 1.35 2004/11/17 22:57:21 fwarmerdam Exp $ 00003 * 00004 * Project: CPL - Common Portability Library 00005 * Purpose: Convenience functions declarations. 00006 * This is intended to remain light weight. 00007 * Author: Frank Warmerdam, warmerdam@pobox.com 00008 * 00009 ****************************************************************************** 00010 * Copyright (c) 1998, Frank Warmerdam 00011 * 00012 * Permission is hereby granted, free of charge, to any person obtaining a 00013 * copy of this software and associated documentation files (the "Software"), 00014 * to deal in the Software without restriction, including without limitation 00015 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00016 * and/or sell copies of the Software, and to permit persons to whom the 00017 * Software is furnished to do so, subject to the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be included 00020 * in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00023 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00024 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00025 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00026 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00027 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00028 * DEALINGS IN THE SOFTWARE. 00029 ****************************************************************************** 00030 * 00031 * $Log: cpl_conv.h,v $ 00032 * Revision 1.35 2004/11/17 22:57:21 fwarmerdam 00033 * added CPLScanPointer() and CPLPrintPointer() 00034 * 00035 * Revision 1.34 2004/08/16 20:24:07 warmerda 00036 * added CPLUnlinkTree 00037 * 00038 * Revision 1.33 2004/08/11 18:41:46 warmerda 00039 * added CPLExtractRelativePath 00040 * 00041 * Revision 1.32 2004/07/31 04:51:36 warmerda 00042 * added shared file open support 00043 * 00044 * Revision 1.31 2004/03/28 16:22:02 warmerda 00045 * const correctness changes in scan functions 00046 * 00047 * Revision 1.30 2004/03/24 09:01:17 dron 00048 * Added CPLPrintUIntBig(). 00049 * 00050 * Revision 1.29 2004/02/07 14:03:30 dron 00051 * CPLDecToPackedDMS() added. 00052 * 00053 * Revision 1.28 2004/02/01 08:37:55 dron 00054 * Added CPLPackedDMSToDec(). 00055 * 00056 * Revision 1.27 2003/12/28 17:24:43 warmerda 00057 * added CPLFreeConfig 00058 * 00059 * Revision 1.26 2003/10/17 07:06:06 dron 00060 * Added locale selection option to CPLScanDouble() and CPLPrintDOuble(). 00061 * 00062 * Revision 1.25 2003/09/28 14:14:16 dron 00063 * Added CPLScanString(). 00064 * 00065 * Revision 1.24 2003/09/08 11:09:53 dron 00066 * Added CPLPrintDouble() and CPLPrintTime(). 00067 * 00068 * Revision 1.23 2003/09/07 14:38:43 dron 00069 * Added CPLPrintString(), CPLPrintStringFill(), CPLPrintInt32(), CPLPrintUIntBig(). 00070 * 00071 * Revision 1.22 2003/08/31 14:48:05 dron 00072 * Added CPLScanLong() and CPLScanDouble(). 00073 * 00074 * Revision 1.21 2003/08/25 20:01:58 dron 00075 * Added CPLFGets() helper function. 00076 * 00077 * Revision 1.20 2003/05/08 21:51:14 warmerda 00078 * added CPL{G,S}etConfigOption() usage 00079 * 00080 * Revision 1.19 2003/03/02 04:44:38 warmerda 00081 * added CPLStringToComplex 00082 * 00083 * Revision 1.18 2002/12/13 06:00:54 warmerda 00084 * added CPLProjectRelativeFilename() and CPLIsFilenameRelative() 00085 * 00086 * Revision 1.17 2002/12/09 18:52:51 warmerda 00087 * added DMS conversion 00088 * 00089 * Revision 1.16 2002/12/03 04:42:02 warmerda 00090 * improved finder cleanup support 00091 * 00092 * Revision 1.15 2002/08/15 09:23:24 dron 00093 * Added CPLGetDirname() function 00094 * 00095 * Revision 1.14 2002/02/01 20:39:50 warmerda 00096 * ensure CPLReadLine() is exported from DLL 00097 * 00098 * Revision 1.13 2001/12/12 17:06:57 warmerda 00099 * added CPLStat 00100 * 00101 * Revision 1.12 2001/03/16 22:15:08 warmerda 00102 * added CPLResetExtension 00103 * 00104 * Revision 1.1 1998/10/18 06:15:11 warmerda 00105 * Initial implementation. 00106 * 00107 */ 00108 00109 #ifndef CPL_CONV_H_INCLUDED 00110 #define CPL_CONV_H_INCLUDED 00111 00112 #include "cpl_port.h" 00113 #include "cpl_vsi.h" 00114 #include "cpl_error.h" 00115 00123 /* -------------------------------------------------------------------- */ 00124 /* Runtime check of various configuration items. */ 00125 /* -------------------------------------------------------------------- */ 00126 CPL_C_START 00127 00128 void CPL_DLL CPLVerifyConfiguration(); 00129 00130 const char CPL_DLL *CPLGetConfigOption( const char *, const char * ); 00131 void CPL_DLL CPLSetConfigOption( const char *, const char * ); 00132 void CPL_DLL CPLFreeConfig(); 00133 00134 /* -------------------------------------------------------------------- */ 00135 /* Safe malloc() API. Thin cover over VSI functions with fatal */ 00136 /* error reporting if memory allocation fails. */ 00137 /* -------------------------------------------------------------------- */ 00138 void CPL_DLL *CPLMalloc( size_t ); 00139 void CPL_DLL *CPLCalloc( size_t, size_t ); 00140 void CPL_DLL *CPLRealloc( void *, size_t ); 00141 char CPL_DLL *CPLStrdup( const char * ); 00142 00143 #define CPLFree VSIFree 00144 00145 /* -------------------------------------------------------------------- */ 00146 /* Read a line from a text file, and strip of CR/LF. */ 00147 /* -------------------------------------------------------------------- */ 00148 char CPL_DLL *CPLFGets( char *, int, FILE *); 00149 const char CPL_DLL *CPLReadLine( FILE * ); 00150 00151 /* -------------------------------------------------------------------- */ 00152 /* Read a numeric value from an ASCII character string. */ 00153 /* -------------------------------------------------------------------- */ 00154 char CPL_DLL *CPLScanString( const char *, int, int, int ); 00155 double CPL_DLL CPLScanDouble( const char *, int, char * ); 00156 long CPL_DLL CPLScanLong( const char *, int ); 00157 GUIntBig CPL_DLL CPLScanUIntBig( const char *, int ); 00158 void CPL_DLL *CPLScanPointer( const char *, int ); 00159 00160 /* -------------------------------------------------------------------- */ 00161 /* Print a value to an ASCII character string. */ 00162 /* -------------------------------------------------------------------- */ 00163 int CPL_DLL CPLPrintString( char *, const char *, int ); 00164 int CPL_DLL CPLPrintStringFill( char *, const char *, int ); 00165 int CPL_DLL CPLPrintInt32( char *, GInt32 , int ); 00166 int CPL_DLL CPLPrintUIntBig( char *, GUIntBig , int ); 00167 int CPL_DLL CPLPrintDouble( char *, const char *, double, char * ); 00168 int CPL_DLL CPLPrintTime( char *, int , const char *, const struct tm *, 00169 char * ); 00170 int CPL_DLL CPLPrintPointer( char *, void *, int ); 00171 00172 /* -------------------------------------------------------------------- */ 00173 /* Fetch a function from DLL / so. */ 00174 /* -------------------------------------------------------------------- */ 00175 00176 void CPL_DLL *CPLGetSymbol( const char *, const char * ); 00177 00178 /* -------------------------------------------------------------------- */ 00179 /* Read a directory (cpl_dir.c) */ 00180 /* -------------------------------------------------------------------- */ 00181 char CPL_DLL **CPLReadDir( const char *pszPath ); 00182 00183 /* -------------------------------------------------------------------- */ 00184 /* Filename handling functions. */ 00185 /* -------------------------------------------------------------------- */ 00186 const char CPL_DLL *CPLGetPath( const char * ); 00187 const char CPL_DLL *CPLGetDirname( const char * ); 00188 const char CPL_DLL *CPLGetFilename( const char * ); 00189 const char CPL_DLL *CPLGetBasename( const char * ); 00190 const char CPL_DLL *CPLGetExtension( const char * ); 00191 const char CPL_DLL *CPLFormFilename( const char *pszPath, 00192 const char *pszBasename, 00193 const char *pszExtension ); 00194 const char CPL_DLL *CPLFormCIFilename( const char *pszPath, 00195 const char *pszBasename, 00196 const char *pszExtension ); 00197 const char CPL_DLL *CPLResetExtension( const char *, const char * ); 00198 const char CPL_DLL *CPLProjectRelativeFilename( const char *pszProjectDir, 00199 const char *pszSecondaryFilename ); 00200 int CPL_DLL CPLIsFilenameRelative( const char *pszFilename ); 00201 const char CPL_DLL *CPLExtractRelativePath(const char *, const char *, int *); 00202 00203 /* -------------------------------------------------------------------- */ 00204 /* Find File Function */ 00205 /* -------------------------------------------------------------------- */ 00206 typedef const char *(*CPLFileFinder)(const char *, const char *); 00207 00208 const char CPL_DLL *CPLFindFile(const char *pszClass, 00209 const char *pszBasename); 00210 const char CPL_DLL *CPLDefaultFindFile(const char *pszClass, 00211 const char *pszBasename); 00212 void CPL_DLL CPLPushFileFinder( CPLFileFinder pfnFinder ); 00213 CPLFileFinder CPL_DLL CPLPopFileFinder(); 00214 void CPL_DLL CPLPushFinderLocation( const char * ); 00215 void CPL_DLL CPLPopFinderLocation(); 00216 void CPL_DLL CPLFinderClean(); 00217 00218 /* -------------------------------------------------------------------- */ 00219 /* Safe version of stat() that works properly on stuff like "C:". */ 00220 /* -------------------------------------------------------------------- */ 00221 int CPL_DLL CPLStat( const char *, VSIStatBuf * ); 00222 00223 /* -------------------------------------------------------------------- */ 00224 /* Reference counted file handle manager. Makes sharing file */ 00225 /* handles more practical. */ 00226 /* -------------------------------------------------------------------- */ 00227 typedef struct { 00228 FILE *fp; 00229 int nRefCount; 00230 int bLarge; 00231 char *pszFilename; 00232 char *pszAccess; 00233 } CPLSharedFileInfo; 00234 00235 FILE CPL_DLL *CPLOpenShared( const char *, const char *, int ); 00236 void CPL_DLL CPLCloseShared( FILE * ); 00237 CPLSharedFileInfo CPL_DLL *CPLGetSharedList( int * ); 00238 void CPL_DLL CPLDumpSharedList( FILE * ); 00239 00240 /* -------------------------------------------------------------------- */ 00241 /* DMS to Dec to DMS conversion. */ 00242 /* -------------------------------------------------------------------- */ 00243 double CPL_DLL CPLDMSToDec( const char *is ); 00244 const char CPL_DLL *CPLDecToDMS( double dfAngle, const char * pszAxis, 00245 int nPrecision ); 00246 double CPL_DLL CPLPackedDMSToDec( double ); 00247 double CPL_DLL CPLDecToPackedDMS( double dfDec ); 00248 00249 void CPL_DLL CPLStringToComplex( const char *pszString, 00250 double *pdfReal, double *pdfImag ); 00251 00252 /* -------------------------------------------------------------------- */ 00253 /* Misc other functions. */ 00254 /* -------------------------------------------------------------------- */ 00255 int CPL_DLL CPLUnlinkTree( const char * ); 00256 CPL_C_END 00257 00258 #endif /* ndef CPL_CONV_H_INCLUDED */