+# Piece of a sed expression that converts a field header line to a shell
+# variable name,
+# NOTE: Keep this in sync with sed_extract_prog above!
+sed_extract_field_header='
+ s/^Description:[ ]*$/description/
+ s/^Comment:[ ]*$/comment/
+ s/^Status:[ ]*$/status/
+ s/^Notice:[ ]*$/notice/
+ s/^Applicability:[ ]*$/applicability/
+ s/^Files:[ ]*$/files/
+ s/^Depends-on:[ ]*$/dependson/
+ s/^configure\.ac-early:[ ]*$/configureac_early/
+ s/^configure\.ac:[ ]*$/configureac/
+ s/^Makefile\.am:[ ]*$/makefile/
+ s/^Include:[ ]*$/include/
+ s/^Link:[ ]*$/link/
+ s/^License:[ ]*$/license/
+ s/^Maintainer:[ ]*$/maintainer/'
+
+if $modcache; then
+
+ # Note: The 'eval' silences stderr output in dash.
+ if (declare -A x && { x[f/2]='foo'; x[f/3]='bar'; eval test '${x[f/2]}' = foo; }) 2>/dev/null; then
+ # Zsh 4 and Bash 4 have associative arrays.
+ have_associative=true
+ else
+ # For other shells, use 'eval' with computed shell variable names.
+ have_associative=false
+ fi
+
+ if $have_associative; then
+
+ # Declare the associative arrays.
+ declare -A modcache_cached
+ sed_to_declare_statement='s|^.*/\([a-zA-Z0-9_]*\)/$|declare -A modcache_\1|p'
+ declare_script=`echo "$sed_extract_field_header" | sed -n -e "$sed_to_declare_statement"`
+ eval "$declare_script"
+
+ else
+
+ # func_cache_var module
+ # computes the cache variable name corresponding to $module.
+ # Note: This computation can map different module names to the same
+ # cachevar (such as 'foo-bar', 'foo_bar', or 'foo/bar'); the caller has
+ # to protect against this case.
+ # Output:
+ # - cachevar a shell variable name
+ if (f=foo; eval echo '${f//o/e}') < /dev/null 2>/dev/null | grep fee >/dev/null; then
+ # Bash 2.0 and newer, ksh, and zsh support the syntax
+ # ${param//pattern/replacement}
+ # as a shorthand for
+ # `echo "$param" | sed -e "s/pattern/replacement/g"`.
+ # Note: The 'eval' above silences stderr output in dash.
+ func_cache_var ()
+ {
+ cachevar=c_${1//[!a-zA-Z0-9_]/_}
+ }
+ else
+ func_cache_var ()
+ {
+ case $1 in
+ *[!a-zA-Z0-9_]*)
+ cachevar=c_`echo "$1" | LC_ALL=C sed -e 's/[^a-zA-Z0-9_]/_/g'` ;;
+ *)
+ cachevar=c_$1 ;;
+ esac
+ }
+ fi
+
+ fi
+
+ # func_init_sed_convert_to_cache_statements
+ # Input:
+ # - modcachevar_assignment
+ # Output:
+ # - sed_convert_to_cache_statements
+ func_init_sed_convert_to_cache_statements ()
+ {
+ # 'sed' script that turns a module description into shell script
+ # assignments, suitable to be eval'ed. All active characters are escaped.
+ # This script turns
+ # Description:
+ # Some module's description
+ #
+ # Files:
+ # lib/file.h
+ # into:
+ # modcache_description[$1]=\
+ # 'Some module'"'"'s description
+ # '
+ # modcache_files[$1]=\
+ # 'lib/file.h'
+ # or:
+ # c_MODULE_description_set=set; c_MODULE_description=\
+ # 'Some module'"'"'s description
+ # '
+ # c_MODULE_files_set=set; c_MODULE_files=\
+ # 'lib/file.h'
+ # The script consists of two parts:
+ # 1) Ignore the lines before the first field header.
+ # 2) A loop, treating non-field-header lines by escaping single quotes
+ # and adding a closing quote in the last line,
+ sed_convert_to_cache_statements="
+ :llla
+ # Here we have not yet seen a field header.
+
+ # See if the current line contains a field header.
+ t llla1
+ :llla1
+ ${sed_extract_field_header}
+ t lllb
+
+ # No field header. Ignore the line.
+
+ # Read the next line. Upon EOF, just exit.
+ n
+ b llla
+
+ :lllb
+ # The current line contains a field header.
+
+ # Turn it into the beginning of an assignment.
+ s/^\\(.*\\)\$/${modcachevar_assignment}\\\\/
+
+ # Move it to the hold space. Don't print it yet,
+ # because we want no assignment if the field is empty.
+ h
+
+ # Read the next line.
+ # Upon EOF, the field was empty. Print no assignment. Just exit.
+ n
+
+ # See if the current line contains a field header.
+ t lllb1
+ :lllb1
+ ${sed_extract_field_header}
+ # If it is, the previous field was empty. Print no assignment.
+ t lllb
+
+ # Not a field header.
+
+ # Print the previous line, held in the hold space.
+ x
+ p
+ x
+
+ # Transform single quotes.
+ s/'/'\"'\"'/g
+
+ # Prepend a single quote.
+ s/^/'/
+
+ :lllc
+
+ # Move it to the hold space.
+ h
+
+ # Read the next line.
+ # Upon EOF, branch.
+ \${
+ b llle
+ }
+ n
+
+ # See if the current line contains a field header.
+ t lllc1
+ :lllc1
+ ${sed_extract_field_header}
+ t llld
+
+ # Print the previous line, held in the hold space.
+ x
+ p
+ x
+
+ # Transform single quotes.
+ s/'/'\"'\"'/g
+
+ b lllc
+
+ :llld
+ # A field header.
+ # Print the previous line, held in the hold space, with a single quote
+ # to end the assignment.
+ x
+ s/\$/'/
+ p
+ x
+
+ b lllb
+
+ :llle
+ # EOF seen.
+ # Print the previous line, held in the hold space, with a single quote
+ # to end the assignment.
+ x
+ s/\$/'/
+ p
+ # Exit.
+ n
+ "
+ if ! $sed_comments; then
+ # Remove comments.
+ sed_convert_to_cache_statements=`echo "$sed_convert_to_cache_statements" \
+ | sed -e 's/^ *//' -e 's/^#.*//'`
+ fi
+ }
+
+ if $have_associative; then
+ # sed_convert_to_cache_statements does not depend on the module.
+ modcachevar_assignment='modcache_\1[$1]='
+ func_init_sed_convert_to_cache_statements
+ fi
+
+ # func_cache_lookup_module module
+ #
+ # looks up a module, like 'func_lookup_file modules/$module', and stores all
+ # of its relevant data in a cache in the memory of the processing shell. If
+ # already cached, it does not look it up again, thus saving file access time.
+ # Parameters:
+ # - module non-empty string
+ # Output if $have_associative:
+ # - modcache_cached[$module] set to yes
+ # - modcache_description[$module] ==
+ # - modcache_status[$module] \ set to the field's value, minus the
+ # - ... / final newline,
+ # - modcache_maintainer[$module] == or unset if the field's value is empty
+ # Output if ! $have_associative:
+ # - cachevar a shell variable name
+ # - ${cachevar}_cached set to $module
+ # - ${cachevar}_description ==
+ # - ${cachevar}_status \ set to the field's value, minus the
+ # - ... / final newline,
+ # - ${cachevar}_maintainer == or unset if the field's value is empty
+ # - ${cachevar}_description_set ==
+ # - ${cachevar}_status_set \ set to non-empty if the field's value
+ # - ... / is non-empty,
+ # - ${cachevar}_maintainer_set == or unset if the field's value is empty
+ func_cache_lookup_module ()
+ {
+ if $have_associative; then
+ cached=${modcache_cached[$1]}
+ else
+ func_cache_var "$1"
+ eval "cached=\"\$${cachevar}_cached\""
+ fi
+ if test -z "$cached"; then
+ # Not found in cache. Look it up on the file system.
+ func_lookup_file "modules/$1"
+ if $have_associative; then
+ modcache_cached[$1]=yes
+ else
+ eval "${cachevar}_cached=\"\$1\""
+ fi
+ if ! $have_associative; then
+ # sed_convert_to_cache_statements depends on the module.
+ modcachevar_assignment="${cachevar}"'_\1_set=set; '"${cachevar}"'_\1='
+ func_init_sed_convert_to_cache_statements
+ fi
+ cache_statements=`LC_ALL=C sed -n -e "$sed_convert_to_cache_statements" < "$lookedup_file"`
+ eval "$cache_statements"
+ else
+ if ! $have_associative; then
+ if test "$1" != "$cached"; then
+ func_fatal_error "cache variable collision between $1 and $cached"
+ fi
+ fi
+ fi
+ }
+
+fi
+