summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-12-05 21:42:21 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-12-05 21:42:21 +0300
commit9f85ac0083423d0345e19edf96fb7a123c98f205 (patch)
tree244274275287e1b03cf39393fead10e43302ed82
parent562a765969f015eda26d27091edc3172e5639f9c (diff)
Complete options file path against referencing file path
-rw-r--r--cli-tests/file/testscript84
-rw-r--r--cli/cli/runtime-source.cxx20
2 files changed, 87 insertions, 17 deletions
diff --git a/cli-tests/file/testscript b/cli-tests/file/testscript
index d86ec1d..71fbfac 100644
--- a/cli-tests/file/testscript
+++ b/cli-tests/file/testscript
@@ -17,10 +17,7 @@ EOI
-b 21
EOI
-# @@ Give tests some meaningfull descriptions.
-#
-
-: 000
+: with-spaces
:
cat <<EOI >=test.ops;
-a 11
@@ -51,7 +48,7 @@ a
b
EOO
-: 001
+: empty
:
cat <<EOI >=test.ops;
# Empty options file.
@@ -67,7 +64,7 @@ test.ops
b
EOO
-: 002
+: non-empty-empty
:
cat <<EOI >=test.ops;
-a 11
@@ -98,7 +95,7 @@ a
b
EOO
-: 003
+: non-existent
:
$* -a 1 --file ../base.ops --file test.ops b >>EOO 2>>EOE
-a
@@ -111,7 +108,7 @@ EOO
unable to open file 'test.ops' or read failure
EOE
-: 004
+: quoted
:
cat <<EOI >=test.ops;
-a a"b"c
@@ -167,7 +164,7 @@ a'b
"
EOO
-: 005
+: unmatched-double-quote1
:
cat <<EOI >=test.ops;
-a "
@@ -176,7 +173,7 @@ $* --file test.ops 2>>EOE
unmatched quote in argument '"'
EOE
-: 006
+: unmatched-double-quote2
:
cat <<EOI >=test.ops;
-a "abc
@@ -185,7 +182,7 @@ $* --file test.ops 2>>EOE
unmatched quote in argument '"abc'
EOE
-: 007
+: unmatched-double-quote3
:
cat <<EOI >=test.ops;
-a abc"
@@ -194,7 +191,7 @@ $* --file test.ops 2>>EOE
unmatched quote in argument 'abc"'
EOE
-: 008
+: unmatched-quote1
:
cat <<EOI >=test.ops;
-a '
@@ -203,7 +200,7 @@ $* --file test.ops 2>>EOE
unmatched quote in argument '''
EOE
-: 009
+: unmatched-quote2
:
cat <<EOI >=test.ops;
-a 'abc
@@ -212,7 +209,7 @@ $* --file test.ops 2>>EOE
unmatched quote in argument ''abc'
EOE
-: 010
+: unmatched-quote3
:
cat <<EOI >=test.ops;
-a abc'
@@ -221,7 +218,7 @@ $* --file test.ops 2>>EOE
unmatched quote in argument 'abc''
EOE
-: 011
+: unmatched-quote4
:
cat <<EOI >=test.ops;
-a "abc'
@@ -230,7 +227,7 @@ $* --file test.ops 2>>EOE
unmatched quote in argument '"abc''
EOE
-: 012
+: unmatched-quote5
:
cat <<EOI >=test.ops;
-a 'abc"
@@ -284,3 +281,58 @@ $* ---- test.ops >>EOO
-a
123
EOO
+
+: relativeness
+:
+{
+ +cat <<EOI >=test1.ops
+ -a 11
+ --file test/test.ops
+ EOI
+
+ +cat <<"EOI" >=test2.ops
+ -a 11
+ --file $~/test/test.ops
+ EOI
+
+ +mkdir test
+ +cat <<EOI >=test/test.ops
+ -b 22
+ EOI
+
+ : relative
+ :
+ $* --file ../test1.ops >>EOO
+ -a
+ 11
+ -b
+ 22
+ EOO
+
+ : absolute
+ :
+ $* --file ../test1.ops >>EOO
+ -a
+ 11
+ -b
+ 22
+ EOO
+
+ : relative-against-absolute
+ :
+ $* --file $~/../test1.ops >>EOO
+ -a
+ 11
+ -b
+ 22
+ EOO
+
+ : relative-against-normalized
+ :
+ $* --file $path.normalize($~/../test1).ops >>EOO
+ -a
+ 11
+ -b
+ 22
+ EOO
+}
diff --git a/cli/cli/runtime-source.cxx b/cli/cli/runtime-source.cxx
index e3d904a..7f582c0 100644
--- a/cli/cli/runtime-source.cxx
+++ b/cli/cli/runtime-source.cxx
@@ -653,8 +653,26 @@ generate_runtime_source (context& ctx, bool complete)
<< "load (f);"
<< "}"
<< "else" << endl
+ << "{"
+ << "// If the path of the file being parsed is not simple and the" << endl
+ << "// path of the file that needs to be loaded is relative, then" << endl
+ << "// complete the later path against the former one." << endl
+ << "//" << endl
+ << "#ifndef _WIN32" << endl
+ << "string::size_type n (file.find_last_of ('/'));"
+ << "bool c (n != string::npos && !(s2.size () != 0 && s2[0] == '/'));"
+ << "#else" << endl
+ << "string::size_type n (file.find_last_of (\"/\\\\\"));"
+ << "bool c (n != string::npos && !(s2.size () > 1 && s2[1] == ':'));"
+ << "#endif" << endl
+ << "if (c)"
+ << "{"
+ << "string s (file, 0, n + 1);"
+ << "s += s2;"
+ << "s2.swap (s);"
+ << "}"
<< "load (s2);"
- << endl
+ << "}"
<< "continue;"
<< "}"
<< "a.value = s1;"