boolean IoSuppOpenSrc( // OPEN A SOURCE FILE (PRIMARY,HEADER) const char *file_name, // - supplied file name enum file_type typ ) // - type of search path to use { struct path_descr fd; // - descriptor for file name #ifdef OPT_BR if( NULL != file_name && file_name[0] != '\0' ) { TOKEN_LOCN locn; switch( typ ) { case FT_SRC : case FT_HEADER : case FT_LIBRARY : SrcFileGetTokenLocn( &locn ); BrinfIncludeSource( file_name, &locn ); break; } } #endif splitFileName( file_name, &fd ); if( doIoSuppOpenSrc( &fd, typ ) ) return TRUE; #if !defined(__DOS__) if( !CompFlags.check_truncated_fnames ) return FALSE; if( strlen( fd.fnm ) <= 8 ) return FALSE; fd.fnm[8] = '\0'; if( doIoSuppOpenSrc( &fd, typ ) ) return TRUE; #endif return FALSE; }
LogMessage::LogMessage(const std::string& file, const int line, const std::string& function, const LEVELS& level) : _timestamp(g3::systemtime_now()) , _call_thread_id(std::this_thread::get_id()) , _microseconds(microsecondsCounter()) , _file(splitFileName(file)) , _line(line) , _function(function) , _level(level) {}
static boolean openSrcPath( // ATTEMPT TO OPEN FILE (PATH TO BE PREPENDED) char *path, // - path char **exts, // - file extensions struct path_descr *fd, // - file descriptor enum file_type typ ) // - type of file being opened { boolean retn; // - return: TRUE ==> opened struct path_descr pd; // - path descriptor char dir[ _MAX_PATH*2 ]; // - new path char *pp; // - pointer into path char *ext; // - extension opened splitFileName( path, &pd ); if( fd->drv[0] == '\0' ) { pp = stpcpy( dir, path ); } else if( pd.drv[0] == '\0' ) { pp = stpcpy( dir, fd->drv ); pp = stpcpy( pp, path ); } else { pp = NULL; } if( pp == NULL ) { retn = FALSE; } else { pp = concSep( pp, dir ); makeDirName( pp, fd ); splitFileName( dir, &pd ); ext = openSrcExts( exts, &pd, typ ); if( ext == NULL ) { retn = FALSE; } else { if( ( typ == FT_SRC ) && ( ext != fd->ext ) ) { _makepath( dir, fd->drv, fd->dir, fd->fnm, ext ); WholeFName = FNameAdd( dir ); } retn = TRUE; } } return retn; }
LogMessage::LogMessage(const std::string& file, const int line, const std::string& function, const LEVELS& level) : _call_thread_id(std::this_thread::get_id()) , _file(splitFileName(file)) , _line(line) , _function(function) , _level(level) { g3::timespec_get(&_timestamp/*, TIME_UTC*/); // Another possibility could be to Falling back to clock_gettime as TIME_UTC // is not recognized by travis CI. // i.e. clock_gettime(CLOCK_REALTIME, &_timestamp); }
LogMessage::LogMessage(const std::string& file, const int line, const std::string& function, const LEVELS& level) : _timestamp(std::chrono::high_resolution_clock::now()) , _call_thread_id(std::this_thread::get_id()) #if defined(G3_LOG_FULL_FILENAME) , _file(file) #else , _file(splitFileName(file)) #endif , _file_path(file) , _line(line) , _function(function) , _level(level) { }
void CommonTestsSuite::test_splitFileName() { string name; string extension; name = extension = "dummy"; splitFileName("", name, extension); TS_ASSERT(name == ""); TS_ASSERT(extension == ""); name = extension = "dummy"; splitFileName("/path/", name, extension); TS_ASSERT(name == "/path/"); TS_ASSERT(extension == ""); name = extension = "dummy"; splitFileName("/path/file", name, extension); TS_ASSERT(name == "/path/file"); TS_ASSERT(extension == ""); name = extension = "dummy"; splitFileName("/path/file.", name, extension); TS_ASSERT(name == "/path/file"); TS_ASSERT(extension == ""); name = extension = "dummy"; splitFileName("/path/file.ext", name, extension); TS_ASSERT(name == "/path/file"); TS_ASSERT(extension == "ext"); name = extension = "dummy"; splitFileName("/path/.ext", name, extension); TS_ASSERT(name == "/path/"); TS_ASSERT(extension == "ext"); name = extension = "dummy"; splitFileName("/path/.", name, extension); TS_ASSERT(name == "/path/"); TS_ASSERT(extension == ""); name = extension = "dummy"; splitFileName(".", name, extension); TS_ASSERT(name == ""); TS_ASSERT(extension == ""); }
static boolean doIoSuppOpenSrc( // OPEN A SOURCE FILE (PRIMARY,HEADER) struct path_descr *fd, // - descriptor for file name enum file_type typ ) // - type of search path to use { char **paths; // - optional paths to prepend char **exts; // - optional extensions to append boolean retn; // - return: TRUE ==> opened char *path; // - next path char bufpth[ _MAX_PATH ]; // - buffer for next path SRCFILE curr; // - current included file SRCFILE stdin_srcfile; // - srcfile for stdin struct path_descr idescr; // - descriptor for included file LINE_NO dummy; // - dummy line number holder char prevpth[ _MAX_PATH ]; // - buffer for previous path switch( typ ) { case FT_SRC: if( fd->fnm[0] == '\0' && fd->ext[0] == '.' && fd->ext[1] == '\0' ) { if( ErrCount != 0 ) { // command line errors may result in "." as the input name // so the user thinks that the compiler is hung! return( FALSE ); } WholeFName = FNameAdd( "stdin" ); stdin_srcfile = SrcFileOpen( stdin, WholeFName ); SrcFileNotAFile( stdin_srcfile ); goto file_was_found; } paths = pathSrc; exts = extsSrc; break; case FT_HEADER: case FT_LIBRARY: if( !CompFlags.ignore_current_dir ) { paths = pathHdr; } else { paths = NULL; } exts = extsHdr; break; case FT_CMD: paths = pathCmd; exts = extsCmd; break; } switch( typ ) { case FT_LIBRARY: if( fd->drv[0] != '\0' || IS_DIR_SEP( fd->dir[0] ) ) { retn = openSrcPath( "", exts, fd, typ ); if( retn ) goto file_was_found; } break; case FT_HEADER: // even if ignoreing current dir, have to look for absolute paths if( !CompFlags.ignore_current_dir || fd->drv[0] != '\0' ) { // look in current directory retn = openSrcPath( "", exts, fd, typ ); if( retn ) goto file_was_found; } /* check directories of currently included files */ if( !IS_PATH_SEP( fd->dir[0] ) ) { prevpth[0] = '\xff'; /* to make it not compare with anything else */ prevpth[1] = '\0'; curr = SrcFileCurrent(); for( ;; ) { if( curr == NULL ) break; splitFileName( SrcFileName( curr ), &idescr ); _makepath( bufpth, idescr.drv, idescr.dir, NULL, NULL ); /*optimization: don't try and open if in previously checked dir*/ if( strcmp( bufpth, prevpth ) != 0 ) { retn = openSrcPath( bufpth, exts, fd, FT_HEADER ); if( retn ) goto file_was_found; } curr = SrcFileIncluded( curr, &dummy ); strcpy( prevpth, bufpth ); } } break; case FT_SRC: case FT_CMD: retn = openSrcPath( "", exts, fd, typ ); if( retn ) goto file_was_found; break; } switch( typ ) { case FT_HEADER: case FT_LIBRARY: HFileListStart(); for( ; ; ) { HFileListNext( bufpth ); if( *bufpth == '\0' ) break; retn = openSrcPath( bufpth, exts, fd, typ ); if( retn ) goto file_was_found; } break; } switch( typ ) { case FT_HEADER: case FT_CMD: case FT_SRC: if( IS_PATH_SEP( fd->dir[0] ) ) { // absolute path break; } if( paths != NULL ) { for( ; ; ) { path = *paths++; if( path == NULL ) break; retn = openSrcPath( path, exts, fd, typ ); if( retn ) goto file_was_found; } } break; } return FALSE; file_was_found: switch( typ ) { case FT_CMD: SrcFileCommand(); break; case FT_LIBRARY: SrcFileLibrary(); break; } return TRUE; }
//====================>>> makefileMaker::saveMakefile <<<========================= void makefileMaker::saveMakefile() { bool isBorland = false; // set up Borland stuff char resName[50]; resName[0] = 0; libsBCC.erase(); //builds the file named makefile using infos stored in project cmdw = ((videApp*)theApp)->GetMsgWindow(); // Now, change directory, drive int ix = strlen(makeName); while (ix > 0) { if (makeName[ix] == '\\' || makeName[ix] == '/') { break; } --ix; } if (ix > 0) { char dirPath[maxFileNameSize]; vOS vos; strcpy(dirPath, makeName); // copy the makefile name makeName[ix] = 0; // strip the name if (dirPath[1] == ':') // a drive { int drive = dirPath[0]; // need to change drive, too. if (drive > 'a') drive = drive - ' '; vos.vChDrive(drive-'A'); } vos.vChDir(dirPath); // change dir } ofstream mkf(makeName); // where to write makefile //header char buff[256]; char date[20]; char time[40]; vGetLocalTime(time); vGetLocalDate(date); isBorland = (stricmp(cc,"BCC32") == 0); if (isBorland) cmdw->AddLine("Building Borland Makefile..."); else cmdw->AddLine("Building Makefile -- Running compiler to generate dependencies..."); mkf << "#=======================================================================\n"; mkf << "#@V@:Note: File automatically generated by VIDE: "; mkf << "(" << time << " " << date << ") (" << cc << ").\n"; mkf << "# This file regenerated each time you run VIDE, so save under a\n"; mkf << "# new name if you hand edit, or it will be overwritten.\n"; mkf << "#=======================================================================\n\n"; mkf << "# Standard defines:\n"; if (isBorland) { #ifdef V_VersionWindows mkf << ".AUTODEPEND\n\n" << "# Borland C++ tools\n" << "IMPLIB\t= $(BCCROOT)\\bin\\Implib\n" << "ILINK32\t= $(BCCROOT)\\bin\\ILink32\n" << "TLIB\t= $(BCCROOT)\\bin\\TLib\n" << "BRC32\t= $(BCCROOT)\\bin\\Brc32\n" << "TASM32\t= $(BCROOT)\\bin\\Tasm32\n" << "CC \t= $(BCCROOT)\\bin\\" << cc << "\n\n"; if (*((videApp*)theApp)->getBCCPath()) mkf << "BCCROOT\t= " << ((videApp*)theApp)->getBCCPath() << "\n\n"; else mkf << "BCCROOT\t= C:\\borland\\bcc55\n\n"; #endif } else // gnu stuff { mkf << "CC \t=\t" << cc << "\n\n"; mkf << "WRES\t=\twindres\n\n"; } // HomeV mkf << "HOMEV\t=\t" << fixBackSlash(homeV,isBorland) << endl; //Dirs if (isBorland) mkf << "VPATH\t=\t$(HOMEV)\\include" << endl; else mkf << "VPATH\t=\t$(HOMEV)/include" << endl; mkf << "oDir\t=\t" << fixBackSlash(ObjDir,isBorland) << endl; //Obj Dir mkf << "Bin\t=\t" << fixBackSlash(BinDir,isBorland) << endl; //Bin Dir mkf << "Src\t=\t" << fixBackSlash(SrcDir, isBorland) << endl; //Src Dir mkf << "libDirs\t="; int nxtld = libDirs.size(); if (isBorland && nxtld > 0) mkf << "\t-L"; for (int ixx = 0 ; ixx < nxtld ; ++ixx) { if (isBorland) // put out ; separated list { mkf << fixBackSlash(libDirs.list[ixx],isBorland); if (ixx + 1 < nxtld) mkf << ";"; } else { mkf << "\t-L" << fixBackSlash(libDirs.list[ixx],isBorland); if (ixx + 1 < nxtld) mkf << " \\"; mkf << endl; } } if (isBorland) mkf << endl; mkf << endl; mkf << "incDirs\t="; int nxtid = incDirs.size(); if (isBorland && nxtid > 0) mkf << "\t-I"; for (int ixa = 0 ; ixa < nxtid ; ++ixa) { if (isBorland) // put out ; separated list { mkf << fixBackSlash(incDirs.list[ixa],isBorland); if (ixa + 1 < nxtid) mkf << ";"; } else { mkf << "\t-I" << fixBackSlash(incDirs.list[ixa],isBorland); if (ixa + 1 < nxtid) mkf << " \\"; mkf << endl; } } if (isBorland) mkf << endl; mkf << endl; //Libs if (isBorland) { mkf << "LIBS\t=\t" << fixBCCLibs() << endl; } else mkf << "LIBS\t=\t" << Libs << endl; //C_FLAGS & paths to includes mkf << "C_FLAGS\t=\t" << fixBackSlash(cFlags,isBorland); //defines int nxtcd = curDefs.size(); for (int ixb = 0 ; ixb < nxtcd ; ++ixb) { mkf << "\\\n\t" << curDefs.list[ixb]; } mkf << endl << endl; //sources int nxtof = objFiles.size(); mkf << "SRCS\t="; for (int ixc = 0 ; ixc < nxtof ; ++ixc) { if (isBorland) mkf << "\\\n\t$(Src)\\" << fixBackSlash(objFiles.list[ixc], isBorland); else mkf << "\\\n\t$(Src)/" << objFiles.list[ixc]; } mkf << endl << endl; //objects mkf << "EXOBJS\t="; for (int ixd = 0 ; ixd < nxtof ; ++ixd) { char *objn; if (isBorland) { objn = fixBackSlash(srcN2ObjN(objFiles.list[ixd],".obj"),isBorland); mkf << "\\" << endl << "\t$(oDir)\\" << objn; if (strstr(objn,".res") != 0) strcpy(resName,srcN2ObjN(objFiles.list[ixd],".obj")); } else { objn = srcN2ObjN(objFiles.list[ixd],".o"); mkf << "\\" << endl << "\t$(oDir)/" << objn; } } mkf << endl << endl; mkf << "ALLOBJS\t=\t$(EXOBJS)" << endl; if (isBorland) { mkf << "BCCJUNK\t=\t*.il* *.csm *.tds\n"; mkf << "ALLBIN\t=\t$(Bin)\\" << exeName << endl; mkf << "ALLTGT\t=\t$(Bin)\\" << exeName << endl << endl; } else { mkf << "ALLBIN\t=\t$(Bin)/" << exeName << endl; mkf << "ALLTGT\t=\t$(Bin)/" << exeName << endl << endl; } // Options mkf << "# User defines:" << endl; int nxtOpts = curOpts.size(); for (int ixe = 0 ; ixe < nxtOpts ; ++ixe) { fixTabs(buff,curOpts.list[ixe]); mkf << buff << endl; } mkf << endl; mkf << "#@# Targets follow ---------------------------------" << endl << endl; //target file //all: mkf << "all:\t$(ALLTGT)" << endl << endl; //objs: mkf << "objs:\t$(ALLOBJS)" << endl << endl; //cleanobjs: mkf << "cleanobjs:\n\trm -f $(ALLOBJS)" << endl << endl; // cleanbin if (isBorland) mkf << "cleanbin:\n\trm -f $(ALLBIN) $(BCCJUNK)" << endl << endl; else mkf << "cleanbin:\n\trm -f $(ALLBIN)" << endl << endl; // clean mkf << "clean:\tcleanobjs cleanbin" << endl << endl; // cleanall mkf << "cleanall:\tcleanobjs cleanbin" << endl << endl; mkf << "#@# User Targets follow ---------------------------------" << endl << endl; for (int ixf = 0 ; userTargets.list[ixf] != 0 ; ++ixf) { fixTabs(buff,userTargets.list[ixf]); mkf << buff << endl; } mkf << endl; mkf << "#@# Dependency rules follow -----------------------------" << endl << endl; //dependency rules // allow user to override the all: target with a #all comment if (!(userTargets.list[0] && strstr(userTargets.list[0],"#all")!=0)) { bool isStaticLib = false; char ext[32]; // check for a static library splitFileName(exeName,0,0,ext); // get the extention if (stricmp(ext,".a") == 0 #ifdef V_VersionWindows || stricmp(ext,".lib") == 0 || stricmp(ext,".LIB") == 0 #endif ) isStaticLib = true; // found a static lib if (isBorland) { #ifdef V_VersionWindows mkf << "$(Bin)\\" << exeName << " : $(EXOBJS)" << endl ; if (isStaticLib) { mkf << " rm -f $<\n"; mkf << " $(TLIB) $< @&&|\n"; for (int ixg = 0 ; objFiles.list[ixg] != 0 ; ixg++) { char* objn = srcN2ObjN(objFiles.list[ixg],".obj"); if (ixg != 0) mkf << " &\n"; mkf << " +$(oDir)\\" << srcN2ObjN(objFiles.list[ixg],".obj"); } mkf << " \n|\n\n"; } else // standard linker commands { mkf << " $(ILINK32) @&&|\n" << " $(LIBS) $(incDirs) $(libDirs) +\n"; mkf << "$(BCC32STARTUP)"; for (int ixg = 0 ; objFiles.list[ixg] != 0 ; ixg++) { char* objn = srcN2ObjN(objFiles.list[ixg],".obj"); if (strstr(objn,".res") == 0) mkf << " +\n$(oDir)\\" << srcN2ObjN(objFiles.list[ixg],".obj"); } mkf << "\n$<,$*\n"; for (int ixa = 0 ; libsBCC.list[ixa] != 0 ; ixa++) { if (ixa != 0) mkf << " +\n"; mkf << libsBCC.list[ixa] ; } if (*resName) // had a .res file mkf << "\n\n$(oDir)\\" << resName << "\n\n|\n"; else mkf << "\n\n\n\n|\n"; } #endif } else // gnu compatible; { mkf << "$(Bin)/" << exeName << ": $(EXOBJS)" << endl; if (isStaticLib) { mkf << "\trm -f $(Bin)/" << exeName << endl; mkf << "\tar cr $(Bin)/" << exeName << " $(EXOBJS)\n"; mkf << "\tranlib $(Bin)" << exeName << endl; } else { mkf << "\t$(CC) -o $(Bin)/" << exeName << " $(EXOBJS) $(incDirs) $(libDirs) $(LIBS)" << endl ; } } } if (isBorland) { // now count on autodependency for borland for (int ixg = 0 ; objFiles.list[ixg] != 0 ; ixg++) { mkf << "$(oDir)\\" << srcN2ObjN(objFiles.list[ixg],".obj"); mkf << " : $(Src)\\" << objFiles.list[ixg] << endl; // check for .rc files if (strstr(objFiles.list[ixg],".rc") != 0 || strstr(objFiles.list[ixg],".RC") != 0) { mkf << " $(BRC32) -r $(incDirs) -fo$@ $(Src)\\" << objFiles.list[ixg] << "\n\n"; } else // it is a .rc file { mkf << " $(CC) -c $(C_FLAGS) $(incDirs) -o$@ $(Src)\\" << objFiles.list[ixg] << "\n\n"; } } } else { rules.erase(); // fix by chorn - 03/08/99 for (int ixg = 0 ; objFiles.list[ixg] != 0 ; ixg++) { #ifdef V_VersionWindows if (strstr(objFiles.list[ixg],".rc") != 0 || strstr(objFiles.list[ixg],".RC") != 0) { mkf << "\n$(oDir)/" << srcN2ObjN(objFiles.list[ixg],".o"); mkf << " : $(Src)/" << objFiles.list[ixg] << endl; mkf << "\t$(WRES) $(Src)/" << objFiles.list[ixg]; mkf << " $(oDir)/" << srcN2ObjN(objFiles.list[ixg],".o"); mkf << "\n"; } else { findRule(objFiles.list[ixg]); } #else findRule(objFiles.list[ixg]); #endif } int lim = rules.size(); for (int ixh = 0 ; ixh < lim ; ++ixh) { mkf << endl << "$(oDir)/" << rules.list[ixh] << endl; // check for continuation lines while (*(rules.list[ixh]+strlen(rules.list[ixh])-1) == '\\') { ++ixh; if (rules.list[ixh]) mkf << rules.list[ixh] << endl; } mkf << "\t$(CC) $(C_FLAGS) $(incDirs) -c -o $@ $<" << endl; } } mkf.close(); strcpy(buff,makeName); strcat(buff," ("); strcat(buff,time); strcat(buff," "); strcat(buff,date); strcat(buff,") - Makefile saved."); cmdw->AddLine(buff); }
bool Initialize() { Logger::Init(); if ((bool)gRs.commandLine["arguments"]["--use-implicit-console-appender"]) { Variant dummy; dummy[CONF_LOG_APPENDER_NAME] = "implicit console appender"; dummy[CONF_LOG_APPENDER_TYPE] = CONF_LOG_APPENDER_TYPE_CONSOLE; dummy[CONF_LOG_APPENDER_COLORED] = (bool)true; dummy[CONF_LOG_APPENDER_LEVEL] = (uint32_t) 6; ConsoleLogLocation * pLogLocation = new ConsoleLogLocation(dummy); pLogLocation->SetLevel(_FINEST_); Logger::AddLogLocation(pLogLocation); } INFO("Reading configuration from %s", STR(gRs.commandLine["arguments"]["configFile"])); #ifdef COMPILE_STATIC gRs.pConfigFile = new ConfigFile(SpawnApplication, SpawnFactory); #else gRs.pConfigFile = new ConfigFile(NULL, NULL); #endif string configFilePath = gRs.commandLine["arguments"]["configFile"]; string fileName; string extension; splitFileName(configFilePath, fileName, extension); if (lowerCase(extension) == "xml") { if (!gRs.pConfigFile->LoadXmlFile(configFilePath, (bool)gRs.commandLine["arguments"]["--daemon"])) { FATAL("Unable to load file %s", STR(configFilePath)); return false; } } else if (lowerCase(extension) == "lua") { #ifdef HAS_LUA if (!gRs.pConfigFile->LoadLuaFile(configFilePath, (bool)gRs.commandLine["arguments"]["--daemon"])) { FATAL("Unable to load file %s", STR(configFilePath)); return false; } #else fprintf(stdout, "Lua is not supported by the current build of the server\n"); ASSERT("Lua is not supported by the current build of the server"); return false; #endif /* HAS_LUA */ } else { FATAL("Invalid file format: %s", STR(configFilePath)); return false; } #ifndef WIN32 if (gRs.pConfigFile->IsDaemon()) { if (!gRs.daemon) { INFO("Daemonize..."); pid_t pid = fork(); if (pid < 0) { FATAL("Unable to start as daemon. fork() failed"); return false; } if (pid > 0) { if (gRs.commandLine["arguments"].HasKey("--pid")) WritePidFile(pid); return false; } FINEST("Create a new SID for the daemon"); pid_t sid = setsid(); if (sid < 0) { FATAL("Unable to start as daemon. setsid() failed"); return false; } int fd = open("/dev/null", O_RDWR, 0); if (fd < 0) { FATAL("Unable to start as daemon. open(/dev/null) failed"); return false; } (void) dup2(fd, STDIN_FILENO); (void) dup2(fd, STDOUT_FILENO); (void) dup2(fd, STDERR_FILENO); if (fd > 2) { (void) close(fd); } gRs.daemon = true; Logger::SignalFork(); } } #endif /* WIN32 */ INFO("Configure logger"); if (!gRs.pConfigFile->ConfigLogAppenders()) { FATAL("Unable to configure log appenders"); return false; } INFO("%s", STR(Version::GetBanner())); INFO("Initialize I/O handlers manager: %s", NETWORK_REACTOR); IOHandlerManager::Initialize(); INFO("Configure modules"); if (!gRs.pConfigFile->ConfigModules()) { FATAL("Unable to configure modules"); return false; } INFO("Plug in the default protocol factory"); gRs.pProtocolFactory = new DefaultProtocolFactory(); if (!ProtocolFactoryManager::RegisterProtocolFactory(gRs.pProtocolFactory)) { FATAL("Unable to register default protocols factory"); return false; } INFO("Configure factories"); if (!gRs.pConfigFile->ConfigFactories()) { FATAL("Unable to configure factories"); return false; } INFO("Configure acceptors"); if (!gRs.pConfigFile->ConfigAcceptors()) { FATAL("Unable to configure acceptors"); return false; } INFO("Configure instances"); if (!gRs.pConfigFile->ConfigInstances()) { FATAL("Unable to configure instances"); return false; } INFO("Start I/O handlers manager: %s", NETWORK_REACTOR); IOHandlerManager::Start(); INFO("Configure applications"); if (!gRs.pConfigFile->ConfigApplications()) { FATAL("Unable to configure applications"); return false; } INFO("Install the quit signal"); installQuitSignal(QuitSignalHandler); return true; }
/** @param baseDir the base directory to work from @param fileName the fileName to squash the case from @param result where to put the result @param resultLen length of the result @return true if it could find the file, the result is in result, false if it couldn't find the file **/ AREXPORT bool ArUtil::matchCase(const char *baseDir, const char *fileName, char *result, size_t resultLen) { /*** ArLog::log(ArLog::Normal, "ArUtil::matchCase() baseDir = \"%s\" fileName = \"%s\"", baseDir, fileName); ***/ DIR *dir; struct dirent *ent; char separator; #ifndef WIN32 separator = '/'; #else separator = '\\'; #endif result[0] = '\0'; std::list<std::string> split = splitFileName(fileName); std::list<std::string>::iterator it = split.begin(); std::string finding = (*it); /* for (it = split.begin(); it != split.end(); it++) { printf("@@@@@@@@ %s\n", (*it).c_str()); } */ // how this works is we start at the base dir then read through // until we find what the next name we need, if entry is a directory // and we're not at the end of our string list then we change into // that dir and the while loop keeps going, if the entry isn't a // directory and matchs and its the last in our string list we've // found what we want if ((dir = opendir(baseDir)) == NULL) { ArLog::log(ArLog::Normal, "ArUtil: No such directory '%s' for base", baseDir); return false; } if (finding == ".") { it++; if (it != split.end()) { finding = (*it); } else { ArLog::log(ArLog::Normal, "ArUtil: No file or directory given (base = %s file = %s)", baseDir, fileName); closedir(dir); // KMC NEED TO DETERMINE WHICH IS CORRECT. // The following change appears to be necessary for maps, but is still // undergoing testing.... // Just return the given ".". (This is necessary to find maps in the local // directory under some circumstances.) // snprintf(result, resultLen, finding.c_str()); // return true; return false; } } while ((ent = readdir(dir)) != NULL) { // ignore some of these if (ent->d_name[0] == '.') { //printf("Ignoring %s\n", ent->d_name[0]); continue; } //printf("NAME %s finding %s\n", ent->d_name, finding.c_str()); // we've found what we were looking for if (ArUtil::strcasecmp(ent->d_name, finding) == 0) { size_t lenOfResult; lenOfResult = strlen(result); // make sure we can put the filename in if (strlen(ent->d_name) > resultLen - lenOfResult - 2) { ArLog::log(ArLog::Normal, "ArUtil::matchCase: result not long enough"); closedir(dir); return false; } //printf("Before %s", result); if (lenOfResult != 0) { result[lenOfResult] = separator; result[lenOfResult+1] = '\0'; } // put the filename in strcpy(&result[strlen(result)], ent->d_name); //printf("after %s\n", result); // see if we're at the end it++; if (it != split.end()) { //printf("Um.........\n"); finding = (*it); std::string wholeDir; wholeDir = baseDir; wholeDir += result; closedir(dir); //printf("'%s' '%s' '%s'\n", baseDir, result, wholeDir.c_str()); if ((dir = opendir(wholeDir.c_str())) == NULL) { ArLog::log(ArLog::Normal, "ArUtil::matchCase: Error going into %s", result); return false; } } else { //printf("\n########## Got it %s\n", result); closedir(dir); return true; } } } ArLog::log(ArLog::Normal, "ArUtil::matchCase: %s doesn't exist in %s", fileName, baseDir); //printf("!!!!!!!! %s", finding.c_str()); closedir(dir); return false; }
gkString getFileNameExt(const gkString& path) { gkString dir, base, ext; splitFileName(path, dir, base, ext); return ext; }
gkString getFileNameBase(const gkString& path) { gkString dir, base, ext; splitFileName(path, dir, base, ext); return base; }
gkString getDirName(const gkString& path) { gkString dir, base, ext; splitFileName(path, dir, base, ext); return dir; }
gkString getFileName(const gkString& path) { gkString dir, base, ext; splitFileName(path, dir, base, ext); return ext.empty() ? base : base + "." + ext; }