From: Wichert Akkerman Date: Sun, 1 Oct 2000 18:35:41 +0000 (+0000) Subject: main/enquiry.c: fix the listpackage output logic X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7df11c0647a9a865cde7766beed1900f6e2ecd7d;p=dpkg main/enquiry.c: fix the listpackage output logic main/filesdb.c: fix error cleanup in ensure_statoverride lib/myopt.c: add myoptfile() so we can read configuration files --- diff --git a/ChangeLog b/ChangeLog index 64269cc2..4344a13f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Oct 1 20:09:42 CEST 2000 Wichert Akkerman + + * main/enquiry.c: fix the listpackage output logic + * main/filesdb.c: fix error cleanup in ensure_statoverride + * lib/myopt.c: add myoptfile() so we can read configuration files + Mon Sep 25 16:19:05 CEST 2000 Wichert Akkerman * scripts/dpkg-divert.pl: don't print version twice on --help diff --git a/lib/myopt.c b/lib/myopt.c index 3a2d4a9c..a28e7538 100644 --- a/lib/myopt.c +++ b/lib/myopt.c @@ -3,6 +3,7 @@ * myopt.c - my very own option parsing * * Copyright (C) 1994,1995 Ian Jackson + * Copyright (C) 2000 Wichert Akkerman * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,6 +26,45 @@ #include #include +void myoptfile(const char* fn, const struct cmdinfo* cmdinfos) { + FILE* file; + char linebuf[MAXDIVERTFILENAME]; + + file= fopen(fn, "r"); + if (!file) ohshite(_("failed to open configuration file `%.255s' for reading"), fn); + + while (fgets(linebuf, sizeof(linebuf), file)) { + char* opt; + const struct cmdinfo *cip; + + if ((linebuf[0]=='#') || (linebuf[0]=='\n')) continue; + for (opt=linebuf;isalnum(*opt)||*opt=='-';opt++) ; + if (*opt==0) + opt=NULL; + else { + *opt++=0; + if (*opt=='=') opt++; + while (isspace(*opt)) opt++; + } + + for (cip=cmdinfos; cip->olong || cip->oshort; cip++) + if (!strcmp(cip->olong,linebuf)) { + if (cip->takesvalue) { + if (!opt) ohshite(_("configuration error: %s needs a value"), linebuf); + if (cip->call) cip->call(cip,opt); + else *cip->sassignto= opt; + } else { + if (opt) ohshite(_("configuration error: %s does not take a value"), linebuf); + if (cip->call) cip->call(cip,0); + else *cip->iassignto= cip->arg; + } + } + if (!cip->olong) ohshite(_("configuration error: unknown option %s"), linebuf); + } + if (ferror(file)) ohshite(_("read error in configuration file `%.255s'"), fn); + if (fclose(file)) ohshite(_("error closing configuration file `%.255s'"), fn); +} + void myopt(const char *const **argvp, const struct cmdinfo *cmdinfos) { const struct cmdinfo *cip; const char *p, *value; diff --git a/main/enquiry.c b/main/enquiry.c index fd2c47a7..494cad32 100644 --- a/main/enquiry.c +++ b/main/enquiry.c @@ -60,48 +60,41 @@ static void limiteddescription(struct pkginfo *pkg, int maxl, *pdesc_r=pdesc; *l_r=l; } -static const char* listformatstring() { +static int getwidth() { int fd; int res; struct winsize ws; - char *columns; - int w, nw, vw, dw; - static char format[80] = ""; - - if (format[0]) - return format; + const char* columns; if ((columns=getenv("COLUMNS")) && ((res=atoi(columns))>0)) ws.ws_col=res; - else if (!isatty(fd)) + else if (!isatty(1)) ws.ws_col=80; 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; + } } - - 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 */ - vw=(14+w); /* version width */ - dw=(44+(2*w)); /* description width */ - sprintf(format,"%%c%%c%%c %%-%d.%ds %%-%d.%ds %%.*s\n", nw, nw, vw, vw); - - return format; + return ws.ws_col; } static void list1package(struct pkginfo *pkg, int *head) { int l,w; - int nw,vw,dw; + static int nw,vw,dw; const char *pdesc; - const char* format; + static char format[80] = ""; - format=listformatstring(); + if (format[0]==0) { + w=getwidth()-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 */ + vw=(14+w); /* version width */ + dw=(44+(2*w)); /* description width */ + sprintf(format,"%%c%%c%%c %%-%d.%ds %%-%d.%ds %%.*s\n", nw, nw, vw, vw); + } if (!*head) { fputs(_("\ diff --git a/main/filesdb.c b/main/filesdb.c index 1545c317..80e8174d 100644 --- a/main/filesdb.c +++ b/main/filesdb.c @@ -354,8 +354,6 @@ void ensure_statoverrides(void) { if (statoverridefile) fclose(statoverridefile); statoverridefile= file; - push_cleanup(cu_closefile,ehflag_bombout, 0,0,1,(void*)file); - loaded_list = nfmalloc(stab2.st_size); loaded_list_end = loaded_list + stab2.st_size; readden=0; @@ -446,8 +444,6 @@ void ensure_statoverrides(void) { thisline=nextline; } - pop_cleanup(ehflag_normaltidy); /* file= fopen() */ - onerr_abort--; } diff --git a/po/dpkg.pot b/po/dpkg.pot index 482d8c22..b6520610 100644 --- a/po/dpkg.pot +++ b/po/dpkg.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2000-09-21 15:38+0200\n" +"POT-Creation-Date: 2000-10-01 20:18+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -479,32 +479,62 @@ msgstr "" msgid "failed in copy on read (control)" msgstr "" -#: lib/myopt.c:48 +#: lib/myopt.c:34 +#, c-format +msgid "failed to open configuration file `%.255s' for reading" +msgstr "" + +#: lib/myopt.c:53 +#, c-format +msgid "configuration error: %s needs a value" +msgstr "" + +#: lib/myopt.c:57 +#, c-format +msgid "configuration error: %s does not take a value" +msgstr "" + +#: lib/myopt.c:62 +#, c-format +msgid "configuration error: unknown option %s" +msgstr "" + +#: lib/myopt.c:64 +#, c-format +msgid "read error in configuration file `%.255s'" +msgstr "" + +#: lib/myopt.c:65 +#, c-format +msgid "error closing configuration file `%.255s'" +msgstr "" + +#: lib/myopt.c:88 #, c-format msgid "unknown option --%s" msgstr "" -#: lib/myopt.c:52 +#: lib/myopt.c:92 #, c-format msgid "--%s option takes a value" msgstr "" -#: lib/myopt.c:57 +#: lib/myopt.c:97 #, c-format msgid "--%s option does not take a value" msgstr "" -#: lib/myopt.c:64 +#: lib/myopt.c:104 #, c-format msgid "unknown option -%c" msgstr "" -#: lib/myopt.c:69 +#: lib/myopt.c:109 #, c-format msgid "-%c option takes a value" msgstr "" -#: lib/myopt.c:77 +#: lib/myopt.c:117 #, c-format msgid "-%c option does not take a value" msgstr "" @@ -1773,64 +1803,64 @@ msgstr "" msgid "failed to fstat previous statoverride file" msgstr "" -#: main/filesdb.c:385 +#: main/filesdb.c:383 msgid "statoverride file contains empty line" msgstr "" -#: main/filesdb.c:472 +#: main/filesdb.c:468 msgid "failed to open diversions file" msgstr "" -#: main/filesdb.c:476 +#: main/filesdb.c:472 msgid "failed to fstat previous diversions file" msgstr "" -#: main/filesdb.c:478 +#: main/filesdb.c:474 msgid "failed to fstat diversions file" msgstr "" -#: main/filesdb.c:500 +#: main/filesdb.c:496 msgid "fgets gave an empty string from diversions [i]" msgstr "" -#: main/filesdb.c:501 +#: main/filesdb.c:497 msgid "diversions file has too-long line or EOF [i]" msgstr "" -#: main/filesdb.c:507 +#: main/filesdb.c:503 msgid "read error in diversions [ii]" msgstr "" -#: main/filesdb.c:508 +#: main/filesdb.c:504 msgid "unexpected EOF in diversions [ii]" msgstr "" -#: main/filesdb.c:511 +#: main/filesdb.c:507 msgid "fgets gave an empty string from diversions [ii]" msgstr "" -#: main/filesdb.c:512 main/filesdb.c:523 +#: main/filesdb.c:508 main/filesdb.c:519 msgid "diversions file has too-long line or EOF [ii]" msgstr "" -#: main/filesdb.c:518 +#: main/filesdb.c:514 msgid "read error in diversions [iii]" msgstr "" -#: main/filesdb.c:519 +#: main/filesdb.c:515 msgid "unexpected EOF in diversions [iii]" msgstr "" -#: main/filesdb.c:522 +#: main/filesdb.c:518 msgid "fgets gave an empty string from diversions [iii]" msgstr "" -#: main/filesdb.c:530 +#: main/filesdb.c:526 #, c-format msgid "conflicting diversions involving `%.250s' or `%.250s'" msgstr "" -#: main/filesdb.c:539 +#: main/filesdb.c:535 msgid "read error in diversions [i]" msgstr ""