summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-09-28 16:44:15 +0200
committerDan McGee <dan@archlinux.org>2011-09-28 16:48:08 +0200
commit1b8bb7c1cd81c1f8f0dcffc952cd464b6a436f06 (patch)
treeef549a816aa644ef8ac2ba2201813daee67803d4
parentf682cbd43355daa7b13389d74e0ffea0370ba89b (diff)
downloadpacman-1b8bb7c1cd81c1f8f0dcffc952cd464b6a436f06.tar.gz
pacman-1b8bb7c1cd81c1f8f0dcffc952cd464b6a436f06.tar.xz
Use unsigned types for indent width and column count
For getcols(), the functions we call return a value of type 'unsigned short', so it makes sense for us to do the same. string_length() is meant to behave like strlen(), so it should return type size_t. This exposes other functions such as indentprint() which should also be using signed return types. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--src/pacman/callback.c4
-rw-r--r--src/pacman/util.c44
-rw-r--r--src/pacman/util.h4
3 files changed, 26 insertions, 26 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 9d4663a0..3ba07b0c 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -375,7 +375,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
int len, wclen, wcwid, padwid;
wchar_t *wcstr;
- const int cols = getcols();
+ const unsigned short cols = getcols();
if(config->noprogressbar || cols == 0) {
return;
@@ -534,7 +534,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
const char *rate_label, *xfered_label;
int file_percent = 0, total_percent = 0;
- const int cols = getcols();
+ const unsigned short cols = getcols();
if(config->noprogressbar || cols == 0 || file_total == -1) {
if(file_xfered == 0) {
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 59462e86..592754f8 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -140,11 +140,11 @@ static int flush_term_input(void) {
}
/* gets the current screen column width */
-int getcols()
+unsigned short getcols(void)
{
- int termwidth = -1;
- const int default_tty = 80;
- const int default_notty = 0;
+ const unsigned short default_tty = 80;
+ const unsigned short default_notty = 0;
+ unsigned short termwidth = 0;
if(!isatty(fileno(stdout))) {
return default_notty;
@@ -161,7 +161,7 @@ int getcols()
termwidth = win.ws_col;
}
#endif
- return termwidth <= 0 ? default_tty : termwidth;
+ return termwidth == 0 ? default_tty : termwidth;
}
/* does the same thing as 'rm -rf' */
@@ -252,12 +252,12 @@ char *mdirname(const char *path)
/* output a string, but wrap words properly with a specified indentation
*/
-void indentprint(const char *str, int indent)
+void indentprint(const char *str, size_t indent)
{
wchar_t *wcstr;
const wchar_t *p;
int len, cidx;
- const int cols = getcols();
+ const unsigned short cols = getcols();
if(!str) {
return;
@@ -297,7 +297,7 @@ void indentprint(const char *str, int indent)
}
if(len > (cols - cidx - 1)) {
/* wrap to a newline and reindent */
- printf("\n%-*s", indent, "");
+ printf("\n%-*s", (int)indent, "");
cidx = indent;
} else {
printf(" ");
@@ -454,7 +454,7 @@ alpm_list_t *strsplit(const char *str, const char splitchar)
return list;
}
-static int string_length(const char *s)
+static size_t string_length(const char *s)
{
int len;
wchar_t *wcstr;
@@ -481,7 +481,7 @@ void string_display(const char *title, const char *string)
printf(_("None"));
} else {
/* compute the length of title + a space */
- int len = string_length(title) + 1;
+ size_t len = string_length(title) + 1;
indentprint(string, len);
}
printf("\n");
@@ -510,9 +510,9 @@ static alpm_list_t *table_create_format(const alpm_list_t *header,
alpm_list_t *formats = NULL;
const alpm_list_t *i, *row, *cell;
char *str, *formatstr;
- const int padding = 2;
- int colwidth, totalwidth = 0;
- int curcol = 0;
+ const unsigned short padding = 2;
+ size_t colwidth, totalwidth = 0;
+ size_t curcol = 0;
/* header determines column count and initial values of longest_strs */
for(i = header; i; i = alpm_list_next(i)) {
@@ -601,7 +601,7 @@ int table_display(const char *title, const alpm_list_t *header,
void list_display(const char *title, const alpm_list_t *list)
{
const alpm_list_t *i;
- int len = 0;
+ size_t len = 0;
if(title) {
len = string_length(title) + 1;
@@ -611,17 +611,17 @@ void list_display(const char *title, const alpm_list_t *list)
if(!list) {
printf("%s\n", _("None"));
} else {
- const int maxcols = getcols();
- int cols = len;
+ const unsigned short maxcols = getcols();
+ size_t cols = len;
const char *str = alpm_list_getdata(list);
printf("%s", str);
cols += string_length(str);
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
str = alpm_list_getdata(i);
- int s = string_length(str);
+ size_t s = string_length(str);
/* wrap only if we have enough usable column space */
if(maxcols > len && cols + s + 2 >= maxcols) {
- int j;
+ size_t j;
cols = len;
printf("\n");
for (j = 1; j <= len; j++) {
@@ -641,7 +641,7 @@ void list_display(const char *title, const alpm_list_t *list)
void list_display_linebreak(const char *title, const alpm_list_t *list)
{
- int len = 0;
+ size_t len = 0;
if(title) {
len = string_length(title) + 1;
@@ -657,7 +657,7 @@ void list_display_linebreak(const char *title, const alpm_list_t *list)
printf("\n");
/* Print the rest */
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
- int j;
+ size_t j;
for(j = 1; j <= len; j++) {
printf(" ");
}
@@ -669,7 +669,7 @@ void list_display_linebreak(const char *title, const alpm_list_t *list)
void signature_display(const char *title, alpm_siglist_t *siglist)
{
- int len = 0;
+ size_t len = 0;
if(title) {
len = string_length(title) + 1;
@@ -686,7 +686,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) {
- int j;
+ size_t j;
for(j = 1; j <= len; j++) {
printf(" ");
}
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 275f9913..dc6995ca 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -50,11 +50,11 @@ int trans_init(alpm_transflag_t flags, int check_valid);
int trans_release(void);
int needs_root(void);
int check_syncdbs(size_t need_repos, int check_valid);
-int getcols(void);
+unsigned short getcols(void);
int rmrf(const char *path);
const char *mbasename(const char *path);
char *mdirname(const char *path);
-void indentprint(const char *str, int indent);
+void indentprint(const char *str, size_t indent);
char *strtoupper(char *str);
char *strtrim(char *str);
char *strreplace(const char *str, const char *needle, const char *replace);