void CLevel::Load(const char* aName) { ASSERT(aName); ASSERT(strlen(aName)>0); FILE *dat; dat=fopen(getdatapath(std::string(aName)).c_str(), "rb"); if (dat != NULL) { Reset(); strcpy(iLevelFileName,aName); try { iVersion = ReadInt(dat); } catch ( CEOFException e ) { throw CFailureException("CLevel::Load: Level file too short."); } fseek( dat, 0, SEEK_SET ); if ( iVersion > 100 ) throw CFailureException("CLevel::Load: Level file corrupted?"); try { if (iVersion>KLastOldFormatVersion) LoadNewFormat( dat ); else LoadOldFormat( dat ); } catch ( CGameException e ) { fclose( dat ); throw; } fclose( dat ); strcpy(iLevelFileName,aName); GenerateReachableMap(); ModifyBorderBlocks(); DarknessCast(); GenerateShadows(); } else throw CFailureException("CLevel::Load: File could not be opened!"); }
void CGraphicsBuffer::Load(std::string aFilename, CPalette* aPalette) { ASSERT(aFilename.length()>0); // Translate the filename to have DATADIR before // calling any of the real loading functions. aFilename = getdatapath(aFilename); const char* ext = aFilename.c_str() + aFilename.find_last_of('.'); if (strcasestr(ext,".efp2")) { LoadEFP2(aFilename,aPalette); return; } if (strcasestr(ext,".efp")) { LoadEFP(aFilename,aPalette); return; } if (strcasestr(ext,".sci")) { LoadSCI(aFilename,aPalette); return; } if (strcasestr(ext,".pcx")) { LoadPCX(aFilename,aPalette); return; } SDL_Surface* surf = IMG_Load(aFilename.c_str()); if ( surf ) { if (CopyFromSurface(surf ,aPalette)==0) { SDL_FreeSurface( surf ); return; } else error("CGraphicsBuffer::Load: Only 8-bit surfaces allowed (%s)!",aFilename.c_str()); } error("CGraphicsBuffer::Load: File format not detected (%s)!",aFilename.c_str()); }
void CSplash::ShowSplash(const char* aImagePath,const char* aIcon,const char* aCaption) { SDL_Surface* screen; SDL_Rect src, dest; if (SDL_Init(SDL_INIT_VIDEO) != 0) { error("Unable to initialize SDL: %s \n", SDL_GetError()); } SDL_Surface* bitmap = SDL_LoadBMP(getdatapath(std::string(aImagePath)).c_str()); if (bitmap == NULL) { error("Unable to load splash.\n"); } src.x = 0; src.y = 0; src.w = bitmap->w; src.h = bitmap->h; dest.x = 0; dest.y = 0; dest.w = bitmap->w; dest.h = bitmap->h; atexit(SDL_Quit); // This must be done before videomode call... if (aIcon!=NULL && exists(aIcon)) { SDL_Surface* icon=SDL_LoadBMP(aIcon); SDL_WM_SetIcon(icon, NULL); } SDL_WM_SetCaption(aCaption,NULL); screen = SDL_SetVideoMode(bitmap->w, bitmap->h, 32, SDL_HWPALETTE|SDL_NOFRAME); if (screen == NULL) { error("Unable to set video mode: %s\n", SDL_GetError()); } SDL_BlitSurface(bitmap, &src, screen, &dest); SDL_UpdateRect(screen, 0, 0, 0, 0); SDL_Flip(screen); SDL_FreeSurface( bitmap ); }
static int initLHA(void) { int i; char buff[500]; if(dataPath) return 1; getdatapath(buff,500); for(i=499; i>=0 && buff[i]==' '; i--) ; if(i<0) { return 0;} buff[i+1]=0; dataPath=malloc(strlen(buff)+1); strcpy(dataPath,buff); return 1; }
FILE *sf_tempfile(char** dataname, const char* mode) /*< Create a temporary file with a unique name >*/ { FILE *tmp; char *path; int stemp; extern FILE * fdopen (int fd, const char *mode); extern int mkstemp (char *tmpl); path = gettmpdatapath(); if (NULL == path) path = getdatapath(); *dataname = sf_charalloc (NAME_MAX+1); snprintf(*dataname,NAME_MAX,"%s%sXXXXXX",path,sf_getprog()); free(path); stemp = mkstemp(*dataname); if (stemp < 0) sf_error ("%s: cannot create %s:",__FILE__,*dataname); tmp = fdopen(stemp,mode); if (NULL == tmp) sf_error ("%s: cannot open %s:",__FILE__,*dataname); return tmp; }
sf_file sf_output (/*@null@*/ const char* tag) /*< Create an output file structure. --- Should do output after the first call to sf_input. >*/ { sf_file file; char *headname, *dataname, *path, *name, *format; size_t namelen; extern int mkstemp (char *tmpl); extern off_t ftello (FILE *stream); file = (sf_file) sf_alloc(1,sizeof(*file)); if (NULL == tag || 0 == strcmp(tag,"out")) { file->stream = stdout; headname = NULL; } else { headname = sf_getstring (tag); if (NULL == headname) { namelen = strlen(tag)+1; headname = sf_charalloc (namelen); memcpy(headname,tag,namelen); } file->stream = fopen(headname,"w"); if (NULL == file->stream) { free(file); sf_error ("%s: Cannot write to header file %s:",__FILE__,headname); } } file->buf = NULL; /* setbuf(file->stream,file->buf); */ file->pars = sf_simtab_init (tabsize); file->head = NULL; file->headname = NULL; file->pipe = (bool) (-1 == ftello(file->stream)); if (file->pipe && ESPIPE != errno) { free(file); sf_error ("%s: pipe problem:",__FILE__); } dataname = sf_getstring("out"); if (NULL == dataname) dataname = sf_getstring("--out"); if (file->pipe) { file->dataname = sf_charalloc (7); memcpy(file->dataname,"stdout",7); } else if (NULL == dataname) { path = getdatapath(); file->dataname = sf_charalloc (PATH_MAX+NAME_MAX+1); strcpy (file->dataname,path); name = file->dataname+strlen(path); free (path); if (getfilename (file->stream,name)) { if(0==strcmp(name,"/dev/null")){ file->dataname = sf_charalloc (7); memcpy(file->dataname,"stdout",7); } else { namelen = strlen(file->dataname); file->dataname[namelen]='@'; file->dataname[namelen+1]='\0'; } } else { /* Invent a name */ /* stdout is not a pipe, not /dev/null, not a file in this directory. One way to get here is to redirect io to a file not in this directory. For example >../myfile.rsf. In this case getfilename cannot find the file from file->stream by looking in the current directory. The function mkstemp is used to create a unique name to contain the binary data. */ sprintf(name,"%sXXXXXX",sf_getprog()); (void) close(mkstemp(file->dataname)); /* (void) unlink(file->dataname); */ /* old code for named pipes below */ /* if (NULL == headname && -1L == fseek(file->stream,0L,SEEK_CUR) && ESPIPE == errno && 0 != mkfifo (file->dataname, S_IRUSR | S_IWUSR)) sf_error ("%s: Cannot make a pipe %s:", __FILE__,file->dataname); */ } } else { namelen = strlen(dataname)+1; file->dataname = sf_charalloc (namelen); memcpy(file->dataname,dataname,namelen); free (dataname); } sf_putstring(file,"in",file->dataname); file->op = XDR_ENCODE; if (NULL == infiles) { infiles = (sf_file *) sf_alloc(1,sizeof(sf_file)); infiles[0] = NULL; nfile=1; } if (NULL != infiles[0]) { if (NULL == infiles[0]->pars) sf_error("The input file was closed prematurely."); if (NULL != (format = sf_histstring(infiles[0],"data_format"))) { sf_setformat(file,format); free (format); } } else { sf_setformat(file,"native_float"); } if (NULL != headname) free(headname); if (!sf_getbool("--readwrite",&(file->rw))) file->rw=false; if (!sf_getbool("--dryrun",&(file->dryrun))) file->dryrun=false; return file; }