From: Wichert Akkerman Date: Mon, 7 Aug 2000 19:04:06 +0000 (+0000) Subject: Fixup packagelisting formatstring creaton X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8defaffef5b0685228fddb3374f47bc290faded;p=dpkg Fixup packagelisting formatstring creaton --- diff --git a/ChangeLog b/ChangeLog index ae457bbd..70cdbdbd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Aug 7 12:02:16 PDT 2000 Wichert Akkerman + + * main/enquiry.c: cache value of packagelist formatstring instead + of recreating it for every package + Tue Aug 1 10:56:52 EDT 2000 Ben Collins * main/packages.c: fix thinko with versioned deps diff --git a/main/enquiry.c b/main/enquiry.c index 14fc4591..0e614d31 100644 --- a/main/enquiry.c +++ b/main/enquiry.c @@ -60,30 +60,29 @@ static void limiteddescription(struct pkginfo *pkg, int maxl, *pdesc_r=pdesc; *l_r=l; } -static int getttywidth() { +static const char* listformatstring() { int fd; int res; struct winsize ws; char *columns; + int w, nw, vw, dw; + static char format[80] = ""; + + if (format[0]) + return format; if ((columns=getenv("COLUMNS")) && ((res=atoi(columns))>0)) - return res; - if ((fd=open("/dev/tty",O_RDONLY))!=-1) { - if (ioctl(fd, TIOCGWINSZ, &ws)==-1) + ws.ws_col=res; + else { + if ((fd=open("/dev/tty",O_RDONLY))!=-1) { + if (ioctl(fd, TIOCGWINSZ, &ws)==-1) + ws.ws_col=80; + close(fd); + } else ws.ws_col=80; - close(fd); - return ws.ws_col; - } else - return 80; -} + } -static void list1package(struct pkginfo *pkg, int *head) { - int l,w; - int nw,vw,dw; - const char *pdesc; - char format[80]; - - w=getttywidth()-80; /* get spare width */ + w=ws.ws_col-80; /* get spare width */ if (w<0) w=0; /* lets not try to deal with terminals that are too small */ w>>=2; /* halve that so we can add that to the both the name and description */ nw=(14+w); /* name width */ @@ -91,6 +90,17 @@ static void list1package(struct pkginfo *pkg, int *head) { dw=(44+(2*w)); /* description width */ sprintf(format,"%%c%%c%%c %%-%d.%ds %%-%d.%ds %%.*s\n", nw, nw, vw, vw); + return format; +} + +static void list1package(struct pkginfo *pkg, int *head) { + int l,w; + int nw,vw,dw; + const char *pdesc; + const char* format[80]; + + format=listformatstring(); + if (!*head) { fputs(_("\ Desired=Unknown/Install/Remove/Purge/Hold\n\