configure.cpp
来自「pwlib源码库」· C++ 代码 · 共 662 行 · 第 1/2 页
CPP
662 行
while (file.good()) { string line; getline(file, line); if (line.find(fileText) != string::npos) { found = true; break; } } } return found;}bool TreeWalk(const string & directory){ bool foundAll = false; string wildcard = directory; wildcard += "*.*"; WIN32_FIND_DATA fileinfo; HANDLE hFindFile = FindFirstFile(wildcard.c_str(), &fileinfo); if (hFindFile != INVALID_HANDLE_VALUE) { do { string subdir = directory; subdir += fileinfo.cFileName; list<string>::const_iterator r = find(excludeDirList.begin(), excludeDirList.end(), subdir); if (r == excludeDirList.end()) { if ((fileinfo.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) != 0 && fileinfo.cFileName[0] != '.' && stricmp(fileinfo.cFileName, "RECYCLER") != 0) { subdir += '\\'; foundAll = true; vector<Feature>::iterator feature; for (feature = features.begin(); feature != features.end(); feature++) { if (!feature->Locate(subdir.c_str())) foundAll = false; } if (foundAll) break; TreeWalk(subdir); } } } while (FindNextFile(hFindFile, &fileinfo)); FindClose(hFindFile); } return foundAll;}bool ProcessHeader(const string & headerFilename){ string inFilename = headerFilename; inFilename += ".in"; ifstream in(inFilename.c_str(), ios::in); if (!in.is_open()) { cerr << "Could not open " << inFilename << endl; return false; } ofstream out(headerFilename.c_str(), ios::out); if (!out.is_open()) { cerr << "Could not open " << headerFilename << endl; return false; } while (in.good()) { string line; getline(in, line); vector<Feature>::iterator feature; for (feature = features.begin(); feature != features.end(); feature++) feature->Adjust(line); out << line << '\n'; } return !in.bad() && !out.bad();}BOOL FeatureEnabled(const string & name){ vector<Feature>::iterator feature; for (feature = features.begin(); feature != features.end(); feature++) { Feature & f = *feature; if (f.featureName == name && f.enabled) return TRUE; } return FALSE;}int main(int argc, char* argv[]){ ifstream conf("configure.ac", ios::in); if (conf.is_open()) { cout << "Opened " << "configure.ac" << endl; } else { conf.clear(); conf.open("configure.in", ios::in); if (conf.is_open()) { cout << "Opened " << "configure.in" << endl; } else { cerr << "Could not open configure.ac/configure.in" << endl; return 1; } } list<string> headers; vector<Feature>::iterator feature; while (conf.good()) { string line; getline(conf, line); int pos; if ((pos = line.find("AC_CONFIG_HEADERS")) != string::npos) { if ((pos = line.find('(', pos)) != string::npos) { int end = line.find(')', pos); if (end != string::npos) headers.push_back(line.substr(pos+1, end-pos-1)); } } else if ((pos = line.find("dnl MSWIN_")) != string::npos) { int space = line.find(' ', pos+10); if (space != string::npos) { string optionName(line, pos+10, space-pos-10); while (line[space] == ' ') space++; int comma = line.find(',', space); if (comma != string::npos) { string optionValue(line, comma+1, INT_MAX); if (!optionValue.empty()) { string featureName(line, space, comma-space); bool found = false; for (feature = features.begin(); feature != features.end(); feature++) { if (feature->featureName == featureName) { found = true; break; } } if (found) feature->Parse(optionName, optionValue); else features.push_back(Feature(featureName, optionName, optionValue)); } } } } } const char EXTERN_DIR[] = "--extern-dir="; const char EXCLUDE_DIR[] = "--exclude-dir="; const char EXCLUDE_ENV[] = "--exclude-env="; bool searchDisk = true; char *externDir = NULL; char *externEnv = NULL; for (int i = 1; i < argc; i++) { if (stricmp(argv[i], "--no-search") == 0 || stricmp(argv[i], "--disable-search") == 0) searchDisk = false; else if (strnicmp(argv[i], EXCLUDE_ENV, sizeof(EXCLUDE_ENV) - 1) == 0){ externEnv = argv[i] + sizeof(EXCLUDE_ENV) - 1; } else if (strnicmp(argv[i], EXTERN_DIR, sizeof(EXTERN_DIR) - 1) == 0){ externDir = argv[i] + sizeof(EXTERN_DIR) - 1; } else if (strnicmp(argv[i], EXCLUDE_DIR, sizeof(EXCLUDE_DIR) - 1) == 0) { string dir(argv[i] + sizeof(EXCLUDE_DIR) - 1); excludeDirList.push_back(dir); cout << "Excluding " << dir << " from feature search" << endl; } else if (stricmp(argv[i], "-v") == 0 || stricmp(argv[i], "--version") == 0) { cout << "configure version " VERSION "\n"; return 1; } else if (stricmp(argv[i], "-h") == 0 || stricmp(argv[i], "--help") == 0) { cout << "configure version " VERSION "\n" "usage: configure args\n" " --no-search Do not search disk for libraries.\n" " --extern-dir=dir Specify where to search disk for libraries.\n" " --exclude-dir=dir Exclude dir from search path.\n"; " --exclude-env=var Exclude dirs decribed by specified env var from search path.\n"; for (feature = features.begin(); feature != features.end(); feature++) { if (feature->featureName[0] != '\0') { cout << " --disable-" << feature->featureName << setw(20-feature->featureName.length()) << "Disable " << feature->displayName << '\n'; if (!feature->checkFiles.empty()) cout << " --" << feature->featureName << "-dir=dir" << setw(30-feature->featureName.length()) << "Set directory for " << feature->displayName << '\n'; } } return 1; } else { for (feature = features.begin(); feature != features.end(); feature++) { if (stricmp(argv[i], ("--no-" + feature->featureName).c_str()) == 0 || stricmp(argv[i], ("--disable-"+ feature->featureName).c_str()) == 0) { feature->enabled = false; break; } else if (stricmp(argv[i], ("--enable-"+ feature->featureName).c_str()) == 0) { feature->enabled = true; break; } else if (strstr(argv[i], ("--" + feature->featureName + "-dir=").c_str()) == argv[i] && !feature->Locate(argv[i] + strlen(("--" + feature->featureName + "-dir=").c_str()))) cerr << feature->displayName << " not found in " << argv[i] + strlen(("--" + feature->featureName+"-dir=").c_str()) << endl; } } } for (i = 0; i < 2; i++) { char * env = NULL; switch (i) { case 0: env = getenv("PWLIB_CONFIGURE_EXCLUDE_DIRS"); break; case 1: if (externEnv != NULL) env = getenv(externEnv); break; } if (env != NULL) { string str(env); string::size_type offs = 0; while (offs < str.length()) { string::size_type n = str.find(';', offs); string dir; if (n != string::npos) { dir = str.substr(offs, n-offs); offs = n+1; } else { dir = str.substr(offs); offs += str.length(); } excludeDirList.push_back(dir); cout << "Excluding " << dir << " from feature search" << endl; } } } bool foundAll = true; for (feature = features.begin(); feature != features.end(); feature++) { if (feature->enabled && !feature->checkFiles.empty()) { bool foundOne = false; list<string>::iterator dir; for (dir = feature->checkDirectories.begin(); dir != feature->checkDirectories.end(); dir++) { if (feature->Locate(dir->c_str())) { foundOne = true; break; } } if (!foundOne) foundAll = false; } } if (searchDisk && !foundAll) { // Do search of entire system char drives[100]; if (!externDir){ if (!GetLogicalDriveStrings(sizeof(drives), drives)) strcpy(drives, "C:\\"); } else { strcpy(drives, externDir); } const char * drive = drives; while (*drive != '\0') { if (GetDriveType(drive) == DRIVE_FIXED) { cout << "Searching " << drive << endl; if (TreeWalk(drive)) break; } drive += strlen(drive)+1; } } for (feature = features.begin(); feature != features.end(); feature++) { cout << " " << feature->displayName << ' '; BOOL output = FALSE; list<string>::const_iterator r; if (feature->enabled) { for (r = feature->ifFeature.begin(); r != feature->ifFeature.end(); ++r) { if (!FeatureEnabled(*r)) { feature->enabled = FALSE; cout << " DISABLED due to absence of feature " << *r; output = TRUE; break; } } } if (feature->enabled) { for (r = feature->ifNotFeature.begin(); r != feature->ifNotFeature.end(); ++r) { if (FeatureEnabled(*r)) { feature->enabled = FALSE; cout << " DISABLED due to presence of feature " << *r; output = TRUE; break; } } if (!feature->checkFiles.empty() && !feature->checkFiles.begin()->found) feature->enabled = FALSE; } if (output) ; else if (feature->checkFiles.empty() && !feature->simpleDefineValue.empty()) cout << "set to " << feature->simpleDefineValue; else if (feature->enabled) cout << "enabled"; else cout << "DISABLED"; cout << '\n'; } cout << endl; for (list<string>::iterator hdr = headers.begin(); hdr != headers.end(); hdr++) ProcessHeader(*hdr); cout << "Configuration completed.\n"; return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?