[pacman-dev] [PATCH 3/4] standardize all *_display functions
Simon Gomizelj
simongmzlj at gmail.com
Mon Mar 25 14:43:40 EDT 2013
Signed-off-by: Simon Gomizelj <simongmzlj at gmail.com>
---
src/pacman/package.c | 8 ++++----
src/pacman/util.c | 34 ++++++++++++++++------------------
src/pacman/util.h | 3 ++-
3 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 42a8635..3d1b108 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -40,21 +40,21 @@
* @param deps a list with items of type alpm_depend_t
*/
static void deplist_display(const char *title,
- alpm_list_t *deps, unsigned short cols)
+ alpm_list_t *deps, unsigned short maxcols)
{
alpm_list_t *i, *text = NULL;
for(i = deps; i; i = alpm_list_next(i)) {
alpm_depend_t *dep = i->data;
text = alpm_list_add(text, alpm_dep_compute_string(dep));
}
- list_display(title, text, cols);
+ list_display(title, text, maxcols);
FREELIST(text);
}
/** Turn a optdepends list into a text list.
* @param optdeps a list with items of type alpm_depend_t
*/
-static void optdeplist_display(alpm_pkg_t *pkg, unsigned short cols)
+static void optdeplist_display(alpm_pkg_t *pkg, unsigned short maxcols)
{
alpm_list_t *i, *text = NULL;
for(i = alpm_pkg_get_optdepends(pkg); i; i = alpm_list_next(i)) {
@@ -69,7 +69,7 @@ static void optdeplist_display(alpm_pkg_t *pkg, unsigned short cols)
}
text = alpm_list_add(text, depstring);
}
- list_display_linebreak(_("Optional Deps :"), text, cols);
+ list_display_linebreak(_("Optional Deps :"), text, maxcols);
FREELIST(text);
}
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 994b79e..a5796bb 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -424,17 +424,20 @@ static size_t string_length(const char *s)
return len;
}
-void string_display(const char *title, const char *string, unsigned short cols)
+void string_display(const char *title, const char *string,
+ unsigned short maxcols)
{
+ unsigned short len = 0;
+
if(title) {
+ len = (unsigned short)string_length(title) + 1;
printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor);
}
+
if(string == NULL || string[0] == '\0') {
printf(_("None"));
} else {
- /* compute the length of title + a space */
- size_t len = string_length(title) + 1;
- indentprint(string, (unsigned short)len, cols);
+ indentprint(string, (unsigned short)len, maxcols);
}
printf("\n");
}
@@ -486,8 +489,6 @@ static void table_print_line(const alpm_list_t *line, short col_padding,
printf("\n");
}
-
-
/**
* Find the max string width of each column. Also determines whether values
* exist in the column and sets the value in has_data accordingly.
@@ -615,19 +616,20 @@ static int table_display(const char *title, const alpm_list_t *header,
void list_display(const char *title, const alpm_list_t *list,
unsigned short maxcols)
{
- const alpm_list_t *i;
- size_t len = 0;
+ unsigned short len = 0;
if(title) {
- len = string_length(title) + 1;
+ len = (unsigned short)string_length(title) + 1;
printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor);
}
if(!list) {
printf("%s\n", _("None"));
} else {
- size_t cols = len;
+ const alpm_list_t *i;
const char *str = list->data;
+ size_t cols = len;
+
fputs(str, stdout);
cols += string_length(str);
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
@@ -667,15 +669,13 @@ void list_display_linebreak(const char *title, const alpm_list_t *list,
printf("%s\n", _("None"));
} else {
const alpm_list_t *i;
+
/* Print the first element */
indentprint((const char *)list->data, len, maxcols);
printf("\n");
/* Print the rest */
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
- size_t j;
- for(j = 1; j <= len; j++) {
- printf(" ");
- }
+ printf("%-*s", (int)len, "");
indentprint((const char *)i->data, len, maxcols);
printf("\n");
}
@@ -691,6 +691,7 @@ void signature_display(const char *title, alpm_siglist_t *siglist,
len = (unsigned short)string_length(title) + 1;
printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor);
}
+
if(siglist->count == 0) {
printf(_("None"));
} else {
@@ -701,10 +702,7 @@ void signature_display(const char *title, alpm_siglist_t *siglist,
alpm_sigresult_t *result = siglist->results + i;
/* Don't re-indent the first result */
if(i != 0) {
- size_t j;
- for(j = 1; j <= len; j++) {
- printf(" ");
- }
+ printf("%-*s", (int)len, "");
}
switch(result->status) {
case ALPM_SIGSTATUS_VALID:
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 0a2a6f7..690bc1d 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -55,7 +55,8 @@ void indentprint(const char *str, unsigned short indent, unsigned short cols);
size_t strtrim(char *str);
char *strreplace(const char *str, const char *needle, const char *replace);
alpm_list_t *strsplit(const char *str, const char splitchar);
-void string_display(const char *title, const char *string, unsigned short cols);
+void string_display(const char *title, const char *string,
+ unsigned short maxcols);
double humanize_size(off_t bytes, const char target_unit, int precision,
const char **label);
void list_display(const char *title, const alpm_list_t *list,
--
1.8.2
More information about the pacman-dev
mailing list