void OpenAirfieldDetails() { TCHAR zfilename[MAX_PATH]; zAirfieldDetails = NULL; _tcscpy(szAirfieldDetailsFile,szAirfieldFile); if (_tcslen(szAirfieldDetailsFile)>0) { ExpandLocalPath(szAirfieldDetailsFile); _tcscpy(zfilename, szAirfieldDetailsFile); _tcscpy(szAirfieldFile,_T("")); } else { #if 0 LocalPath(zfilename, _T(KD_WAYPOINTS)); _tcscat(zfilename, _T("\\")); _tcscat(zfilename, _T(LKF_AIRFIELDS)); #else _tcscpy(zfilename, _T("")); #endif } if (_tcslen(zfilename)>0) { StartupStore(_T(". open AirfieldFile <%s> %s"), zfilename, NEWLINE); zAirfieldDetails = zzip_fopen(zfilename, "rb"); } };
SDL_RWops *SDL_RWFromZZIP(const char* file, const char* mode) { register SDL_RWops* rwops; register ZZIP_FILE* zzip_file; if (! strchr (mode, 'r')) return SDL_RWFromFile(file, mode); zzip_file = zzip_fopen (file, mode); if (! zzip_file) return 0; rwops = SDL_AllocRW (); if (! rwops) { errno=ENOMEM; zzip_close (zzip_file); return 0; } SDL_RWOPS_ZZIP_DATA(rwops) = zzip_file; rwops->read = _zzip_read; rwops->write = _zzip_write; rwops->seek = _zzip_seek; rwops->close = _zzip_close; return rwops; }
bool ReadAirspace(AirspaceDatabase &airspace_database, const char *path) { ZZIP_FILE *fp = zzip_fopen(path, "rt"); if (fp == NULL) return false; ReadAirspace(airspace_database, fp); zzip_fclose(fp); return true; }
ZipSource::ZipSource(const TCHAR *path) :BufferedSource<char>(4096), file(NULL) { char narrow_path[4096]; int length = WideCharToMultiByte(CP_UTF8, 0, path, -1, narrow_path, sizeof(narrow_path), NULL, NULL); if (length == 0) return; file = zzip_fopen(narrow_path, "rb"); }
bool RasterWeather::ExistsItem(const TCHAR* name, unsigned time_index) const { TCHAR rasp_filename[MAX_PATH]; GetFilename(rasp_filename, name, time_index); ZZIP_FILE *zf = zzip_fopen(NarrowPathName(rasp_filename), "rb"); if (zf == NULL) return false; zzip_fclose(zf); return true; }
int ACEXML_ZipCharStream::open (const ACEXML_Char *name) { delete[] this->filename_; this->filename_ = 0; delete[] this->encoding_; this->encoding_ = 0; this->infile_ = zzip_fopen (name, ACE_TEXT ("r")); if (this->infile_ == 0) return -1; this->filename_ = ACE::strnew (ACE::basename (name)); return this->determine_encoding(); }
bool ReadWayPointZipFile(const TCHAR *path, WayPointList &way_points, RasterTerrain &terrain) { char path_ascii[MAX_PATH]; ZZIP_FILE *fp; unicode2ascii(path, path_ascii, sizeof(path_ascii)); fp = zzip_fopen(path_ascii, "rt"); if (fp == NULL) return false; ReadWayPointFile(fp, path, way_points, terrain); zzip_fclose(fp); return true; }
void * ZIPROMReaderInit(const char * filename) { ZZIP_DIR * dir = zzip_opendir(filename); ZZIP_DIRENT * dirent = zzip_readdir(dir); if (dir != NULL) { char tmp1[1024]; char tmp2[1024]; memset(tmp1,0,sizeof(tmp1)); memset(tmp2,0,sizeof(tmp2)); strncpy(tmp1, filename, strlen(filename) - 4); sprintf(tmp2, "%s/%s", tmp1, dirent->d_name); return zzip_fopen(tmp2, "rb"); } return NULL; }
ZZIP_FILE *ppc_fopen(const char *filename, const char *mode) { /* WCHAR wszFileName[256]; // Unicode user name WCHAR wszMode[10]; MultiByteToWideChar( CP_ACP, 0, filename, strlen(filename)+1, wszFileName, sizeof(wszFileName)/sizeof(wszFileName[0]) ); MultiByteToWideChar( CP_ACP, 0, mode, strlen(mode)+1, wszMode, sizeof(wszMode)/sizeof(wszMode[0]) ); return _tfopen(wszFileName, wszMode); */ return zzip_fopen(filename, mode); }
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; }
TCHAR *LKgethelptext(const TCHAR *TextIn) { static TCHAR sFile[MAX_PATH]; static TCHAR sPath[MAX_PATH]; static TCHAR sTmp[MAX_HELP+1]; static TCHAR sHelp[MAX_HELP+1]; bool foundnotfound=false; if (TextIn == NULL) return (TCHAR *)TextIn; short tlen=_tcslen(TextIn); if (tlen<5 || tlen>8) return (TCHAR *)TextIn; if ( (TextIn[0]!='_') || (TextIn[1]!='@') || (TextIn[tlen-1]!='_') ) return (TCHAR *)TextIn; // get the item index number, quick conversion from unicode char snum[6]; // char *pnum=(char *)&TextIn[3]; short i; for (i=0; i<tlen-4; i++) { /* snum[i++]=*pnum; // advance to unicode 0 pnum++; // advance to next char pnum++; // advance to next char */ snum[i] = (char)TextIn[3+i]; } snum[i]='\0'; unsigned short inumber=atoi(snum); #if DEBUG_GETTEXT StartupStore(_T(".... Help item TextIn=<%s> snum= <%S> number=%d \n"),TextIn, snum, inumber); #endif if (inumber>9999) { #if DEBUG_GETTEXT StartupStore(_T(".... Help item snum= <%S> number=%d \n"),snum, inumber); #endif _stprintf(sHelp,_T("ERROR, wrong index number <%d> from XML: <%s>\r\n"),inumber,TextIn); return (sHelp); } // get the type character char ttype = TextIn[2]; TCHAR suffix[20]; if (ttype=='H') { _tcscpy(suffix,_T("_HELP.TXT")); LocalPath(sPath,_T(LKD_LANGUAGE)); _stprintf(sFile,_T("%s\\%s%s"),sPath,LKLangSuffix,suffix); // Help File, dynamically handled #if DEBUG_GETTEXT StartupStore(_T("... Open Language file type <%C>: <%s>%s"),ttype,sFile,NEWLINE); #endif TCHAR sNum[10]; _stprintf(sNum,_T("%d"),inumber); ZZIP_FILE *helpFile = zzip_fopen(sFile, "rb"); if (helpFile == NULL) { #if ALPHADEBUG StartupStore(_T("... Missing HELP FILE <%s>%s"),sFile,NEWLINE); #endif // we can only have one Help call at a time, from the user interface. Ok static sHelp. _stprintf(sHelp,_T("ERROR, help file not found:\r\n%s\r\nCheck configuration!"),sFile); return (sHelp); } // search for beginning of code index @000 bool found=false; while (ReadULine(helpFile, sTmp, countof(sTmp))) { int slen=_tcslen(sTmp); // includes cr or lf or both if (slen<3|| slen>8) { #if DEBUG_GETTEXT StartupStore(_T("... skip line <3||>8 : %s\n"),sTmp); #endif continue; } if (sTmp[0]=='#') { #if DEBUG_GETTEXT StartupStore(_T("... skip remark: %s\n"),sTmp); #endif continue; } if (sTmp[0]=='@') { for (i=1; i<slen; i++) { if ( sTmp[i] < '0' || sTmp[i] > '9' ) { sTmp[i] = '\0'; break; } } // sTmp[slen-1]='\0'; // remove cr if ( _tcscmp(&sTmp[1],sNum) == 0 ) { #if DEBUG_GETTEXT StartupStore(_T("... found correct index: %s\n"),sTmp); #endif found=true; break; } else { // this one should be the very last line in the help file if ( _tcscmp(&sTmp[1],_T("9999")) == 0 ) { foundnotfound=true; #if DEBUG_GETTEXT StartupStore(_T("... found NOTFOUND index: %s\n"),&sTmp[1]); #endif // warning this means that placing 9999 not at the end of HELP file will // make all other messages ignored! always check HELP file to have 9999 at the end break; } else { #if DEBUG_GETTEXT StartupStore(_T("... found wrong index: %s not %s\n"),&sTmp[1],sNum); #endif } } } } if (!found && !foundnotfound) { #if DEBUG_GETTEXT StartupStore(_T("... index <%s> not found in help file <%s>\n"),sNum,sFile); #endif _stprintf(sHelp,_T("ERROR: index <%s> not found in language help file:\r\n%s\r\n"),sNum,sFile); zzip_fclose(helpFile); return (sHelp); } // now load the help text for this index _tcscpy(sHelp,_T("")); int hlen=0; while (ReadULine(helpFile, sTmp, countof(sTmp))) { int slen=_tcslen(sTmp); // including cr or lf or both if (slen==0 || sTmp[0]=='#') continue; if (slen>2 && slen<9) { // is it another index marker? if (sTmp[0]=='@') { if (hlen==0) continue; // multihelp section, continue loading help else break; // another marker, close the help } } if ( sTmp[slen-1]=='\r' ) { sTmp[slen-1]='\0'; slen--; } // add it to the help, if possible if ( (hlen+slen+2) > MAX_HELP) { #if DEBUG_GETTEXT StartupStore(_T("... help too long: truncating line <%s>\n"),sTmp); #endif _tcsncat(sHelp,sTmp,MAX_HELP-hlen-1); break; } hlen+=slen; #if DEBUG_GETTEXT //StartupStore(_T(".. adding line <%s>\n"),sTmp); #endif _tcscat(sHelp,sTmp); _tcscat(sHelp,_T("\r\n")); } zzip_fclose(helpFile); return (sHelp); } // end ttype == H #if ALPHADEBUG StartupStore(_T(".... Unknown Text type <%c> in <%s>%s"),ttype,TextIn,NEWLINE); #endif return (TCHAR *)TextIn; }
/** * @brief Load language MSG file into memory * * @param fillup Switch value: * - false - load from scratch removing anything existing * - true - load over existing messages, adding only missing items filling up gaps * * @return @c false if language file problem, in this case english is reloaded from calling function */ bool LKLoadMessages(bool fillup) { TCHAR sFile[MAX_PATH]; TCHAR sPath[MAX_PATH]; TCHAR suffix[20]; unsigned int i, j; #if DEBUG_GETTEXT int maxsize=0; #endif static bool doinit=true; short mnumber=0; #if ALPHADEBUG short fillupstart=0; #endif if (doinit) { for (i=0; i<MAX_MESSAGES; i++) { LKMessages[i]=NULL; LKMessagesIndex[i]=-1; } doinit=false; } else { if (!fillup) { // init data when reloading language files or changing it // but not in fillup mode of course for (i=0; i<MAX_MESSAGES; i++) { if (LKMessages[i] != NULL) free(LKMessages[i]); LKMessages[i]=NULL; LKMessagesIndex[i]=-1; } } else { // in fillup mode we need to add at the bottom of message array for (i=0; i<MAX_MESSAGES; i++) { if (LKMessages[i]!=NULL) ++mnumber; } if (mnumber == MAX_MESSAGES) { #if ALPHADEBUG StartupStore(_T("... Fillup language MSG already full\n")); #endif return false; } #if ALPHADEBUG fillupstart=mnumber; StartupStore(_T("... Fillup language MSG starting from pos.%d\n"),mnumber); #endif } } LocalPath(sPath,_T(LKD_LANGUAGE)); _tcscpy(suffix,_T("_MSG.TXT")); _stprintf(sFile,_T("%s\\%s%s"),sPath,LKLangSuffix,suffix); ZZIP_FILE *hFile = zzip_fopen(sFile, "rb"); if (hFile == NULL) { StartupStore(_T("... LoadText Missing Language File: <%s>%s"),sFile,NEWLINE); return false; } else { if (fillup) StartupStore(_T(". Language fillup load file: <%s>%s"),sFile,NEWLINE); else StartupStore(_T(". Language load file: <%s>%s"),sFile,NEWLINE); } // search for beginning of code index, in the range _@M1_ _@M9999_ TCHAR sTmp[300]; char snum[6]; TCHAR scapt[MAX_MESSAGE_SIZE+1]; TCHAR scaptraw[MAX_MESSAGE_SIZE+1]; bool havewarned=false; while (ReadULine(hFile, sTmp, countof(sTmp))) { unsigned int slen=_tcslen(sTmp); // includes cr or lf or both if (slen<9) continue; if ( (sTmp[0]!='_') || (sTmp[1]!='@') || (sTmp[2]!='M') ) { #if DEBUG_GETTEXT StartupStore(_T(".... MSG_ENG missing _@M line <%s>\n"),sTmp); #endif continue; } snum[0]=(char)sTmp[3]; snum[1]=(char)sTmp[4]; snum[2]=(char)sTmp[5]; snum[3]=(char)sTmp[6]; snum[4]=(char)'\0'; if (snum[3]=='_') snum[3]='\0'; if (snum[2]=='_') snum[2]='\0'; if (snum[1]=='_') snum[1]='\0'; unsigned short inumber; inumber=atoi(snum); if (inumber >=MAX_MESSAGES) { if (!havewarned) { StartupStore(_T("...... ERROR LOADING NON-COMPATIBLE MSG FILE!%s"),NEWLINE); havewarned=true; } StartupStore(_T("...... MSG token <%d> over limit!%s"),inumber,NEWLINE); continue; } int start=0; for (i=3; i<slen; i++) { if (sTmp[i]=='\"') { start=i; break; } } int end=0; if (start==0) { #if DEBUG_GETTEXT StartupStore(_T(".... MSG_ENG no start\n")); #endif continue; } for (i=start+1; i<slen; i++) { if (sTmp[i]=='\"') { sTmp[i]='\0'; end=i; break; } } if (end==0) { #if DEBUG_GETTEXT StartupStore(_T(".... MSG_ENG no end <%s> start=%d\n"),sTmp,start); #endif continue; } int newlen; newlen=_tcslen(&sTmp[start+1]); if (newlen>MAX_MESSAGE_SIZE) { #if DEBUG_GETTEXT StartupStore(_T(".... MSG_ENG caption too big, len=%d\n"),newlen); #endif continue; } if (newlen==0) { #if DEBUG_GETTEXT StartupStore(_T(".... MSG_ENG TOKEN # %d : caption is empty, null text.\n"),inumber); #endif continue; } #if DEBUG_GETTEXT if (newlen>maxsize) maxsize=newlen; #endif // transcode special charcaters while loading from file TCHAR tcode; bool donetcode; _tcscpy(scaptraw,&sTmp[start+1]); for (i=0, j=0; i<_tcslen(scaptraw); i++) { donetcode=false; if (scaptraw[i] == '\\') { if ( (i+1) <_tcslen(scaptraw)) { switch(scaptraw[i+1]) { case 'n': tcode='\n'; break; case 'r': tcode='\r'; break; default: tcode=' '; break; } scapt[j++]=tcode; i++; donetcode=true; } } if (!donetcode) { scapt[j++]=scaptraw[i]; } } scapt[j]='\0'; if (LKMessagesIndex[inumber]!= -1) { // only for debugging translations #if ALPHADEBUG if (!fillup) StartupStore(_T("... INVALID LANGUAGE MESSAGE INDEX <%d> duplicated!\n"),inumber); #endif continue; } LKMessagesIndex[inumber]=mnumber; LKMessages[mnumber] = (TCHAR *)malloc((wcslen(scapt)+1)*sizeof(TCHAR)); _tcscpy(LKMessages[mnumber],scapt); mnumber++; if (mnumber>=MAX_MESSAGES) { #if ALPHADEBUG StartupStore(_T("... TOO MANY MESSAGES, MAX %d%s"), MAX_MESSAGES, NEWLINE); #endif break; } } #if DEBUG_GETTEXT StartupStore(_T("... LOADED %d MESSAGES, max size = %d\n"),mnumber-1,maxsize); #endif #if ALPHADEBUG if (fillup) { if ((mnumber-fillupstart-1)>0) StartupStore(_T("... Fillup Loaded %d missing messages\n"),mnumber-fillupstart-1); else StartupStore(_T("... Fillup no messages to load, translation OK\n")); } #endif zzip_fclose(hFile); return true; }
void LKReadLanguageFile() { static bool doinit=true; static TCHAR oldLang[4]; if (doinit) { _tcscpy(LKLangSuffix,_T("")); _tcscpy(oldLang,_T("XXX")); doinit=false; } bool english=false; TCHAR szFile1[MAX_PATH] = TEXT("\0"); _tcscpy(LKLangSuffix,_T("")); GetRegistryString(szRegistryLanguageFile, szFile1, MAX_PATH); tryeng: if (_tcslen(szFile1)==0) { _tcscpy(szFile1,_T("%LOCAL_PATH%\\\\_Language\\ENGLISH.LNG")); english=true; } ExpandLocalPath(szFile1); // SetRegistryString(szRegistryLanguageFile, TEXT("\0")); // ? ZZIP_FILE *langFile = zzip_fopen(szFile1, "rb"); if (langFile == NULL) { if (english) { StartupStore(_T("--- CRITIC, NO ENGLISH LANGUAGE FILES!%s"),NEWLINE); // critic point, no default language! BIG PROBLEM here! for (unsigned short i=0; i<MAX_MESSAGES; i++) { LKMessages[i]=NULL; LKMessagesIndex[i]=-1; } return; } else { StartupStore(_T("--- NO LANGUAGE FILE FOUND <%s>, retrying with ENGlish!%s"),szFile1,NEWLINE); _tcscpy(szFile1,_T("")); goto tryeng; } return; } bool found=false; TCHAR sTmp[200]; TCHAR mylang[30]; while (ReadULine(langFile, sTmp, countof(sTmp))) { if (_tcslen(sTmp)<3) continue; if ((sTmp[0]=='L')&&(sTmp[1]=='=')) { _tcscpy(mylang,&sTmp[2]); for (unsigned short i=0; i<_tcslen(mylang); i++) { if (mylang[i]=='\r' || mylang[i]=='\n') { mylang[i]='\0'; break; } } found=true; break; } } if (found) { if (_tcslen(mylang)>3) mylang[3]='\0'; _tcscpy(LKLangSuffix,mylang); } if (_tcscmp(oldLang,LKLangSuffix)!=0) { if ( !LKLoadMessages(false) ) { // force reload of english if (_tcscmp(_T("ENG"),LKLangSuffix) == 0 ) { StartupStore(_T("... CRITICAL, no english langauge available!%s"),NEWLINE); } else { StartupStore(_T("... LoadText failed, fallback to english language\n")); _tcscpy(szFile1,_T("%LOCAL_PATH%\\\\_Language\\ENGLISH.LNG")); SetRegistryString(szRegistryLanguageFile, szFile1); _tcscpy(LKLangSuffix,_T("ENG")); LKLoadMessages(false); } } else { _tcscpy(oldLang,mylang); // Now overload english messages filling gaps in translations // only if current lang is not english of course: no reason to load it twice if (_tcscmp(_T("ENG"),LKLangSuffix) != 0 ) { _tcscpy(LKLangSuffix,_T("ENG")); LKLoadMessages(true); _tcscpy(LKLangSuffix,oldLang); } } } zzip_fclose(langFile); return; }
ZipSource::ZipSource(const char *path) :BufferedSource<char>(4096) { file = zzip_fopen(path, "rb"); }
void TopologyStore::Open() { StartupStore(TEXT("OpenTopology\n")); XCSoarInterface::CreateProgressDialog(gettext(TEXT("Loading Topology File..."))); Poco::ScopedRWLock protect(lock, true); // Start off by getting the names and paths static TCHAR szOrigFile[MAX_PATH] = TEXT("\0"); static TCHAR szFile[MAX_PATH] = TEXT("\0"); static TCHAR Directory[MAX_PATH] = TEXT("\0"); for (int z=0; z<MAXTOPOLOGY; z++) { topology_store[z] = 0; } GetRegistryString(szRegistryTopologyFile, szFile, MAX_PATH); ExpandLocalPath(szFile); _tcscpy(szOrigFile,szFile); // make copy of original ContractLocalPath(szOrigFile); // remove it in case it causes a crash (will restore later) SetRegistryString(szRegistryTopologyFile, TEXT("\0")); if (_tcslen(szFile)==0) { // file is blank, so look for it in a map file static TCHAR szMapFile[MAX_PATH] = TEXT("\0"); GetRegistryString(szRegistryMapFile, szMapFile, MAX_PATH); if (_tcslen(szMapFile)==0) { return; } ExpandLocalPath(szMapFile); // Look for the file within the map zip file... _tcscpy(Directory,szMapFile); _tcscat(Directory,TEXT("/")); szFile[0]=0; _tcscat(szFile,Directory); _tcscat(szFile,TEXT("topology.tpl")); } else { ExtractDirectory(Directory,szFile); } // Ready to open the file now.. static ZZIP_FILE* zFile; char zfilename[MAX_PATH]; unicode2ascii(szFile, zfilename, MAX_PATH); zFile = zzip_fopen(zfilename, "rt"); if (!zFile) { StartupStore(TEXT("No topology file\n%s\n"), szFile); return; } TCHAR ctemp[80]; TCHAR TempString[READLINE_LENGTH+1]; TCHAR ShapeName[50]; double ShapeRange; long ShapeIcon; long ShapeField; TCHAR wShapeFilename[MAX_PATH]; TCHAR *Stop; int numtopo = 0; char ShapeFilename[MAX_PATH]; while(ReadString(zFile,READLINE_LENGTH,TempString)) { if((_tcslen(TempString) > 0) && (_tcsstr(TempString,TEXT("*")) != TempString)) // Look For Comment { BYTE red, green, blue; // filename,range,icon,field // File name PExtractParameter(TempString, ctemp, 0); _tcscpy(ShapeName, ctemp); _tcscpy(wShapeFilename, Directory); _tcscat(wShapeFilename,ShapeName); _tcscat(wShapeFilename,TEXT(".shp")); #ifdef _UNICODE WideCharToMultiByte( CP_ACP, 0, wShapeFilename, _tcslen(wShapeFilename)+1, ShapeFilename, 200, NULL, NULL); #else strcpy(ShapeFilename, wShapeFilename); #endif // Shape range PExtractParameter(TempString, ctemp, 1); ShapeRange = StrToDouble(ctemp,NULL); // Shape icon PExtractParameter(TempString, ctemp, 2); ShapeIcon = _tcstol(ctemp, &Stop, 10); // Shape field for text display // sjt 02NOV05 - field parameter enabled PExtractParameter(TempString, ctemp, 3); if (_istalnum(ctemp[0])) { ShapeField = _tcstol(ctemp, &Stop, 10); ShapeField--; } else { ShapeField = -1; } // Red component of line / shading colour PExtractParameter(TempString, ctemp, 4); red = (BYTE)_tcstol(ctemp, &Stop, 10); // Green component of line / shading colour PExtractParameter(TempString, ctemp, 5); green = (BYTE)_tcstol(ctemp, &Stop, 10); // Blue component of line / shading colour PExtractParameter(TempString, ctemp, 6); blue = (BYTE)_tcstol(ctemp, &Stop, 10); if ((red==64) && (green==96) && (blue==240)) { // JMW update colours to ICAO standard red = 85; // water colours green = 160; blue = 255; } if (ShapeField<0) { Topology* newtopo; newtopo = new Topology(ShapeFilename, Color(red,green,blue)); topology_store[numtopo] = newtopo; } else { TopologyLabel *newtopol; newtopol = new TopologyLabel(ShapeFilename, Color(red,green,blue), ShapeField); topology_store[numtopo] = newtopol; } if (ShapeIcon!=0) topology_store[numtopo]->loadBitmap(ShapeIcon); topology_store[numtopo]->scaleThreshold = ShapeRange; numtopo++; } } zzip_fclose(zFile); // file was OK, so save it SetRegistryString(szRegistryTopologyFile, szOrigFile); }
jas_stream_t *jas_stream_fopen(const char *filename, const char *mode) { jas_stream_t *stream; jas_stream_fileobj_t *obj; int openflags; /* Allocate a stream object. */ if (!(stream = jas_stream_create())) { return 0; } /* Parse the mode string. */ stream->openmode_ = jas_strtoopenmode(mode); /* Determine the correct flags to use for opening the file. */ if ((stream->openmode_ & JAS_STREAM_READ) && (stream->openmode_ & JAS_STREAM_WRITE)) { openflags = O_RDWR; } else if (stream->openmode_ & JAS_STREAM_READ) { openflags = O_RDONLY; } else if (stream->openmode_ & JAS_STREAM_WRITE) { openflags = O_WRONLY; } else { openflags = 0; } if (stream->openmode_ & JAS_STREAM_APPEND) { openflags |= O_APPEND; } if (stream->openmode_ & JAS_STREAM_BINARY) { openflags |= O_BINARY; } if (stream->openmode_ & JAS_STREAM_CREATE) { openflags |= O_CREAT | O_TRUNC; } /* Allocate space for the underlying file stream object. */ if (!(obj = jas_malloc(sizeof(jas_stream_fileobj_t)))) { jas_stream_destroy(stream); return 0; } obj->fd = -1; obj->flags = 0; //obj->pathname[0] = '\0'; strncpy(obj->pathname, filename, DIM_MAX_FILE_NAME); //dima stream->obj_ = (void *) obj; /* Select the operations for a file stream object. */ stream->ops_ = &jas_stream_fileops; /* Open the underlying file. */ /* if ((obj->fd = open(filename, openflags, JAS_STREAM_PERMS)) < 0) { jas_stream_destroy(stream); return 0; } */ // JMW quick hack! if ((obj->zfile = zzip_fopen(filename, "rb")) == NULL) { jas_stream_close(stream); return 0; } /* By default, use full buffering for this type of stream. */ jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); return stream; }
ZipSource::ZipSource(const char *path) { file = zzip_fopen(path, "rb"); }