00001 /****************************************************************************** 00002 * $Id: cpl_conv.h,v 1.38 2005/08/25 18:06:48 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.38 2005/08/25 18:06:48 fwarmerdam 00033 * void in empty arg lists. 00034 * 00035 * Revision 1.37 2005/06/10 15:00:00 fwarmerdam 00036 * added cpl_getexecpath.cpp 00037 * 00038 * Revision 1.36 2005/04/04 15:23:31 fwarmerdam 00039 * some functions now CPL_STDCALL 00040 * 00041 * Revision 1.35 2004/11/17 22:57:21 fwarmerdam 00042 * added CPLScanPointer() and CPLPrintPointer() 00043 * 00044 * Revision 1.34 2004/08/16 20:24:07 warmerda 00045 * added CPLUnlinkTree 00046 * 00047 * Revision 1.33 2004/08/11 18:41:46 warmerda 00048 * added CPLExtractRelativePath 00049 * 00050 * Revision 1.32 2004/07/31 04:51:36 warmerda 00051 * added shared file open support 00052 * 00053 * Revision 1.31 2004/03/28 16:22:02 warmerda 00054 * const correctness changes in scan functions 00055 * 00056 * Revision 1.30 2004/03/24 09:01:17 dron 00057 * Added CPLPrintUIntBig(). 00058 * 00059 * Revision 1.29 2004/02/07 14:03:30 dron 00060 * CPLDecToPackedDMS() added. 00061 * 00062 * Revision 1.28 2004/02/01 08:37:55 dron 00063 * Added CPLPackedDMSToDec(). 00064 * 00065 * Revision 1.27 2003/12/28 17:24:43 warmerda 00066 * added CPLFreeConfig 00067 * 00068 * Revision 1.26 2003/10/17 07:06:06 dron 00069 * Added locale selection option to CPLScanDouble() and CPLPrintDOuble(). 00070 * 00071 * Revision 1.25 2003/09/28 14:14:16 dron 00072 * Added CPLScanString(). 00073 * 00074 * Revision 1.24 2003/09/08 11:09:53 dron 00075 * Added CPLPrintDouble() and CPLPrintTime(). 00076 * 00077 * Revision 1.23 2003/09/07 14:38:43 dron 00078 * Added CPLPrintString(), CPLPrintStringFill(), CPLPrintInt32(), CPLPrintUIntBig(). 00079 * 00080 * Revision 1.22 2003/08/31 14:48:05 dron 00081 * Added CPLScanLong() and CPLScanDouble(). 00082 * 00083 * Revision 1.21 2003/08/25 20:01:58 dron 00084 * Added CPLFGets() helper function. 00085 * 00086 * Revision 1.20 2003/05/08 21:51:14 warmerda 00087 * added CPL{G,S}etConfigOption() usage 00088 * 00089 * Revision 1.19 2003/03/02 04:44:38 warmerda 00090 * added CPLStringToComplex 00091 * 00092 * Revision 1.18 2002/12/13 06:00:54 warmerda 00093 * added CPLProjectRelativeFilename() and CPLIsFilenameRelative() 00094 * 00095 * Revision 1.17 2002/12/09 18:52:51 warmerda 00096 * added DMS conversion 00097 * 00098 * Revision 1.16 2002/12/03 04:42:02 warmerda 00099 * improved finder cleanup support 00100 * 00101 * Revision 1.15 2002/08/15 09:23:24 dron 00102 * Added CPLGetDirname() function 00103 * 00104 * Revision 1.14 2002/02/01 20:39:50 warmerda 00105 * ensure CPLReadLine() is exported from DLL 00106 * 00107 * Revision 1.13 2001/12/12 17:06:57 warmerda 00108 * added CPLStat 00109 * 00110 * Revision 1.12 2001/03/16 22:15:08 warmerda 00111 * added CPLResetExtension 00112 * 00113 * Revision 1.1 1998/10/18 06:15:11 warmerda 00114 * Initial implementation. 00115 * 00116 */ 00117 00118 #ifndef CPL_CONV_H_INCLUDED 00119 #define CPL_CONV_H_INCLUDED 00120 00121 #include "cpl_port.h" 00122 #include "cpl_vsi.h" 00123 #include "cpl_error.h" 00124 00132 /* -------------------------------------------------------------------- */ 00133 /* Runtime check of various configuration items. */ 00134 /* -------------------------------------------------------------------- */ 00135 CPL_C_START 00136 00137 void CPL_DLL CPLVerifyConfiguration(void); 00138 00139 const char CPL_DLL * CPL_STDCALL 00140 CPLGetConfigOption( const char *, const char * ); 00141 void CPL_DLL CPL_STDCALL CPLSetConfigOption( const char *, const char * ); 00142 void CPL_DLL CPL_STDCALL CPLFreeConfig(void); 00143 00144 /* -------------------------------------------------------------------- */ 00145 /* Safe malloc() API. Thin cover over VSI functions with fatal */ 00146 /* error reporting if memory allocation fails. */ 00147 /* -------------------------------------------------------------------- */ 00148 void CPL_DLL *CPLMalloc( size_t ); 00149 void CPL_DLL *CPLCalloc( size_t, size_t ); 00150 void CPL_DLL *CPLRealloc( void *, size_t ); 00151 char CPL_DLL *CPLStrdup( const char * ); 00152 00153 #define CPLFree VSIFree 00154 00155 /* -------------------------------------------------------------------- */ 00156 /* Read a line from a text file, and strip of CR/LF. */ 00157 /* -------------------------------------------------------------------- */ 00158 char CPL_DLL *CPLFGets( char *, int, FILE *); 00159 const char CPL_DLL *CPLReadLine( FILE * ); 00160 00161 /* -------------------------------------------------------------------- */ 00162 /* Read a numeric value from an ASCII character string. */ 00163 /* -------------------------------------------------------------------- */ 00164 char CPL_DLL *CPLScanString( const char *, int, int, int ); 00165 double CPL_DLL CPLScanDouble( const char *, int, char * ); 00166 long CPL_DLL CPLScanLong( const char *, int ); 00167 GUIntBig CPL_DLL CPLScanUIntBig( const char *, int ); 00168 void CPL_DLL *CPLScanPointer( const char *, int ); 00169 00170 /* -------------------------------------------------------------------- */ 00171 /* Print a value to an ASCII character string. */ 00172 /* -------------------------------------------------------------------- */ 00173 int CPL_DLL CPLPrintString( char *, const char *, int ); 00174 int CPL_DLL CPLPrintStringFill( char *, const char *, int ); 00175 int CPL_DLL CPLPrintInt32( char *, GInt32 , int ); 00176 int CPL_DLL CPLPrintUIntBig( char *, GUIntBig , int ); 00177 int CPL_DLL CPLPrintDouble( char *, const char *, double, char * ); 00178 int CPL_DLL CPLPrintTime( char *, int , const char *, const struct tm *, 00179 char * ); 00180 int CPL_DLL CPLPrintPointer( char *, void *, int ); 00181 00182 /* -------------------------------------------------------------------- */ 00183 /* Fetch a function from DLL / so. */ 00184 /* -------------------------------------------------------------------- */ 00185 00186 void CPL_DLL *CPLGetSymbol( const char *, const char * ); 00187 00188 /* -------------------------------------------------------------------- */ 00189 /* Read a directory (cpl_dir.c) */ 00190 /* -------------------------------------------------------------------- */ 00191 char CPL_DLL **CPLReadDir( const char *pszPath ); 00192 00193 /* -------------------------------------------------------------------- */ 00194 /* Fetch executable path. */ 00195 /* -------------------------------------------------------------------- */ 00196 int CPL_DLL CPLGetExecPath( char *pszPathBuf, int nMaxLength ); 00197 00198 /* -------------------------------------------------------------------- */ 00199 /* Filename handling functions. */ 00200 /* -------------------------------------------------------------------- */ 00201 const char CPL_DLL *CPLGetPath( const char * ); 00202 const char CPL_DLL *CPLGetDirname( const char * ); 00203 const char CPL_DLL *CPLGetFilename( const char * ); 00204 const char CPL_DLL *CPLGetBasename( const char * ); 00205 const char CPL_DLL *CPLGetExtension( const char * ); 00206 const char CPL_DLL *CPLFormFilename( const char *pszPath, 00207 const char *pszBasename, 00208 const char *pszExtension ); 00209 const char CPL_DLL *CPLFormCIFilename( const char *pszPath, 00210 const char *pszBasename, 00211 const char *pszExtension ); 00212 const char CPL_DLL *CPLResetExtension( const char *, const char * ); 00213 const char CPL_DLL *CPLProjectRelativeFilename( const char *pszProjectDir, 00214 const char *pszSecondaryFilename ); 00215 int CPL_DLL CPLIsFilenameRelative( const char *pszFilename ); 00216 const char CPL_DLL *CPLExtractRelativePath(const char *, const char *, int *); 00217 00218 /* -------------------------------------------------------------------- */ 00219 /* Find File Function */ 00220 /* -------------------------------------------------------------------- */ 00221 typedef const char *(*CPLFileFinder)(const char *, const char *); 00222 00223 const char CPL_DLL *CPLFindFile(const char *pszClass, 00224 const char *pszBasename); 00225 const char CPL_DLL *CPLDefaultFindFile(const char *pszClass, 00226 const char *pszBasename); 00227 void CPL_DLL CPLPushFileFinder( CPLFileFinder pfnFinder ); 00228 CPLFileFinder CPL_DLL CPLPopFileFinder(void); 00229 void CPL_DLL CPLPushFinderLocation( const char * ); 00230 void CPL_DLL CPLPopFinderLocation(void); 00231 void CPL_DLL CPLFinderClean(void); 00232 00233 /* -------------------------------------------------------------------- */ 00234 /* Safe version of stat() that works properly on stuff like "C:". */ 00235 /* -------------------------------------------------------------------- */ 00236 int CPL_DLL CPLStat( const char *, VSIStatBuf * ); 00237 00238 /* -------------------------------------------------------------------- */ 00239 /* Reference counted file handle manager. Makes sharing file */ 00240 /* handles more practical. */ 00241 /* -------------------------------------------------------------------- */ 00242 typedef struct { 00243 FILE *fp; 00244 int nRefCount; 00245 int bLarge; 00246 char *pszFilename; 00247 char *pszAccess; 00248 } CPLSharedFileInfo; 00249 00250 FILE CPL_DLL *CPLOpenShared( const char *, const char *, int ); 00251 void CPL_DLL CPLCloseShared( FILE * ); 00252 CPLSharedFileInfo CPL_DLL *CPLGetSharedList( int * ); 00253 void CPL_DLL CPLDumpSharedList( FILE * ); 00254 00255 /* -------------------------------------------------------------------- */ 00256 /* DMS to Dec to DMS conversion. */ 00257 /* -------------------------------------------------------------------- */ 00258 double CPL_DLL CPLDMSToDec( const char *is ); 00259 const char CPL_DLL *CPLDecToDMS( double dfAngle, const char * pszAxis, 00260 int nPrecision ); 00261 double CPL_DLL CPLPackedDMSToDec( double ); 00262 double CPL_DLL CPLDecToPackedDMS( double dfDec ); 00263 00264 void CPL_DLL CPLStringToComplex( const char *pszString, 00265 double *pdfReal, double *pdfImag ); 00266 00267 /* -------------------------------------------------------------------- */ 00268 /* Misc other functions. */ 00269 /* -------------------------------------------------------------------- */ 00270 int CPL_DLL CPLUnlinkTree( const char * ); 00271 CPL_C_END 00272 00273 #endif /* ndef CPL_CONV_H_INCLUDED */