/** * Reads and parses the config file. * Defaults to ${HOME}/.acre.config if path is empty. * @param path path to config file */ void AcreConfig::initConfig(std::string path) { if (path.empty()) { path = expandString("${HOME}/.acre.config"); } try { config.readFile(path.c_str()); if (config.exists(CONFIG_IGNORE)) { libconfig::Setting &igList = config.lookup(CONFIG_IGNORE); for (int i = 0; i < igList.getLength(); i++) ignore.insert(expandString(igList[i])); } } // Silently ignore I/O errors catch(libconfig::FileIOException &e) {} }
static void writeProjectItem(const ProjectItem* item, const StringMap& params, const StringSet& urlSchemes) { if (!item) return; // Open input file auto inMode = item->replaceParams ? ios::in : ios::binary; ifstream ifs(item->inFile.c_str(), inMode); if (!ifs.is_open()) { SBLog::warning() << "Failed to open " << item->inFile << " for reading." << std::endl; return; } // Open output file ofstream ofs; auto outMode = item->replaceParams ? ios::out : ios::binary; openOutputFileStream(ofs, item->outFile, outMode); if (item->replaceParams) { // Expand input line by line and write it out std::string line; while (std::getline(ifs, line)) { expandString(line, params); ofs << line << std::endl; } } else { // Copy the file contents ofs << ifs.rdbuf(); } if (!urlSchemes.empty() && isAppxManifestFileName(item->inFile)) { ofs.close(); insertUrlSchemes(item->outFile, urlSchemes); } }
std::wstring BaseOption::expandString(const std::wstring& string, const std::map<BaseOption*, size_t>& values) { std::map<std::wstring, std::wstring> substitutions; for (auto i : values) { substitutions[i.first->displayName()] = i.first->value(i.second).value; } return expandString(string, substitutions); }
static void expandProjectItem(const std::string& srcDir, const std::string& destDir, const StringMap& params, ProjectItem* item) { // Expand paths to be absolute and pretty if (item) { expandString(item->outFile, params); item->outFile = joinPaths(destDir, item->outFile); item->outFile = platformPath(sanitizePath(item->outFile)); item->inFile = joinPaths(srcDir, item->inFile); item->inFile = platformPath(sanitizePath(item->inFile)); } }
void ex3_3(){ char myString[] = "a-z"; char myString2[] = "A-z"; char myString3[] = "a-b-c-"; char myString4[] = "a-z0-9"; //add 0-9 after char myString5[] = "-a-zA-F4-9c"; char myString6[100]; char myString7[100]; char myString8[100]; char myString9[100]; char myString10[100]; int i; for(i = 0; i < 100; i++){ myString6[i] = '\0'; myString7[i] = '\0'; myString8[i] = '\0'; myString9[i] = '\0'; myString10[i] = '\0'; } printf("String1:%s\n", myString); printf("String2:%s\n", myString2); printf("String3:%s\n", myString3); printf("String4:%s\n", myString4); printf("String5:%s\n", myString5); expandString(myString, myString6); expandString(myString2, myString7); expandString(myString3, myString8); expandString(myString4, myString9); expandString(myString5, myString10); printf("String6:%s\n", myString6); printf("String7:%s\n", myString7); printf("String8:%s\n", myString8); printf("String9:%s\n", myString9); printf("String10:%s\n", myString10); }
void VSTemplateProject::expand(const std::string& srcDir, const std::string& destDir, const VSTemplateParameters& params) { // Make a copy of the parameters map m_params = params.getValuesMap(); // Expand the output directory and update destDir expandString(m_outputDir, m_params); std::string updatedDestDir = joinPaths(destDir, m_outputDir); // Handle the project items for (auto item : m_items) { expandProjectItem(srcDir, updatedDestDir, m_params, item);; } }
void StdOutputRedirector::init(const Arguments & theArguments) { if (theArguments.haveOption("--std-logfile")) { const char * myEnv = ::getenv(LOG_WRAPAROUND_FILESIZE); if (myEnv) { string mylogFileSize(myEnv); _myMaximumFileSize = asl::as<long>(mylogFileSize); } myEnv = ::getenv(LOG_CREATE_ON_EACH_RUN); if (myEnv) { string myTmpStr(myEnv); _myLogInOneFileFlag = !(strcmp(toLowerCase(myTmpStr).c_str(), "true") == 0); } myEnv = ::getenv(LOG_REMOVE_OLD_ARCHIVE); if (myEnv) { string myTmpStr(myEnv); _myRemoveOldArchiveFlag = (strcmp(toLowerCase(myTmpStr).c_str(), "true") == 0); } myEnv = ::getenv(LOG_WRAPAROUND_CHECK_SEC); if (myEnv) { string myTmpStr(myEnv); _myFileSizeCheckFrequInSec = asl::as<long>(myTmpStr); } std::string myFilenameWithTimestamp = expandString(theArguments.getOptionArgument("--std-logfile"), _myOutputFilename); if (!_myLogInOneFileFlag) { _myOutputFilename = myFilenameWithTimestamp; } // for syncing c like stderr & c++ cerr // default is true, not syncing is supposted to be faster, so maybe we should disable it //ios_base::sync_with_stdio(false); redirect(); // write a timestamp cout << ourAppStartMessage << _myOutputFilename << endl; cout << "Timestamp: " << getCurrentTimeString() << endl; cout << "---------" << endl; // remove all but latest archives if (_myRemoveOldArchiveFlag) { removeoldArchives(); } } }
std::wstring AppOption::arguments(size_t index, const std::map<BaseOption*, size_t>& values) const { return expandString(m_options[index].arguments, values); }
std::wstring BaseOption::expandValue(size_t index, const std::map<BaseOption*, size_t>& values) { return expandString(value(index).value, values); }