From cf8a7b1769671b7f0f3e7d82bb3b8e9c9ce09155 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 21 Oct 2016 12:27:50 +0200 Subject: [PATCH] inline-source: inline also if $srcdir contains spaces Add new syntax for source inline: # set '$inline_source_dir' to `dirname "$0"/` inline_source_dir=`echo "$0" |${SED-sed} 's|[^/]*$||'` . "$inline_source_dir"/sourced-file This version avoids "`"sth"`" like commands (nested quotes), while we are now able to use inline-source script within directory which pathname contains spaces. As a side effect, we save some fork() calls because the directory is constructed only once. Related to github issue #6. * build-aux/inline-source: Move ourself to the new syntax, document new syntax. (func_include): Parse the new syntax, quote $progpath properly. * build-aux/bootstrap.in: Use new syntax. * bootstrap: Sync with new sources. --- bootstrap | 1 + build-aux/bootstrap.in | 8 +++++--- build-aux/inline-source | 37 +++++++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/bootstrap b/bootstrap index 306f83e..5a228ae 100644 --- a/bootstrap +++ b/bootstrap @@ -222,6 +222,7 @@ vc_ignore= ## External Libraries. ## ## ------------------- ## + # Source required external libraries: # Set a version string for this script. scriptversion=2016-02-28.16; # UTC diff --git a/build-aux/bootstrap.in b/build-aux/bootstrap.in index b8cb699..d798025 100755 --- a/build-aux/bootstrap.in +++ b/build-aux/bootstrap.in @@ -220,10 +220,12 @@ vc_ignore= ## External Libraries. ## ## ------------------- ## +inline_source_dir=`echo "$0" |${SED-sed} 's|[^/]*$||'` + # Source required external libraries: -. `echo "$0" |${SED-sed} 's|[^/]*$||'`"funclib.sh" -. `echo "$0" |${SED-sed} 's|[^/]*$||'`"options-parser" -. `echo "$0" |${SED-sed} 's|[^/]*$||'`"extract-trace" +. "$inline_source_dir"funclib.sh +. "$inline_source_dir"options-parser +. "$inline_source_dir"extract-trace # Set a version string for *this* script. scriptversion=2016-02-28.16; # UTC diff --git a/build-aux/inline-source b/build-aux/inline-source index 7c24075..e715a90 100755 --- a/build-aux/inline-source +++ b/build-aux/inline-source @@ -18,9 +18,11 @@ # Please report bugs or propose patches to: # +inline_source_dir=`echo "$0" |${SED-sed} 's|[^/]*$||'` + # Source required external libraries: -. `echo "$0" |${SED-sed} 's|[^/]*$||'`"funclib.sh" -. `echo "$0" |${SED-sed} 's|[^/]*$||'`"options-parser" +. "$inline_source_dir"funclib.sh +. "$inline_source_dir"options-parser # Set a version string for *this* script. scriptversion=2016-02-21.11; # UTC @@ -35,9 +37,14 @@ scriptversion=2016-02-21.11; # UTC # Recursively scan through a FILE passed on the command line, replacing # either of the following: -# . "relative/file" -# . `echo "$0" |edit`"relative/file" -# with the contents of the referenced files. +# +# a) . "relative/file" +# b) . `echo "$0" |edit`"relative/file" +# c) . "$inline_source_dir"/relative/file +# +# with the contents of the referenced files. When the c) option is used, +# '$inline_source_dir' must be explicitly set to script's source directory +# within the source file. See the example few lines above. ## ---------------- ## @@ -118,6 +125,11 @@ func_include () _G_scriptdir=`echo "$1" |$SED 's|[^/]*$||'` test -n "$_G_scriptdir" || _G_scriptdir="./" + func_quote_arg unquoted "$progpath" + prog=$func_quote_arg_unquoted_result + + export inline_source_dir=$_G_scriptdir + $AWK ' BEGIN { magic = '${_RECURSE_MAGIC-0}'; } @@ -129,16 +141,25 @@ func_include () next; } + /^inline_source_dir=.*/ { + next; + } + + /^\. "\$inline_source_dir.*/ { + system (sprintf ("env _RECURSE_MAGIC=%d \"'"$prog"'\" %s", magic, $2)); + next; + } + /^\. ['\''"].*['\''"]$/ { file = substr ($2, 2, length ($2) -2); - system (sprintf ("env _RECURSE_MAGIC=%d '$progpath' %s", magic, file)); + system (sprintf ("env _RECURSE_MAGIC=%d \"'"$prog"'\" %s", magic, file)); next; } /^\. `echo [^`]*`['\''"][^'\''"]*['\''"]$/ { tail = substr ($0, match ($0, /`['\''"]/)); - file = substr (tail, 3, length (tail) -3); - system (sprintf ("env _RECURSE_MAGIC=%d '$progpath' '"$_G_scriptdir"'%s", magic, file)); + file = substr (tail, 3, length (tail) -3); + system (sprintf ("env _RECURSE_MAGIC=%d \"'"$progpath"'\" '"$_G_scriptdir"'%s", magic, file)); next; }