summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2014-11-20 22:17:43 -0500
committerDave Reisner <dreisner@archlinux.org>2014-11-20 22:23:50 -0500
commit3883784575303a5d1de2b0ad8fc72ed1db03ed17 (patch)
treece8c3a84b43e51bc868c51be86f4ab505e524d6e
parent0075c5b195400daa4f9cf76ef54902a74dbb166f (diff)
downloadexpac-3883784575303a5d1de2b0ad8fc72ed1db03ed17.tar.xz
cleanup printing code
This fixes a bug where unknown escape sequences would be flat out skipped.
-rw-r--r--expac.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/expac.c b/expac.c
index d57e8b6..cc806ac 100644
--- a/expac.c
+++ b/expac.c
@@ -274,8 +274,11 @@ static int print_escaped(const char *delim) {
case '0':
fputc('\0', stdout);
break;
- ++out;
+ default:
+ fputc(*f, stdout);
+ break;
}
+ ++out;
} else {
fputc(*f, stdout);
++out;
@@ -407,21 +410,23 @@ static alpm_list_t *get_validation_method(alpm_pkg_t *pkg) {
return validation;
}
-static int print_pkg(alpm_pkg_t *pkg, const char *format) {
+static void print_pkg(alpm_pkg_t *pkg, const char *format) {
const char *f, *end;
- int len, out = 0;
+ int out = 0;
end = format + strlen(format);
for (f = format; f < end; f++) {
- len = 0;
if (*f == '%') {
- char fmt[64];
- len = strspn(f + 1 + len, printf_flags);
- len += strspn(f + 1 + len, digits);
- snprintf(fmt, len + 3, "%ss", f);
- fmt[len + 1] = 's';
- f += len + 1;
+ char fmt[64] = {0};
+ int l = 1;
+
+ l += strspn(f + l, printf_flags);
+ l += strspn(f + l, digits);
+ memcpy(fmt, f, l);
+ fmt[l] = 's';
+
+ f += l;
switch (*f) {
/* simple attributes */
case 'f': /* filename */
@@ -445,7 +450,7 @@ static int print_pkg(alpm_pkg_t *pkg, const char *format) {
case 's': /* md5sum */
out += printf(fmt, alpm_pkg_get_md5sum(pkg));
break;
- case 'a': /* architecutre */
+ case 'a': /* architecture */
out += printf(fmt, alpm_pkg_get_arch(pkg));
break;
case 'i': /* has install scriptlet? */
@@ -552,8 +557,6 @@ static int print_pkg(alpm_pkg_t *pkg, const char *format) {
/* only print a delimeter if any package data was outputted */
if (out > 0)
print_escaped(opt_delim);
-
- return !out;
}
static alpm_list_t *all_packages(alpm_list_t *dbs) {