void write_all_ply() { HFINDFILE hff; char filename[256]; creature *ply; FILE *fp; fp = fopen( player_file, "w"); if ( fp != NULL ) { hff = find_first_file(get_player_path(), filename, 256); if ( hff ) { do { if ( filename[0] != '.') { if (load_ply_from_file(filename, &ply)) printf("Unable to read binary player %s.\n", filename); else { write_player(fp, filename, ply); free_crt(ply); } } } while( find_next_file( hff, filename, 256 )); close_find_file(hff); } fclose(fp); } return; }
void dir_read() { ino_t inode = 0; fprintf(stderr, "#CONTROL_MSG#pid=%d\n", getpid()); while((inode = find_next_file(dirTime, 0)) <= 0) sleep(1); //printf("Next file: inode %ld\n", inode); while((inode = read_log_online(inode)) > 0) { //printf("Next file: inode %ld\n", inode); } }
void write_all_obj() { HFINDFILE hff; char filename[256]; object *obj; int num; int index; FILE *fp; fp = fopen( object_file, "w"); if ( fp != NULL ) { hff = find_first_file(get_object_path(), filename, 256); if ( hff ) { do { if ( filename[0] != '.' && toupper(filename[0]) == 'O' && strlen(filename) == 3) { index = OFILESIZE * atoi(&filename[1]); for (num=0; num < OFILESIZE ; num++) { if (load_obj_from_file(index + num, &obj ) == 0 ) { write_object(fp, index+num,obj); free_obj(obj); } } } } while( find_next_file( hff, filename, 256 )); close_find_file(hff); } fclose(fp); } return; }
void write_all_crt() { HFINDFILE hff; char filename[256]; creature *crt; int num; int index; FILE *fp; fp = fopen( creature_file, "w"); if ( fp != NULL ) { hff = find_first_file(get_monster_path(), filename, 256); if ( hff ) { do { if ( filename[0] != '.' && toupper(filename[0]) == 'M' && strlen(filename) == 3) { index = MFILESIZE * atoi(&filename[1]); for (num=0; num != MFILESIZE; num++) { if (load_crt_from_file(index + num, &crt ) == 0 ) { write_creature(fp, index+num,crt); free_crt(crt); } } } } while( find_next_file( hff, filename, 256 )); close_find_file(hff); } fclose(fp); } return; }
ino_t read_log_online(ino_t inode) { char buffer[BUFFER_LENGTH]; struct stat sbuf; time_t time; FILE *fp = open_inode(inode); if(fp == NULL) { fprintf(stderr, "file open error 1: inode %ld\n", inode); return -1; } do{ while (TRUE) { memset(&buffer, 0, BUFFER_LENGTH); while(fgets(& buffer[0], BUFFER_LENGTH, fp) == NULL) { if(fstat(fileno(fp), &sbuf) == -1) { fprintf(stderr, "stat fails: inode %ld\n", inode); continue; } time = sbuf.st_mtime; ino_t next_inode = find_next_file(time, sbuf.st_ino); if(next_inode > 0) { while(fgets(& buffer[0], BUFFER_LENGTH, fp) != NULL) { // check the log again. UBSI_buffer(buffer); } // At this point, the next log is available and the current log does not have any new event. //Safe to close the current one and process the next log fclose(fp); return next_inode; } } UBSI_buffer(buffer); } } while (FALSE); }
void write_all_rom() { HFINDFILE hff; char filename[256]; room *rom; FILE *fp; int n=0; fp = fopen( room_file, "w"); if ( fp != NULL ) { hff = find_first_file(get_room_path(), filename, 256); if ( hff ) { do { if ( filename[0] != '.' ) { if (load_rom_from_file( atoi(&filename[1]), &rom)) printf("Unable to read binary room %d. Continuing.\n", atoi(&filename[1]) ); else { n++; write_room(fp, rom); free_rom(rom); } } } while( find_next_file( hff, filename, 256 )); close_find_file(hff); } fclose(fp); } }
int ScanFile(HXCFLOPPYEMULATOR* floppycontext,struct Volume * adfvolume,char * folder,char * file) { long hfindfile; filefoundinfo FindFileData; int bbool; int byte_written; FILE * ftemp; unsigned char tempbuffer[512]; struct File* adffile; unsigned char * fullpath;//,*fileimg; int size,filesize; RETCODE rc; hfindfile=find_first_file(folder,file, &FindFileData); if(hfindfile!=-1) { bbool=TRUE; while(hfindfile!=-1 && bbool) { if(FindFileData.isdirectory) { if(strcmp(".",FindFileData.filename)!=0 && strcmp("..",FindFileData.filename)!=0) { if(adfCountFreeBlocks(adfvolume)>4) { floppycontext->hxc_printf(MSG_INFO_1,"Adding directory %s",FindFileData.filename); rc=adfCreateDir(adfvolume,adfvolume->curDirPtr,FindFileData.filename); if(rc==RC_OK) { floppycontext->hxc_printf(MSG_INFO_1,"entering directory %s",FindFileData.filename); rc=adfChangeDir(adfvolume, FindFileData.filename); if(rc==RC_OK) { fullpath=malloc(strlen(FindFileData.filename)+strlen(folder)+2); sprintf(fullpath,"%s\\%s",folder,FindFileData.filename); if(ScanFile(floppycontext,adfvolume,fullpath,file)) { adfParentDir(adfvolume); free(fullpath); return 1; } floppycontext->hxc_printf(MSG_INFO_1,"Leaving directory %s",FindFileData.filename); free(fullpath); adfParentDir( adfvolume); } else { floppycontext->hxc_printf(MSG_ERROR,"Cannot enter to the directory %s !",FindFileData.filename); return 1; } } else { floppycontext->hxc_printf(MSG_ERROR,"Cannot Add the directory %s !",FindFileData.filename); return 1; } } else { floppycontext->hxc_printf(MSG_ERROR,"Cannot Add a directory ! : no more free block!!!"); return 1; } } } else { if(adfCountFreeBlocks(adfvolume)>4) { floppycontext->hxc_printf(MSG_INFO_1,"Adding file %s, %dB",FindFileData.filename,FindFileData.size); adffile = adfOpenFile(adfvolume, FindFileData.filename, "w"); if(adffile) { if(FindFileData.size) { fullpath=malloc(strlen(FindFileData.filename)+strlen(folder)+2); sprintf(fullpath,"%s\\%s",folder,FindFileData.filename); ftemp=fopen(fullpath,"rb"); if(ftemp) { fseek(ftemp,0,SEEK_END); filesize=ftell(ftemp); fseek(ftemp,0,SEEK_SET); do { if(filesize>=512) { size=512; } else { size=filesize; } fread(&tempbuffer,size,1,ftemp); byte_written=adfWriteFile(adffile, size, tempbuffer); if((byte_written!=size) || (adfCountFreeBlocks(adfvolume)<2) ) { floppycontext->hxc_printf(MSG_ERROR,"Error while writting the file %s. No more free block ?",FindFileData.filename); adfCloseFile(adffile); fclose(ftemp); free(fullpath); return 1; } filesize=filesize-512; }while( (filesize>0) && (byte_written==size)); /*fileimg=(unsigned char*)malloc(filesize); memset(fileimg,0,filesize); fread(fileimg,filesize,1,ftemp); adfWriteFile(adffile, filesize, fileimg); free(fileimg);*/ adfCloseFile(adffile); fclose(ftemp); free(fullpath); } else { floppycontext->hxc_printf(MSG_ERROR,"Error : Cannot open %s !!!",fullpath); free(fullpath); return 1; } } } else { floppycontext->hxc_printf(MSG_ERROR,"Error : Cannot create %s, %dB!!!",FindFileData.filename,FindFileData.size); return 1; } } else { floppycontext->hxc_printf(MSG_ERROR,"Error : Cannot add a file : no more free block"); return 1; } } bbool=find_next_file(hfindfile,folder,file,&FindFileData); } } else printf("Error FindFirstFile\n"); find_close(hfindfile); return 0; }
void increment() { BOOST_ASSERT("out of range" && m_found); find_next_file(); }
int ScanFileAndAddToFAT(HXCFLOPPYEMULATOR* floppycontext,char * folder,char * file, char * fattable,char *entriestable,char *datatable,int parentcluster,FATCONFIG * fatconfig,int numberofcluster) { long hfindfile; filefoundinfo FindFileData; int bbool; int tii; FILE * ftemp; char * newentry; char * subnewentry; char tempstr[256]; int lefttoread; int fatclusternb; unsigned char * fullpath; fat_directory_entry *entry; fat_directory_entry *subentry; int i,j; struct stat repstate; struct tm * ts; tii=0; hfindfile=find_first_file(folder,file, &FindFileData); if(hfindfile!=-1) { bbool=1; while(hfindfile!=-1 && bbool) { if(FindFileData.isdirectory) { if(strcmp(".",FindFileData.filename)!=0 && strcmp("..",FindFileData.filename)!=0) { newentry=findfreeentry(entriestable); entry=(fat_directory_entry *)newentry; memset(entry->DIR_Name,0x20,8+3); sprintf((char*)tempstr,"%s",FindFileData.filename); floppycontext->hxc_printf(MSG_INFO_1,"Adding directory %s",FindFileData.filename); strupper(tempstr); if(strchr(tempstr,'.')) { memcpy(&entry->DIR_Name[8],strchr(tempstr,'.')+1,strlen(strchr(tempstr,'.')+1)); *strchr(tempstr,'.')=0; } memcpy(entry->DIR_Name,tempstr,strlen(tempstr)); entry->DIR_Attr=entry->DIR_Attr|0x10; entry->DIR_FileSize=FindFileData.size; fatclusternb=findfreecluster(fattable,numberofcluster); if(fatclusternb==-1) { floppycontext->hxc_printf(MSG_ERROR,"Cannot add this directory ! : No more cluster free !"); find_close(hfindfile); return 1; } memset(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize],0,fatconfig->sectorsize*fatconfig->clustersize); entry->DIR_FstClusLO=fatclusternb; //*( (unsigned short*) &newentry[0x1A])=fatclusternb; setclusterptr(fattable,fatclusternb,0xFFF); subnewentry=findfreeentry(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize]); subentry=(fat_directory_entry *)subnewentry; sprintf(subentry->DIR_Name,". "); //memcpy(subnewentry,". ",strlen(". ")); subentry->DIR_Attr=0x10; subentry->DIR_FstClusLO=fatclusternb; subnewentry=findfreeentry(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize]); subentry=(fat_directory_entry *)subnewentry; sprintf(subentry->DIR_Name,".. "); subentry->DIR_Attr=0x10; subentry->DIR_FstClusLO=parentcluster; //*( (unsigned short*) &subnewentry[0x1A])=parentcluster; floppycontext->hxc_printf(MSG_INFO_1,"Entering directory %s",FindFileData.filename); fullpath=malloc(strlen(FindFileData.filename)+strlen(folder)+2); sprintf(fullpath,"%s\\%s",folder,FindFileData.filename); if(ScanFileAndAddToFAT(floppycontext,fullpath,file,fattable,&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize],datatable,fatclusternb,fatconfig,numberofcluster)) { free(fullpath); find_close(hfindfile); return 1; } free(fullpath); floppycontext->hxc_printf(MSG_INFO_1,"Leaving directory %s",FindFileData.filename); } } else { floppycontext->hxc_printf(MSG_INFO_1,"Adding file %s, %dB",FindFileData.filename,FindFileData.size); sprintf(tempstr,"%s",FindFileData.filename); strupper(tempstr); newentry=findfreeentry(entriestable); entry=(fat_directory_entry *)newentry; memset(entry->DIR_Name,0x20,8+3); i=0; while(tempstr[i] && (i<8) && tempstr[i]!='.') { if(tempstr[i]==' ') { newentry[i]='_'; } else { newentry[i]=tempstr[i]; } i++; } if(strchr(tempstr,'.')) { i=0; while(tempstr[i]!='.') { i++; } j=0; i++; while(tempstr[i] && (j<3)) { if(tempstr[i]==' ') { newentry[8+j]='_'; } else { newentry[8+j]=tempstr[i]; } i++; j++; } memcpy(newentry+8,strchr(tempstr,'.')+1,strlen(strchr(tempstr,'.')+1)); *strchr(tempstr,'.')=0; } entry->DIR_FileSize=FindFileData.size; if(FindFileData.size) { lefttoread=FindFileData.size; fatclusternb=findfreecluster(fattable,numberofcluster); memset(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize],0,fatconfig->sectorsize*fatconfig->clustersize); if(fatclusternb==-1) { floppycontext->hxc_printf(MSG_ERROR,"Cannot add this file ! : No more cluster free !"); find_close(hfindfile); return 1; } entry->DIR_FstClusLO=fatclusternb; if(file) { fullpath=malloc(strlen(FindFileData.filename)+strlen(folder)+2); sprintf(fullpath,"%s\\%s",folder,FindFileData.filename); } else { fullpath=malloc(strlen(folder)+1); sprintf(fullpath,"%s",folder); } stat(fullpath,&repstate); ts=localtime(&repstate.st_ctime); if(ts) { entry->DIR_CrtDate= (((ts->tm_year-80) &0x7F)<<9) | ((ts->tm_mon+1 &0xF)<<5) | (ts->tm_mday &0x1F); entry->DIR_CrtTime= ((ts->tm_hour&0x1F)<<11) | ((ts->tm_min &0x3F)<<5) | ((ts->tm_sec/2)&0x1F); } else { entry->DIR_CrtDate= 0; entry->DIR_CrtTime= 0; } stat(fullpath,&repstate); ts=localtime(&repstate.st_mtime); if(ts) { entry->DIR_WrtDate= (((ts->tm_year-80) &0x7F)<<9) | ((ts->tm_mon+1 &0xF)<<5) | (ts->tm_mday &0x1F); entry->DIR_WrtTime= ((ts->tm_hour&0x1F)<<11) | ((ts->tm_min &0x3F)<<5) | ((ts->tm_sec/2)&0x1F); } else { entry->DIR_WrtDate= 0; entry->DIR_WrtTime= 0; } ftemp=fopen(fullpath,"rb"); if(ftemp) { do { fatclusternb=findfreecluster(fattable,numberofcluster); if(fatclusternb==-1) { floppycontext->hxc_printf(MSG_ERROR,"Error while adding this file ! : No more cluster free !"); free(fullpath); find_close(hfindfile); fclose(ftemp); return 1; } memset(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize],0x00,fatconfig->sectorsize*fatconfig->clustersize); fread(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize],fatconfig->sectorsize*fatconfig->clustersize,1,ftemp); setclusterptr(fattable,fatclusternb,0xFFF); if(lefttoread>(fatconfig->sectorsize*fatconfig->clustersize)) { setclusterptr(fattable,fatclusternb,findfreecluster(fattable,numberofcluster)); } lefttoread=lefttoread-(fatconfig->sectorsize*fatconfig->clustersize); }while(lefttoread>0); fclose(ftemp); } else { floppycontext->hxc_printf(MSG_ERROR,"Error while adding this file ! : Access error !"); } free(fullpath); } } bbool=find_next_file(hfindfile,folder,file,&FindFileData); } } else printf("Error FindFirstFile\n"); find_close(hfindfile); return 0; }
int main (int argc, char *argv[]) /* plist command provides a quick way to check a given players * * level, class, password and inventory without having to log * * the player in or use the editor */ { int i, adj; char filename[256]; char flags = 0; HFINDFILE hff; lvl=0; adj = 1; if (argc < 1) { usage(); return(1); } for (i=1;i<argc;i++){ if (argv[i][0] == '-'){ switch(argv[i][1]){ case 'i': set_flag(flags,0); continue; break; case 'n': set_flag(flags,1); continue; case 'p': set_flag(flags,2); continue; break; } if(i+1 < argc && isdigit(argv[i+1][0])){ switch(argv[i][1]){ case 'l': lvl = atoi(argv[i+1]); break; case 's': Spellnum = atoi(argv[i+1]); spl=1; break; default: set_flag(flags,3); break; } i++; } else set_flag(flags,3); } else break; if (is_fset(flags,3)){ usage(); return(1); } } adj = i; if (adj > argc) { usage(); return(1); } else if ( adj == argc ) { /* wants all players */ hff = find_first_file(get_player_path(), filename, 256); if ( hff ) { do { if ( filename[0] != '.') { print_player( filename, flags ); } } while( find_next_file( hff, filename, 256 )); close_find_file(hff); } } else { for(i= adj;i < argc; i++) { print_player( argv[i], flags ); } } return(0); }