int main() { char* cwd=gnu_getcwd(); strcat(cwd,"/"); //listfiles("./"); listfiles(cwd); }
int main(int argc,char* argv[]) { yield(); char a[100] = { 0 }; //printf("reached ls %s %s %s \n",argv[0],argv[1],argv[2]); if (argc >= 2){ strcpy(a,argv[1]); } else { strcpy(a,"/rootfs/bin/"); } int flag; if (argc == 3){ if (strcmp(argv[2],"wr_pipe") == 0) flag = 1; else if (strcmp(argv[2],"rd_pipe") == 0) flag = 2; else flag = 0; } else { flag = 0; } //printf("%d",flag); listfiles(a,flag); return 0; }
void load_json_dir(std::string const &dirname) { // get a list of all files in the directory std::vector<std::string> dir = listfiles(dirname); // iterate over each file std::vector<std::string>::iterator it; for (it = dir.begin(); it != dir.end(); it++) { // open the file as a stream std::ifstream infile(it->c_str(), std::ifstream::in | std::ifstream::binary); // parse it try { JsonIn jsin(&infile); load_all_from_json(jsin); } catch (std::string e) { throw *(it) + ": " + e; } } }
int main(int argc, char** argv){ char str[256]; int print = 0; if(argc < 3){ printf("Usage : patchfirm.exe <patches_folder_path> <patch_path> <-v = verbose>\n"); exit(-1); } if(argc > 3) if(!strcmp(argv[3], "-v")) print = 1; listfiles(argv[1]); FILE* patch = fopen(argv[2], "wb"); if(!patch){ printf("No patch path specified!\n"); exit(-1); } fwrite(&npatch, 1, 4, patch); for(int i = 0; i < npatch; i++){ unsigned int off = 0, size = 0; sscanf(patch_name[i], "%08x.bin", &off); sprintf(str, "%s/%s", argv[1], patch_name[i]); FILE* fp = fopen(str, "rb"); fseek(fp, 0, 2); size = ftell(fp); rewind(fp); if(size > 0){ unsigned char* buf = (unsigned char*) malloc (size); fread(buf, 1, size, fp); fclose(fp); unsigned int pos = FirmAddr(off); fwrite(&pos, 1, 4, patch); fwrite(&size, 1, 4, patch); fwrite(buf, 1, size, patch); while((ftell(patch) % 4) != 0) fputc(0, patch); //Aligned 4 if(print) printf("Addr : %08X Size : %d\n", off, size); free(buf); } fclose(fp); } return 0; }
void listfilesrecursive(const char *dir, vector<char *> &files, int level) { if(level > 8) return; // 8 levels is insane enough... vector<char *> dirs, thisdir; listsubdirs(dir, dirs, stringsort); loopv(dirs) { if(dirs[i][0] != '.') // ignore "." and ".." (and also other directories starting with '.', like it is unix-convention - and doesn't hurt on windows) { defformatstring(name)("%s/%s", dir, dirs[i]); listfilesrecursive(name, files, level + 1); } delstring(dirs[i]); } listfiles(dir, NULL, thisdir); loopv(thisdir) { defformatstring(name)("%s/%s", dir, thisdir[i]); files.add(newstring(name)); delstring(thisdir[i]); } }
int listfiles(char* path_dir) { //if (!chdir(path_dir)) // printf("CHanged DIRECTORY SUCCESSFULLY\n"); printf("CD %s\n",path_dir); DIR *dp; struct dirent *ep; dp = opendir (path_dir); if (dp != NULL) { while (ep = readdir (dp)) { //puts (ep->d_name); if (!strcmp(ep->d_name,".") || !strcmp(ep->d_name,"..")) { //printf("skip\n"); continue; } struct stat* buf; buf=(struct stat*)malloc(sizeof(struct stat)); //stat structure object to hold file attributes //printf("%d\n",ep->d_fileno); if (buf ==NULL) { printf("Not able to allocate space to buffer\n"); // exit(1); } char *tmp_path; tmp_path=malloc(sizeof(char)*(strlen(path_dir)+strlen(ep->d_name)+2)); //Since ep->dname and / are also added later if (tmp_path==NULL) { printf("Not able to allocate space to buffer\n"); // exit(1); } strcpy(tmp_path,path_dir); strcat(tmp_path,ep->d_name); printf("FILE :- %s\n",tmp_path); if (!stat(tmp_path,buf)) //Stat fn Return all attributes of file in struct stat (buf) object { //When stat successful mode_t mode = buf->st_mode; printf("Address %d\n",buf->st_mode); if ((mode & S_IFMT) == S_IFDIR) //If current file is Directory { strcat(tmp_path,"/"); listfiles(tmp_path); } else if ((mode & S_IFMT) == S_IFREG) //Regular file {} else { printf("Dont know\n"); } printf("%s\n",tmp_path); } else{ printf("Stat Func is not able to return file attributes\n"); } printf("Debugg\n"); printf("Tmp_path %s\n",tmp_path); printf("Tmp_path %u\n",tmp_path); free(tmp_path); printf("Debugg\n"); free(buf); printf("Debugg\n"); } (void) closedir (dp); } else puts ("Couldn't open the directory."); return 0; }
void playcampaignmenu(void) { int count,count2; int changeddir; int numoffiles; int pagenum; changeddir=chdir("level"); listfiles("*.gmp",levellist,0); if (changeddir==0) chdir(".."); numoffiles=0; while (levellist[numoffiles][0]!=0) numoffiles++; pagenum=0; resetmenuitems(); joymenunum=1; while (!menuitem[0].active && !windowinfo.shutdown) { glClearColor(0.0f,0.0f,0.0f,0.0f); glClear(GL_COLOR_BUFFER_BIT); numofmenuitems=0; createmenuitem(TXT_BACK,0,0,16,1.0f,1.0f,1.0f,1.0f); setmenuitem(MO_HOTKEY,SCAN_ESC); count=0; for (count2=0;count2<8;count2++) if (pagenum+count<numoffiles) { createmenuitem(levellist[pagenum+count],64,320+count2*12,12,1.0f,1.0f,1.0f,1.0f); count++; } for (count2=0;count2<8;count2++) if (pagenum+count<numoffiles) { createmenuitem(levellist[pagenum+count],256,320+count2*12,12,1.0f,1.0f,1.0f,1.0f); count++; } for (count2=0;count2<8;count2++) if (pagenum+count<numoffiles) { createmenuitem(levellist[pagenum+count],448,320+count2*12,12,1.0f,1.0f,1.0f,1.0f); count++; } createmenuitem(TXT_PAGE_UP,(304|TEXT_END),416,16,1.0f,1.0f,1.0f,1.0f); setmenuitem(MO_HOTKEY,SCAN_PAGEUP); setmenuitem(MO_SET,&pagenum,pagenum-24); if (pagenum<24) setmenuitem(MO_HIGHLIGHT,0); createmenuitem(TXT_PAGE_DOWN,320,416,16,1.0f,1.0f,1.0f,1.0f); setmenuitem(MO_HOTKEY,SCAN_PAGEDOWN); setmenuitem(MO_SET,&pagenum,pagenum+24); if (pagenum+24>=numoffiles) setmenuitem(MO_HIGHLIGHT,0); checksystemmessages(); checkkeyboard(); checkmouse(); checkjoystick(); checkmenuitems(); setuptextdisplay(); glColor4f(1.0f,1.0f,1.0f,1.0f); displaybackground(620); drawtext(TXT_PLAY_CAMPAIGN,(320|TEXT_CENTER),304,16,1.0f,1.0f,1.0f,1.0f); drawmenuitems(); drawmousecursor(768+font.cursornum,mouse.x,mouse.y,16,1.0f,1.0f,1.0f,1.0f); SDL_GL_SwapBuffers(); for (count=1;count<=24;count++) if (pagenum+count-1<numoffiles) if (menuitem[count].active) { strcpy(mappack.filename,levellist[pagenum+count-1]); loadmappack(); campaignmenu(); } } resetmenuitems(); }
int sbbs_t::exec_file(csi_t *csi) { char str[256],ch; int s; uint i,j,x,y; file_t f; switch(*(csi->ip++)) { case CS_FILE_SELECT_AREA: csi->logic=LOGIC_FALSE; if(!usrlibs) return(0); while(online) { j=0; if(usrlibs>1) { sprintf(str,"%smenu/libs.*", cfg.text_dir); if(fexist(str)) menu("libs"); else { bputs(text[CfgLibLstHdr]); for(i=0;i<usrlibs && !msgabort();i++) { if(i==curlib) outchar('*'); else outchar(' '); if(i<9) outchar(' '); if(i<99) outchar(' '); bprintf(text[CfgLibLstFmt] ,i+1,cfg.lib[usrlib[i]]->lname); } } sprintf(str,text[JoinWhichLib],curlib+1); mnemonics(str); j=getnum(usrlibs); if((int)j==-1) return(0); if(!j) j=curlib; else j--; } sprintf(str,"%smenu/dirs%u.*", cfg.text_dir, usrlib[j]+1); if(fexist(str)) { sprintf(str,"dirs%u",usrlib[j]+1); menu(str); } else { CLS; bprintf(text[DirLstHdr], cfg.lib[usrlib[j]]->lname); for(i=0;i<usrdirs[j] && !msgabort();i++) { if(i==curdir[j]) outchar('*'); else outchar(' '); sprintf(str,text[DirLstFmt],i+1 ,cfg.dir[usrdir[j][i]]->lname,nulstr ,getfiles(&cfg,usrdir[j][i])); if(i<9) outchar(' '); if(i<99) outchar(' '); bputs(str); } } sprintf(str,text[JoinWhichDir],curdir[j]+1); mnemonics(str); i=getnum(usrdirs[j]); if((int)i==-1) { if(usrlibs==1) return(0); continue; } if(!i) i=curdir[j]; else i--; curlib=j; curdir[curlib]=i; csi->logic=LOGIC_TRUE; return(0); } return(0); case CS_FILE_GET_DIR_NUM: if(useron.misc&COLDKEYS) { i=atoi(csi->str); if(i && i<=usrdirs[curlib] && usrlibs) curdir[curlib]=i-1; return(0); } ch=getkey(K_UPPER); outchar(ch); if((ch&0xf)*10U<=usrdirs[curlib] && (ch&0xf) && usrlibs) { i=(ch&0xf)*10; ch=getkey(K_UPPER); if(!isdigit(ch) && ch!=CR) { ungetkey(ch); curdir[curlib]=(i/10)-1; return(0); } outchar(ch); if(ch==CR) { curdir[curlib]=(i/10)-1; return(0); } logch(ch,0); i+=ch&0xf; if(i*10<=usrdirs[curlib]) { /* 100+ dirs */ i*=10; ch=getkey(K_UPPER); if(!isdigit(ch) && ch!=CR) { ungetkey(ch); curdir[curlib]=(i/10)-1; return(0); } outchar(ch); if(ch==CR) { curdir[curlib]=(i/10)-1; return(0); } logch(ch,0); i+=ch&0xf; } if(i<=usrdirs[curlib]) curdir[curlib]=i-1; return(0); } if((ch&0xf)<=(int)usrdirs[curlib] && (ch&0xf) && usrlibs) curdir[curlib]=(ch&0xf)-1; return(0); case CS_FILE_GET_LIB_NUM: if(useron.misc&COLDKEYS) { i=atoi(csi->str); if(i && i<=usrlibs) curlib=i-1; return(0); } ch=getkey(K_UPPER); outchar(ch); if((ch&0xf)*10U<=usrlibs && (ch&0xf)) { i=(ch&0xf)*10; ch=getkey(K_UPPER); if(!isdigit(ch) && ch!=CR) { ungetkey(ch); curlib=(i/10)-1; return(0); } outchar(ch); if(ch==CR) { curlib=(i/10)-1; return(0); } logch(ch,0); i+=ch&0xf; if(i<=usrlibs) curlib=i-1; return(0); } if((ch&0xf)<=(int)usrlibs && (ch&0xf)) curlib=(ch&0xf)-1; return(0); case CS_FILE_SHOW_LIBRARIES: if(!usrlibs) return(0); sprintf(str,"%smenu/libs.*", cfg.text_dir); if(fexist(str)) { menu("libs"); return(0); } bputs(text[LibLstHdr]); for(i=0;i<usrlibs && !msgabort();i++) { if(i==curlib) outchar('*'); else outchar(' '); if(i<9) outchar(' '); bprintf(text[LibLstFmt],i+1 ,cfg.lib[usrlib[i]]->lname,nulstr,usrdirs[i]); } return(0); case CS_FILE_SHOW_DIRECTORIES: if(!usrlibs) return(0); sprintf(str,"%smenu/dirs%u.*", cfg.text_dir, usrlib[curlib]+1); if(fexist(str)) { sprintf(str,"dirs%u",usrlib[curlib]+1); menu(str); return(0); } CRLF; bprintf(text[DirLstHdr],cfg.lib[usrlib[curlib]]->lname); for(i=0;i<usrdirs[curlib] && !msgabort();i++) { if(i==curdir[curlib]) outchar('*'); else outchar(' '); sprintf(str,text[DirLstFmt],i+1 ,cfg.dir[usrdir[curlib][i]]->lname,nulstr ,getfiles(&cfg,usrdir[curlib][i])); if(i<9) outchar(' '); if(i<99) outchar(' '); bputs(str); } return(0); case CS_FILE_LIBRARY_UP: curlib++; if(curlib>=usrlibs) curlib=0; return(0); case CS_FILE_LIBRARY_DOWN: if(!curlib) curlib=usrlibs-1; else curlib--; return(0); case CS_FILE_DIRECTORY_UP: if(!usrlibs) return(0); curdir[curlib]++; if(curdir[curlib]>=usrdirs[curlib]) curdir[curlib]=0; return(0); case CS_FILE_DIRECTORY_DOWN: if(!usrlibs) return(0); if(!curdir[curlib]) curdir[curlib]=usrdirs[curlib]-1; else curdir[curlib]--; return(0); case CS_FILE_SET_AREA: csi->logic=LOGIC_TRUE; for(i=0;i<usrlibs;i++) for(j=0;j<usrdirs[i];j++) if(!stricmp(csi->str,cfg.dir[usrdir[i][j]]->code)) { curlib=i; curdir[i]=j; return(0); } csi->logic=LOGIC_FALSE; return(0); case CS_FILE_SET_LIBRARY: csi->logic=LOGIC_TRUE; for(i=0;i<usrlibs;i++) if(!stricmp(cfg.lib[usrlib[i]]->sname,csi->str)) break; if(i<usrlibs) curlib=i; else csi->logic=LOGIC_FALSE; return(0); case CS_FILE_UPLOAD: csi->logic=LOGIC_FALSE; if(usrlibs) { i=usrdir[curlib][curdir[curlib]]; if(cfg.upload_dir!=INVALID_DIR && !dir_op(i) && !(useron.exempt&FLAG('U')) && !chk_ar(cfg.dir[i]->ul_ar,&useron,&client)) i=cfg.upload_dir; } else i=cfg.upload_dir; csi->logic=upload(i) ? LOGIC_TRUE:LOGIC_FALSE; return(0); case CS_FILE_UPLOAD_USER: csi->logic=LOGIC_FALSE; if(cfg.user_dir==INVALID_DIR) { bputs(text[NoUserDir]); return(0); } csi->logic=upload(cfg.user_dir) ? LOGIC_TRUE:LOGIC_FALSE; return(0); case CS_FILE_UPLOAD_SYSOP: csi->logic=LOGIC_FALSE; if(cfg.sysop_dir==INVALID_DIR) { bputs(text[NoSysopDir]); return(0); } csi->logic=upload(cfg.sysop_dir) ? LOGIC_TRUE:LOGIC_FALSE; return(0); case CS_FILE_DOWNLOAD: if(!usrlibs) return(0); if(useron.rest&FLAG('D')) { bputs(text[R_Download]); return(0); } padfname(csi->str,str); strupr(str); if(!listfileinfo(usrdir[curlib][curdir[curlib]],str,FI_DOWNLOAD)) { bputs(text[SearchingAllDirs]); for(i=0;i<usrdirs[curlib];i++) if(i!=curdir[curlib] && (s=listfileinfo(usrdir[curlib][i],str,FI_DOWNLOAD))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); bputs(text[SearchingAllLibs]); for(i=0;i<usrlibs;i++) { if(i==curlib) continue; for(j=0;j<usrdirs[i];j++) if((s=listfileinfo(usrdir[i][j],str,FI_DOWNLOAD))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); } } return(0); case CS_FILE_DOWNLOAD_USER: /* Download from user dir */ csi->logic=LOGIC_FALSE; if(cfg.user_dir==INVALID_DIR) { bputs(text[NoUserDir]); return(0); } if(useron.rest&FLAG('D')) { bputs(text[R_Download]); return(0); } CRLF; if(!listfileinfo(cfg.user_dir,nulstr,FI_USERXFER)) bputs(text[NoFilesForYou]); else csi->logic=LOGIC_TRUE; return(0); case CS_FILE_DOWNLOAD_BATCH: if(batdn_total && (text[DownloadBatchQ][0]==0 || yesno(text[DownloadBatchQ]))) { start_batch_download(); csi->logic=LOGIC_TRUE; } else csi->logic=LOGIC_FALSE; return(0); case CS_FILE_BATCH_ADD_LIST: batch_add_list(csi->str); return(0); case CS_FILE_BATCH_ADD: csi->logic=LOGIC_FALSE; if(!csi->str[0]) return(0); padfname(csi->str,f.name); for(x=y=0;x<usrlibs;x++) { for(y=0;y<usrdirs[x];y++) if(findfile(&cfg,usrdir[x][y],f.name)) break; if(y<usrdirs[x]) break; } if(x>=usrlibs) return(0); f.dir=usrdir[x][y]; getfileixb(&cfg,&f); f.size=0; getfiledat(&cfg,&f); addtobatdl(&f); csi->logic=LOGIC_TRUE; return(0); case CS_FILE_BATCH_CLEAR: if(!batdn_total) { csi->logic=LOGIC_FALSE; return(0); } csi->logic=LOGIC_TRUE; for(i=0;i<batdn_total;i++) { f.dir=batdn_dir[i]; f.datoffset=batdn_offset[i]; f.size=batdn_size[i]; strcpy(f.name,batdn_name[i]); closefile(&f); } batdn_total=0; return(0); case CS_FILE_VIEW: if(!usrlibs) return(0); padfname(csi->str,str); strupr(str); csi->logic=LOGIC_TRUE; if(listfiles(usrdir[curlib][curdir[curlib]],str,0,FL_VIEW)) return(0); bputs(text[SearchingAllDirs]); for(i=0;i<usrdirs[curlib];i++) { if(i==curdir[curlib]) continue; if(listfiles(usrdir[curlib][i],str,0,FL_VIEW)) break; } if(i<usrdirs[curlib]) return(0); bputs(text[SearchingAllLibs]); for(i=0;i<usrlibs;i++) { if(i==curlib) continue; for(j=0;j<usrdirs[i];j++) if(listfiles(usrdir[i][j],str,0,FL_VIEW)) return(0); } csi->logic=LOGIC_FALSE; bputs(text[FileNotFound]); return(0); case CS_FILE_LIST: /* List files in current dir */ if(!usrlibs) return(0); csi->logic=LOGIC_FALSE; if(!getfiles(&cfg,usrdir[curlib][curdir[curlib]])) { bputs(text[EmptyDir]); return(0); } padfname(csi->str,str); strupr(str); s=listfiles(usrdir[curlib][curdir[curlib]],str,0,0); if(s>1) { bprintf(text[NFilesListed],s); } csi->logic=!s; return(0); case CS_FILE_LIST_EXTENDED: /* Extended Information on files */ if(!usrlibs) return(0); padfname(csi->str,str); strupr(str); if(!listfileinfo(usrdir[curlib][curdir[curlib]],str,FI_INFO)) { bputs(text[SearchingAllDirs]); for(i=0;i<usrdirs[curlib];i++) if(i!=curdir[curlib] && (s=listfileinfo(usrdir[curlib][i] ,str,FI_INFO))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); bputs(text[SearchingAllLibs]); for(i=0;i<usrlibs;i++) { if(i==curlib) continue; for(j=0;j<usrdirs[i];j++) if((s=listfileinfo(usrdir[i][j],str,FI_INFO))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); } } return(0); case CS_FILE_FIND_TEXT: /* Find text in descriptions */ scandirs(FL_FINDDESC); return(0); case CS_FILE_FIND_TEXT_ALL: /* Find text in descriptions */ scanalldirs(FL_FINDDESC); return(0); case CS_FILE_FIND_NAME: /* Find text in descriptions */ scandirs(FL_NO_HDR); return(0); case CS_FILE_FIND_NAME_ALL: /* Find text in descriptions */ scanalldirs(FL_NO_HDR); return(0); case CS_FILE_BATCH_SECTION: batchmenu(); return(0); case CS_FILE_TEMP_SECTION: temp_xfer(); return(0); case CS_FILE_PTRS_CFG: csi->logic=!inputnstime(&ns_time); return(0); case CS_FILE_NEW_SCAN: scandirs(FL_ULTIME); return(0); case CS_FILE_NEW_SCAN_ALL: scanalldirs(FL_ULTIME); return(0); case CS_FILE_REMOVE: if(!usrlibs) return(0); if(useron.rest&FLAG('R')) { bputs(text[R_RemoveFiles]); return(0); } padfname(csi->str,str); strupr(str); if(!listfileinfo(usrdir[curlib][curdir[curlib]],str,FI_REMOVE)) { if(cfg.user_dir!=INVALID_DIR && cfg.user_dir!=usrdir[curlib][curdir[curlib]]) if((s=listfileinfo(cfg.user_dir,str,FI_REMOVE))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); bputs(text[SearchingAllDirs]); for(i=0;i<usrdirs[curlib];i++) if(i!=curdir[curlib] && i!=cfg.user_dir && (s=listfileinfo(usrdir[curlib][i],str,FI_REMOVE))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); bputs(text[SearchingAllLibs]); for(i=0;i<usrlibs;i++) { if(i==curlib || i==cfg.user_dir) continue; for(j=0;j<usrdirs[i]; j++) if((s=listfileinfo(usrdir[i][j],str,FI_REMOVE))!=0) if(s==-1 || (!strchr(str,'?') && !strchr(str,'*'))) return(0); } } return(0); } errormsg(WHERE,ERR_CHK,"shell function",*(csi->ip-1)); return(0); }
int main(int argc, char** argv) { int c; opterr = 0; int dflag=0; int lflag=0; int rflag=0; int oflag=0; char* diskpath = NULL; char* lpath = NULL; char* r_targetpath = NULL; char* o_outputpath = NULL; while((c=getopt(argc,argv,"l:r:d:o:")) !=-1) { switch(c) { case 'd': dflag = 1; diskpath = optarg; break; case 'l': lflag = 1; lpath = optarg; if(dflag==0) printusage(argv[0]); break; case 'r': rflag=1; r_targetpath = optarg; if(dflag==0) printusage(argv[0]); break; case 'o': oflag=1; o_outputpath = optarg; if(dflag==0) printusage(argv[0]); break; case '?': printusage(argv[0]); } } //printf("d: %s\nl: %s\nr: %s\no: %s\n",diskpath, lpath, r_targetpath, o_outputpath); //now, we know d must exist. Hence consider l^(r&&o) == 1. if((lflag^(rflag&&oflag))!=1) printusage(argv[0]); //now, we know only one side is 1 if(lflag==1) { if((rflag||oflag)==1) printusage(argv[0]); } int i= 0; struct BootEntry boot; readBoot(&boot,diskpath); BytesPerClus = boot.BPB_BytsPerSec * boot.BPB_SecPerClus; fat_start_address = boot.BPB_RsvdSecCnt * boot.BPB_BytsPerSec; start_data_address = (boot.BPB_RsvdSecCnt + boot.BPB_NumFATs * boot.BPB_FATSz32)*boot.BPB_BytsPerSec; //handle -l cases if(lflag==1) { inittokens(tokens); tokenize(lpath,tokens); char *teml; // has been tokenize by / while(strcmp(teml=tokens[i++],"")!=0) { int pre_count_l =0; int suf_count_l =0; int dotflag_l = 0; while(*teml!='\0') { if(*teml == '.') { dotflag_l = 1; } else if(dotflag_l == 0) { if(*teml!='/') pre_count_l++; } else if(dotflag_l == 1) { suf_count_l++; } teml++; } if(pre_count_l >8 || suf_count_l >3 || (suf_count_l == 0 && dotflag_l == 1)) { printf("Not in 8.3 format!\n"); printusage(argv[0]); } } //Now, finished reading input //if not in 8.3, print listfiles(&boot,diskpath,lpath); } //handle -r -o cases. //input won't be empty, because of getopt else { inittokens(rtokens); tokenize(r_targetpath,rtokens); char *temr = r_targetpath; while(strcmp(temr=rtokens[i++],"")!=0) { int pre_count_r =0; int suf_count_r =0; int dotflag_r = 0; while(*temr!='\0') { if(*temr == '.') { dotflag_r = 1; } else if(dotflag_r == 0) { if(*temr!='/') pre_count_r++; } else if(dotflag_r == 1) { suf_count_r++; } temr++; } if(pre_count_r >8 || suf_count_r >3 || (suf_count_r == 0 && dotflag_r == 1)) { printf("Not in 8.3 format!\n"); printusage(argv[0]); } } recoverfiles(r_targetpath,o_outputpath,&boot); } //printf("pre_count:%d\n suf_count:%d\n dotflag:%d\n",pre_count_l,suf_count_l,dotflag_l); }
program() { printl(listfiles().convert(FM,"\n")); }
int main(int argc, char** argv) { int i; char str[256]; int print = 0; if(argc < 4) { printf("Usage : patchfirm.exe <patches_folder_path> <patch_path> <mode> <-v = verbose>\n"); exit(-1); } if(argc > 4) if(!strcmp(argv[4], "-v")) print = 1; listfiles(argv[1]); FILE* patch = fopen(argv[2], "wb"); if(!patch) { printf("No patch path specified!\n"); exit(-1); } firm_info info; switch(argv[3][0]) { case 'n': info = native_info; break; case 'a': info = agb_info; break; case 't': info = twl_info; break; default : info = native_info; break; } printf("cfwtool - generating : %s\n", info.name); fwrite(&npatch, 1, 4, patch); for(i = 0; i < npatch; i++) { unsigned int size = 0; sprintf(str, "%s/%s", argv[1], files[i].name); FILE* fp = fopen(str, "rb"); fseek(fp, 0, 2); size = ftell(fp); rewind(fp); if(size > 0) { unsigned char* buf = (unsigned char*) malloc (size); fread(buf, 1, size, fp); fclose(fp); unsigned int pos = FirmAddr(files[i].off, info); fwrite(&pos, 1, 4, patch); fwrite(&size, 1, 4, patch); fwrite(buf, 1, size, patch); while((ftell(patch) % 4) != 0) fputc(0, patch); //Aligned 4 if(print) printf("Addr : %08X Size : %d\n", files[i].off, size); free(buf); } else { fclose(fp); } } fclose(patch); return 0; }
int main (int argc, char **argv) { char cmd[MAXCOMMANDLEN + 1]; char filename[MAXFILENAME + 1]; char string[MAXSTRLEN + 1]; int len; file* lst; char *data; long fsize; int res; while (1) { printf ("$"); *string = '\0'; len = nextin(cmd, filename, string); if (len < 0) { exit(0); } if (strcmp(cmd, OPEN) == 0) { res = create(filename); if (res == 0) { int length = atoi(string); if (length <= 0) { printf("please speficy the number of bytes to read from file %s\n", filename); continue; } data = malloc(length); fsize = readfile(data, length, filename); if (fsize < 0) { printf("Error in opening:\n"); } else { printf("%s\n", data); } } else if(res == -1) { printf("Error in opening %s\n", filename); } else { printf("File %s has been created \n", filename); } } else if (strcmp(cmd, FIND) == 0) { if ((fsize = lookup(filename)) < 0) { printf("Could not find %s\n", filename); } else { printf("File %s has %ld bytes\n", filename, fsize); } } else if (strcmp(cmd, REMOVE) == 0) { res = delete(filename); if (res == 0) { printf("File %s has been removed\n", filename); } else if (res == -2) { printf("File %s does not exist\n", filename); } else { printf("Error in deleting %s\n", filename); } } else if (strcmp(cmd, SHOW) == 0) { lst = listfiles(); if (lst == NULL) { printf("Error in showing:\n"); } else { for (; lst != (file *) NULL; lst = lst->next) { printf("%s\n", lst->filename); } } } else if (strcmp(cmd, WRITE) == 0) { fsize = writefile(string, len, filename); if (fsize < 0) { printf("Error in writing:\n"); } else { printf("%d bypes of data were written to file %s\n", fsize, filename); } } else if (strcmp(cmd, "exit") == 0) { printf("exiting...\n"); exit(0); } } }
void threadmain(int argc, char *argv[]) { char *q; char *srvname; char *mntpt; int list; mntpt = "/mnt"; user = strdup(getuser()); srvname = nil; list = 0; // mainmem->flags |= POOL_NOREUSE; ARGBEGIN{ case 'l': list = 1; break; case 'm': mntpt = ARGF(); break; case 'd': debug = strtoul(ARGF(), nil, 0); break; case 's': srvname = ARGF(); break; case 'f': fflag = 1; break; default: fprint(2, usage, argv0); exits("usage"); }ARGEND switch (argc) { default: fprint(2, usage, argv0); exits("usage"); case 0: mapname = DEFAULTMAP; break; case 1: mapname = argv[0]; break; } quotefmtinstall(); if((f = Bopen(mapname, OREAD)) == nil) sysfatal("%s: %r", mapname); free(file); file = strdup(mapname); free(startdir); startdir = strdup(mapname); if ((q = strrchr(startdir, '/'))) *q = '\0'; else startdir[0] = '\0'; inittokenlist(); getobject(Root, nil); Bterm(f); f = nil; root->parent = root; if(list){ listfiles(root); threadexits(nil); } if(pipe(p) < 0) sysfatal("pipe failed: %r"); mfd[0] = p[0]; mfd[1] = p[0]; threadnotify(robusthandler, 1); user = strdup(getuser()); if(debug) fmtinstall('F', fcallfmt); procrfork(io, nil, STACKSIZE, RFFDG); //RFNOTEG? close(p[0]); /* don't deadlock if child fails */ if(srvname){ srvname = smprint("/srv/jukefs.%s", srvname); remove(srvname); post(srvname, "jukefs", p[1]); } if(mount(p[1], -1, mntpt, MBEFORE, "") < 0) sysfatal("mount failed: %r"); threadexits(nil); }