bool openFile(const char* name, struct fat_file_struct** file) { struct fat_dir_entry_struct fileEntry; if(!findFileInDir(name, &fileEntry)) { return false; } *file = fat_open_file(fs, &fileEntry); return true; }
QString misc::findFileInDir(QString dir_path, QString fileName) { QDir dir(dir_path); if(dir.exists(fileName)) { return dir.filePath(fileName); } QStringList subDirs = dir.entryList(QDir::Dirs); QString subdir_name; foreach(subdir_name, subDirs) { QString result = findFileInDir(dir.path()+QDir::separator()+subdir_name, fileName); if(!result.isNull()) { return result; } }
int findFileInDirList(char *dirList, char *name) { char * buf=malloc(512); char * p1,*p2; int isOK; if (!buf) error("Internal compiler error: out of mem"); debugParserpp("include findFileInDirList: dirlist %s, name %s\n",dirList,name); debugVerbose("include: Looking for file %s in directory list %s\n",name,dirList); /* the separator is either ':' or ';' */ for(isOK=0,p1=buf,p2=dirList;*p2;p2++) { if(*p2==':' || *p2==';') { // TODO also check last dir list ! *(p2+1)=='\0' *p1++='\0'; debugParserpp("include findFileInDirList: buf %s, name %s\n",buf,name); isOK=findFileInDir(buf,name); if(isOK) goto out_found; *buf='\0'; p1=buf; } else { /* TODO: check length of buf, and if >512 allocate larger */ *p1++=*p2; } } goto out_not_found; out_found: ; debugVerbose("include: found the file %s in path %s\n",name,buf); free(buf); return 1; out_not_found:; free(buf); return 0; }