strings.subr (249751) | strings.subr (250701) |
---|---|
1if [ ! "$_STRINGS_SUBR" ]; then _STRINGS_SUBR=1 2# 3# Copyright (c) 2006-2013 Devin Teske 4# All Rights Reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# | 1if [ ! "$_STRINGS_SUBR" ]; then _STRINGS_SUBR=1 2# 3# Copyright (c) 2006-2013 Devin Teske 4# All Rights Reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# |
27# $FreeBSD: head/usr.sbin/bsdconfig/share/strings.subr 249751 2013-04-22 05:52:06Z dteske $ | 27# $FreeBSD: head/usr.sbin/bsdconfig/share/strings.subr 250701 2013-05-16 16:46:02Z dteske $ |
28# 29############################################################ GLOBALS 30 31# 32# Valid characters that can appear in an sh(1) variable name 33# 34# Please note that the character ranges A-Z and a-z should be avoided because 35# these can include accent characters (which are not valid in a variable name). --- 10 unchanged lines hidden (view full) --- 46# Simple wrapper to awk(1)'s `substr' function. 47# 48f_substr() 49{ 50 local string="$1" start="${2:-0}" len="${3:-0}" 51 echo "$string" | awk "{ print substr(\$0, $start, $len) }" 52} 53 | 28# 29############################################################ GLOBALS 30 31# 32# Valid characters that can appear in an sh(1) variable name 33# 34# Please note that the character ranges A-Z and a-z should be avoided because 35# these can include accent characters (which are not valid in a variable name). --- 10 unchanged lines hidden (view full) --- 46# Simple wrapper to awk(1)'s `substr' function. 47# 48f_substr() 49{ 50 local string="$1" start="${2:-0}" len="${3:-0}" 51 echo "$string" | awk "{ print substr(\$0, $start, $len) }" 52} 53 |
54# f_snprintf $var_to_set $size $format ... 55# 56# Similar to snprintf(3), write at most $size number of bytes into $var_to_set 57# using printf(1) syntax (`$format ...'). The value of $var_to_set is NULL 58# unless at-least one byte is stored from the output. 59# 60f_snprintf() 61{ 62 local __var_to_set="$1" __size="$2" 63 shift 2 # var_to_set/size 64 eval "$__var_to_set"=\$\( printf \"\$@\" \| awk -v max=\"\$__size\" \'' 65 { 66 len = length($0) 67 max -= len 68 print substr($0,0,(max > 0 ? len : max + len)) 69 if ( max < 0 ) exit 70 max-- 71 }'\' \) 72} 73 |
|
54# f_longest_line_length 55# 56# Simple wrapper to an awk(1) script to print the length of the longest line of 57# input (read from stdin). Supports the newline escape-sequence `\n' for 58# splitting a single line into multiple lines. 59# 60f_longest_line_length_awk=' 61BEGIN { longest = 0 } --- 210 unchanged lines hidden --- | 74# f_longest_line_length 75# 76# Simple wrapper to an awk(1) script to print the length of the longest line of 77# input (read from stdin). Supports the newline escape-sequence `\n' for 78# splitting a single line into multiple lines. 79# 80f_longest_line_length_awk=' 81BEGIN { longest = 0 } --- 210 unchanged lines hidden --- |