?? avc_e00gen.c
字號:
/********************************************************************** * $Id: avc_e00gen.c,v 1.17 2006/06/14 15:01:33 daniel Exp $ * * Name: avc_e00gen.c * Project: Arc/Info vector coverage (AVC) BIN->E00 conversion library * Language: ANSI C * Purpose: Functions to generate ASCII E00 lines form binary structures. * Author: Daniel Morissette, dmorissette@dmsolutions.ca * ********************************************************************** * Copyright (c) 1999-2005, Daniel Morissette * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ********************************************************************** * * $Log: avc_e00gen.c,v $ * Revision 1.17 2006/06/14 15:01:33 daniel * Remove any embeded '\0' from data line in AVCE00GenTableRec() * * Revision 1.16 2005/06/03 03:49:58 daniel * Update email address, website url, and copyright dates * * Revision 1.15 2004/08/19 17:48:20 warmerda * Avoid uninitialized variable warnings. * * Revision 1.14 2001/11/25 21:15:23 daniel * Added hack (AVC_MAP_TYPE40_TO_DOUBLE) to map type 40 fields bigger than 8 * digits to double precision as we generate E00 output (bug599) * * Revision 1.13 2001/11/19 20:39:48 daniel * Change to correctly format 0-arc PAL records, so that they have a * single "filler" arc record * * Revision 1.12 2000/09/26 20:21:04 daniel * Added AVCCoverPC write * * Revision 1.11 2000/09/22 19:45:20 daniel * Switch to MIT-style license * * Revision 1.10 2000/02/04 04:54:03 daniel * Fixed warnings * * Revision 1.9 2000/02/03 07:21:02 daniel * TXT/TX6 with string longer than 80 chars: split string in 80 chars chunks * * Revision 1.8 2000/02/02 04:28:00 daniel * Fixed support of TX6/RXP/RPL coming from "weird" coverages * * Revision 1.7 1999/08/23 18:20:49 daniel * Fixed support for attribute fields type 40 * * Revision 1.6 1999/05/17 16:19:39 daniel * Made sure ACVE00GenTableRec() removes all spaces at the end of a * table record line (it used to leave one space) * * Revision 1.5 1999/05/11 02:08:17 daniel * Simple changes related to the addition of coverage write support. * * Revision 1.4 1999/03/03 02:06:38 daniel * Properly handle 8 bytes floats inside single precision tables. * * Revision 1.3 1999/02/25 17:01:58 daniel * Added support for 16 bit integers in INFO tables (type=50, size=2) * * Revision 1.2 1999/02/25 04:17:51 daniel * Added TXT, TX6/TX7, RXP and RPL support + some minor changes * * Revision 1.1 1999/01/29 16:28:52 daniel * Initial revision * **********************************************************************/#include "avc.h"#include <ctype.h> /* toupper() *//********************************************************************** * AVCE00GenInfoAlloc() * * Allocate and initialize a new AVCE00GenInfo structure. * * The structure will eventually have to be freed with AVCE00GenInfoFree(). **********************************************************************/AVCE00GenInfo *AVCE00GenInfoAlloc(int nCoverPrecision){ AVCE00GenInfo *psInfo; psInfo = (AVCE00GenInfo*)CPLCalloc(1,sizeof(AVCE00GenInfo)); /* Allocate output buffer. * 2k should be enough... the biggest thing we'll need to store * in it will be 1 complete INFO table record. */ psInfo->nBufSize = 2048; psInfo->pszBuf = (char *)CPLMalloc(psInfo->nBufSize*sizeof(char)); psInfo->nPrecision = nCoverPrecision; return psInfo;}/********************************************************************** * AVCE00GenInfoFree() * * Free any memory associated with a AVCE00GenInfo structure. **********************************************************************/void AVCE00GenInfoFree(AVCE00GenInfo *psInfo){ if (psInfo) CPLFree(psInfo->pszBuf); CPLFree(psInfo);}/********************************************************************** * AVCE00GenReset() * * Reset the fields in the AVCE00GenInfo structure so that further calls * with bCont = TRUE (ex: AVCE00GenArc(psInfo, TRUE)) would return NULL. **********************************************************************/void AVCE00GenReset(AVCE00GenInfo *psInfo){ /* Reinitialize counters so that further calls with bCont = TRUE, * like AVCE00GenArc(psInfo, TRUE) would return NULL. */ psInfo->iCurItem = psInfo->numItems = 0;}/********************************************************************** * AVCE00GenStartSection() * * Generate the first line of an E00 section. * * pszClassName applies only to JABBERWOCKY type of sections. **********************************************************************/const char *AVCE00GenStartSection(AVCE00GenInfo *psInfo, AVCFileType eType, const char *pszClassName){ char *pszName = "UNK"; AVCE00GenReset(psInfo); if (eType == AVCFileTX6 || eType == AVCFileRXP || eType == AVCFileRPL) { /* TX6/RXP/RPL sections start with the class name (the basename * of the file) in uppercase. * ex: The section for "cities.txt" would start with "CITIES" */ int i; for(i=0; pszClassName[i] != '\0'; i++) { psInfo->pszBuf[i] = toupper(pszClassName[i]); } psInfo->pszBuf[i] = '\0'; } else { /* In most cases, the section starts with a 3 letters code followed * by the precision code (2 or 3) */ switch(eType) { case AVCFileARC: pszName = "ARC"; break; case AVCFilePAL: pszName = "PAL"; break; case AVCFileCNT: pszName = "CNT"; break; case AVCFileLAB: pszName = "LAB"; break; case AVCFileTOL: pszName = "TOL"; break; case AVCFilePRJ: pszName = "PRJ"; break; case AVCFileTXT: pszName = "TXT"; break; default: CPLError(CE_Failure, CPLE_NotSupported, "Unsupported E00 section type!"); } if (psInfo->nPrecision == AVC_DOUBLE_PREC) sprintf(psInfo->pszBuf, "%s 3", pszName); else sprintf(psInfo->pszBuf, "%s 2", pszName); } return psInfo->pszBuf;}/********************************************************************** * AVCE00GenEndSection() * * Generate the last line(s) of an E00 section. * * This function should be called once with bCont=FALSE to get the * first "end of section" line for the current section, and then call * with bCont=TRUE to get all the other lines. * * The function returns NULL when there are no more lines to generate * for this "end of section". **********************************************************************/const char *AVCE00GenEndSection(AVCE00GenInfo *psInfo, AVCFileType eType, GBool bCont){ if (bCont == FALSE) { /*------------------------------------------------------------- * Most section types end with only 1 line. *------------------------------------------------------------*/ AVCE00GenReset(psInfo); psInfo->iCurItem = 0; if (eType == AVCFileARC || eType == AVCFilePAL || eType == AVCFileRPL || eType == AVCFileCNT || eType == AVCFileTOL || eType == AVCFileTXT || eType == AVCFileTX6 ) { sprintf(psInfo->pszBuf, " -1 0 0 0 0 0 0"); } else if (eType == AVCFileLAB) { if (psInfo->nPrecision == AVC_DOUBLE_PREC) sprintf(psInfo->pszBuf, " -1 0 0.00000000000000E+00 0.00000000000000E+00"); else sprintf(psInfo->pszBuf, " -1 0 0.0000000E+00 0.0000000E+00"); } else if (eType == AVCFilePRJ) { sprintf(psInfo->pszBuf, "EOP"); } else if (eType == AVCFileRXP ) { sprintf(psInfo->pszBuf," -1 0"); } else { CPLError(CE_Failure, CPLE_NotSupported, "Unsupported E00 section type!"); return NULL; } } else if ( psInfo->iCurItem == 0 && psInfo->nPrecision == AVC_DOUBLE_PREC && (eType == AVCFilePAL || eType == AVCFileRPL) ) { /*--------------------------------------------------------- * Return the 2nd line for the end of a PAL or RPL section. *--------------------------------------------------------*/ sprintf(psInfo->pszBuf, " 0.00000000000000E+00 0.00000000000000E+00"); psInfo->iCurItem++; } else { /*----------------------------------------------------- * All other section types end with only one line, and thus * we return NULL when bCont==TRUE *----------------------------------------------------*/ return NULL; } return psInfo->pszBuf;}/********************************************************************** * AVCE00GenObject() * * Cover function on top of AVCE00GenArc/Pal/Cnt/Lab() that will * call the right function according to argument eType. * * Since there is no compiler type checking on psObj, you have to * be very careful to make sure you pass an object of the right type * when you use this function! * * The function returns NULL when there are no more lines to generate * for this ARC. **********************************************************************/const char *AVCE00GenObject(AVCE00GenInfo *psInfo, AVCFileType eType, void *psObj, GBool bCont){ const char *pszLine = NULL; switch(eType) { case AVCFileARC: pszLine = AVCE00GenArc(psInfo, (AVCArc*)psObj, bCont); break; case AVCFilePAL: case AVCFileRPL: pszLine = AVCE00GenPal(psInfo, (AVCPal*)psObj, bCont); break; case AVCFileCNT: pszLine = AVCE00GenCnt(psInfo, (AVCCnt*)psObj, bCont); break; case AVCFileLAB: pszLine = AVCE00GenLab(psInfo, (AVCLab*)psObj, bCont); break; case AVCFileTOL: pszLine = AVCE00GenTol(psInfo, (AVCTol*)psObj, bCont); break; case AVCFileTXT: pszLine = AVCE00GenTxt(psInfo, (AVCTxt*)psObj, bCont); break; case AVCFileTX6: pszLine = AVCE00GenTx6(psInfo, (AVCTxt*)psObj, bCont); break; case AVCFilePRJ: pszLine = AVCE00GenPrj(psInfo, (char**)psObj, bCont); break; case AVCFileRXP: pszLine = AVCE00GenRxp(psInfo, (AVCRxp*)psObj, bCont); break; default: CPLError(CE_Failure, CPLE_NotSupported, "AVCE00GenObject(): Unsupported file type!"); } return pszLine;}/*===================================================================== ARC stuff =====================================================================*//********************************************************************** * AVCE00GenArc() * * Generate the next line of an E00 ARC. *
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -