diff options
| author | Stefan Eßer <se@FreeBSD.org> | 2022-06-11 09:50:28 +0000 |
|---|---|---|
| committer | Stefan Eßer <se@FreeBSD.org> | 2022-06-11 09:50:28 +0000 |
| commit | 5bdd626528a2bb3e341e283b2eb279235997b8f4 (patch) | |
| tree | 76ed2ffea2671f693d61e61f456805da8c39c7b2 /scripts/functions.sh | |
| parent | ed0603704174b01c25b49efc08c82e1532dc5622 (diff) | |
vendor/bc: import of version 5.3.0vendor/bc/5.3.0
This version adds support for command line editing and history using
the editline or readline libraries in addition to the line editing
features available in previous versions.
Diffstat (limited to 'scripts/functions.sh')
| -rwxr-xr-x | scripts/functions.sh | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/scripts/functions.sh b/scripts/functions.sh index 65ec0a1167fe..53778ad4d16b 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -326,3 +326,97 @@ gen_nlspath() { # Return the result. printf '%s' "$_gen_nlspath_nlspath" } + +ALL=0 +NOSKIP=1 +SKIP=2 + +# Filters text out of a file according to the build type. +# @param in File to filter. +# @param out File to write the filtered output to. +# @param type Build type. +filter_text() { + + _filter_text_in="$1" + shift + + _filter_text_out="$1" + shift + + _filter_text_buildtype="$1" + shift + + # Set up some local variables. + _filter_text_status="$ALL" + _filter_text_temp="$_filter_text_out.tmp" + + # We need to set IFS, so we store it here for restoration later. + _filter_text_ifs="$IFS" + + # Remove the file- that will be generated. + rm -rf "$_filter_text_out" "$_filter_text_temp" + + # Here is the magic. This loop reads the template line-by-line, and based on + # _filter_text_status, either prints it to the markdown manual or not. + # + # Here is how the template is set up: it is a normal markdown file except + # that there are sections surrounded tags that look like this: + # + # {{ <build_type_list> }} + # ... + # {{ end }} + # + # Those tags mean that whatever build types are found in the + # <build_type_list> get to keep that section. Otherwise, skip. + # + # Obviously, the tag itself and its end are not printed to the markdown + # manual. + while IFS= read -r line; do + + # If we have found an end, reset the status. + if [ "$line" = "{{ end }}" ]; then + + # Some error checking. This helps when editing the templates. + if [ "$_filter_text_status" -eq "$ALL" ]; then + err_exit "{{ end }} tag without corresponding start tag" 2 + fi + + _filter_text_status="$ALL" + + # We have found a tag that allows our build type to use it. + elif [ "${line#\{\{* $_filter_text_buildtype *\}\}}" != "$line" ]; then + + # More error checking. We don't want tags nested. + if [ "$_filter_text_status" -ne "$ALL" ]; then + err_exit "start tag nested in start tag" 3 + fi + + _filter_text_status="$NOSKIP" + + # We have found a tag that is *not* allowed for our build type. + elif [ "${line#\{\{*\}\}}" != "$line" ]; then + + if [ "$_filter_text_status" -ne "$ALL" ]; then + err_exit "start tag nested in start tag" 3 + fi + + _filter_text_status="$SKIP" + + # This is for normal lines. If we are not skipping, print. + else + if [ "$_filter_text_status" -ne "$SKIP" ]; then + printf '%s\n' "$line" >> "$_filter_text_temp" + fi + fi + + done < "$_filter_text_in" + + # Remove multiple blank lines. + uniq "$_filter_text_temp" "$_filter_text_out" + + # Remove the temp file. + #rm -rf "$_filter_text_temp" + + # Reset IFS. + IFS="$_filter_text_ifs" +} |
