FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-01-2011, 06:29 PM
Dan McGee
 
Default Ensure list_display works on non-TTY terminals

If getcols() returns 0, we were getting stuck before in a loop of no
return. Coerce any returned value of 0 to 80 for a sane width for our
list. Also make a few other cleanups while diagnosing this issue.

Noticed-by: Dave Reisner <d@falconindy.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
---
src/pacman/util.c | 17 ++++++++---------
1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 3d26803..e1bc3ed 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -209,14 +209,13 @@ void indentprint(const char *str, int indent)
{
wchar_t *wcstr;
const wchar_t *p;
- int len, cidx, cols;
+ int len, cidx;
+ const int cols = getcols();

if(!str) {
return;
}

- cols = getcols();
-
/* if we're not a tty, print without indenting */
if(cols == 0) {
printf("%s", str);
@@ -425,8 +424,6 @@ static int string_length(const char *s)

void string_display(const char *title, const char *string)
{
- int len = 0;
-
if(title) {
printf("%s ", title);
}
@@ -434,7 +431,7 @@ void string_display(const char *title, const char *string)
printf(_("None"));
} else {
/* compute the length of title + a space */
- len = string_length(title) + 1;
+ int len = string_length(title) + 1;
indentprint(string, len);
}
printf("
");
@@ -443,7 +440,7 @@ void string_display(const char *title, const char *string)
void list_display(const char *title, const alpm_list_t *list)
{
const alpm_list_t *i;
- int cols, len = 0;
+ int len = 0;

if(title) {
len = string_length(title) + 1;
@@ -453,11 +450,13 @@ void list_display(const char *title, const alpm_list_t *list)
if(!list) {
printf("%s
", _("None"));
} else {
+ int cols, maxcols = getcols();
+ /* coerce to 80 if we couldn't determine terminal width */
+ maxcols = maxcols ? maxcols : 80;
for(i = list, cols = len; i; i = alpm_list_next(i)) {
char *str = alpm_list_getdata(i);
int s = string_length(str);
- int maxcols = getcols();
- if(maxcols > 0 && (cols + s + 2) >= maxcols) {
+ if(cols + s + 2 >= maxcols) {
int j;
cols = len;
printf("
");
--
1.7.5.2
 

Thread Tools




All times are GMT. The time now is 07:06 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org