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>
This commit is contained in:
parent
f682cbd433
commit
1b8bb7c1cd
3 changed files with 26 additions and 26 deletions
|
@ -375,7 +375,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
|
||||||
int len, wclen, wcwid, padwid;
|
int len, wclen, wcwid, padwid;
|
||||||
wchar_t *wcstr;
|
wchar_t *wcstr;
|
||||||
|
|
||||||
const int cols = getcols();
|
const unsigned short cols = getcols();
|
||||||
|
|
||||||
if(config->noprogressbar || cols == 0) {
|
if(config->noprogressbar || cols == 0) {
|
||||||
return;
|
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;
|
const char *rate_label, *xfered_label;
|
||||||
int file_percent = 0, total_percent = 0;
|
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(config->noprogressbar || cols == 0 || file_total == -1) {
|
||||||
if(file_xfered == 0) {
|
if(file_xfered == 0) {
|
||||||
|
|
|
@ -140,11 +140,11 @@ static int flush_term_input(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* gets the current screen column width */
|
/* gets the current screen column width */
|
||||||
int getcols()
|
unsigned short getcols(void)
|
||||||
{
|
{
|
||||||
int termwidth = -1;
|
const unsigned short default_tty = 80;
|
||||||
const int default_tty = 80;
|
const unsigned short default_notty = 0;
|
||||||
const int default_notty = 0;
|
unsigned short termwidth = 0;
|
||||||
|
|
||||||
if(!isatty(fileno(stdout))) {
|
if(!isatty(fileno(stdout))) {
|
||||||
return default_notty;
|
return default_notty;
|
||||||
|
@ -161,7 +161,7 @@ int getcols()
|
||||||
termwidth = win.ws_col;
|
termwidth = win.ws_col;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return termwidth <= 0 ? default_tty : termwidth;
|
return termwidth == 0 ? default_tty : termwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* does the same thing as 'rm -rf' */
|
/* 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
|
/* 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;
|
wchar_t *wcstr;
|
||||||
const wchar_t *p;
|
const wchar_t *p;
|
||||||
int len, cidx;
|
int len, cidx;
|
||||||
const int cols = getcols();
|
const unsigned short cols = getcols();
|
||||||
|
|
||||||
if(!str) {
|
if(!str) {
|
||||||
return;
|
return;
|
||||||
|
@ -297,7 +297,7 @@ void indentprint(const char *str, int indent)
|
||||||
}
|
}
|
||||||
if(len > (cols - cidx - 1)) {
|
if(len > (cols - cidx - 1)) {
|
||||||
/* wrap to a newline and reindent */
|
/* wrap to a newline and reindent */
|
||||||
printf("\n%-*s", indent, "");
|
printf("\n%-*s", (int)indent, "");
|
||||||
cidx = indent;
|
cidx = indent;
|
||||||
} else {
|
} else {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
|
@ -454,7 +454,7 @@ alpm_list_t *strsplit(const char *str, const char splitchar)
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int string_length(const char *s)
|
static size_t string_length(const char *s)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
wchar_t *wcstr;
|
wchar_t *wcstr;
|
||||||
|
@ -481,7 +481,7 @@ void string_display(const char *title, const char *string)
|
||||||
printf(_("None"));
|
printf(_("None"));
|
||||||
} else {
|
} else {
|
||||||
/* compute the length of title + a space */
|
/* compute the length of title + a space */
|
||||||
int len = string_length(title) + 1;
|
size_t len = string_length(title) + 1;
|
||||||
indentprint(string, len);
|
indentprint(string, len);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -510,9 +510,9 @@ static alpm_list_t *table_create_format(const alpm_list_t *header,
|
||||||
alpm_list_t *formats = NULL;
|
alpm_list_t *formats = NULL;
|
||||||
const alpm_list_t *i, *row, *cell;
|
const alpm_list_t *i, *row, *cell;
|
||||||
char *str, *formatstr;
|
char *str, *formatstr;
|
||||||
const int padding = 2;
|
const unsigned short padding = 2;
|
||||||
int colwidth, totalwidth = 0;
|
size_t colwidth, totalwidth = 0;
|
||||||
int curcol = 0;
|
size_t curcol = 0;
|
||||||
|
|
||||||
/* header determines column count and initial values of longest_strs */
|
/* header determines column count and initial values of longest_strs */
|
||||||
for(i = header; i; i = alpm_list_next(i)) {
|
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)
|
void list_display(const char *title, const alpm_list_t *list)
|
||||||
{
|
{
|
||||||
const alpm_list_t *i;
|
const alpm_list_t *i;
|
||||||
int len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
if(title) {
|
if(title) {
|
||||||
len = string_length(title) + 1;
|
len = string_length(title) + 1;
|
||||||
|
@ -611,17 +611,17 @@ void list_display(const char *title, const alpm_list_t *list)
|
||||||
if(!list) {
|
if(!list) {
|
||||||
printf("%s\n", _("None"));
|
printf("%s\n", _("None"));
|
||||||
} else {
|
} else {
|
||||||
const int maxcols = getcols();
|
const unsigned short maxcols = getcols();
|
||||||
int cols = len;
|
size_t cols = len;
|
||||||
const char *str = alpm_list_getdata(list);
|
const char *str = alpm_list_getdata(list);
|
||||||
printf("%s", str);
|
printf("%s", str);
|
||||||
cols += string_length(str);
|
cols += string_length(str);
|
||||||
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
|
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
|
||||||
str = alpm_list_getdata(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 */
|
/* wrap only if we have enough usable column space */
|
||||||
if(maxcols > len && cols + s + 2 >= maxcols) {
|
if(maxcols > len && cols + s + 2 >= maxcols) {
|
||||||
int j;
|
size_t j;
|
||||||
cols = len;
|
cols = len;
|
||||||
printf("\n");
|
printf("\n");
|
||||||
for (j = 1; j <= len; j++) {
|
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)
|
void list_display_linebreak(const char *title, const alpm_list_t *list)
|
||||||
{
|
{
|
||||||
int len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
if(title) {
|
if(title) {
|
||||||
len = string_length(title) + 1;
|
len = string_length(title) + 1;
|
||||||
|
@ -657,7 +657,7 @@ void list_display_linebreak(const char *title, const alpm_list_t *list)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
/* Print the rest */
|
/* Print the rest */
|
||||||
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
|
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
|
||||||
int j;
|
size_t j;
|
||||||
for(j = 1; j <= len; j++) {
|
for(j = 1; j <= len; j++) {
|
||||||
printf(" ");
|
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)
|
void signature_display(const char *title, alpm_siglist_t *siglist)
|
||||||
{
|
{
|
||||||
int len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
if(title) {
|
if(title) {
|
||||||
len = string_length(title) + 1;
|
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;
|
alpm_sigresult_t *result = siglist->results + i;
|
||||||
/* Don't re-indent the first result */
|
/* Don't re-indent the first result */
|
||||||
if(i != 0) {
|
if(i != 0) {
|
||||||
int j;
|
size_t j;
|
||||||
for(j = 1; j <= len; j++) {
|
for(j = 1; j <= len; j++) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,11 +50,11 @@ int trans_init(alpm_transflag_t flags, int check_valid);
|
||||||
int trans_release(void);
|
int trans_release(void);
|
||||||
int needs_root(void);
|
int needs_root(void);
|
||||||
int check_syncdbs(size_t need_repos, int check_valid);
|
int check_syncdbs(size_t need_repos, int check_valid);
|
||||||
int getcols(void);
|
unsigned short getcols(void);
|
||||||
int rmrf(const char *path);
|
int rmrf(const char *path);
|
||||||
const char *mbasename(const char *path);
|
const char *mbasename(const char *path);
|
||||||
char *mdirname(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 *strtoupper(char *str);
|
||||||
char *strtrim(char *str);
|
char *strtrim(char *str);
|
||||||
char *strreplace(const char *str, const char *needle, const char *replace);
|
char *strreplace(const char *str, const char *needle, const char *replace);
|
||||||
|
|
Loading…
Add table
Reference in a new issue