Skip to content

Commit 0b9a3be

Browse files
committed
Remove existing command parsing
1 parent 958a8ec commit 0b9a3be

2 files changed

Lines changed: 0 additions & 129 deletions

File tree

lib/importproject.cpp

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -334,134 +334,6 @@ ImportProject::Type ImportProject::import(const std::string &filename, Settings
334334
return ImportProject::Type::FAILURE;
335335
}
336336

337-
static std::string readUntil(const std::string &command, std::string::size_type *pos, const char until[], bool str = false)
338-
{
339-
std::string ret;
340-
bool escapedString = false;
341-
bool escape = false;
342-
for (; *pos < command.size() && (str || !std::strchr(until, command[*pos])); (*pos)++) {
343-
if (escape)
344-
escape = false;
345-
else if (command[*pos] == '\\') {
346-
if (str)
347-
escape = true;
348-
else if (command[*pos + 1] == '"') {
349-
if (escapedString)
350-
return ret + "\\\"";
351-
escapedString = true;
352-
ret += "\\\"";
353-
(*pos)++;
354-
continue;
355-
}
356-
} else if (command[*pos] == '\"')
357-
str = !str;
358-
ret += command[*pos];
359-
}
360-
return ret;
361-
}
362-
363-
static std::string unescape(const std::string &in)
364-
{
365-
std::string out;
366-
bool escape = false;
367-
for (const char c: in) {
368-
if (escape) {
369-
escape = false;
370-
if (!std::strchr("\\\"\'",c))
371-
out += "\\";
372-
out += c;
373-
} else if (c == '\\')
374-
escape = true;
375-
else
376-
out += c;
377-
}
378-
return out;
379-
}
380-
381-
void ImportProject::fsParseCommand(FileSettings& fs, const std::string& command, bool doUnescape)
382-
{
383-
std::string defs;
384-
385-
// Parse command..
386-
std::string::size_type pos = 0;
387-
while (std::string::npos != (pos = command.find(' ',pos))) {
388-
while (pos < command.size() && command[pos] == ' ')
389-
pos++;
390-
if (pos >= command.size())
391-
break;
392-
bool wholeArgQuoted = false;
393-
if (command[pos] == '"') {
394-
wholeArgQuoted = true;
395-
pos++;
396-
if (pos >= command.size())
397-
break;
398-
}
399-
if (command[pos] != '/' && command[pos] != '-')
400-
continue;
401-
pos++;
402-
if (pos >= command.size())
403-
break;
404-
const char F = command[pos++];
405-
if (std::strchr("DUI", F)) {
406-
while (pos < command.size() && command[pos] == ' ')
407-
++pos;
408-
}
409-
std::string fval = readUntil(command, &pos, " =", wholeArgQuoted);
410-
if (wholeArgQuoted && fval.back() == '\"')
411-
fval.resize(fval.size() - 1);
412-
if (F=='D') {
413-
std::string defval = readUntil(command, &pos, " ");
414-
defs += fval;
415-
if (doUnescape) {
416-
if (defval.size() >= 3 && startsWith(defval,"=\"") && defval.back()=='\"')
417-
defval = "=" + unescape(defval.substr(2, defval.size() - 3));
418-
else if (defval.size() >= 5 && startsWith(defval, "=\\\"") && endsWith(defval, "\\\""))
419-
defval = "=\"" + unescape(defval.substr(3, defval.size() - 5)) + "\"";
420-
}
421-
if (!defval.empty())
422-
defs += defval;
423-
defs += ';';
424-
} else if (F=='U')
425-
fs.undefs.insert(std::move(fval));
426-
else if (F=='I') {
427-
std::string i = std::move(fval);
428-
if (i.size() > 1 && i[0] == '\"' && i.back() == '\"')
429-
i = unescape(i.substr(1, i.size() - 2));
430-
if (std::find(fs.includePaths.cbegin(), fs.includePaths.cend(), i) == fs.includePaths.cend())
431-
fs.includePaths.push_back(std::move(i));
432-
} else if (F=='s' && startsWith(fval,"td")) {
433-
++pos;
434-
fs.standard = readUntil(command, &pos, " ");
435-
} else if (F == 'i' && fval == "system") {
436-
++pos;
437-
std::string isystem = readUntil(command, &pos, " ");
438-
fs.systemIncludePaths.push_back(std::move(isystem));
439-
} else if (F=='m') {
440-
if (fval == "unicode") {
441-
defs += "UNICODE";
442-
defs += ";";
443-
}
444-
} else if (F=='f') {
445-
if (fval == "pic") {
446-
defs += "__pic__";
447-
defs += ";";
448-
} else if (fval == "PIC") {
449-
defs += "__PIC__";
450-
defs += ";";
451-
} else if (fval == "pie") {
452-
defs += "__pie__";
453-
defs += ";";
454-
} else if (fval == "PIE") {
455-
defs += "__PIE__";
456-
defs += ";";
457-
}
458-
// TODO: support -fsigned-char and -funsigned-char?
459-
// we can only set it globally but in this context it needs to be treated per file
460-
}
461-
}
462-
fsSetDefines(fs, std::move(defs));
463-
}
464-
465337
bool ImportProject::importCompileCommands(std::istream &istr)
466338
{
467339
picojson::value compileCommands;

lib/importproject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
6969
CPPCHECK_GUI
7070
};
7171

72-
static void fsParseCommand(FileSettings& fs, const std::string& command, bool doUnescape);
7372
static void fsSetDefines(FileSettings& fs, std::string defs);
7473
static void fsSetIncludePaths(FileSettings& fs, const std::string &basepath, const std::list<std::string> &in, std::map<std::string, std::string, cppcheck::stricmp> &variables);
7574

0 commit comments

Comments
 (0)