diff options
author | Brad King <brad.king@kitware.com> | 2014-03-31 20:07:21 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-03-31 20:23:23 (GMT) |
commit | 9b059184628f1d7dea927a6f08a3ac70f8036da4 (patch) | |
tree | 29889f394645f1ad89de81297251c0d29228f2e4 | |
parent | 5fe01fccd1ffd755c799fb79c4234d97fb8dc317 (diff) | |
download | CastXML-9b059184628f1d7dea927a6f08a3ac70f8036da4.zip CastXML-9b059184628f1d7dea927a6f08a3ac70f8036da4.tar.gz CastXML-9b059184628f1d7dea927a6f08a3ac70f8036da4.tar.bz2 |
castxml: Use parentheses for '--castxml-cc-<id>' commands
Avoid requiring the option to be last by using the form
--castxml-cc-<id> "(" <cc> <cc-opt>... ")"
to specify compiler commands with arguments.
-rw-r--r-- | src/castxml.cxx | 52 | ||||
-rw-r--r-- | test/CMakeLists.txt | 4 | ||||
-rw-r--r-- | test/expect/cmd.cc-option-result.txt | 1 | ||||
-rw-r--r-- | test/expect/cmd.cc-option-stderr.txt | 3 | ||||
-rw-r--r-- | test/expect/cmd.cc-paren-castxml-result.txt | 1 | ||||
-rw-r--r-- | test/expect/cmd.cc-paren-castxml-stderr.txt | 3 | ||||
-rw-r--r-- | test/expect/cmd.cc-paren-nested-result.txt | 1 | ||||
-rw-r--r-- | test/expect/cmd.cc-paren-nested-stderr.txt | 3 | ||||
-rw-r--r-- | test/expect/cmd.cc-paren-unbalanced-result.txt | 1 | ||||
-rw-r--r-- | test/expect/cmd.cc-paren-unbalanced-stderr.txt | 3 |
10 files changed, 68 insertions, 4 deletions
diff --git a/src/castxml.cxx b/src/castxml.cxx index 148dabd..8f496d0 100644 --- a/src/castxml.cxx +++ b/src/castxml.cxx @@ -74,10 +74,10 @@ int main(int argc_in, const char** argv_in) "\n" "Options:\n" "\n" - " --castxml-cc-<id> <cc> [ <cc-args>... ]\n" + " --castxml-cc-<id> <cc>\n" + " --castxml-cc-<id> \"(\" <cc> <cc-opt>... \")\"\n" " Simulate given <id>-like compiler command, where <id> is\n" " one of: gnu, msvc\n" - " (This option must appear last and consumes remaining options)\n" "\n" " --castxml-gccxml\n" " Write gccxml-format output to <src>.xml or file named by '-o'\n" @@ -125,10 +125,54 @@ int main(int argc_in, const char** argv_in) } else if(strncmp(argv[i], "--castxml-cc-", 13) == 0) { if(!cc_id) { cc_id = argv[i] + 13; - for(++i;i < argc && strncmp(argv[i], "--castxml-", 10) != 0; ++i) { + if((i+1) >= argc) { + continue; + } + ++i; + if(strncmp(argv[i], "-", 1) == 0) { + std::cerr << + "error: argument to '--castxml-cc-" << cc_id << + "' may not start with '-'\n" + "\n" << + usage + ; + return 1; + } + if(strcmp(argv[i], "(") == 0) { + unsigned int depth = 1; + for(++i; i < argc && depth > 0; ++i) { + if(strncmp(argv[i], "--castxml-", 10) == 0) { + std::cerr << + "error: arguments to '--castxml-cc-" << cc_id << + "' may not start with '--castxml-'\n" + "\n" << + usage + ; + return 1; + } else if(strcmp(argv[i], "(") == 0) { + ++depth; + cc_args.push_back(argv[i]); + } else if(strcmp(argv[i], ")") == 0) { + if(--depth) { + cc_args.push_back(argv[i]); + } + } else { + cc_args.push_back(argv[i]); + } + } + if(depth) { + std::cerr << + "error: unbalanced parentheses after '--castxml-cc-" << + cc_id << "'\n" + "\n" << + usage + ; + return 1; + } + --i; + } else { cc_args.push_back(argv[i]); } - --i; } else { std::cerr << "error: '--castxml-cc-<id>' may be given at most once!\n" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ac60cd6..6d3d8a9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -67,6 +67,10 @@ castxml_test_cmd(no-arguments) castxml_test_cmd(version --version) castxml_test_cmd(cc-missing --castxml-cc-gnu) +castxml_test_cmd(cc-option --castxml-cc-gnu -) +castxml_test_cmd(cc-paren-castxml --castxml-cc-gnu "(" --castxml-cc-msvc ")") +castxml_test_cmd(cc-paren-nested --castxml-cc-gnu "(" "(" ")" ")") +castxml_test_cmd(cc-paren-unbalanced --castxml-cc-gnu "(") castxml_test_cmd(cc-twice --castxml-cc-msvc cl --castxml-cc-gnu gcc) castxml_test_cmd(cc-unknown --castxml-cc-unknown cc) castxml_test_cmd(gccxml-and-E --castxml-gccxml -E) diff --git a/test/expect/cmd.cc-option-result.txt b/test/expect/cmd.cc-option-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/expect/cmd.cc-option-result.txt @@ -0,0 +1 @@ +1 diff --git a/test/expect/cmd.cc-option-stderr.txt b/test/expect/cmd.cc-option-stderr.txt new file mode 100644 index 0000000..199d57c --- /dev/null +++ b/test/expect/cmd.cc-option-stderr.txt @@ -0,0 +1,3 @@ +^error: argument to '--castxml-cc-gnu' may not start with '-' + +Usage: castxml .*$ diff --git a/test/expect/cmd.cc-paren-castxml-result.txt b/test/expect/cmd.cc-paren-castxml-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/expect/cmd.cc-paren-castxml-result.txt @@ -0,0 +1 @@ +1 diff --git a/test/expect/cmd.cc-paren-castxml-stderr.txt b/test/expect/cmd.cc-paren-castxml-stderr.txt new file mode 100644 index 0000000..a53db2f --- /dev/null +++ b/test/expect/cmd.cc-paren-castxml-stderr.txt @@ -0,0 +1,3 @@ +^error: arguments to '--castxml-cc-gnu' may not start with '--castxml-' + +Usage: castxml .*$ diff --git a/test/expect/cmd.cc-paren-nested-result.txt b/test/expect/cmd.cc-paren-nested-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/expect/cmd.cc-paren-nested-result.txt @@ -0,0 +1 @@ +1 diff --git a/test/expect/cmd.cc-paren-nested-stderr.txt b/test/expect/cmd.cc-paren-nested-stderr.txt new file mode 100644 index 0000000..5e1957c --- /dev/null +++ b/test/expect/cmd.cc-paren-nested-stderr.txt @@ -0,0 +1,3 @@ +^error: '--castxml-cc-gnu' compiler command failed: + + '\(' '\)' .*$ diff --git a/test/expect/cmd.cc-paren-unbalanced-result.txt b/test/expect/cmd.cc-paren-unbalanced-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/expect/cmd.cc-paren-unbalanced-result.txt @@ -0,0 +1 @@ +1 diff --git a/test/expect/cmd.cc-paren-unbalanced-stderr.txt b/test/expect/cmd.cc-paren-unbalanced-stderr.txt new file mode 100644 index 0000000..5d45f56 --- /dev/null +++ b/test/expect/cmd.cc-paren-unbalanced-stderr.txt @@ -0,0 +1,3 @@ +^error: unbalanced parentheses after '--castxml-cc-gnu' + +Usage: castxml .*$ |