Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add new %N pkg_printf() escape: Repository name, plus doccumentation and testing for the same.
Matthew Seaman committed 12 years ago
commit bfba1d18d536f93390babc2336aca45806b4e17d
parent 56da60a
4 files changed +41 -3
modified libpkg/pkg_printf.3
@@ -30,7 +30,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-
.Dd June 8, 2013
+
.Dd June 9, 2013
.Dt PKG_PRINTF 3
.Os
.Sh NAME
@@ -583,6 +583,9 @@ Licence name [string]
.It Cm %M
Package message [string]
.Vt struct pkg *
+
.It Cm %N
+
Repository name [string]
+
.Vt struct pkg *
.It Cm \^%O
Options [array]
.Vt struct pkg *
modified libpkg/pkg_printf.c
@@ -86,8 +86,7 @@
 * Ln pkg_license  Licence name
 *
 * M  pkg          Message
-
 *
-
 * N
+
 * N  pkg          Reponame
 *
 * O  pkg          List of options
 * On pkg_option   Option name (key)
@@ -424,6 +423,15 @@ static const struct pkg_printf_fmt fmt[] = {
		PP_ALL,
		&format_message,
	},
+
	[PP_PKG_REPO_NAME] =
+
	{
+
		'N',
+
		'\0',
+
		false,
+
		true,
+
		PP_ALL,
+
		&format_repo_name,
+
	},
	[PP_PKG_OPTION_NAME] =
	{
		'O',
@@ -1256,6 +1264,19 @@ format_message(struct sbuf *sbuf, const void *data, struct percent_esc *p)
}

/*
+
 * %N -- Repository name. string.  Accepts field-width, left-align
+
 */
+
struct sbuf *
+
format_repo_name(struct sbuf *sbuf, const void *data, struct percent_esc *p)
+
{
+
	const struct pkg	*pkg = data;
+
	const char		*repo_name;
+

+
	pkg_get(pkg, PKG_REPONAME, &repo_name);
+
	return (string_val(sbuf, repo_name, p));
+
}
+

+
/*
 * %O -- Options. list of {option,value} tuples. Optionally accepts
 * following per-field format in %{ %| %}, where %On is replaced by the
 * option name and %Ov by the value.  Default %{%On %Ov\n%|%}
modified libpkg/private/pkg_printf.h
@@ -102,6 +102,7 @@ typedef enum _fmt_code_t {
	PP_PKG_LICENSE_NAME,
	PP_PKG_LICENSES,
	PP_PKG_MESSAGE,
+
	PP_PKG_REPO_NAME,
	PP_PKG_OPTION_NAME,
	PP_PKG_OPTION_VALUE,
	PP_PKG_OPTIONS,
@@ -186,6 +187,7 @@ _static struct sbuf *format_row_counter(struct sbuf *, const void *, struct perc
_static struct sbuf *format_licenses(struct sbuf *, const void *, struct percent_esc *);
_static struct sbuf *format_license_name(struct sbuf *, const void *, struct percent_esc *);
_static struct sbuf *format_message(struct sbuf *, const void *, struct percent_esc *);
+
_static struct sbuf *format_repo_name(struct sbuf *, const void *, struct percent_esc *);
_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 *);
modified tests/lib/pkg_printf_test.c
@@ -1375,6 +1375,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_PKG, PP_PKG_LICENSE_NAME,        2, '\0', },
		{ "L",  PP_PKG, PP_PKG_LICENSES,            1, '\0', },
		{ "M",  PP_PKG, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_PKG, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_PKG, PP_PKG_OPTION_NAME,         2, '\0', },
		{ "Ov", PP_PKG, PP_PKG_OPTION_VALUE,        2, '\0', },
		{ "O",  PP_PKG, PP_PKG_OPTIONS,             1, '\0', },
@@ -1439,6 +1440,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_B, PP_UNKNOWN,                 0, 'L',  },
		{ "L",  PP_B, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_B, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_B, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_B, PP_UNKNOWN,                 0, 'O',  },
		{ "Ov", PP_B, PP_UNKNOWN,                 0, 'O',  },
		{ "O",  PP_B, PP_UNKNOWN,                 0, 'O',  },
@@ -1503,6 +1505,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_C, PP_UNKNOWN,                 0, 'L',  },
		{ "L",  PP_C, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_C, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_C, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_C, PP_UNKNOWN,                 0, 'O',  },
		{ "Ov", PP_C, PP_UNKNOWN,                 0, 'O',  },
		{ "O",  PP_C, PP_UNKNOWN,                 0, 'O',  },
@@ -1567,6 +1570,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_D, PP_UNKNOWN,                 0, 'L',  },
		{ "L",  PP_D, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_D, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_D, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_D, PP_UNKNOWN,                 0, 'O',  },
		{ "Ov", PP_D, PP_UNKNOWN,                 0, 'O',  },
		{ "O",  PP_D, PP_UNKNOWN,                 0, 'O',  },
@@ -1631,6 +1635,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_F, PP_UNKNOWN,                 0, 'L',  },
		{ "L",  PP_F, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_F, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_F, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_F, PP_UNKNOWN,                 0, 'O',  },
		{ "Ov", PP_F, PP_UNKNOWN,                 0, 'O',  },
		{ "O",  PP_F, PP_UNKNOWN,                 0, 'O',  },
@@ -1695,6 +1700,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_G, PP_UNKNOWN,                 0, 'L',  },
		{ "L",  PP_G, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_G, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_G, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_G, PP_UNKNOWN,                 0, 'O',  },
		{ "Ov", PP_G, PP_UNKNOWN,                 0, 'O',  },
		{ "O",  PP_G, PP_UNKNOWN,                 0, 'O',  },
@@ -1759,6 +1765,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_L, PP_PKG_LICENSE_NAME,        2, '\0', },
		{ "L",  PP_L, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_L, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_L, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_L, PP_UNKNOWN,                 0, 'O',  },
		{ "Ov", PP_L, PP_UNKNOWN,                 0, 'O',  },
		{ "O",  PP_L, PP_UNKNOWN,                 0, 'O',  },
@@ -1823,6 +1830,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_O, PP_UNKNOWN,                 0, 'L',  },
		{ "L",  PP_O, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_O, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_O, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_O, PP_PKG_OPTION_NAME,         2, '\0', },
		{ "Ov", PP_O, PP_PKG_OPTION_VALUE,        2, '\0', },
		{ "O",  PP_O, PP_UNKNOWN,                 0, 'O',  },
@@ -1887,6 +1895,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_U, PP_UNKNOWN,                 0, 'L',  },
		{ "L",  PP_U, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_U, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_U, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_U, PP_UNKNOWN,                 0, 'O',  },
		{ "Ov", PP_U, PP_UNKNOWN,                 0, 'O',  },
		{ "O",  PP_U, PP_UNKNOWN,                 0, 'O',  },
@@ -1951,6 +1960,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_b, PP_UNKNOWN,                 0, 'L',  },
		{ "L",  PP_b, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_b, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_b, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_b, PP_UNKNOWN,                 0, 'O',  },
		{ "Ov", PP_b, PP_UNKNOWN,                 0, 'O',  },
		{ "O",  PP_b, PP_UNKNOWN,                 0, 'O',  },
@@ -2016,6 +2026,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_d, PP_UNKNOWN,                 0, 'L',  },
		{ "L",  PP_d, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_d, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_d, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_d, PP_UNKNOWN,                 0, 'O',  },
		{ "Ov", PP_d, PP_UNKNOWN,                 0, 'O',  },
		{ "O",  PP_d, PP_UNKNOWN,                 0, 'O',  },
@@ -2080,6 +2091,7 @@ ATF_TC_BODY(format_code, tc)
		{ "Ln", PP_r, PP_UNKNOWN,                 0, 'L',  },
		{ "L",  PP_r, PP_UNKNOWN,                 0, 'L',  },
		{ "M",  PP_r, PP_PKG_MESSAGE,             1, '\0', },
+
		{ "N",  PP_r, PP_PKG_REPO_NAME,           1, '\0', },
		{ "On", PP_r, PP_UNKNOWN,                 0, 'O',  },
		{ "Ov", PP_r, PP_UNKNOWN,                 0, 'O',  },
		{ "O",  PP_r, PP_UNKNOWN,                 0, 'O',  },