From 83e6857822c6bb5aea89b72b305d8480015546ca 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 | 5 +++-- build-aux/bootstrap.in | 10 ++++++---- build-aux/inline-source | 39 ++++++++++++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/bootstrap b/bootstrap index 306f83e..4a68d79 100644 --- a/bootstrap +++ b/bootstrap @@ -1,6 +1,6 @@ #! /bin/sh ## DO NOT EDIT - This file generated from build-aux/bootstrap.in -## by inline-source v2016-02-21.11 +## by inline-source v2016-10-21.11 # Bootstrap an Autotooled package from checked-out sources. # Written by Gary V. Vaughan, 2010 @@ -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 @@ -2822,7 +2823,7 @@ test extract-trace = "$progname" && func_main "$@" # End: # Set a version string for *this* script. -scriptversion=2016-02-28.16; # UTC +scriptversion=2016-10-21.11; # UTC ## ------------------- ## diff --git a/build-aux/bootstrap.in b/build-aux/bootstrap.in index b8cb699..ca40827 100755 --- a/build-aux/bootstrap.in +++ b/build-aux/bootstrap.in @@ -220,13 +220,15 @@ 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 +scriptversion=2016-10-21.11; # UTC ## ------------------- ## diff --git a/build-aux/inline-source b/build-aux/inline-source index 7c24075..404d407 100755 --- a/build-aux/inline-source +++ b/build-aux/inline-source @@ -18,12 +18,14 @@ # 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 +scriptversion=2016-10-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 \"'"$prog"'\" '"$_G_scriptdir"'%s", magic, file)); next; }