Deleted Added
full compact
strings.subr (251272) strings.subr (251278)
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 251272 2013-06-02 23:08:21Z dteske $
27# $FreeBSD: head/usr.sbin/bsdconfig/share/strings.subr 251278 2013-06-02 23:25:27Z 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).

--- 30 unchanged lines hidden (view full) ---

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

--- 30 unchanged lines hidden (view full) ---

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
74# f_vsnprintf $var_to_set $size $format $format_args
75#
76# Similar to vsnprintf(3), write at most $size number of bytes into $var_to_set
77# using printf(1) syntax (`$format $format_args'). The value of $var_to_set is
78# NULL unless at-least one byte is stored from the output.
79#
80# Example 1:
81#
82# limit=7 format="%s"
83# format_args="'abc 123'" # 3-spaces between abc and 123
84# f_vsnprintf foo $limit "$format" "$format_args" # foo=[abc 1]
85#
86# Example 2:
87#
88# limit=12 format="%s %s"
89# format_args=" 'doghouse' 'foxhound' "
90# # even more spaces added to illustrate escape-method
91# f_vsnprintf foo $limit "$format" "$format_args" # foo=[doghouse fox]
92#
93# Example 3:
94#
95# limit=13 format="%s %s"
96# f_shell_escape arg1 'aaa"aaa' # arg1=[aaa"aaa] (no change)
97# f_shell_escape arg2 "aaa'aaa" # arg2=[aaa'\''aaa] (escaped s-quote)
98# format_args="'$arg1' '$arg2'" # use single-quotes to surround args
99# f_vsnprintf foo $limit "$format" "$format_args" # foo=[aaa"aaa aaa'a]
100#
101# In all of the above examples, the call to f_vsnprintf() does not change. Only
102# the contents of $limit, $format, and $format_args changes in each example.
103#
104f_vsnprintf()
105{
106 eval f_snprintf \"\$1\" \"\$2\" \"\$3\" $4
107}
108
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 ---
109# f_longest_line_length
110#
111# Simple wrapper to an awk(1) script to print the length of the longest line of
112# input (read from stdin). Supports the newline escape-sequence `\n' for
113# splitting a single line into multiple lines.
114#
115f_longest_line_length_awk='
116BEGIN { longest = 0 }

--- 210 unchanged lines hidden ---