static void searchDiskTreeNode(SHPTreeHandle disktree, rectObj aoi, char *status) { int i; long offset; int numshapes, numsubnodes; rectObj rect; int *ids=NULL; zzip_fread( &offset, 4, 1, disktree->zfp ); if ( disktree->needswap ) SwapWord ( 4, &offset ); zzip_fread( &rect, sizeof(rectObj), 1, disktree->zfp ); if ( disktree->needswap ) SwapWord ( 8, &rect.minx ); if ( disktree->needswap ) SwapWord ( 8, &rect.miny ); if ( disktree->needswap ) SwapWord ( 8, &rect.maxx ); if ( disktree->needswap ) SwapWord ( 8, &rect.maxy ); zzip_fread( &numshapes, 4, 1, disktree->zfp ); if ( disktree->needswap ) SwapWord ( 4, &numshapes ); if(!msRectOverlap(&rect, &aoi)) { // skip rest of this node and sub-nodes offset += numshapes*sizeof(int) + sizeof(int); fseek(disktree->fp, offset, SEEK_CUR); return; } if(numshapes > 0) { ids = (int *)malloc(numshapes*sizeof(int)); zzip_fread( ids, numshapes*sizeof(int), 1, disktree->zfp ); if (disktree->needswap ) { for( i=0; i<numshapes; i++ ) { SwapWord( 4, &ids[i] ); msSetBit(status, ids[i], 1); } } else { for(i=0; i<numshapes; i++) msSetBit(status, ids[i], 1); } free(ids); } zzip_fread( &numsubnodes, 4, 1, disktree->zfp ); if ( disktree->needswap ) SwapWord ( 4, &numsubnodes ); for(i=0; i<numsubnodes; i++) searchDiskTreeNode(disktree, aoi, status); return; }
short RasterMapCache::LookupTerrainCacheFile(const long &SeekPos) { // put new value in slot tcpmin __int16 NewAlt = 0; long SeekRes; short Alt; if(!isMapLoaded()) return TERRAIN_INVALID; Lock(); SeekRes = zzip_seek(fpTerrain, SeekPos, SEEK_SET); if(SeekRes != SeekPos) { // error, not found! Alt = TERRAIN_INVALID; } else { if (zzip_fread(&NewAlt, 1, sizeof(__int16), fpTerrain) != sizeof(__int16)) Alt = TERRAIN_INVALID; else { // FIX HERE NETHERLAND Alt = max((short int)0,NewAlt); } } Unlock(); return Alt; }
// Reads line from UTF-8 encoded text file. // File must be open in binary read mode. // ATTENTION: if buffer is not large enough, the zzip_fread will fail // and ReadULine will return , but you will not be able to know if it returned // for a string overflow (managed) or because it reached EOF! bool ReadULine(ZZIP_FILE* fp, TCHAR *unicode, int maxChars) { // This is a char, and we need space for at least MAX_HELP TCHARS! // unsigned char buf[1500 * 2]; long startPos = zzip_tell(fp); if (startPos < 0) { StartupStore(_T(". ftell() error = %d%s"), errno, NEWLINE); return(false); } size_t nbRead = zzip_fread(buf, 1, sizeof(buf) - 1, fp); if (nbRead == 0) return(false); buf[nbRead] = '\0'; // find new line (CR/LF/CRLF) in the string and terminate string at that position size_t i; for (i = 0; i < nbRead; i++) { if (buf[i] == '\n') { buf[i++] = '\0'; if (buf[i] == '\r') i++; break; } if (buf[i] == '\r') { buf[i++] = '\0'; if (buf[i] == '\n') i++; break; } } // next reading will continue after new line zzip_seek(fp, startPos + i, SEEK_SET); // skip leading BOM char* begin = (char*) buf; if (buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF) begin += 3; return(utf2unicode(begin, unicode, maxChars) >= 0); }
treeNodeObj *readTreeNode( SHPTreeHandle disktree ) { int i,res; long offset; treeNodeObj *node; node = (treeNodeObj *) malloc(sizeof(treeNodeObj)); node->ids = NULL; res = zzip_fread( &offset, 4, 1, disktree->zfp ); if ( !res ) return NULL; if ( disktree->needswap ) SwapWord ( 4, &offset ); zzip_fread( &node->rect, sizeof(rectObj), 1, disktree->zfp ); if ( disktree->needswap ) SwapWord ( 8, &node->rect.minx ); if ( disktree->needswap ) SwapWord ( 8, &node->rect.miny ); if ( disktree->needswap ) SwapWord ( 8, &node->rect.maxx ); if ( disktree->needswap ) SwapWord ( 8, &node->rect.maxy ); zzip_fread( &node->numshapes, 4, 1, disktree->zfp ); if ( disktree->needswap ) SwapWord ( 4, &node->numshapes ); if( node->numshapes > 0 ) node->ids = (int *)malloc(sizeof(int)*node->numshapes); zzip_fread( node->ids, node->numshapes*4, 1, disktree->zfp ); for( i=0; i < node->numshapes; i++ ) { if ( disktree->needswap ) SwapWord ( 4, &node->ids[i] ); } zzip_fread( &node->numsubnodes, 4, 1, disktree->zfp ); if ( disktree->needswap ) SwapWord ( 4, &node->numsubnodes ); return node; }
BOOL ReadString(ZZIP_FILE *zFile, int Max, TCHAR *String) { char sTmp[READLINE_LENGTH+1]; char FileBuffer[READLINE_LENGTH+1]; long dwNumBytesRead=0; long dwTotalNumBytesRead=0; long dwFilePos; String[0] = '\0'; sTmp[0] = 0; #if BUGSTOP LKASSERT((unsigned)Max<sizeof(sTmp)); #endif if (Max >= (int)(sizeof(sTmp))) return(FALSE); if (!zFile) return(FALSE); dwFilePos = zzip_tell(zFile); dwNumBytesRead = zzip_fread(FileBuffer, 1, Max, zFile); if (dwNumBytesRead <= 0) return(FALSE); int i = 0; int j = 0; while((i<Max) && (j<(int)dwNumBytesRead)) { char c = FileBuffer[j]; j++; dwTotalNumBytesRead++; if((c == '\n')){ break; } sTmp[i] = c; i++; } sTmp[i] = 0; zzip_seek(zFile, dwFilePos+j, SEEK_SET); sTmp[Max-1] = '\0'; mbstowcs(String, sTmp, strlen(sTmp)+1); return (dwTotalNumBytesRead>0); }
static int read_chars (lua_State *L, ZZIP_FILE *f, size_t n) { size_t rlen; /* how much to read */ size_t nr; /* number of chars actually read */ luaL_Buffer b; luaL_buffinit(L, &b); rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ do { char *p = luaL_prepbuffer(&b); if (rlen > n) rlen = n; /* cannot read more than asked */ nr = zzip_fread(p, sizeof(char), rlen, f); luaL_addsize(&b, nr); n -= nr; /* still have to read `n' chars */ } while (n > 0 && nr == rlen); /* until end of count or eof */ luaL_pushresult(&b); /* close buffer */ return (n == 0 || lua_strlen(L, -1) > 0); }
int ACEXML_ZipCharStream::read (ACEXML_Char *str, size_t len) { if (this->infile_ == 0) return -1; size_t i = 0; for (; i < len && this->pos_ < this->limit_; ++i) str[i] = this->buf_[this->pos_++]; if (i == len) return len; len = len - i; this->pos_ = 0; this->limit_ = 0; int bytes = zzip_fread (str + i, sizeof (ACEXML_Char), len, this->infile_); return (bytes + i); }
PSAR_ENTRY *LPP_PsarDecoder_getEntry(const char *filename) { if(!initialized) return NULL; zzip_strings_t ext[] = {"", 0}; ZZIP_FILE *fd = zzip_open_ext_io(filename, O_RDONLY | (0x0), ZZIP_ONLYZIP, ext, &psar_handlers); if(fd == NULL) { #ifdef DEBUG dwrite_output("Function %s Line %d : Cannot open the file '%s' for read.\n", __FUNCTION__, __LINE__, filename); #endif return NULL; } PSAR_ENTRY *entry = (PSAR_ENTRY*)malloc(sizeof(PSAR_ENTRY)); if(!entry) { #ifdef DEBUG dwrite_output("Function %s Line %d : Cannot allocate 'entry' to memory.\n", __FUNCTION__, __LINE__); #endif zzip_close(fd); return NULL; } memset(entry, 0, sizeof(PSAR_ENTRY)); zzip_seek(fd, 0, SEEK_END); entry->len = zzip_tell(fd); zzip_rewind(fd); if(entry->len <= 0) { free(entry); zzip_fclose(fd); #ifdef DEBUG dwrite_output("Function %s Line %d : file len is lower than zero.\n", __FUNCTION__, __LINE__); #endif return NULL; } entry->data = (u8*)malloc(entry->len); zzip_fread(entry->data, 1, entry->len, fd); zzip_fclose(fd); return(entry); }
bool RasterMapCache::Open(const TCHAR* zfilename) { terrain_valid = false; if (_tcslen(zfilename)<=0) { return false; } if (!fpTerrain) { fpTerrain = zzip_fopen(zfilename, "rb"); if (!fpTerrain) { return false; } if (!zzip_file_real(fpTerrain)) { // don't allow cache mode on files in zip, because way too slow zzip_fclose(fpTerrain); fpTerrain = NULL; // was false return false; }; } DWORD dwBytesRead; dwBytesRead = zzip_fread(&TerrainInfo, 1, sizeof(TERRAIN_INFO), fpTerrain); if (dwBytesRead != sizeof(TERRAIN_INFO)) { Close(); return false; } if (!TerrainInfo.StepSize) { Close(); return false; } terrain_valid = true; ClearTerrainCache(); return terrain_valid; }
static int zzip_getc (ZZIP_FILE *f) { char c; return (zzip_fread(&c, sizeof(char), 1, f) == 0) ? EOF : (int)c; }
static char *msDBFReadAttribute(DBFHandle psDBF, int hEntity, int iField ) { int nRecordOffset, i; const uchar *pabyRec; char *pReturnField = NULL; /* -------------------------------------------------------------------- */ /* Is the request valid? */ /* -------------------------------------------------------------------- */ if( iField < 0 || iField >= psDBF->nFields ) { msSetError(MS_DBFERR, "Invalid field index %d.", "msDBFGetItemIndex()",iField ); return( NULL ); } if( hEntity < 0 || hEntity >= psDBF->nRecords ) { msSetError(MS_DBFERR, "Invalid record number %d.", "msDBFGetItemIndex()",hEntity ); return( NULL ); } /* -------------------------------------------------------------------- */ /* Have we read the record? */ /* -------------------------------------------------------------------- */ if( psDBF->nCurrentRecord != hEntity ) { #ifdef SHAPELIB_DISABLED flushRecord( psDBF ); #endif /* SHAPELIB_DISABLED */ nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength; zzip_seek( psDBF->zfp, nRecordOffset, 0 ); zzip_fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->zfp ); psDBF->nCurrentRecord = hEntity; } pabyRec = (const uchar *) psDBF->pszCurrentRecord; /* -------------------------------------------------------------------- */ /* Ensure our field buffer is large enough to hold this buffer. */ /* -------------------------------------------------------------------- */ if( psDBF->panFieldSize[iField]+1 > psDBF->nStringFieldLen ) { psDBF->nStringFieldLen = psDBF->panFieldSize[iField]*2 + 10; psDBF->pszStringField = (char *) SfRealloc(psDBF->pszStringField,psDBF->nStringFieldLen); } /* -------------------------------------------------------------------- */ /* Extract the requested field. */ /* -------------------------------------------------------------------- */ strncpy( psDBF->pszStringField,(const char *) pabyRec+psDBF->panFieldOffset[iField], psDBF->panFieldSize[iField] ); psDBF->pszStringField[psDBF->panFieldSize[iField]] = '\0'; /* ** Trim trailing blanks (SDL Modification) */ for(i=strlen(psDBF->pszStringField)-1;i>=0;i--) { if(psDBF->pszStringField[i] != ' ') { psDBF->pszStringField[i+1] = '\0'; break; } } if(i == -1) psDBF->pszStringField[0] = '\0'; /* whole string is blank (SDL fix) */ /* ** Trim/skip leading blanks (SDL/DM Modification - only on numeric types) */ if( psDBF->pachFieldType[iField] == 'N' || psDBF->pachFieldType[iField] == 'F' || psDBF->pachFieldType[iField] == 'D' ) { for(i=0; psDBF->pszStringField[i] != '\0' ;i++) { if(psDBF->pszStringField[i] != ' ') break; } pReturnField = psDBF->pszStringField+i; } else pReturnField = psDBF->pszStringField; return( pReturnField ); }
DBFHandle msDBFOpen(struct zzip_dir *zdir, const char *pszFilename, const char *pszAccess) { DBFHandle psDBF; uchar *pabyBuf; int nFields, nRecords, nHeadLen, nRecLen, iField; char *pszDBFFilename; /* -------------------------------------------------------------------- */ /* We only allow the access strings "rb" and "r+". */ /* -------------------------------------------------------------------- */ if( strcmp(pszAccess,"r") != 0 && strcmp(pszAccess,"r+") != 0 && strcmp(pszAccess,"rb") != 0 && strcmp(pszAccess,"r+b") != 0 ) return( NULL ); /* -------------------------------------------------------------------- */ /* Ensure the extension is converted to dbf or DBF if it is */ /* currently .shp or .shx. */ /* -------------------------------------------------------------------- */ pszDBFFilename = (char *) malloc(strlen(pszFilename)+1); strcpy( pszDBFFilename, pszFilename ); if( strcmp(pszFilename+strlen(pszFilename)-4,".shp") || strcmp(pszFilename+strlen(pszFilename)-4,".shx") ) { strcpy( pszDBFFilename+strlen(pszDBFFilename)-4, ".dbf"); } else if( strcmp(pszFilename+strlen(pszFilename)-4,".SHP") || strcmp(pszFilename+strlen(pszFilename)-4,".SHX") ) { strcpy( pszDBFFilename+strlen(pszDBFFilename)-4, ".DBF"); } /* -------------------------------------------------------------------- */ /* Open the file. */ /* -------------------------------------------------------------------- */ psDBF = (DBFHandle) calloc( 1, sizeof(DBFInfo) ); psDBF->zfp = zzip_open_rb(zdir, pszDBFFilename); if( psDBF->zfp == NULL ) return( NULL ); #ifdef SHAPELIB_DISABLED psDBF->bNoHeader = MS_FALSE; #endif /* SHAPELIB_DISABLED */ psDBF->nCurrentRecord = -1; #ifdef SHAPELIB_DISABLED psDBF->bCurrentRecordModified = MS_FALSE; #endif /* SHAPELIB_DISABLED */ psDBF->pszStringField = NULL; psDBF->nStringFieldLen = 0; free( pszDBFFilename ); /* -------------------------------------------------------------------- */ /* Read Table Header info */ /* -------------------------------------------------------------------- */ pabyBuf = (uchar *) malloc(500); zzip_fread( pabyBuf, 32, 1, psDBF->zfp ); psDBF->nRecords = nRecords = pabyBuf[4] + pabyBuf[5]*256 + pabyBuf[6]*256*256 + pabyBuf[7]*256*256*256; psDBF->nHeaderLength = nHeadLen = pabyBuf[8] + pabyBuf[9]*256; psDBF->nRecordLength = nRecLen = pabyBuf[10] + pabyBuf[11]*256; psDBF->nFields = nFields = (nHeadLen - 32) / 32; psDBF->pszCurrentRecord = (char *) malloc(nRecLen); /* -------------------------------------------------------------------- */ /* Read in Field Definitions */ /* -------------------------------------------------------------------- */ pabyBuf = (uchar *) SfRealloc(pabyBuf,nHeadLen); psDBF->pszHeader = (char *) pabyBuf; zzip_seek( psDBF->zfp, 32, 0 ); zzip_fread( pabyBuf, nHeadLen, 1, psDBF->zfp ); psDBF->panFieldOffset = (int *) malloc(sizeof(int) * nFields); psDBF->panFieldSize = (int *) malloc(sizeof(int) * nFields); psDBF->panFieldDecimals = (int *) malloc(sizeof(int) * nFields); psDBF->pachFieldType = (char *) malloc(sizeof(char) * nFields); for( iField = 0; iField < nFields; iField++ ) { uchar *pabyFInfo; pabyFInfo = pabyBuf+iField*32; if( pabyFInfo[11] == 'N' || pabyFInfo[11] == 'F' ) { psDBF->panFieldSize[iField] = pabyFInfo[16]; psDBF->panFieldDecimals[iField] = pabyFInfo[17]; } else { psDBF->panFieldSize[iField] = pabyFInfo[16] + pabyFInfo[17]*256; psDBF->panFieldDecimals[iField] = 0; } psDBF->pachFieldType[iField] = (char) pabyFInfo[11]; if( iField == 0 ) psDBF->panFieldOffset[iField] = 1; else psDBF->panFieldOffset[iField] = psDBF->panFieldOffset[iField-1] + psDBF->panFieldSize[iField-1]; } return( psDBF ); }
SHPTreeHandle msSHPDiskTreeOpen(const TCHAR* pszTree, int debug) { TCHAR *pszFullname, *pszBasename; SHPTreeHandle psTree; char pabyBuf[16]; int i; char bBigEndian; /* -------------------------------------------------------------------- */ /* Establish the byte order on this machine. */ /* -------------------------------------------------------------------- */ i = 1; if( *((uchar *) &i) == 1 ) bBigEndian = MS_FALSE; else bBigEndian = MS_TRUE; /* -------------------------------------------------------------------- */ /* Initialize the info structure. */ /* -------------------------------------------------------------------- */ psTree = (SHPTreeHandle) malloc(sizeof(SHPTreeInfo)); /* -------------------------------------------------------------------- */ /* Compute the base (layer) name. If there is any extension */ /* on the passed in filename we will strip it off. */ /* -------------------------------------------------------------------- */ pszBasename = (TCHAR *) malloc((_tcslen(pszTree)+5) * sizeof(TCHAR) * 2); _tcscpy( pszBasename, pszTree ); for( i = _tcslen(pszBasename)-1; i > 0 && pszBasename[i] != _T('.') && pszBasename[i] != _T('/') && pszBasename[i] != _T('\\'); i-- ) {} if( pszBasename[i] == _T('.') ) pszBasename[i] = _T('\0'); /* -------------------------------------------------------------------- */ /* Open the .shp and .shx files. Note that files pulled from */ /* a PC to Unix with upper case filenames won't work! */ /* -------------------------------------------------------------------- */ pszFullname = (TCHAR *) malloc((_tcslen(pszBasename) + _tcslen(_T(MS_INDEX_EXTENSION)) + 1) * sizeof(TCHAR) * 2); _stprintf( pszFullname, _T("%s%s"), pszBasename, _T(MS_INDEX_EXTENSION)); if (FileExists(pszFullname)) // prevent codegurad warnings (open unexisting file for reading) psTree->zfp = openzip(pszFullname, "rb" ); else psTree->zfp = NULL; msFree(pszBasename); // don't need these any more msFree(pszFullname); if( psTree->zfp == NULL ) { msFree(psTree); return( NULL ); } zzip_fread( pabyBuf, 8, 1, psTree->zfp ); memcpy( &psTree->signature, pabyBuf, 3 ); if( strncmp(psTree->signature,"SQT",3) ) { /* ---------------------------------------------------------------------- */ /* must check if the 2 first bytes equal 0 of max depth that cannot */ /* be more than 65535. If yes, we must swap all value. The problem */ /* here is if there's no Depth (bytea 5,6,7,8 in the file) all bytes */ /* will be set to 0. So,we will test with the number of shapes (bytes */ /* 1,2,3,4) that cannot be more than 65535 too. */ /* ---------------------------------------------------------------------- */ #if MAPSHAPEERROR if (debug) { msDebug("WARNING in msSHPDiskTreeOpen(): %ls is in old index format " "which has been deprecated. It is strongly recommended to " "regenerate it in new format.\n", pszTree); } #endif if((pabyBuf[4] == 0 && pabyBuf[5] == 0 && pabyBuf[6] == 0 && pabyBuf[7] == 0)) { psTree->LSB_order = !(pabyBuf[0] == 0 && pabyBuf[1] == 0); } else { psTree->LSB_order = !(pabyBuf[4] == 0 && pabyBuf[5] == 0); } psTree->needswap = ((psTree->LSB_order) != (!bBigEndian)); /* ---------------------------------------------------------------------- */ /* poor hack to see if this quadtree was created by a computer with a */ /* different Endian */ /* ---------------------------------------------------------------------- */ psTree->version = 0; } else { psTree->needswap = (( pabyBuf[3] == MS_NEW_MSB_ORDER ) ^ ( bBigEndian )); psTree->LSB_order = ( pabyBuf[3] == MS_NEW_LSB_ORDER ); memcpy( &psTree->version, pabyBuf+4, 1 ); memcpy( &psTree->flags, pabyBuf+5, 3 ); zzip_fread( pabyBuf, 8, 1, psTree->zfp ); } if( psTree->needswap ) SwapWord( 4, pabyBuf ); memcpy( &psTree->nShapes, pabyBuf, 4 ); if( psTree->needswap ) SwapWord( 4, pabyBuf+4 ); memcpy( &psTree->nDepth, pabyBuf+4, 4 ); return( psTree ); }
SHPTreeHandle msSHPDiskTreeOpen(struct zzip_dir *zdir, const char * pszTree, int debug) { char *pszFullname, *pszBasename; SHPTreeHandle psTree; char pabyBuf[16]; int i; #ifdef SHAPELIB_DISABLED char bBigEndian; /* -------------------------------------------------------------------- */ /* Establish the byte order on this machine. */ /* -------------------------------------------------------------------- */ i = 1; if( *((uchar *) &i) == 1 ) bBigEndian = MS_FALSE; else bBigEndian = MS_TRUE; #endif /* SHAPELIB_DISABLED */ /* -------------------------------------------------------------------- */ /* Initialize the info structure. */ /* -------------------------------------------------------------------- */ psTree = (SHPTreeHandle) msSmallMalloc(sizeof(SHPTreeInfo)); /* -------------------------------------------------------------------- */ /* Compute the base (layer) name. If there is any extension */ /* on the passed in filename we will strip it off. */ /* -------------------------------------------------------------------- */ pszBasename = (char *) msSmallMalloc(strlen(pszTree)+5); strcpy( pszBasename, pszTree ); for( i = strlen(pszBasename)-1; i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/' && pszBasename[i] != '\\'; i-- ) {} if( pszBasename[i] == '.' ) pszBasename[i] = '\0'; /* -------------------------------------------------------------------- */ /* Open the .shp and .shx files. Note that files pulled from */ /* a PC to Unix with upper case filenames won't work! */ /* -------------------------------------------------------------------- */ pszFullname = (char *) msSmallMalloc(strlen(pszBasename) + 5); sprintf( pszFullname, "%s%s", pszBasename, MS_INDEX_EXTENSION); psTree->fp = zzip_open_rb(zdir, pszFullname); msFree(pszBasename); /* don't need these any more */ msFree(pszFullname); if( psTree->fp == NULL ) { msFree(psTree); return( NULL ); } zzip_fread( pabyBuf, 8, 1, psTree->fp ); memcpy( &psTree->signature, pabyBuf, 3 ); if( strncmp(psTree->signature,"SQT",3) ) { /* ---------------------------------------------------------------------- */ /* must check if the 2 first bytes equal 0 of max depth that cannot */ /* be more than 65535. If yes, we must swap all value. The problem */ /* here is if there's no Depth (bytea 5,6,7,8 in the file) all bytes */ /* will be set to 0. So,we will test with the number of shapes (bytes */ /* 1,2,3,4) that cannot be more than 65535 too. */ /* ---------------------------------------------------------------------- */ if (debug) { msDebug("WARNING in msSHPDiskTreeOpen(): %s is in old index format " "which has been deprecated. It is strongly recommended to " "regenerate it in new format.\n", pszTree); } if((pabyBuf[4] == 0 && pabyBuf[5] == 0 && pabyBuf[6] == 0 && pabyBuf[7] == 0)) { psTree->LSB_order = !(pabyBuf[0] == 0 && pabyBuf[1] == 0); } else { psTree->LSB_order = !(pabyBuf[4] == 0 && pabyBuf[5] == 0); } psTree->needswap = ((psTree->LSB_order) != (!bBigEndian)); /* ---------------------------------------------------------------------- */ /* poor hack to see if this quadtree was created by a computer with a */ /* different Endian */ /* ---------------------------------------------------------------------- */ psTree->version = 0; } else { psTree->needswap = (( pabyBuf[3] == MS_NEW_MSB_ORDER ) ^ ( bBigEndian )); psTree->LSB_order = ( pabyBuf[3] == MS_NEW_LSB_ORDER ); memcpy( &psTree->version, pabyBuf+4, 1 ); memcpy( &psTree->flags, pabyBuf+5, 3 ); zzip_fread( pabyBuf, 8, 1, psTree->fp ); } if( psTree->needswap ) SwapWord( 4, pabyBuf ); memcpy( &psTree->nShapes, pabyBuf, 4 ); if( psTree->needswap ) SwapWord( 4, pabyBuf+4 ); memcpy( &psTree->nDepth, pabyBuf+4, 4 ); return( psTree ); }
// Rescale automatically dialogs, using negative values to force rescaling // Notice: SHOULD BE CALLED ONLY IF rWidth is negative, in order to avoid useless SetWindowPos int RescaleWidth(const int rWidth) { // Always rescale negative widths if (rWidth <-1) { // Special case is when width is also the scale unit, which demonstrate we have a bug to fix here! #if USEIBOX if (rWidth == (int)(-246*InfoBoxLayout::dscale)){ #else if (rWidth == (int)(-246*ScreenDScale)){ #endif return LKwdlgConfig; } double i=(246.0 / abs(rWidth)); if (i==0) { FailStore(_T("INTERNAL ERROR RESCALEWIDTH rWidth=%d"),rWidth); DoStatusMessage(_T("RESCALE ERR-001")); return rWidth; } #if USEIBOX int ri=(int)( (LKwdlgConfig/i) *InfoBoxLayout::dscale ); #else int ri=(int)( (LKwdlgConfig/i) *ScreenDScale ); #endif // StartupStore(_T("... RescaleWidth(): rescale %d to %d\n"),rWidth, ri); if (ri>ScreenSizeX) return(ScreenSizeX); return (ri); } // else use the incoming rWidth but it is clearly an error DoStatusMessage(_T("RESCALE WARN-001")); return rWidth; } void ChangeWindCalcSpeed(const int newspeed) { WindCalcSpeed += (double)newspeed/SPEEDMODIFY; } // runmode 0: exec inside LocalPath home of LK8000 // runmode 1: exec inside bool LKRun(const TCHAR *prog, const int runmode, const DWORD dwaitime) { if (_tcslen(prog) <5) { StartupStore(_T("... LKRun failure: invalid exec path <%s>%s"),prog,NEWLINE); return false; } TCHAR path[MAX_PATH]; if (runmode<0 || runmode>1) { StartupStore(_T("... LKRun failure: invalid runmode=%d %s"),runmode,NEWLINE); return false; } // mode 0: localpath , forced execution, with warnings if something goes wrong // mode 1: optional execution, no warnings if nothing found if (runmode<2) { LocalPath(path,prog); if (runmode==0) StartupStore(_T(". LKRun: exec <%s> background=%u%s"),path,dwaitime,NEWLINE); PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si,sizeof(STARTUPINFO)); si.cb=sizeof(STARTUPINFO); si.wShowWindow= SW_SHOWNORMAL; si.dwFlags = STARTF_USESHOWWINDOW; // if (!::CreateProcess(_T("C:\\WINDOWS\\notepad.exe"),_T(""), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) if (!::CreateProcess(path,_T(""), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) { if (runmode==0) StartupStore(_T("... LKRun exec FAILED%s"),NEWLINE); return false; } ::WaitForSingleObject(pi.hProcess, dwaitime); StartupStore(_T(". LKRun exec terminated%s"),NEWLINE); return true; } return false; } void GotoWaypoint(const int wpnum) { if (!ValidWayPoint(wpnum)) { DoStatusMessage(_T("ERR-639 INVALID GOTO WPT")); return; } if (ValidTaskPoint(ActiveWayPoint) && ValidTaskPoint(1)) { TCHAR wpname[NAME_SIZE+1]; _tcscpy(wpname,WayPointList[wpnum].Name); wpname[10] = '\0'; if (MessageBoxX(hWndMapWindow, // LKTOKEN _@M158_ = "CONFIRM GOTO, ABORTING TASK?" gettext(TEXT("_@M158_")), // LKTOKEN _@M40_ = "A task is running!" gettext(TEXT("_@M40_")), MB_YESNO|MB_ICONQUESTION) == IDYES) { LockTaskData(); FlyDirectTo(wpnum); OvertargetMode=OVT_TASK; UnlockTaskData(); } } else { LockTaskData(); FlyDirectTo(wpnum); OvertargetMode=OVT_TASK; UnlockTaskData(); } } void ToggleBaroAltitude() { if (!GPS_INFO.BaroAltitudeAvailable) { // LKTOKEN _@M121_ = "BARO ALTITUDE NOT AVAILABLE" DoStatusMessage(gettext(TEXT("_@M121_"))); return; } EnableNavBaroAltitude=!EnableNavBaroAltitude; if (EnableNavBaroAltitude) // LKTOKEN _@M756_ = "USING BARO ALTITUDE" DoStatusMessage(gettext(TEXT("_@M756_"))); else // LKTOKEN _@M757_ = "USING GPS ALTITUDE" DoStatusMessage(gettext(TEXT("_@M757_"))); } TCHAR * GetSizeSuffix(void) { static TCHAR suffixname[12]; _stprintf(suffixname,_T("%03dx%03d"),ScreenSizeX,ScreenSizeY); return(suffixname); } void LKRunStartEnd(bool start) { if (start) { LKRun(_T("PREROTATE1.EXE"),1,5000); LKRun(_T("PREROTATE2.EXE"),1,5000); LKRun(_T("PREROTATE3.EXE"),1,5000); LKRun(_T("PRELOAD_00.EXE"),1,0); LKRun(_T("PRELOAD_05.EXE"),1,5000); LKRun(_T("PRELOAD_30.EXE"),1,30000); LKRun(_T("PRELOAD_60.EXE"),1,60000); LKRun(_T("PRELOAD_99.EXE"),1,INFINITE); } else { LKRun(_T("ENDLOAD_00.EXE"),1,0); LKRun(_T("ENDLOAD_05.EXE"),1,5000); LKRun(_T("ENDLOAD_30.EXE"),1,30000); LKRun(_T("ENDLOAD_60.EXE"),1,60000); LKRun(_T("ENDROTATE1.EXE"),1,5000); LKRun(_T("ENDROTATE2.EXE"),1,5000); LKRun(_T("ENDROTATE3.EXE"),1,5000); LKRun(_T("ENDLOAD_99.EXE"),1,INFINITE); } } // Reads line from UTF-8 encoded text file. // File must be open in binary read mode. bool ReadULine(ZZIP_FILE* fp, TCHAR *unicode, int maxChars) { unsigned char buf[READLINE_LENGTH * 2]; long startPos = zzip_tell(fp); if (startPos < 0) { StartupStore(_T(". ftell() error = %d%s"), errno, NEWLINE); return(false); } size_t nbRead = zzip_fread(buf, 1, sizeof(buf) - 1, fp); if (nbRead == 0) return(false); buf[nbRead] = '\0'; // find new line (CR/LF/CRLF) in the string and terminate string at that position size_t i; for (i = 0; i < nbRead; i++) { if (buf[i] == '\n') { buf[i++] = '\0'; if (buf[i] == '\r') i++; break; } if (buf[i] == '\r') { buf[i++] = '\0'; if (buf[i] == '\n') i++; break; } } // next reading will continue after new line zzip_seek(fp, startPos + i, SEEK_SET); // skip leading BOM char* begin = (char*) buf; if (buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF) begin += 3; return(utf2unicode(begin, unicode, maxChars) >= 0); }