summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/share/strings.subr
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2013-11-21 03:38:47 +0000
committerdteske <dteske@FreeBSD.org>2013-11-21 03:38:47 +0000
commit7f36b7bf087251733bd30c159e873d5bd427ed53 (patch)
treeaae33fabe9f1e42be0a42e4ffb105e726fff344b /usr.sbin/bsdconfig/share/strings.subr
parenta2ed0ef7f6d3effa506eee672d738f5ec99b5254 (diff)
downloadFreeBSD-src-7f36b7bf087251733bd30c159e873d5bd427ed53.zip
FreeBSD-src-7f36b7bf087251733bd30c159e873d5bd427ed53.tar.gz
MFC r257755-257756,257780-257785,257787-257793, and
257795,257817,257819,257937-257938,258029,258263-258267: 257755: SRV records 257756: fix spurious error message 257780: Whitespace 257781: Comments and funny syntax 257782: Debug file truncation is optional 257783: f_show_err for debugging 257784: f_eval_catch for debugging 257785: fix size calculations bug 257787: fix broken HTTP "any" media type 257788: more debugging 257789: Comments 257790: fix printf usage bug 257791: f_[v]sprintf added 257792: Comments 257793: fix off-by-one error in size calcs 257795: Replace pkg-tools with pkgng 257817: fix cosmetic typos 257819: Use `pkg -vv' to get ABI 257937: Adjustment to last 257938: Adjustment to last 258029: Comments 258263: Shuffle code around 258264: Remove unused code 258265: Debugging. Use f_eval_catch with pkg 258266: Shutdown media on exit from packages 258267: Fix pkg install from DVD Reviewed by: many Discussed on: -current Approved by: re (hrs)
Diffstat (limited to 'usr.sbin/bsdconfig/share/strings.subr')
-rw-r--r--usr.sbin/bsdconfig/share/strings.subr35
1 files changed, 29 insertions, 6 deletions
diff --git a/usr.sbin/bsdconfig/share/strings.subr b/usr.sbin/bsdconfig/share/strings.subr
index f78948b..25cceee 100644
--- a/usr.sbin/bsdconfig/share/strings.subr
+++ b/usr.sbin/bsdconfig/share/strings.subr
@@ -46,7 +46,7 @@ VALID_VARNAME_CHARS="0-9ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"
############################################################ FUNCTIONS
-# f_substr "$string" $start [ $length ]
+# f_substr "$string" $start [$length]
#
# Simple wrapper to awk(1)'s `substr' function.
#
@@ -56,17 +56,18 @@ f_substr()
echo "$string" | awk "{ print substr(\$0, $start, $len) }"
}
-# f_snprintf $var_to_set $size $format ...
+# f_snprintf $var_to_set $size $format [$arguments ...]
#
# Similar to snprintf(3), write at most $size number of bytes into $var_to_set
-# using printf(1) syntax (`$format ...'). The value of $var_to_set is NULL
-# unless at-least one byte is stored from the output.
+# using printf(1) syntax (`$format [$arguments ...]'). The value of $var_to_set
+# is NULL unless at-least one byte is stored from the output.
#
f_snprintf()
{
local __var_to_set="$1" __size="$2"
- shift 2 # var_to_set/size
- eval "$__var_to_set"=\$\( printf \"\$@\" \| awk -v max=\"\$__size\" \''
+ shift 2 # var_to_set size
+ eval "$__var_to_set"=\$\( printf -- \"\$@\" \| \
+ awk -v max=\"\$__size\" \''
{
len = length($0)
max -= len
@@ -76,6 +77,18 @@ f_snprintf()
}'\' \)
}
+# f_sprintf $var_to_set $format [$arguments ...]
+#
+# Similar to sprintf(3), write a string into $var_to_set using printf(1) syntax
+# (`$format [$arguments ...]').
+#
+f_sprintf()
+{
+ local __var_to_set="$1"
+ shift 1 # var_to_set
+ eval "$__var_to_set"=\$\( printf -- \"\$@\" \)
+}
+
# f_vsnprintf $var_to_set $size $format $format_args
#
# Similar to vsnprintf(3), write at most $size number of bytes into $var_to_set
@@ -111,6 +124,16 @@ f_vsnprintf()
eval f_snprintf \"\$1\" \"\$2\" \"\$3\" $4
}
+# f_vsprintf $var_to_set $format $format_args
+#
+# Similar to vsprintf(3), write a string into $var_to_set using printf(1)
+# syntax (`$format $format_args').
+#
+f_vsprintf()
+{
+ eval f_sprintf \"\$1\" \"\$2\" $3
+}
+
# f_longest_line_length
#
# Simple wrapper to an awk(1) script to print the length of the longest line of
OpenPOWER on IntegriCloud