Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add %S as a new format code to print arbitrary character strings.
Matthew Seaman committed 12 years ago
commit 2761e8a8a8c041cc79be7474663f4944fdc9ba39
parent 8938697
3 files changed +28 -1
modified libpkg/pkg_printf.3
@@ -553,6 +553,9 @@ Option name [string]
.It Cm %Ov
Option value [string]
.Vt struct pkg_option *
+
.It Cm \^%S
+
Arbitrary character string [string]
+
.Vt const char *
.It Cm \^%U
Users [array]
.Vt struct pkg *
modified libpkg/pkg_printf.c
@@ -96,7 +96,9 @@
 * P
 * Q
 * R
-
 * S
+
 *
+
 * S  char*        Arbitrary character string
+
 *
 * T
 *
 * U  pkg          List of users
@@ -453,6 +455,15 @@ static const struct pkg_printf_fmt fmt[] = {
		PP_PKG,
		&format_options,
	},
+
	[PP_PKG_CHAR_STRING] =
+
	{
+
		'S',
+
		'\0',
+
		false,
+
		false,
+
		PP_PKG,
+
		&format_char_string,
+
	},
	[PP_PKG_USER_NAME] =
	{
		'U',
@@ -1267,6 +1278,17 @@ format_option_value(struct sbuf *sbuf, const void *data, struct percent_esc *p)
}

/*
+
 * %S -- Character string.
+
 */
+
struct sbuf *
+
format_char_string(struct sbuf *sbuf, const void *data, struct percent_esc *p)
+
{
+
	const char	*charstring = data;
+

+
	return (string_val(sbuf, charstring, p));
+
}
+

+
/*
 * %U -- Users. list of string values.  Optionally accepts following
 * per-field format in %{ %| %} where %Un will be replaced by each
 * username or %#Un by the uid or %Uu by the uidstr -- a line from
modified libpkg/private/pkg_printf.h
@@ -105,6 +105,7 @@ typedef enum _fmt_code_t {
	PP_PKG_OPTION_NAME,
	PP_PKG_OPTION_VALUE,
	PP_PKG_OPTIONS,
+
	PP_PKG_CHAR_STRING,
	PP_PKG_USER_NAME,
	PP_PKG_USER_UIDSTR,
	PP_PKG_USERS,
@@ -184,6 +185,7 @@ _static struct sbuf *format_message(struct sbuf *, const void *, struct percent_
_static struct sbuf *format_options(struct sbuf *, const void *, struct percent_esc *);
_static struct sbuf *format_option_name(struct sbuf *, const void *, struct percent_esc *);
_static struct sbuf *format_option_value(struct sbuf *, const void *, struct percent_esc *);
+
_static struct sbuf *format_char_string(struct sbuf *, const void *, struct percent_esc *);
_static struct sbuf *format_users(struct sbuf *, const void *, struct percent_esc *);
_static struct sbuf *format_user_name(struct sbuf *, const void *, struct percent_esc *);
_static struct sbuf *format_user_uidstr(struct sbuf *, const void *, struct percent_esc *);