QString PreferencesManager::getLang() { mp_ConfFile->beginGroup("openfluid.builder.interface"); if (!mp_ConfFile->contains("lang")) mp_ConfFile->setValue("lang",guessLang()); mp_ConfFile->endGroup(); mp_ConfFile->beginGroup("openfluid.builder.interface"); QString Lang = mp_ConfFile->value("lang").toString(); mp_ConfFile->endGroup(); return Lang; }
bool GccArguments::parse(ByteArray args, const Path &base) { mLang = NoLang; mClangArgs.clear(); mInputFiles.clear(); mBase = base; char quote = '\0'; List<ByteArray> split; ByteArray old2 = args; { char *cur = args.data(); char *prev = cur; // ### handle escaped quotes? int size = args.size(); while (size > 0) { switch (*cur) { case '"': case '\'': if (quote == '\0') quote = *cur; else if (*cur == quote) quote = '\0'; break; case ' ': if (quote == '\0') { if (cur > prev) split.append(trim(prev, cur - prev)); prev = cur + 1; } break; default: break; } --size; ++cur; } if (cur > prev) split.append(trim(prev, cur - prev)); } eatAutoTools(split); if (split.isEmpty()) { clear(); return false; } debug() << "GccArguments::parse (" << args << ") => " << split; Path path; if (split.front() == "cd" && split.size() > 3 && split.at(2) == "&&") { path = Path::resolved(split.at(1), base); split.erase(split.begin(), split.begin() + 3); } else { path = base; } mLang = guessLang(split.front()); if (mLang == NoLang) { clear(); return false; } const int s = split.size(); bool seenCompiler = false; for (int i=0; i<s; ++i) { const ByteArray &arg = split.at(i); if (arg.isEmpty()) continue; if (arg.startsWith('-')) { if (arg.startsWith("-x")) { ByteArray a; if (arg.size() == 2 && i + 1 < s) { a = split.at(++i); } else { a = arg.mid(2); } if (a == "c-header" || a == "c++-header") return false; mClangArgs.append("-x"); mClangArgs.append(a); } else if (arg.startsWith("-o")) { if (!mOutputFile.isEmpty()) { warning("Already have an output file: %s (new %s)", mOutputFile.constData(), arg.constData()); } const Path out = Path::resolved(arg, path); mOutputFile = out; } else if (arg.startsWith("-D")) { ByteArray a; if (arg.size() == 2 && i + 1 < s) { a = (arg + split.at(++i)); } else { a = arg; } mClangArgs.append(a); } else if (arg.startsWith("-I")) { Path inc; bool ok = false; if (arg.size() > 2) { inc = Path::resolved(arg.mid(2), path, &ok); } else if (i + 1 < s) { inc = Path::resolved(split.at(++i), path, &ok); } if (ok) mClangArgs.append("-I" + inc); } else if (arg.startsWith("-std") || arg == "-m32") { mClangArgs.append(arg); } } else { if (!seenCompiler) { seenCompiler = true; } else { bool ok; Path input = Path::resolved(arg, path, &ok); if (input.isSource()) { if (ok) mInputFiles.append(input); mUnresolvedInputFiles.append(arg); } } } } if (mUnresolvedInputFiles.isEmpty()) { clear(); return false; } if (mInputFiles.isEmpty()) { error("Unable to find or resolve input files"); const int c = mUnresolvedInputFiles.size(); for (int i=0; i<c; ++i) { const ByteArray &input = mUnresolvedInputFiles.at(i); error(" %s", input.constData()); } clear(); return false; } mOutputFile = Path::resolved(mOutputFile, path); static Map<Path, Path> resolvedFromPath; Path &compiler = resolvedFromPath[split.front()]; if (compiler.isEmpty()) { compiler = Process::findCommand(split.front()); if (compiler.isEmpty()) { compiler = split.front(); } } mCompiler = compiler; return true; }