From c918f33c44f660116a09c5ee3db44b6a70c26269 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 5 Dec 2020 21:42:21 +0300 Subject: Complete options file path using referencing file path as base --- cli-tests/file/testscript | 84 +++++++++++++++++++++++++++++++++++++--------- cli/cli/runtime-source.cxx | 19 +++++++++-- 2 files changed, 85 insertions(+), 18 deletions(-) diff --git a/cli-tests/file/testscript b/cli-tests/file/testscript index d86ec1d..6f83f91 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 <=test.ops; -a 11 @@ -51,7 +48,7 @@ a b EOO -: 001 +: empty : cat <=test.ops; # Empty options file. @@ -67,7 +64,7 @@ test.ops b EOO -: 002 +: non-empty-empty : cat <=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 <=test.ops; -a a"b"c @@ -167,7 +164,7 @@ a'b " EOO -: 005 +: unmatched-double-quote1 : cat <=test.ops; -a " @@ -176,7 +173,7 @@ $* --file test.ops 2>>EOE unmatched quote in argument '"' EOE -: 006 +: unmatched-double-quote2 : cat <=test.ops; -a "abc @@ -185,7 +182,7 @@ $* --file test.ops 2>>EOE unmatched quote in argument '"abc' EOE -: 007 +: unmatched-double-quote3 : cat <=test.ops; -a abc" @@ -194,7 +191,7 @@ $* --file test.ops 2>>EOE unmatched quote in argument 'abc"' EOE -: 008 +: unmatched-quote1 : cat <=test.ops; -a ' @@ -203,7 +200,7 @@ $* --file test.ops 2>>EOE unmatched quote in argument ''' EOE -: 009 +: unmatched-quote2 : cat <=test.ops; -a 'abc @@ -212,7 +209,7 @@ $* --file test.ops 2>>EOE unmatched quote in argument ''abc' EOE -: 010 +: unmatched-quote3 : cat <=test.ops; -a abc' @@ -221,7 +218,7 @@ $* --file test.ops 2>>EOE unmatched quote in argument 'abc'' EOE -: 011 +: unmatched-quote4 : cat <=test.ops; -a "abc' @@ -230,7 +227,7 @@ $* --file test.ops 2>>EOE unmatched quote in argument '"abc'' EOE -: 012 +: unmatched-quote5 : cat <=test.ops; -a 'abc" @@ -284,3 +281,58 @@ $* ---- test.ops >>EOO -a 123 EOO + +: relativeness +: +{ + +cat <=test1.ops + -a 11 + --file test/test.ops + EOI + + +cat <<"EOI" >=test2.ops + -a 11 + --file $~/test/test.ops + EOI + + +mkdir test + +cat <=test/test.ops + -b 22 + EOI + + : relative + : + $* --file ../test1.ops >>EOO + -a + 11 + -b + 22 + EOO + + : absolute + : + $* --file ../test2.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..3864163 100644 --- a/cli/cli/runtime-source.cxx +++ b/cli/cli/runtime-source.cxx @@ -648,13 +648,28 @@ generate_runtime_source (context& ctx, bool complete) << endl << "if (oi->search_func != 0)" << "{" - << "std::string f (oi->search_func (s2.c_str (), oi->arg));" + << "string f (oi->search_func (s2.c_str (), oi->arg));" << "if (!f.empty ())" << endl << "load (f);" << "}" << "else" << endl - << "load (s2);" + << "{" + << "// 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 latter using the former as a base." << endl + << "//" << endl + << "#ifndef _WIN32" << endl + << "string::size_type p (file.find_last_of ('/'));" + << "bool c (p != string::npos && s2[0] != '/');" + << "#else" << endl + << "string::size_type p (file.find_last_of (\"/\\\\\"));" + << "bool c (p != string::npos && s2[1] != ':');" + << "#endif" << endl + << "if (c)" << endl + << "s2.insert (0, file, 0, p + 1);" << endl + << "load (s2);" + << "}" << "continue;" << "}" << "a.value = s1;" -- cgit v1.1