void SWMgr::augmentModules(const char *ipath, bool multiMod) { SWBuf path = ipath; if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/')) path += "/"; if (FileMgr::existsDir(path.c_str(), "mods.d")) { char *savePrefixPath = 0; char *saveConfigPath = 0; SWConfig *saveConfig = 0; stdstr(&savePrefixPath, prefixPath); stdstr(&prefixPath, path.c_str()); path += "mods.d"; stdstr(&saveConfigPath, configPath); stdstr(&configPath, path.c_str()); saveConfig = config; config = myconfig = 0; loadConfigDir(configPath); if (multiMod) { // fix config's Section names to rename modules which are available more than once // find out which sections are in both config objects // inserting all configs first is not good because that overwrites old keys and new modules would share the same config for (SectionMap::iterator it = config->Sections.begin(); it != config->Sections.end();) { if (saveConfig->Sections.find( (*it).first ) != saveConfig->Sections.end()) { //if the new section is already present rename it ConfigEntMap entMap((*it).second); SWBuf name; int i = 1; do { //module name already used? name.setFormatted("%s_%d", (*it).first.c_str(), i); i++; } while (config->Sections.find(name) != config->Sections.end()); config->Sections.insert(SectionMap::value_type(name, entMap) ); SectionMap::iterator toErase = it++; config->Sections.erase(toErase); } else ++it; } } CreateMods(multiMod); stdstr(&prefixPath, savePrefixPath); delete []savePrefixPath; stdstr(&configPath, saveConfigPath); delete []saveConfigPath; (*saveConfig) += *config; homeConfig = myconfig; config = myconfig = saveConfig; } }
/* Returns 0 if requested config files were loaded, * 1 if default files were loaded, * -1 if no files were loaded. * Prints error message if files cannot be loaded. */ int loadSystemConfig( char *which, int size ) { char *buf, *bp, *cp; int ret, len, doDefault=0; buf = bp = malloc(256); if (which && size) { for(cp = which, len = size; len && *cp && *cp != LP; cp++, len--) ; if (*cp == LP) { while (len-- && *cp && *cp++ != RP) ; /* cp now points past device */ strncpy(buf,which,cp - which); bp += cp - which; } else { cp = which; len = size; } if (*cp != '/') { strcpy(bp, IO_SYSTEM_CONFIG_DIR); strncat(bp, cp, len); if (strncmp(cp + len - strlen(IO_TABLE_EXTENSION), IO_TABLE_EXTENSION, strlen(IO_TABLE_EXTENSION)) != 0) strcat(bp, IO_TABLE_EXTENSION); } else { strncpy(bp, cp, len); bp[size] = '\0'; } if (strcmp(bp, SYSTEM_DEFAULT_FILE) == 0) doDefault = 1; ret = loadConfigFile(bp = buf, 0, 0); } else { ret = loadConfigDir((bp = SYSTEM_CONFIG), 0, 0, 0); } if (ret < 0) { error("System config file '%s' not found\n", bp); } else sysConfigValid = 1; free(buf); return (ret < 0 ? ret : doDefault); }
int loadOtherConfigs( int useDefault ) { char *val, *table; int count; char *string; int fd, ret; if (getValueForKey( "Boot Drivers", &val, &count)) { while (string = newStringFromList(&val, &count)) { ret = loadConfigDir(string, useDefault, &table, 0); if (ret >= 0) { if ((fd = openDriverReloc(string)) >= 0) { localPrintf("Loading binary for %s\n",string); if (loadDriver(string, fd) < 0) error("Error loading driver %s\n",string); close(fd); } driverWasLoaded(string, table); free(string); } else { driverIsMissing(string); } if (ret == 1) useDefault = 1; // use defaults from now on } } else { error("Warning: No active drivers specified in system config\n"); } bootArgs->first_addr0 = (int)bootArgs->configEnd + 1024; return 0; }
signed char SWMgr::Load() { signed char ret = 0; if (!config) { // If we weren't passed a config object at construction, find a config file if (!configPath) { // If we weren't passed a config path at construction... SWLog::getSystemLog()->logDebug("LOOKING UP MODULE CONFIGURATION..."); SWConfig *externalSysConf = sysConfig; // if we have a sysConf before findConfig, then we were provided one from an external source. findConfig(&configType, &prefixPath, &configPath, &augPaths, &sysConfig); if (!externalSysConf) mysysconfig = sysConfig; // remind us to delete our own sysConfig in d-tor SWLog::getSystemLog()->logDebug("LOOKING UP MODULE CONFIGURATION COMPLETE."); } if (configPath) { if (configType) loadConfigDir(configPath); else config = myconfig = new SWConfig(configPath); } } if (config) { SectionMap::iterator Sectloop, Sectend; ConfigEntMap::iterator Entryloop, Entryend; DeleteMods(); for (Sectloop = config->Sections.lower_bound("Globals"), Sectend = config->Sections.upper_bound("Globals"); Sectloop != Sectend; Sectloop++) { // scan thru all 'Globals' sections for (Entryloop = (*Sectloop).second.lower_bound("AutoInstall"), Entryend = (*Sectloop).second.upper_bound("AutoInstall"); Entryloop != Entryend; Entryloop++) // scan thru all AutoInstall entries InstallScan((*Entryloop).second.c_str()); // Scan AutoInstall entry directory for new modules and install } if (configType) { // force reload on config object because we may have installed new modules delete myconfig; config = myconfig = 0; loadConfigDir(configPath); } else config->Load(); CreateMods(mgrModeMultiMod); for (std::list<SWBuf>::iterator pathIt = augPaths.begin(); pathIt != augPaths.end(); pathIt++) { augmentModules(pathIt->c_str(), mgrModeMultiMod); } if (augmentHome) { // augment config with ~/.sword/mods.d if it exists --------------------- SWBuf homeDir = getHomeDir(); if (homeDir.length() && configType != 2) { // 2 = user only SWBuf path = homeDir; path += ".sword/"; augmentModules(path.c_str(), mgrModeMultiMod); path = homeDir; path += "sword/"; augmentModules(path.c_str(), mgrModeMultiMod); } } // ------------------------------------------------------------------------- if (!Modules.size()) // config exists, but no modules ret = 1; } else { SWLog::getSystemLog()->logError("SWMgr: Can't find 'mods.conf' or 'mods.d'. Try setting:\n\tSWORD_PATH=<directory containing mods.conf>\n\tOr see the README file for a full description of setup options (%s)", (configPath) ? configPath : "<configPath is null>"); ret = -1; } return ret; }
LocaleMgr::LocaleMgr(const char *iConfigPath) { locales = new LocaleMap(); char *prefixPath = 0; char *configPath = 0; SWConfig *sysConf = 0; char configType = 0; SWBuf path; std::list<SWBuf> augPaths; ConfigEntMap::iterator entry; defaultLocaleName = 0; if (!iConfigPath) { SWLog::getSystemLog()->logDebug("LOOKING UP LOCALE DIRECTORY..."); SWMgr::findConfig(&configType, &prefixPath, &configPath, &augPaths, &sysConf); if (sysConf) { if ((entry = sysConf->Sections["Install"].find("LocalePath")) != sysConf->Sections["Install"].end()) { configType = 9; // our own stdstr(&prefixPath, (char *)entry->second.c_str()); SWLog::getSystemLog()->logDebug("LocalePath provided in sysConfig."); } } SWLog::getSystemLog()->logDebug("LOOKING UP LOCALE DIRECTORY COMPLETE."); } else { loadConfigDir(iConfigPath); } if (prefixPath) { switch (configType) { case 2: int i; for (i = strlen(configPath)-1; ((i) && (configPath[i] != '/') && (configPath[i] != '\\')); i--); configPath[i] = 0; path = configPath; path += "/"; break; default: path = prefixPath; if ((prefixPath[strlen(prefixPath)-1] != '\\') && (prefixPath[strlen(prefixPath)-1] != '/')) path += "/"; break; } if (FileMgr::existsDir(path.c_str(), "locales.d")) { path += "locales.d"; loadConfigDir(path.c_str()); } } if (augPaths.size() && configType != 9) { //load locale files from all augmented paths std::list<SWBuf>::iterator it = augPaths.begin(); std::list<SWBuf>::iterator end = augPaths.end(); for (;it != end; ++it) { if (FileMgr::existsDir((*it).c_str(), "locales.d")) { SWBuf path = (*it) + "locales.d"; loadConfigDir(path.c_str()); } } } // Locales will be invalidated if you change the StringMgr // So only use the default hardcoded locale and let the // frontends change the locale if they want stdstr(&defaultLocaleName, SWLocale::DEFAULT_LOCALE_NAME); if (prefixPath) delete [] prefixPath; if (configPath) delete [] configPath; if (sysConf) delete sysConf; }