?? avc_misc.c
字號:
* Unix case. *----------------------------------------------------------------*/ VSIStatBuf sStatBuf; char *pszTmpPath = NULL; int nTotalLen, iTmpPtr; GBool bValidPath; /*----------------------------------------------------------------- * Remap '\\' to '/' *----------------------------------------------------------------*/ for(pszTmpPath = pszFname; *pszTmpPath != '\0'; pszTmpPath++) { if (*pszTmpPath == '\\') *pszTmpPath = '/'; } /*----------------------------------------------------------------- * First check if the filename is OK as is. *----------------------------------------------------------------*/ if (VSIStat(pszFname, &sStatBuf) == 0) { return pszFname; } pszTmpPath = CPLStrdup(pszFname); nTotalLen = strlen(pszTmpPath); /*----------------------------------------------------------------- * Try all lower case, check if the filename is OK as that. *----------------------------------------------------------------*/ for (iTmpPtr=0; iTmpPtr< nTotalLen; iTmpPtr++) { if ( pszTmpPath[iTmpPtr] >= 0x41 && pszTmpPath[iTmpPtr] <= 0x5a ) pszTmpPath[iTmpPtr] += 32; } if (VSIStat(pszTmpPath, &sStatBuf) == 0) { strcpy(pszFname, pszTmpPath); CPLFree(pszTmpPath); return pszFname; } /*----------------------------------------------------------------- * Try all upper case, check if the filename is OK as that. *----------------------------------------------------------------*/ for (iTmpPtr=0; iTmpPtr< nTotalLen; iTmpPtr++) { if ( pszTmpPath[iTmpPtr] >= 0x61 && pszTmpPath[iTmpPtr] <= 0x7a ) pszTmpPath[iTmpPtr] -= 32; } if (VSIStat(pszTmpPath, &sStatBuf) == 0) { strcpy(pszFname, pszTmpPath); CPLFree(pszTmpPath); return pszFname; } /*----------------------------------------------------------------- * OK, file either does not exist or has the wrong cases... we'll * go backwards until we find a portion of the path that is valid. *----------------------------------------------------------------*/ iTmpPtr = nTotalLen; bValidPath = FALSE; while(iTmpPtr > 0 && !bValidPath) { /*------------------------------------------------------------- * Move back to the previous '/' separator *------------------------------------------------------------*/ pszTmpPath[--iTmpPtr] = '\0'; while( iTmpPtr > 0 && pszTmpPath[iTmpPtr-1] != '/' ) { pszTmpPath[--iTmpPtr] = '\0'; } if (iTmpPtr > 0 && VSIStat(pszTmpPath, &sStatBuf) == 0) bValidPath = TRUE; } CPLAssert(iTmpPtr >= 0); /*----------------------------------------------------------------- * Assume that CWD is valid... so an empty path is a valid path *----------------------------------------------------------------*/ if (iTmpPtr == 0) bValidPath = TRUE; /*----------------------------------------------------------------- * OK, now that we have a valid base, reconstruct the whole path * by scanning all the sub-directories. * If we get to a point where a path component does not exist then * we simply return the rest of the path as is. *----------------------------------------------------------------*/ while(bValidPath && strlen(pszTmpPath) < nTotalLen) { char **papszDir=NULL; int iEntry, iLastPartStart; iLastPartStart = iTmpPtr; papszDir = CPLReadDir(pszTmpPath); /*------------------------------------------------------------- * Add one component to the current path *------------------------------------------------------------*/ pszTmpPath[iTmpPtr] = pszFname[iTmpPtr]; iTmpPtr++; for( ; pszFname[iTmpPtr] != '\0' && pszFname[iTmpPtr]!='/'; iTmpPtr++) { pszTmpPath[iTmpPtr] = pszFname[iTmpPtr]; } while(iLastPartStart < iTmpPtr && pszTmpPath[iLastPartStart] == '/') iLastPartStart++; /*------------------------------------------------------------- * And do a case insensitive search in the current dir... *------------------------------------------------------------*/ for(iEntry=0; papszDir && papszDir[iEntry]; iEntry++) { if (EQUAL(pszTmpPath+iLastPartStart, papszDir[iEntry])) { /* Fount it! */ strcpy(pszTmpPath+iLastPartStart, papszDir[iEntry]); break; } } if (iTmpPtr > 0 && VSIStat(pszTmpPath, &sStatBuf) != 0) bValidPath = FALSE; CSLDestroy(papszDir); } /*----------------------------------------------------------------- * We reached the last valid path component... just copy the rest * of the path as is. *----------------------------------------------------------------*/ if (iTmpPtr < nTotalLen-1) { strncpy(pszTmpPath+iTmpPtr, pszFname+iTmpPtr, nTotalLen-iTmpPtr); } /*----------------------------------------------------------------- * Update the source buffer and return. *----------------------------------------------------------------*/ strcpy(pszFname, pszTmpPath); CPLFree(pszTmpPath); return pszFname;#endif}/********************************************************************** * AVCPrintRealValue() * * Format a floating point value according to the specified coverage * precision (AVC_SINGLE/DOUBLE_PREC), and append the formatted value * to the end of the pszBuf buffer. * * The function returns the number of characters added to the buffer. **********************************************************************/int AVCPrintRealValue(char *pszBuf, int nPrecision, AVCFileType eType, double dValue){ static int numExpDigits=-1; int nLen = 0; /* WIN32 systems' printf for floating point output generates 3 * digits exponents (ex: 1.23E+012), but E00 files must have 2 digits * exponents (ex: 1.23E+12). * Run a test (only once per prg execution) to establish the number * of exponent digits on the current platform. */ if (numExpDigits == -1) { char szBuf[50]; int i; sprintf(szBuf, "%10.7E", 123.45); numExpDigits = 0; for(i=strlen(szBuf)-1; i>0; i--) { if (szBuf[i] == '+' || szBuf[i] == '-') break; numExpDigits++; } } /* We will append the value at the end of the current buffer contents. */ pszBuf = pszBuf+strlen(pszBuf); if (dValue < 0.0) { *pszBuf = '-'; dValue = -1.0*dValue; } else *pszBuf = ' '; /* Just to make things more complicated, double values are * output in a different format in attribute tables than in * the other files! */ if (nPrecision == AVC_FORMAT_DBF_FLOAT) { /* Float stored in DBF table in PC coverages */ sprintf(pszBuf+1, "%9.6E", dValue); nLen = 13; } else if (nPrecision == AVC_DOUBLE_PREC && eType == AVCFileTABLE) { sprintf(pszBuf+1, "%20.17E", dValue); nLen = 24; } else if (nPrecision == AVC_DOUBLE_PREC) { sprintf(pszBuf+1, "%17.14E", dValue); nLen = 21; } else { sprintf(pszBuf+1, "%10.7E", dValue); nLen = 14; } /* Adjust number of exponent digits if necessary */ if (numExpDigits > 2) { int n; n = strlen(pszBuf); pszBuf[n - numExpDigits] = pszBuf[n-2]; pszBuf[n - numExpDigits +1] = pszBuf[n-1]; pszBuf[n - numExpDigits +2] = '\0'; } /* Just make sure that the actual output length is what we expected. */ CPLAssert(strlen(pszBuf) == nLen); return nLen;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -