From b8cec4a2571596692c1e0b27cc3953ecff712178 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Jun 2010 09:25:29 +0200 Subject: Add support for single quotes in option files --- cli/options.cli | 8 ++++---- cli/options.cxx | 5 +++-- cli/runtime-source.cxx | 5 +++-- doc/cli.1 | 10 +++++----- doc/cli.xhtml | 11 ++++++----- doc/guide/index.xhtml | 12 ++++++------ tests/file/makefile | 20 ++++---------------- tests/file/test-004.ops | 11 +++++++++++ tests/file/test-004.std | 20 ++++++++++++++++++++ tests/file/test-008.ops | 1 + tests/file/test-008.std | 1 + tests/file/test-009.ops | 1 + tests/file/test-009.std | 1 + tests/file/test-010.ops | 1 + tests/file/test-010.std | 1 + tests/file/test-011.ops | 1 + tests/file/test-011.std | 1 + tests/file/test-012.ops | 1 + tests/file/test-012.std | 1 + 19 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 tests/file/test-008.ops create mode 100644 tests/file/test-008.std create mode 100644 tests/file/test-009.ops create mode 100644 tests/file/test-009.std create mode 100644 tests/file/test-010.ops create mode 100644 tests/file/test-010.std create mode 100644 tests/file/test-011.ops create mode 100644 tests/file/test-011.std create mode 100644 tests/file/test-012.ops create mode 100644 tests/file/test-012.std diff --git a/cli/options.cli b/cli/options.cli index 58f9565..ffa92df 100644 --- a/cli/options.cli +++ b/cli/options.cli @@ -214,10 +214,10 @@ class options "Read additional options from with each option appearing on a separate line optionally followed by space and an option value. Empty lines and lines starting with \cb{#} are ignored. Option values can - be enclosed in double quotes (\cb{\"\"}) to preserve leading and - trailing whitespaces as well as to specify empty values. If the value - itself contains trailing or leading double quote, enclose it with an - extra pair of double quotes, for example \cb{\"\"x\"\"}. Non-leading + be enclosed in double (\cb{\"}) or single (\cb{'}) quotes to preserve + leading and trailing whitespaces as well as to specify empty values. + If the value itself contains trailing or leading double quote, enclose + it with an extra pair of quotes, for example \cb{'\"x\"'}. Non-leading and non-trailing quotes are interpreted as being part of the option value. diff --git a/cli/options.cxx b/cli/options.cxx index 3f3c1b9..1c46fd4 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -351,10 +351,11 @@ namespace cli // If the string is wrapped in quotes, remove them. // n = s2.size (); + char cf (s2[0]), cl (s2[n - 1]); - if (s2[0] == '"' || s2[n - 1] == '"') + if (cf == '"' || cf == '\'' || cl == '"' || cl == '\'') { - if (n == 1 || s2[0] != s2[n - 1]) + if (n == 1 || cf != cl) throw unmatched_quote (s2); s2 = string (s2, 1, n - 2); diff --git a/cli/runtime-source.cxx b/cli/runtime-source.cxx index 348d7b7..e2008ad 100644 --- a/cli/runtime-source.cxx +++ b/cli/runtime-source.cxx @@ -392,10 +392,11 @@ generate_runtime_source (context& ctx) << "// If the string is wrapped in quotes, remove them." << endl << "//" << endl << "n = s2.size ();" + << "char cf (s2[0]), cl (s2[n - 1]);" << endl - << "if (s2[0] == '\"' || s2[n - 1] == '\"')" + << "if (cf == '\"' || cf == '\\'' || cl == '\"' || cl == '\\'')" << "{" - << "if (n == 1 || s2[0] != s2[n - 1])" << endl + << "if (n == 1 || cf != cl)" << endl << "throw unmatched_quote (s2);" << endl << "s2 = string (s2, 1, n - 2);" diff --git a/doc/cli.1 b/doc/cli.1 index 739b845..ec7d9fc 100644 --- a/doc/cli.1 +++ b/doc/cli.1 @@ -186,11 +186,11 @@ is used instead\. All C++ keywords are already in this list\. Read additional options from \fIfile\fP with each option appearing on a separate line optionally followed by space and an option value\. Empty lines and lines starting with \fB#\fP are ignored\. Option values can be enclosed -in double quotes (\fB""\fP) to preserve leading and trailing whitespaces as -well as to specify empty values\. If the value itself contains trailing or -leading double quote, enclose it with an extra pair of double quotes, for -example \fB""x""\fP\. Non-leading and non-trailing quotes are interpreted as -being part of the option value\. +in double (\fB"\fP) or single (\fB'\fP) quotes to preserve leading and +trailing whitespaces as well as to specify empty values\. If the value +itself contains trailing or leading double quote, enclose it with an extra +pair of quotes, for example \fB'"x"'\fP\. Non-leading and non-trailing +quotes are interpreted as being part of the option value\. The semantics of providing options in a file is equivalent to providing the same set of options in the same order on the command line at the point where diff --git a/doc/cli.xhtml b/doc/cli.xhtml index 5a136af..e23b55a 100644 --- a/doc/cli.xhtml +++ b/doc/cli.xhtml @@ -212,11 +212,12 @@
Read additional options from file with each option appearing on a separate line optionally followed by space and an option value. Empty lines and lines starting with # are ignored. Option values can - be enclosed in double quotes ("") to preserve leading - and trailing whitespaces as well as to specify empty values. If the value - itself contains trailing or leading double quote, enclose it with an extra - pair of double quotes, for example ""x"". Non-leading - and non-trailing quotes are interpreted as being part of the option value. + be enclosed in double (") or single + (') quotes to preserve leading and trailing whitespaces + as well as to specify empty values. If the value itself contains trailing or + leading double quote, enclose it with an extra pair of quotes, for example + '"x"'. Non-leading and non-trailing quotes are + interpreted as being part of the option value.

The semantics of providing options in a file is equivalent to providing the same set of options in the same order on the command line at the point diff --git a/doc/guide/index.xhtml b/doc/guide/index.xhtml index fe094cf..aeb7892 100644 --- a/doc/guide/index.xhtml +++ b/doc/guide/index.xhtml @@ -750,12 +750,12 @@ namespace cli options. Such a file contains a set of options, each appearing on a separate line optionally followed by space and an option value. Empty lines and lines starting with # are ignored. Option values can - be enclosed in double quotes ("") to preserve leading - and trailing whitespaces as well as to specify empty values. If the - value itself contains trailing or leading double quote, enclose - it with an extra pair of double quotes, for example ""x"". - Non-leading and non-trailing quotes are interpreted as being part of - the option value.

+ be enclosed in double (") or single (') + quotes to preserve leading and trailing whitespaces as well as to + specify empty values. If the value itself contains trailing or leading + quote, enclose it with an extra pair of quotes, for example + '"x"'. Non-leading and non-trailing quotes are interpreted + as being part of the option value.

The semantics of providing options in a file is equivalent to providing the same set of options in the same order on the command line at the diff --git a/tests/file/makefile b/tests/file/makefile index 2029d83..af71907 100644 --- a/tests/file/makefile +++ b/tests/file/makefile @@ -8,7 +8,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make cxx_tun := driver.cxx cli_tun := test.cli -tests := 000 001 002 003 004 005 006 007 +tests := 000 001 002 003 004 005 006 007 008 009 010 011 012 # # @@ -63,21 +63,9 @@ $(out_base)/.test-003: $(driver) $(call message,test $(out_base)/003,$(driver) -a 1 --file \ $(src_base)/base.ops --file test-003.ops b | diff -u $(src_base)/test-003.std -) -$(out_base)/.test-004: $(driver) $(src_base)/test-004.ops - $(call message,test $(out_base)/004,$(driver) --file \ -$(src_base)/test-004.ops | diff -u $(src_base)/test-004.std -) - -$(out_base)/.test-005: $(driver) $(src_base)/test-005.ops - $(call message,test $(out_base)/005,$(driver) --file \ -$(src_base)/test-005.ops | diff -u $(src_base)/test-005.std -) - -$(out_base)/.test-006: $(driver) $(src_base)/test-006.ops - $(call message,test $(out_base)/006,$(driver) --file \ -$(src_base)/test-006.ops | diff -u $(src_base)/test-006.std -) - -$(out_base)/.test-007: $(driver) $(src_base)/test-007.ops - $(call message,test $(out_base)/007,$(driver) --file \ -$(src_base)/test-007.ops | diff -u $(src_base)/test-007.std -) +$(out_base)/.test-%: $(driver) $(src_base)/test-%.ops $(src_base)/test-%.std + $(call message,test $(out_base)/$*,$(driver) --file \ +$(src_base)/test-$*.ops | diff -u $(src_base)/test-$*.std -) # Clean. # diff --git a/tests/file/test-004.ops b/tests/file/test-004.ops index 3246233..dee1b30 100644 --- a/tests/file/test-004.ops +++ b/tests/file/test-004.ops @@ -4,3 +4,14 @@ -a "" -a " abc " -a " " +-a """ +-a "'" + +-a a'b'c +-a 'abc' +-a 'a'b' +-a '' +-a ' abc ' +-a ' ' +-a ''' +-a '"' diff --git a/tests/file/test-004.std b/tests/file/test-004.std index 01114a0..b06e8b9 100644 --- a/tests/file/test-004.std +++ b/tests/file/test-004.std @@ -10,3 +10,23 @@ a"b abc -a +-a +" +-a +' +-a +a'b'c +-a +abc +-a +a'b +-a + +-a + abc +-a + +-a +' +-a +" diff --git a/tests/file/test-008.ops b/tests/file/test-008.ops new file mode 100644 index 0000000..773a366 --- /dev/null +++ b/tests/file/test-008.ops @@ -0,0 +1 @@ +-a ' diff --git a/tests/file/test-008.std b/tests/file/test-008.std new file mode 100644 index 0000000..5d74dc3 --- /dev/null +++ b/tests/file/test-008.std @@ -0,0 +1 @@ +unmatched quote in argument ''' diff --git a/tests/file/test-009.ops b/tests/file/test-009.ops new file mode 100644 index 0000000..6c3d5c9 --- /dev/null +++ b/tests/file/test-009.ops @@ -0,0 +1 @@ +-a 'abc diff --git a/tests/file/test-009.std b/tests/file/test-009.std new file mode 100644 index 0000000..b212446 --- /dev/null +++ b/tests/file/test-009.std @@ -0,0 +1 @@ +unmatched quote in argument ''abc' diff --git a/tests/file/test-010.ops b/tests/file/test-010.ops new file mode 100644 index 0000000..eb33825 --- /dev/null +++ b/tests/file/test-010.ops @@ -0,0 +1 @@ +-a abc' diff --git a/tests/file/test-010.std b/tests/file/test-010.std new file mode 100644 index 0000000..868ee9d --- /dev/null +++ b/tests/file/test-010.std @@ -0,0 +1 @@ +unmatched quote in argument 'abc'' diff --git a/tests/file/test-011.ops b/tests/file/test-011.ops new file mode 100644 index 0000000..2330c9c --- /dev/null +++ b/tests/file/test-011.ops @@ -0,0 +1 @@ +-a "abc' diff --git a/tests/file/test-011.std b/tests/file/test-011.std new file mode 100644 index 0000000..2133ddf --- /dev/null +++ b/tests/file/test-011.std @@ -0,0 +1 @@ +unmatched quote in argument '"abc'' diff --git a/tests/file/test-012.ops b/tests/file/test-012.ops new file mode 100644 index 0000000..d5efe67 --- /dev/null +++ b/tests/file/test-012.ops @@ -0,0 +1 @@ +-a 'abc" diff --git a/tests/file/test-012.std b/tests/file/test-012.std new file mode 100644 index 0000000..2e85d39 --- /dev/null +++ b/tests/file/test-012.std @@ -0,0 +1 @@ +unmatched quote in argument ''abc"' -- cgit v1.1