Reduce number of calls to getcols()

Every call to getcols() results in two ioctl() calls, which we really didn't
need as changing the number of columns in mid-print would be pretty crazy.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-09-20 10:09:17 -05:00
parent f9be2334f7
commit ce3d70aa99
2 changed files with 9 additions and 8 deletions

View file

@ -59,7 +59,7 @@ int trans_init(pmtranstype_t type, pmtransflag_t flags)
return(0); return(0);
} }
int trans_release() int trans_release(void)
{ {
if(alpm_trans_release() == -1) { if(alpm_trans_release() == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"),
@ -69,7 +69,7 @@ int trans_release()
return(0); return(0);
} }
int needs_transaction() int needs_transaction(void)
{ {
if(config->op != PM_OP_MAIN && config->op != PM_OP_QUERY && config->op != PM_OP_DEPTEST) { if(config->op != PM_OP_MAIN && config->op != PM_OP_QUERY && config->op != PM_OP_DEPTEST) {
if((config->op == PM_OP_SYNC && !config->op_s_sync && if((config->op == PM_OP_SYNC && !config->op_s_sync &&
@ -85,7 +85,7 @@ int needs_transaction()
} }
/* gets the current screen column width */ /* gets the current screen column width */
int getcols() int getcols(void)
{ {
if(!isatty(1)) { if(!isatty(1)) {
/* We will default to 80 columns if we're not a tty /* We will default to 80 columns if we're not a tty
@ -252,7 +252,7 @@ void indentprint(const char *str, int indent)
{ {
wchar_t *wcstr; wchar_t *wcstr;
const wchar_t *p; const wchar_t *p;
int len, cidx; int len, cidx, cols;
if(!str) { if(!str) {
return; return;
@ -267,6 +267,7 @@ void indentprint(const char *str, int indent)
if(!p) { if(!p) {
return; return;
} }
cols = getcols();
while(*p) { while(*p) {
if(*p == L' ') { if(*p == L' ') {
@ -283,7 +284,7 @@ void indentprint(const char *str, int indent)
while(q < next) { while(q < next) {
len += wcwidth(*q++); len += wcwidth(*q++);
} }
if(len > (getcols() - cidx - 1)) { if(len > (cols - cidx - 1)) {
/* wrap to a newline and reindent */ /* wrap to a newline and reindent */
fprintf(stdout, "\n%-*s", indent, ""); fprintf(stdout, "\n%-*s", indent, "");
cidx = indent; cidx = indent;

View file

@ -37,9 +37,9 @@
#define UPDATE_SPEED_SEC 0.2f #define UPDATE_SPEED_SEC 0.2f
int trans_init(pmtranstype_t type, pmtransflag_t flags); int trans_init(pmtranstype_t type, pmtransflag_t flags);
int trans_release(); int trans_release(void);
int needs_transaction(); int needs_transaction(void);
int getcols(); int getcols(void);
int makepath(const char *path); int makepath(const char *path);
int rmrf(const char *path); int rmrf(const char *path);
char *mbasename(const char *path); char *mbasename(const char *path);