[pacman-dev] [PATCH] Remove trailing whitespaces in the output for -Qi/-Si
--- src/pacman/util.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index 115b367..e23d96d 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -446,8 +446,11 @@ void list_display(const char *title, const alpm_list_t *list) for(i = list, cols = len; i; i = alpm_list_next(i)) { char *str = alpm_list_getdata(i); int s = string_length(str); - /* two additional spaces are added to the length */ - s += 2; + /* two additional spaces are added to the length, if this is not the + * last element in the list */ + if (alpm_list_next(i)) { + s += 2; + } int maxcols = getcols(); if(s + cols > maxcols && maxcols > 0) { int j; @@ -457,7 +460,11 @@ void list_display(const char *title, const alpm_list_t *list) printf(" "); } } - printf("%s ", str); + if (alpm_list_next(i)) { + printf("%s ", str); + } else { + printf("%s", str); + } cols += s; } printf("\n"); -- 1.6.5.5
On Sat, Dec 12, 2009 at 9:27 AM, Laszlo Papp
--- src/pacman/util.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 115b367..e23d96d 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -446,8 +446,11 @@ void list_display(const char *title, const alpm_list_t *list) for(i = list, cols = len; i; i = alpm_list_next(i)) { char *str = alpm_list_getdata(i); int s = string_length(str); - /* two additional spaces are added to the length */ - s += 2; + /* two additional spaces are added to the length, if this is not the + * last element in the list */ + if (alpm_list_next(i)) { + s += 2; + } int maxcols = getcols(); if(s + cols > maxcols && maxcols > 0) { int j; @@ -457,7 +460,11 @@ void list_display(const char *title, const alpm_list_t *list) printf(" "); } } - printf("%s ", str); + if (alpm_list_next(i)) { + printf("%s ", str); + } else { + printf("%s", str); + } cols += s; } printf("\n"); -- 1.6.5.5
Dan McGee wrote:
On Sat, Dec 12, 2009 at 9:27 AM, Laszlo Papp
wrote: Seems fine to me, anyone else?
Ack.
--- src/pacman/util.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 115b367..e23d96d 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -446,8 +446,11 @@ void list_display(const char *title, const alpm_list_t *list) for(i = list, cols = len; i; i = alpm_list_next(i)) { char *str = alpm_list_getdata(i); int s = string_length(str); - /* two additional spaces are added to the length */ - s += 2; + /* two additional spaces are added to the length, if this is not the + * last element in the list */ + if (alpm_list_next(i)) { + s += 2; + } int maxcols = getcols(); if(s + cols > maxcols && maxcols > 0) { int j; @@ -457,7 +460,11 @@ void list_display(const char *title, const alpm_list_t *list) printf(" "); } } - printf("%s ", str); + if (alpm_list_next(i)) { + printf("%s ", str); + } else { + printf("%s", str); + } cols += s; } printf("\n"); -- 1.6.5.5
This ensures we never have trailing whitespace. Take the following text,
with line numbers added for clarity:
1. Title : item1 item2 item3 item4
2. item5 item6 item7 item8
3. item9 itemA itemB itemC
Laszlo Papp helpfully pointed out we would have two trailing spaces on line
three after the last item. However, we also had these trailing spaces on
lines one and two, which the initial patch didn't take care of. This can be
seen on something like `pacman -Qi glibc`.
Signed-off-by: Dan McGee
participants (4)
-
Allan McRae
-
Dan McGee
-
Dan McGee
-
Laszlo Papp