File: inline-source

package info (click to toggle)
recode 3.7.15-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,400 kB
  • sloc: ansic: 73,177; sh: 8,107; python: 3,861; makefile: 198; lisp: 181; lex: 171; sed: 16
file content (159 lines) | stat: -rwxr-xr-x 4,078 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#! /bin/sh

# Output the contents of a shell script with sourced files inlined.
# Written by Gary V. Vaughan, 2012

# This is free software.  There is NO warranty; not even for
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Copyright (C) 2012-2019 Bootstrap Authors
#
# This file is dual licensed under the terms of the MIT license
# <https://opensource.org/license/MIT>, and GPL version 2 or later
# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
# these licenses when using or redistributing this software or any of
# the files within it.  See the URLs above, or the file `LICENSE`
# included in the Bootstrap distribution for the full license texts.

# Please report bugs or propose patches to:
# <https://github.com/gnulib-modules/bootstrap/issues>

# Source required external libraries:
. `echo "$0" |${SED-sed} 's|[^/]*$||'`"funclib.sh"
. `echo "$0" |${SED-sed} 's|[^/]*$||'`"options-parser"

# Set a version string for *this* script.
scriptversion=2019-02-19.15; # UTC


## ------ ##
## Usage. ##
## ------ ##

# Run 'build-aux/inline-source --help' for help with using this script
# from the command line.

# 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.


## ---------------- ##
## Options parsing. ##
## ---------------- ##

usage='$progpath [OPTION]... FILE'

# Short help message in response to '-h'.
usage_message='Options:
       --debug        enable verbose shell tracing
       --version      print version information and exit
   -h, --help         print help message and exit
'

long_help_message="\
Report bugs to <bug-libtool@gnu.org>
General help using GNU software: <http://www.gnu.org/gethelp/>."

func_options ${1+"$@"}
eval set dummy "$func_options_result"; shift


## -------------------- ##
## Resource management. ##
## -------------------- ##

# require_AWK
# -----------
# Search for a "not hopeless" awk.
require_AWK=func_require_AWK
func_require_AWK ()
{
    $debug_cmd

    test -n "$AWK" || {
      # Find the first executable in the list.
      for _G_prog in gawk mawk nawk awk
      do
        require_AWK_IFS=$IFS
	IFS=${PATH_SEPARATOR-:}
	for _G_dir in $PATH
        do
	  IFS=$require_AWK_IFS
          if test -f "$_G_dir/$_G_prog" && test -x "$_G_dir/$_G_prog"
	  then
	    AWK=$_G_dir/$_G_prog
            break 2
          fi
        done
	IFS=$require_AWK_IFS
      done
    }

    test -n "$AWK" || func_fatal_error "\
Please install GNU Awk, or 'export AWK=/path/to/gnu/awk'."

    func_verbose "found '$AWK'."

    require_AWK=:
}


## --------------- ##
## Core functions. ##
## --------------- ##

# func_include LINE
# -----------------
# Output the contents of file included by LINE.
func_include ()
{
    $require_AWK

    test -f "$1" \
        || func_fatal_error "file '$1' not found"

    _G_scriptdir=`echo "$1" |$SED 's|[^/]*$||'`
    test -n "$_G_scriptdir" || _G_scriptdir="./"

    $AWK '
        BEGIN { magic = '${_RECURSE_MAGIC-0}'; }

        /^#!/ && magic == 0 {
            print $0;
            print "## DO NOT EDIT - This file generated from '$1'";
            print "##               by '$progname' v'$scriptversion'";
            magic++;
            next;
        }

        /^\. ['\''"].*['\''"]$/ {
            file = substr ($2, 2, length ($2) -2);
	    system (sprintf ("env _RECURSE_MAGIC=%d '$progpath' %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));
            next;
        }

        { print; }
    ' < "$1"
}

func_include "$1"

exit 0

# Local variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'before-save-hook 'time-stamp)
# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
# time-stamp-time-zone: "UTC"
# End: