void AaptDir::print() const { const size_t ND=getDirs().size(); size_t i; for (i=0; i<ND; i++) { getDirs().valueAt(i)->print(); } const size_t NF=getFiles().size(); for (i=0; i<NF; i++) { getFiles().valueAt(i)->print(); } }
static bool maybeAddDirectory(const std::string& newPath, Array<Directory>& directoryArray, bool recurse = true) { if (fileExists(newPath)) { Directory& d = directoryArray.next(); d.path = newPath; getFiles(pathConcat(newPath, "*"), d.contents); Array<std::string> dirs; getDirs(pathConcat(newPath, "*"), dirs); d.contents.append(dirs); if (recurse) { // Look for subdirectories static const std::string subdirs[] = {"font", "gui", "SuperShader", "cubemap", "icon", "material", "image", "md2", "md3", "ifs", "3ds", "sky", ""}; for (int j = 0; j < dirs.size(); ++j) { for (int i = 0; ! subdirs[i].empty(); ++i) { if (dirs[j] == subdirs[i]) { maybeAddDirectory(pathConcat(newPath, dirs[j]), directoryArray, false); } } } } return true; } else { return false; } }
void FileUtils::getDirs(const std::string& dirPath, std::vector<std::string>& dirs, bool includeChild)const { std::string finallyPath = dirPath; if (*(finallyPath.end() - 1) != '/' && *(finallyPath.end() - 1) != '\\') { finallyPath.append("/"); } DIR* dir = opendir(finallyPath.c_str()); if (!dir) return; dirent* entry = readdir(dir); while (entry) { if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { entry = readdir(dir); continue; } if (entry->d_type == DT_DIR) { dirs.push_back(finallyPath+entry->d_name); if (includeChild) { getDirs(finallyPath + entry->d_name, dirs, includeChild); } } entry = readdir(dir); } closedir(dir); }
struct wormFeature *wormGenesInRange(char *chromId, int start, int end) /* Get names of all genes that overlap the range. */ { /* This routine looks through the .PGO files made by makePgo */ getDirs(); return wormSomeGenesInRange(chromId, start, end, sangerDir); }
FILE *wormOpenGoodAli() /* Opens good alignment file and reads signature. * (You can then cdaLoadOne() it.) */ { char fileName[512]; getDirs(); sprintf(fileName, "%sgood.ali", cdnaDir); return cdaOpenVerify(fileName); }
struct wormFeature *wormCosmidsInRange(char *chromId, int start, int end) /* Get names of all genes that overlap the range. */ { /* This routine looks through the .COO files made by makePgo */ getDirs(); return scanChromOffsetFile(featDir, ".coo", pgoSig, 2*sizeof(int)+1, chromId, start, end, 1); }
struct wormFeature *wormCdnasInRange(char *chromId, int start, int end) /* Get all cDNAs that overlap the range. freeDnaSeqList the returned * list when you are through with it. */ { /* This routine looks through the .CDO files made by cdnaOff */ getDirs(); return scanChromOffsetFile(cdnaDir, ".cdo", cdoSig, 2*sizeof(int)+1, chromId, start, end, 0); }
boolean wormSearchAllCdna(struct wormCdnaIterator **retSi) /* Set up to search entire database or worm cDNA */ { char buf[512]; struct wormCdnaIterator *it; it = needMem(sizeof(*it)); getDirs(); sprintf(buf, "%s%s", cdnaDir, "allcdna.fa"); it->faFile = mustOpen(buf, "rb"); *retSi = it; return TRUE; }
static void wormCdnaCache() /* Set up to read cDNAs */ { getDirs(); if (cdnaSnof == NULL) { char buf[512]; sprintf(buf, "%s%s", cdnaDir, "allcdna"); cdnaSnof = snofMustOpen(buf); sprintf(buf, "%s%s", cdnaDir, "allcdna.fa"); cdnaFa = mustOpen(buf, "rb"); } }
/* * Steps recursively through a directory and collects all music files in a list * curdir: current directory path * files: the list to store filenames in * returns the LAST entry of the list. So the next item is the first in the list */ mptitle *recurse( char *curdir, mptitle *files ) { char dirbuff[2*MAXPATHLEN]; struct dirent **entry; int num, i; if( '/' == curdir[strlen( curdir )-1] ) { curdir[strlen( curdir )-1]=0; } addMessage( 3, "Checking %s", curdir ); /* get all music files */ num = getMusic( curdir, &entry ); if( num < 0 ) { addMessage( 0, "getMusic failed in %s", curdir ); return files; } for( i=0; i<num; i++ ) { activity( "Scanning" ); sprintf( dirbuff, "%s/%s", curdir, entry[i]->d_name ); files=insertTitle( files, dirbuff ); free( entry[i] ); } free( entry ); /* step down subdirectories */ num=getDirs( curdir, &entry ); if( num < 0 ) { addMessage( 0, "getDirs failed on %s", curdir ); return files; } for( i=0; i<num; i++ ) { sprintf( dirbuff, "%s/%s", curdir, entry[i]->d_name ); files=recurse( dirbuff, files ); free( entry[i] ); } free( entry ); return files; }
static void wormCacheSomeGdf(struct wormGdfCache *cache) /* Cache one gene prediction set. */ { if (cache->snof == NULL) { char fileName[512]; char *dir; bits32 sig; getDirs(); dir = *(cache->pDir); sprintf(fileName, "%sgenes", dir); cache->snof = snofMustOpen(fileName); sprintf(fileName, "%sgenes.gdf", dir); cache->file = mustOpen(fileName, "rb"); mustReadOne(cache->file, sig); if (sig != glSig) errAbort("%s is not a good file", fileName); } }
int DirectoryDAO::addDirectory(const QString& newDir) { // Do nothing if the dir to add is a child of a directory that is already in // the db. ScopedTransaction transaction(m_database); QStringList dirs = getDirs(); QString childDir; QString parentDir; foreach (const QString& dir, dirs) { if (isChildDir(newDir, dir)) { childDir = dir; } if (isChildDir(dir, newDir)) { parentDir = dir; } } if (!childDir.isEmpty()) { qDebug() << "return already watching"; return ALREADY_WATCHING; } if (!parentDir.isEmpty()) { // removeing the old directory won't harm because we are adding the // parent later in this function removeDirectory(parentDir); } QSqlQuery query(m_database); query.prepare("INSERT INTO " % DIRECTORYDAO_TABLE % " (" % DIRECTORYDAO_DIR % ") VALUES (:dir)"); query.bindValue(":dir", newDir); if (!query.exec()) { LOG_FAILED_QUERY(query) << "Adding new dir (" % newDir % ") failed."; return SQL_ERROR; } transaction.commit(); return ALL_FINE; }
static void makeChromFileName(char *chromId, char *buf) { getDirs(); sprintf(buf, "%s%s.nt4", nt4Dir, chromId); }
/*!\brief Gets all the file names of every .png image found in the given directory. Outputs a series of power 2 sized textures which contain all * the individual images as one sheet (or several depending on how many images you have and what your max sized square is). It also outputs * a single textfile which lists which texture pack contains which images. They are listed using their file names minus the png extension. * If a series of images are found, they are listed as an animation with a single reference name. So if you have cat_1.png cat_2.png cat_3.png * you will get animation 'cat' with 3 frames. */ int main(int argc, const char *argv[], const char **envp ){ char const *refstrSourceDir = DEFAULT_SOURCE; char const *refstrOutputFile = DEFAULT_OUTPUT; char const *refstrJavapak = NULL; char const *refstrManClass = NULL; unsigned int maxSquare = 1024; eOutputFormat format = eFormatDefault; char ignoreOutputFiles[256]; memset(ignoreOutputFiles, 0, sizeof(ignoreOutputFiles)); short usePadding=FALSE; bool enforcePow2=FALSE; printf("---Texture Cram---\n"); /** parse command arguments */ while(argc > 0){ if(argc > 1 && strncmp(argv[argc-2], SWITCH_DIR, 2)==0 ){ refstrSourceDir = argv[argc-1]; printf("Source directory is %s\n", refstrSourceDir); --argc; }else if(argc > 1 && strncmp(argv[argc-2], SWITCH_OUTPUT, 2)==0 ){ refstrOutputFile = argv[argc-1]; printf("Output path is %s\n", refstrOutputFile); --argc; }else if(argc > 1 && strncmp(argv[argc-2], SWITCH_MAXSQUARE, 2)==0 ){ maxSquare = atoi(argv[argc-1]); --argc; }else if(argc > 1 && strncmp(argv[argc-2], SWITCH_MAN_FORMAT, 2)==0 ){ if( strncmp(argv[argc-1], MAN_FORMAT_C, strlen(MAN_FORMAT_C) ) == 0 ){ format = eFormatC; printf("Manifest is C\n"); }else if( strncmp(argv[argc-1], MAN_FORMAT_JAVA, strlen(MAN_FORMAT_JAVA) ) == 0 ){ format = eFormatJava; printf("Manifest is java\n"); }else{ printf("Manifest is default\n"); } //- todo others --argc; }else if(argc > 1 && strncmp(argv[argc-2], SWITCH_JAVAPAK, 5)==0 ){ refstrJavapak = argv[argc-1]; printf("Java pack is: %s\n", refstrJavapak); --argc; }else if(argc > 1 && strncmp(argv[argc-2], SWITCH_CLASS, 5)==0 ){ refstrManClass = argv[argc-1]; printf("parent class is: %s\n", refstrManClass); --argc; }else if(argc > 1 && strncmp(argv[argc-2], SWITCH_PAD, 4)==0 ){ usePadding=TRUE; printf("Padding used\n"); --argc; }else if(strncmp(argv[argc-1], SWITCH_NEARPOW2, 2)==0){ enforcePow2 = TRUE; } --argc; } printf("The max size is %i\n", maxSquare); char *strBaseOut=NULL; getBaseDir(&strBaseOut, refstrOutputFile); char *strBaseName=NULL; getOutputNameFromFullPath(&strBaseName, refstrOutputFile); char **subDirs = calloc(2, sizeof(char*)); size_t numDirs = 1; copyString(&subDirs[0], refstrSourceDir); subDirs[1] = NULL; char buffCurOut[256]; size_t iDir; for(iDir=0; iDir < numDirs; ++iDir){ sTex **dynarrTextures = NULL; sSheetList sheets; memset(&sheets, 0, sizeof(sheets)); sFileList files; memset(&files, 0, sizeof(files)); sStillList stills; memset(&stills, 0, sizeof(stills)); sSeqList seqs; memset(&seqs, 0, sizeof(seqs)); sFontList fonts; memset(&fonts, 0, sizeof(fonts)); sManifest theMan; memset(&theMan, 0, sizeof(theMan)); if(getFiles(subDirs[iDir], &files, ignoreOutputFiles, SEARCH_PATTERN) != NOPROB) continue; if(strBaseName == NULL) getOutputNameFromFullPath(&strBaseName, subDirs[iDir]); snprintf(ignoreOutputFiles, 256, "%s*", strBaseName); if(strBaseOut != NULL) snprintf(buffCurOut, 256, "%s%s", strBaseOut, strBaseName); else strncpy(buffCurOut, strBaseName, 256); if(files.num > 0){ if(genTextures(subDirs[iDir], &files, &dynarrTextures) != NOPROB) goto LOOP_PROB; } if(dynarrTextures != NULL){ /** we only need to sort sequences and stills */ if(sortTextures(dynarrTextures, &seqs, &stills) != NOPROB) goto LOOP_PROB; } { /** fonts */ sTex **dynarrFntTexs =NULL; sFontInfo **dynarrFntIfo = genFontInfos(subDirs[iDir], ignoreOutputFiles); if(dynarrFntIfo != NULL && genTexFromFonts(dynarrFntIfo, &dynarrFntTexs, &fonts) != NOPROB) goto LOOP_PROB; unsigned int startIdx; if(dynarrTextures == NULL){ startIdx = 0; }else{ for(startIdx=0; dynarrTextures[startIdx] != NULL; ++startIdx) ; } appendTexArr(&dynarrTextures, dynarrFntTexs); genFontFromInfo((const sFontInfo **)dynarrFntIfo, &fonts, startIdx); cleanupFontInfos(&dynarrFntIfo); } if(dynarrTextures == NULL){ DBUG_WARN("No textures found"); goto LOOP_PROB; } if(arrangeTextures(dynarrTextures, &seqs, &stills, &fonts, &sheets, maxSquare) != NOPROB) goto LOOP_PROB; if(genMan( strBaseName, &seqs, &stills, &fonts, &sheets, (const sTex **)dynarrTextures, &theMan ) != NOPROB) goto LOOP_PROB; switch(format){ case eFormatDefault: if(writeManifestInTxt(buffCurOut, &theMan, (const sTex **)dynarrTextures) != NOPROB) goto LOOP_PROB; break; case eFormatC: if(writeManifestInC(buffCurOut, &theMan, (const sTex **)dynarrTextures) != NOPROB) goto LOOP_PROB; break; case eFormatJava: if(writeManifestInJava(buffCurOut, refstrJavapak, refstrManClass, &theMan, (const sTex **)dynarrTextures)!=NOPROB) goto LOOP_PROB; break; default: break; } if(writeSheets(strBaseOut, strBaseName, dynarrTextures, &sheets) != NOPROB) goto LOOP_PROB; { char **moreDirs = NULL; getDirs(subDirs[iDir], &moreDirs); if(moreDirs != NULL){ size_t iMore; for(iMore = 0; moreDirs[iMore] != NULL; ++iMore){ ++numDirs; subDirs = realloc(subDirs, (numDirs + 1) * sizeof(char*)); snprintf(buffCurOut, 245, "%s/%s", subDirs[iDir], moreDirs[iMore]); SAFE_DELETE(moreDirs[iMore]); copyString(&subDirs[ numDirs - 1], buffCurOut); subDirs[numDirs] = NULL; } } SAFE_DELETE(moreDirs); } LOOP_PROB: cleanupFileList(&files); cleanupTextures(&dynarrTextures); cleanupSheetList(&sheets); cleanupStillList(&stills); cleanupSeqList(&seqs); cleanupManifest(&theMan); SAFE_DELETE(subDirs[iDir]); SAFE_DELETE(strBaseName); } SAFE_DELETE(strBaseName); SAFE_DELETE(strBaseOut); SAFE_DELETE(subDirs); LOG("Finished!\n"); return 0; }
char *wormFeaturesDir() /* Return the features directory. (Includes trailing slash.) */ { getDirs(); return featDir; }
boolean wormGeneRange(char *name, char **retChrom, char *retStrand, int *retStart, int *retEnd) /* Return chromosome position of a chrom range, gene, ORF, cosmid, or nameless cluster. */ { static struct snof *c2gSnof = NULL, *c2cSnof = NULL; static FILE *c2gFile = NULL, *c2cFile = NULL; long offset; char fileName[512]; struct slName *syn = NULL; boolean ok; if (wormIsChromRange(name)) { *retStrand = '.'; return wormParseChromRange(name, retChrom, retStart, retEnd); } getDirs(); /* Translate biologist type name to cosmid.N name */ if (wormIsGeneName(name)) { syn = wormGeneToOrfNames(name); if (syn != NULL) { name = syn->name; } } if (wormFixupOrfName(name)) /* See if ORF, and if so make nice. */ { if (c2gSnof == NULL) { sprintf(fileName, "%sc2g", featDir); c2gSnof = snofMustOpen(fileName); sprintf(fileName, "%sc2g", featDir); c2gFile = mustOpen(fileName, "rb"); } ok = findAltSpliceRange(name, c2gSnof, c2gFile, retChrom, retStart, retEnd, retStrand); } else /* Lets say it's a cosmid. */ { char lineBuf[128]; char *words[3]; int wordCount; touppers(name); if (c2cSnof == NULL) { sprintf(fileName, "%sc2c", featDir); c2cSnof = snofMustOpen(fileName); sprintf(fileName, "%sc2c", featDir); c2cFile = mustOpen(fileName, "rb"); } if (!snofFindOffset(c2cSnof, name, &offset) ) return FALSE; fseek(c2cFile, offset, SEEK_SET); mustGetLine(c2cFile, lineBuf, sizeof(lineBuf)); wordCount = chopLine(lineBuf, words); assert(wordCount == 3); assert(strcmp(words[2], name) == 0); assert(wormIsChromRange(words[0])); *retStrand = words[1][0]; ok = wormParseChromRange(words[0], retChrom, retStart, retEnd); } slFreeList(&syn); return ok; }
char *wormGenieDir() /* Return directory with Genie specific gene predictions. */ { getDirs(); return genieDir; }
char *wormSangerDir() /* Return directory with Sanger specific gene predictions. */ { getDirs(); return sangerDir; }
char *wormCdnaDir() /* Return directory with cDNA data. */ { getDirs(); return cdnaDir; }
char *wormXenoDir() /* Return directory with cross-species alignments. */ { getDirs(); return xenoDir; }
char *wormChromDir() /* Return the directory with the chromosomes. */ { getDirs(); return nt4Dir; }
/* * Steps recursively through a directory and collects all music files in a list * curdir: current directory path * files: the list to store filenames in */ struct entry_t *recurse( char *curdir, struct entry_t *files ) { struct entry_t *buff=NULL; char dirbuff[MAXPATHLEN]; DIR *directory; FILE *file; struct dirent **entry; int num, i; char *pos; if( _ftverbosity > 2 ) { printf("Checking %s\n", curdir ); } // get all music files according to the blacklist num = getMusic( curdir, &entry ); if( num < 0 ) { fail( "getMusic", curdir, errno ); } for( i=0; i<num; i++ ) { activity("Scanning"); strncpy( dirbuff, curdir, MAXPATHLEN ); if( '/' != dirbuff[strlen(dirbuff)] ) { strncat( dirbuff, "/", MAXPATHLEN ); } strncat( dirbuff, entry[i]->d_name, MAXPATHLEN ); if( isValid(dirbuff) ) { int alen; file=fopen( dirbuff, "r"); if( NULL == file ) fail("Couldn't open file ", dirbuff, errno); if( -1 == fseek( file, 0L, SEEK_END ) ) fail( "fseek() failed on ", dirbuff, errno ); buff=(struct entry_t *)calloc(1, sizeof(struct entry_t)); if(buff == NULL) fail("Out of memory!", "", errno); strncpy( buff->name, entry[i]->d_name, MAXPATHLEN ); alen=genPathName( buff->display, dirbuff, MAXPATHLEN ); // strncpy( buff->title, entry[i]->d_name, MAXPATHLEN ); strncpy( buff->path, curdir, MAXPATHLEN ); strncpy( buff->artist, buff->display, alen ); buff->artist[alen+1]=0; buff->prev=files; buff->next=NULL; if(files != NULL)files->next=buff; buff->size=ftell( file )/1024; files=buff; fclose(file); } free(entry[i]); } free(entry); num=getDirs( curdir, &entry ); if( num < 0 ) { fail( "getDirs", curdir, errno ); } for( i=0; i<num; i++ ) { // activity("Scanning"); sprintf( dirbuff, "%s/%s", curdir, entry[i]->d_name ); files=recurse( dirbuff, files ); free(entry[i]); } free(entry); return files; }