diff options
author | Aaron Griffin <aaron@archlinux.org> | 2007-01-18 16:52:57 +0000 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2007-01-18 16:52:57 +0000 |
commit | 86b136bb592bf576a3da950fee153f6d4f5b9d15 (patch) | |
tree | f6289e427de5c5b2cfd3e3d37b75fc9506eb3bdb /src/pacman/util.c | |
parent | 46e26ac5c8d15fbb2385ad972f2f69891a0bd8d0 (diff) |
Dan McGee <dpmcgee@gmail.com>
* Removed some unnecessary headers and library links
* Made things static if possible
* Cleaned up makefiles a bit
* Fixed some old comments in the code
* Fixed some errors the static code checker splint pointed out
* Backwards arguments in a memset call in _alpm_db_read (could have been worse)
* Other various small fixes
Other:
* Default to 80 columns when getcols cannot determine display width
* Removal of ._install as a valid install file in packages
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r-- | src/pacman/util.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c index 6d395bb1..406583d3 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -30,7 +30,6 @@ #include "config.h" #include <stdio.h> #include <stdlib.h> -#include <stdarg.h> #include <string.h> #include <errno.h> #include <fcntl.h> @@ -52,27 +51,28 @@ extern config_t *config; extern int neednl; /* gets the current screen column width */ -int getcols() +unsigned int getcols() { if(!isatty(1)) { /* We will default to 80 columns if we're not a tty * this seems a fairly standard file width. */ return 80; - } + } else { #ifdef TIOCGSIZE - struct ttysize win; - if(ioctl(1, TIOCGSIZE, &win) == 0) { - return win.ts_cols; - } + struct ttysize win; + if(ioctl(1, TIOCGSIZE, &win) == 0) { + return win.ts_cols; + } #elif defined(TIOCGWINSZ) - struct winsize win; - if(ioctl(1, TIOCGWINSZ, &win) == 0) { - return win.ws_col; - } + struct winsize win; + if(ioctl(1, TIOCGWINSZ, &win) == 0) { + return win.ws_col; + } #endif - else { - return -1; + /* If we can't figure anything out, we'll just assume 80 columns */ + /* TODO any problems caused by this assumption? */ + return 80; } /* Original envvar way - prone to display issues const char *cenv = getenv("COLUMNS"); @@ -155,15 +155,14 @@ int rmrf(char *path) } return(errflag); } - return(0); } /* output a string, but wrap words properly with a specified indentation */ -void indentprint(const char *str, int indent) +void indentprint(const char *str, unsigned int indent) { const char *p = str; - int cidx = indent; + unsigned int cidx = indent; while(*p) { if(*p == ' ') { @@ -178,7 +177,7 @@ void indentprint(const char *str, int indent) len = next - p; if(len > (getcols()-cidx-1)) { /* newline */ - int i; + unsigned int i; fprintf(stdout, "\n"); for(i = 0; i < indent; i++) { fprintf(stdout, " "); @@ -200,7 +199,7 @@ void indentprint(const char *str, int indent) char *buildstring(list_t *strlist) { char *str; - int size = 1; + size_t size = 1; list_t *lp; for(lp = strlist; lp; lp = lp->next) { @@ -208,7 +207,7 @@ char *buildstring(list_t *strlist) } str = (char *)malloc(size); if(str == NULL) { - ERR(NL, _("failed to allocated %d bytes\n"), size); + ERR(NL, _("failed to allocate %d bytes\n"), size); } str[0] = '\0'; for(lp = strlist; lp; lp = lp->next) { |