From ebdddeed75f5fadd1f1ea090e504a17d5c1093d5 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sun, 29 Jun 2008 22:31:38 +0300 Subject: [PATCH] libdpkg: Split some parse functions into error and warning variants --- ChangeLog | 15 ++++ lib/fields.c | 221 ++++++++++++++++++++++++++---------------------- lib/parse.c | 102 +++++++++++----------- lib/parsedump.h | 19 +++-- lib/parsehelp.c | 81 ++++++++++++------ 5 files changed, 253 insertions(+), 185 deletions(-) diff --git a/ChangeLog b/ChangeLog index 95b97800..afefeedb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-06-29 Guillem Jover + + * lib/parsedump.h (parseerr, parsemustfield): Remove prototypes. + (parse_error, parse_warn): New prototypes. + (parse_must_have_field, parse_ensure_have_field): Likewise. + * lib/parsehelp.c (parseerr): Split into ... + (parse_error_msg, parse_error, parse_warn): ... these. New functions. + Fix all callers. + (parsemustfield): Split into ... + (parse_must_have_field, parse_ensure_have_field): ... there. New + functions. Fix all callers. + * lib/fields.c (convert_string): Remove now unused warning related + arguments. Fix all callers. + (conffvalue_lastword): Likewise. + 2008-06-29 Guillem Jover * lib/Makefile.am (libdpkg_a_SOURCES): Add 'string.c'. diff --git a/lib/fields.c b/lib/fields.c index 01e114e4..421f2893 100644 --- a/lib/fields.c +++ b/lib/fields.c @@ -30,11 +30,11 @@ #include #include "parsedump.h" -static int convert_string -(const char *filename, int lno, const char *what, int otherwise, - FILE *warnto, int *warncount, const struct pkginfo *pigp, - const char *startp, const struct namevalue *ivip, - const char **endpp) +static int +convert_string(const char *filename, int lno, const char *what, int otherwise, + const struct pkginfo *pigp, + const char *startp, const struct namevalue *ivip, + const char **endpp) { const char *ep; int c, l = 0; @@ -43,7 +43,7 @@ static int convert_string ep= startp; if (!*ep) - parseerr(filename, lno, warnto, warncount, pigp, 0, _("%s is missing"), what); + parse_error(filename, lno, pigp, _("%s is missing"), what); while (nvip->name) { if ((l= nvip->length) == 0) { l= strlen(nvip->name); @@ -56,14 +56,14 @@ static int convert_string } if (!nvip->name) { if (otherwise != -1) return otherwise; - parseerr(filename, lno, warnto, warncount, pigp, 0, _("`%.*s' is not allowed for %s"), - l > 50 ? 50 : l, startp, what); + parse_error(filename, lno, pigp, _("`%.*s' is not allowed for %s"), + l > 50 ? 50 : l, startp, what); } ep = startp + l; c = *ep; while (isspace(c)) c= *++ep; if (c && !endpp) - parseerr(filename, lno, warnto, warncount, pigp, 0, _("junk after %s"), what); + parse_error(filename, lno, pigp, _("junk after %s"), what); if (endpp) *endpp= ep; return nvip->value; } @@ -73,7 +73,7 @@ void f_name(struct pkginfo *pigp, struct pkginfoperfile *pifp, enum parsedbflags const char *value, const struct fieldinfo *fip) { const char *e; if ((e= illegal_packagename(value,NULL)) != NULL) - parseerr(filename, lno, warnto, warncount, pigp, 0, _("invalid package name (%.250s)"), e); + parse_error(filename, lno, pigp, _("invalid package name (%.250s)"), e); pigp->name= findpackage(value)->name; /* We use the new name, as findpackage() may have done a tolower for us. @@ -89,11 +89,11 @@ void f_filecharf(struct pkginfo *pigp, struct pkginfoperfile *pifp, int allowextend; if (!*value) - parseerr(filename, lno, warnto, warncount, pigp, 0, - _("empty file details field `%s'"),fip->name); + parse_error(filename, lno, pigp, _("empty file details field `%s'"), fip->name); if (!(flags & pdb_recordavailable)) - parseerr(filename, lno, warnto, warncount, pigp, 0, - _("file details field `%s' not allowed in status file"),fip->name); + parse_error(filename, lno, pigp, + _("file details field `%s' not allowed in status file"), + fip->name); allowextend= !pigp->files; fdpp= &pigp->files; cpos= nfstrsave(value); @@ -103,8 +103,9 @@ void f_filecharf(struct pkginfo *pigp, struct pkginfoperfile *pifp, fdp= *fdpp; if (!fdp) { if (!allowextend) - parseerr(filename, lno, warnto, warncount, pigp, 0, _("too many values " - "in file details field `%s' (compared to others)"),fip->name); + parse_error(filename, lno, pigp, + _("too many values in file details field `%s' " + "(compared to others)"), fip->name); fdp= nfmalloc(sizeof(struct filedetails)); fdp->next= NULL; fdp->name= fdp->msdosname= fdp->size= fdp->md5sum= NULL; @@ -116,8 +117,9 @@ void f_filecharf(struct pkginfo *pigp, struct pkginfoperfile *pifp, cpos= space; } if (*fdpp) - parseerr(filename, lno, warnto, warncount, pigp, 0, _("too few values " - "in file details field `%s' (compared to others)"),fip->name); + parse_error(filename, lno, pigp, + _("too few values in file details field `%s' " + "(compared to others)"), fip->name); } void f_charfield(struct pkginfo *pigp, struct pkginfoperfile *pifp, @@ -131,11 +133,10 @@ void f_boolean(struct pkginfo *pigp, struct pkginfoperfile *pifp, enum parsedbflags flags, const char *filename, int lno, FILE *warnto, int *warncount, const char *value, const struct fieldinfo *fip) { - pifp->essential= - *value ? convert_string(filename,lno,_("yes/no in boolean field"), -1, - warnto,warncount,pigp, - value,booleaninfos,NULL) - : 0; + pifp->essential = *value ? + convert_string(filename, lno, _("yes/no in boolean field"), + -1, pigp, value, booleaninfos, NULL) : + 0; } void f_section(struct pkginfo *pigp, struct pkginfoperfile *pifp, @@ -152,8 +153,7 @@ void f_priority(struct pkginfo *pigp, struct pkginfoperfile *pifp, const char *value, const struct fieldinfo *fip) { if (!*value) return; pigp->priority = convert_string(filename, lno, _("word in `priority' field"), - pri_other, warnto, warncount, pigp, - value, priorityinfos, NULL); + pri_other, pigp, value, priorityinfos, NULL); if (pigp->priority == pri_other) pigp->otherpriority= nfstrsave(value); } @@ -164,22 +164,22 @@ void f_status(struct pkginfo *pigp, struct pkginfoperfile *pifp, const char *ep; if (flags & pdb_rejectstatus) - parseerr(filename, lno, warnto, warncount, pigp, 0, - _("value for `status' field not allowed in this context")); + parse_error(filename, lno, pigp, + _("value for `status' field not allowed in this context")); if (flags & pdb_recordavailable) return; pigp->want = convert_string(filename, lno, _("first (want) word in `status' field"), -1, - warnto,warncount,pigp, value,wantinfos,&ep); + pigp, value, wantinfos, &ep); pigp->eflag = convert_string(filename, lno, _("second (error) word in `status' field"), -1, - warnto,warncount,pigp, ep,eflaginfos,&ep); + pigp, ep, eflaginfos, &ep); if (pigp->eflag & eflagf_obsoletehold) { pigp->want= want_hold; pigp->eflag &= ~eflagf_obsoletehold; } pigp->status= convert_string(filename,lno,_("third (status) word in `status' field"), -1, - warnto,warncount,pigp, ep,statusinfos,NULL); + pigp, ep, statusinfos, NULL); } void f_version(struct pkginfo *pigp, struct pkginfoperfile *pifp, @@ -189,8 +189,9 @@ void f_version(struct pkginfo *pigp, struct pkginfoperfile *pifp, const char *emsg; emsg= parseversion(&pifp->version,value); - if (emsg) parseerr(filename, lno, warnto, warncount, pigp, 0, _("error " - "in Version string `%.250s': %.250s"),value,emsg); + if (emsg) + parse_error(filename, lno, pigp, + _("error in Version string `%.250s': %.250s"), value, emsg); } void f_revision(struct pkginfo *pigp, struct pkginfoperfile *pifp, @@ -199,8 +200,8 @@ void f_revision(struct pkginfo *pigp, struct pkginfoperfile *pifp, const char *value, const struct fieldinfo *fip) { char *newversion; - parseerr(filename, lno, warnto, warncount, pigp, 1, - _("obsolete `Revision' or `Package-Revision' field used")); + parse_warn(filename, lno, warnto, warncount, pigp, + _("obsolete `Revision' or `Package-Revision' field used")); if (!*value) return; if (pifp->version.revision && *pifp->version.revision) { newversion= nfmalloc(strlen(pifp->version.version)+strlen(pifp->version.revision)+2); @@ -217,21 +218,23 @@ void f_configversion(struct pkginfo *pigp, struct pkginfoperfile *pifp, const char *emsg; if (flags & pdb_rejectstatus) - parseerr(filename, lno, warnto, warncount, pigp, 0, - _("value for `config-version' field not allowed in this context")); + parse_error(filename, lno, pigp, + _("value for `config-version' field not allowed in this context")); if (flags & pdb_recordavailable) return; emsg= parseversion(&pigp->configversion,value); - if (emsg) parseerr(filename, lno, warnto, warncount, pigp, 0, _("error " - "in Config-Version string `%.250s': %.250s"),value,emsg); + if (emsg) + parse_error(filename, lno, pigp, + _("error in Config-Version string `%.250s': %.250s"), + value, emsg); } static void conffvalue_lastword(const char *value, const char *from, const char *endent, const char **word_start_r, int *word_len_r, const char **new_from_r, - const char *filename, int lno, FILE *warnto, - int *warncount, struct pkginfo *pigp) + const char *filename, int lno, + struct pkginfo *pigp) { /* the code in f_conffiles ensures that value[-1]==' ', which is helpful */ const char *lastspc; @@ -246,9 +249,9 @@ static void conffvalue_lastword(const char *value, const char *from, return; malformed: - parseerr(filename, lno, warnto, warncount, pigp, 0, - _("value for `conffiles' has malformatted line `%.*s'"), - (int)(endent-value > 250 ? 250 : endent-value), value); + parse_error(filename, lno, pigp, + _("value for `conffiles' has malformatted line `%.*s'"), + (int)(endent - value > 250 ? 250 : endent - value), value); } void f_conffiles(struct pkginfo *pigp, struct pkginfoperfile *pifp, @@ -265,23 +268,26 @@ void f_conffiles(struct pkginfo *pigp, struct pkginfoperfile *pifp, while (*value) { c= *value++; if (c == '\n') continue; - if (c != ' ') parseerr(filename, lno, warnto, warncount, pigp, 0, _("value for" - " `conffiles' has line starting with non-space `%c'"), c); + if (c != ' ') + parse_error(filename, lno, pigp, + _("value for `conffiles' has line starting with non-space `%c'"), + c); for (endent= value; (c= *endent)!=0 && c != '\n'; endent++); conffvalue_lastword(value, endent, endent, &hashstart, &hashlen, &endfn, - filename,lno,warnto,warncount,pigp); + filename, lno, pigp); obsolete= (hashlen == sizeof(obsolete_str)-1 && !memcmp(hashstart, obsolete_str, hashlen)); if (obsolete) conffvalue_lastword(value, endfn, endent, &hashstart, &hashlen, &endfn, - filename,lno,warnto,warncount,pigp); + filename, lno, pigp); newlink= nfmalloc(sizeof(struct conffile)); value= skip_slash_dotslash(value); namelen= (int)(endfn-value); - if (namelen <= 0) parseerr(filename, lno, warnto, warncount, pigp, 0, - _("root or null directory is listed as a conffile")); + if (namelen <= 0) + parse_error(filename, lno, pigp, + _("root or null directory is listed as a conffile")); newptr = nfmalloc(namelen+2); newptr[0]= '/'; memcpy(newptr+1,value,namelen); @@ -337,12 +343,14 @@ void f_dependency(struct pkginfo *pigp, struct pkginfoperfile *pifp, strncpy(depname, depnamestart, depnamelength); *(depname + depnamelength)= 0; if (!*depname) - parseerr(filename, lno, warnto, warncount, pigp, 0, _("`%s' field, missing" - " package name, or garbage where package name expected"), fip->name); + parse_error(filename, lno, pigp, + _("`%s' field, missing package name, or garbage where " + "package name expected"), fip->name); emsg= illegal_packagename(depname,NULL); - if (emsg) parseerr(filename, lno, warnto, warncount, pigp, 0, _("`%s' field," - " invalid package name `%.255s': %s"), - fip->name,depname,emsg); + if (emsg) + parse_error(filename, lno, pigp, + _("`%s' field, invalid package name `%.255s': %s"), + fip->name, depname, emsg); dop= nfmalloc(sizeof(struct deppossi)); dop->up= dyp; dop->ed= findpackage(depname); @@ -370,37 +378,39 @@ void f_dependency(struct pkginfo *pigp, struct pkginfoperfile *pifp, dop->verrel |= (dvrf_strict | dvrf_builtup); p++; } else if (c2 == '<' || c2 == '>') { - parseerr(filename, lno, warnto, warncount, pigp, 0, - _("`%s' field, reference to `%.255s':\n" - " bad version relationship %c%c"), - fip->name,depname,c1,c2); + parse_error(filename, lno, pigp, + _("`%s' field, reference to `%.255s':\n" + " bad version relationship %c%c"), + fip->name, depname, c1, c2); dop->verrel= dvr_none; } else { - parseerr(filename, lno, warnto, warncount, pigp, 1, - _("`%s' field, reference to `%.255s':\n" - " `%c' is obsolete, use `%c=' or `%c%c' instead"), - fip->name,depname,c1,c1,c1,c1); + parse_warn(filename, lno, warnto, warncount, pigp, + _("`%s' field, reference to `%.255s':\n" + " `%c' is obsolete, use `%c=' or `%c%c' instead"), + fip->name, depname, c1, c1, c1, c1); dop->verrel |= (dvrf_orequal | dvrf_builtup); } } else if (c1 == '=') { dop->verrel= dvr_exact; p++; } else { - parseerr(filename, lno, warnto, warncount, pigp, 1, - _("`%s' field, reference to `%.255s':\n" - " implicit exact match on version number, suggest using `=' instead"), - fip->name,depname); + parse_warn(filename, lno, warnto, warncount, pigp, + _("`%s' field, reference to `%.255s':\n" + " implicit exact match on version number, " + "suggest using `=' instead"), + fip->name, depname); dop->verrel= dvr_exact; } if ((dop->verrel!=dvr_exact) && (fip->integer==dep_provides)) - parseerr(filename, lno, warnto, warncount, pigp, 1, - _("Only exact versions may be used for Provides")); + parse_warn(filename, lno, warnto, warncount, pigp, + _("Only exact versions may be used for Provides")); if (!isspace(*p) && !isalnum(*p)) { - parseerr(filename, lno, warnto, warncount, pigp, 1, - _("`%s' field, reference to `%.255s':\n" - " version value starts with non-alphanumeric, suggest adding a space"), - fip->name,depname); + parse_warn(filename, lno, warnto, warncount, pigp, + _("`%s' field, reference to `%.255s':\n" + " version value starts with non-alphanumeric, " + "suggest adding a space"), + fip->name, depname); } /* skip spaces between the relation and the version */ while (isspace(*p)) p++; @@ -412,15 +422,18 @@ void f_dependency(struct pkginfo *pigp, struct pkginfoperfile *pifp, } versionlength= p - versionstart; while (isspace(*p)) p++; - if (*p == '(') parseerr(filename, lno, warnto, warncount, pigp, 0, - _("`%s' field, reference to `%.255s': " - "version contains `%c'"), fip->name,depname, ')'); - else if (*p != ')') parseerr(filename, lno, warnto, warncount, pigp, 0, - _("`%s' field, reference to `%.255s': " - "version contains `%c'"), fip->name,depname, ' '); - else if (*p == 0) parseerr(filename, lno, warnto, warncount, pigp, 0, - _("`%s' field, reference to `%.255s': " - "version unterminated"),fip->name,depname); + if (*p == '(') + parse_error(filename, lno, pigp, + _("`%s' field, reference to `%.255s': " + "version contains `%c'"), fip->name,depname, ')'); + else if (*p != ')') + parse_error(filename, lno, pigp, + _("`%s' field, reference to `%.255s': " + "version contains `%c'"), fip->name,depname, ' '); + else if (*p == 0) + parse_error(filename, lno, pigp, + _("`%s' field, reference to `%.255s': " + "version unterminated"), fip->name, depname); if (versionlength >= versionused) { versionused= versionlength; version = m_realloc(version, versionlength + 1); @@ -428,9 +441,10 @@ void f_dependency(struct pkginfo *pigp, struct pkginfoperfile *pifp, strncpy(version, versionstart, versionlength); *(version + versionlength)= 0; emsg= parseversion(&dop->version,version); - if (emsg) parseerr(filename, lno, warnto, warncount, pigp, 0, - _("`%s' field, reference to `%.255s': " - "error in version: %.255s"),fip->name,depname,emsg); + if (emsg) + parse_error(filename, lno, pigp, + _("`%s' field, reference to `%.255s': " + "error in version: %.255s"), fip->name, depname, emsg); p++; while (isspace(*p)) p++; } else { dop->verrel= dvr_none; @@ -438,16 +452,15 @@ void f_dependency(struct pkginfo *pigp, struct pkginfoperfile *pifp, } if (!*p || *p == ',') break; if (*p != '|') - parseerr(filename, lno, warnto, warncount, pigp, 0, _("`%s' field, syntax" - " error after reference to package `%.255s'"), - fip->name, dop->ed->name); + parse_error(filename, lno, pigp, + _("`%s' field, syntax error after reference to package `%.255s'"), + fip->name, dop->ed->name); if (fip->integer == dep_conflicts || fip->integer == dep_breaks || fip->integer == dep_provides || fip->integer == dep_replaces) - parseerr(filename, lno, warnto, warncount, pigp, 0, - _("alternatives (`|') not allowed in %s field"), - fip->name); + parse_error(filename, lno, pigp, + _("alternatives (`|') not allowed in %s field"), fip->name); p++; while (isspace(*p)) p++; } if (!*p) break; @@ -506,18 +519,19 @@ f_trigpend(struct pkginfo *pend, struct pkginfoperfile *pifp, const char *word, *emsg; if (flags & pdb_rejectstatus) - parseerr(filename, lno, warnto, warncount, pend, 0, - _("value for `triggers-pending' field not allowed in this context")); + parse_error(filename, lno, pend, + _("value for `triggers-pending' field not allowed in " + "this context")); while ((word = scan_word(&value))) { emsg = illegal_triggername(word); if (emsg) - parseerr(filename, lno, warnto, warncount, pend, 0, - _("illegal pending trigger name `%.255s': %s"), word, emsg); + parse_error(filename, lno, pend, + _("illegal pending trigger name `%.255s': %s"), word, emsg); if (!trig_note_pend_core(pend, nfstrsave(word))) - parseerr(filename, lno, warnto, warncount, pend, 0, - _("duplicate pending trigger `%.255s'"), word); + parse_error(filename, lno, pend, + _("duplicate pending trigger `%.255s'"), word); } } @@ -531,20 +545,21 @@ f_trigaw(struct pkginfo *aw, struct pkginfoperfile *pifp, struct pkginfo *pend; if (flags & pdb_rejectstatus) - parseerr(filename, lno, warnto, warncount, aw, 0, - _("value for `triggers-awaited' field not allowed in this context")); + parse_error(filename, lno, aw, + _("value for `triggers-awaited' field not allowed in " + "this context")); while ((word = scan_word(&value))) { emsg = illegal_packagename(word, NULL); if (emsg) - parseerr(filename, lno, warnto, warncount, aw, 0, - _("illegal package name in awaited trigger `%.255s': %s"), - word, emsg); + parse_error(filename, lno, aw, + _("illegal package name in awaited trigger `%.255s': %s"), + word, emsg); pend = findpackage(word); if (!trig_note_aw(pend, aw)) - parseerr(filename, lno, warnto, warncount, aw, 0, - _("duplicate awaited trigger package `%.255s'"), word); + parse_error(filename, lno, aw, + _("duplicate awaited trigger package `%.255s'"), word); } } diff --git a/lib/parse.c b/lib/parse.c index 80badee1..99968c1e 100644 --- a/lib/parse.c +++ b/lib/parse.c @@ -151,30 +151,32 @@ int parsedb(const char *filename, enum parsedbflags flags, fieldlen= dataptr - fieldstart - 1; while (!EOF_mmap(dataptr, endptr) && c != '\n' && isspace(c)) c= getc_mmap(dataptr); if (EOF_mmap(dataptr, endptr)) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("EOF after field name `%.*s'"),fieldlen,fieldstart); + parse_error(filename, lno, &newpig, + _("EOF after field name `%.*s'"), fieldlen, fieldstart); if (c == '\n') - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("newline in field name `%.*s'"),fieldlen,fieldstart); + parse_error(filename, lno, &newpig, + _("newline in field name `%.*s'"), fieldlen, fieldstart); if (c == MSDOS_EOF_CHAR) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("MSDOS EOF (^Z) in field name `%.*s'"),fieldlen,fieldstart); + parse_error(filename, lno, &newpig, + _("MSDOS EOF (^Z) in field name `%.*s'"), + fieldlen, fieldstart); if (c != ':') - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("field name `%.*s' must be followed by colon"),fieldlen,fieldstart); + parse_error(filename, lno, &newpig, + _("field name `%.*s' must be followed by colon"), + fieldlen, fieldstart); /* Skip space after ':' but before value and eol */ while(!EOF_mmap(dataptr, endptr)) { c= getc_mmap(dataptr); if (c == '\n' || !isspace(c)) break; } if (EOF_mmap(dataptr, endptr)) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("EOF before value of field `%.*s' (missing final newline)"), + parse_error(filename, lno, &newpig, + _("EOF before value of field `%.*s' (missing final newline)"), fieldlen,fieldstart); if (c == MSDOS_EOF_CHAR) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("MSDOS EOF char in value of field `%.*s' (missing newline?)"), - fieldlen,fieldstart); + parse_error(filename, lno, &newpig, + _("MSDOS EOF char in value of field `%.*s' (missing newline?)"), + fieldlen,fieldstart); valuestart= dataptr - 1; for (;;) { if (c == '\n' || c == MSDOS_EOF_CHAR) { @@ -186,9 +188,9 @@ int parsedb(const char *filename, enum parsedbflags flags, ungetc_mmap(c,dataptr, data); c= '\n'; } else if (EOF_mmap(dataptr, endptr)) { - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("EOF during value of field `%.*s' (missing final newline)"), - fieldlen,fieldstart); + parse_error(filename, lno, &newpig, + _("EOF during value of field `%.*s' (missing final newline)"), + fieldlen,fieldstart); } c= getc_mmap(dataptr); } @@ -209,18 +211,20 @@ int parsedb(const char *filename, enum parsedbflags flags, memcpy(value,valuestart,valuelen); *(value+valuelen)= 0; if (*ip++) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("duplicate value for `%s' field"), fip->name); + parse_error(filename, lno, &newpig, + _("duplicate value for `%s' field"), fip->name); fip->rcall(&newpig,newpifp,flags,filename,lno-1,warnto,warncount,value,fip); } else { if (fieldlen<2) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("user-defined field name `%.*s' too short"), fieldlen,fieldstart); + parse_error(filename, lno, &newpig, + _("user-defined field name `%.*s' too short"), + fieldlen, fieldstart); larpp= &newpifp->arbs; while ((arp= *larpp) != NULL) { if (!strncasecmp(arp->name,fieldstart,fieldlen)) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("duplicate value for user-defined field `%.*s'"), fieldlen,fieldstart); + parse_error(filename, lno, &newpig, + _("duplicate value for user-defined field `%.*s'"), + fieldlen, fieldstart); larpp= &arp->next; } arp= nfmalloc(sizeof(struct arbitraryfield)); @@ -232,22 +236,21 @@ int parsedb(const char *filename, enum parsedbflags flags, if (EOF_mmap(dataptr, endptr) || c == '\n' || c == MSDOS_EOF_CHAR) break; } /* loop per field */ if (pdone && donep) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("several package info entries found, only one allowed")); - parsemustfield(filename, lno, warnto, warncount, &newpig, 0, - &newpig.name, "package name"); + parse_error(filename, lno, &newpig, + _("several package info entries found, only one allowed")); + parse_must_have_field(filename, lno, &newpig, newpig.name, "package name"); if ((flags & pdb_recordavailable) || newpig.status != stat_notinstalled) { - parsemustfield(filename, lno, warnto, warncount, &newpig, 1, - (const char **)&newpifp->description, "description"); - parsemustfield(filename, lno, warnto, warncount, &newpig, 1, - (const char **)&newpifp->maintainer, "maintainer"); + parse_ensure_have_field(filename, lno, warnto, warncount, &newpig, + (const char **)&newpifp->description, "description"); + parse_ensure_have_field(filename, lno, warnto, warncount, &newpig, + (const char **)&newpifp->maintainer, "maintainer"); if (newpig.status != stat_halfinstalled) - parsemustfield(filename, lno, warnto, warncount, &newpig, 0, - &newpifp->version.version, "version"); + parse_must_have_field(filename, lno, &newpig, + newpifp->version.version, "version"); } if (flags & pdb_recordavailable) - parsemustfield(filename, lno, warnto, warncount, &newpig, 1, - (const char **)&newpifp->architecture, "architecture"); + parse_ensure_have_field(filename, lno, warnto, warncount, &newpig, + (const char **)&newpifp->architecture, "architecture"); /* Check the Config-Version information: * If there is a Config-Version it is definitely to be used, but @@ -258,8 +261,8 @@ int parsedb(const char *filename, enum parsedbflags flags, if (!(flags & pdb_recordavailable)) { if (newpig.configversion.version) { if (newpig.status == stat_installed || newpig.status == stat_notinstalled) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("Configured-Version for package with inappropriate Status")); + parse_error(filename, lno, &newpig, + _("Configured-Version for package with inappropriate Status")); } else { if (newpig.status == stat_installed) newpig.configversion= newpifp->version; } @@ -268,22 +271,24 @@ int parsedb(const char *filename, enum parsedbflags flags, if (newpig.trigaw.head && (newpig.status <= stat_configfiles || newpig.status >= stat_triggerspending)) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("package has status %s but triggers are awaited"), - statusinfos[newpig.status].name); + parse_error(filename, lno, &newpig, + _("package has status %s but triggers are awaited"), + statusinfos[newpig.status].name); else if (newpig.status == stat_triggersawaited && !newpig.trigaw.head) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("package has status triggers-awaited but no triggers awaited")); + parse_error(filename, lno, &newpig, + _("package has status triggers-awaited but no triggers " + "awaited")); if (!(newpig.status == stat_triggerspending || newpig.status == stat_triggersawaited) && newpig.trigpend_head) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("package has status %s but triggers are pending"), - statusinfos[newpig.status].name); + parse_error(filename, lno, &newpig, + _("package has status %s but triggers are pending"), + statusinfos[newpig.status].name); else if (newpig.status == stat_triggerspending && !newpig.trigpend_head) - parseerr(filename, lno, warnto, warncount, &newpig, 0, - _("package has status triggers-pending but no triggers pending")); + parse_error(filename, lno, &newpig, + _("package has status triggers-pending but no triggers " + "pending")); /* There was a bug that could make a not-installed package have * conffiles, so we check for them here and remove them (rather than @@ -292,8 +297,9 @@ int parsedb(const char *filename, enum parsedbflags flags, if (!(flags & pdb_recordavailable) && newpig.status == stat_notinstalled && newpifp->conffiles) { - parseerr(filename, lno, warnto, warncount, &newpig, 1, - _("Package which in state not-installed has conffiles, forgetting them")); + parse_warn(filename, lno, warnto, warncount, &newpig, + _("Package which in state not-installed has conffiles, " + "forgetting them")); newpifp->conffiles= NULL; } diff --git a/lib/parsedump.h b/lib/parsedump.h index 8837bbd9..c4a57078 100644 --- a/lib/parsedump.h +++ b/lib/parsedump.h @@ -59,13 +59,18 @@ struct fieldinfo { size_t integer; }; -void parseerr(const char *filename, int lno, FILE *warnto, int *warncount, - const struct pkginfo *pigp, int warnonly, - const char *fmt, ...) PRINTFFORMAT(7,8); -void parsemustfield(const char *filename, int lno, - FILE *warnto, int *warncount, - const struct pkginfo *pigp, int warnonly, - const char **value, const char *what); +void parse_error(const char *filename, int lno, const struct pkginfo *pigp, + const char *fmt, ...) PRINTFFORMAT(4,5); +void parse_warn(const char *filename, int lno, FILE *warnto, int *warncount, + const struct pkginfo *pigp, + const char *fmt, ...) PRINTFFORMAT(6,7); +void parse_must_have_field(const char *filename, int lno, + const struct pkginfo *pigp, + const char *value, const char *what); +void parse_ensure_have_field(const char *filename, int lno, + FILE *warnto, int *warncount, + const struct pkginfo *pigp, + const char **value, const char *what); #define MSDOS_EOF_CHAR '\032' /* ^Z */ diff --git a/lib/parsehelp.c b/lib/parsehelp.c index a311f73b..87bfd16c 100644 --- a/lib/parsehelp.c +++ b/lib/parsehelp.c @@ -30,29 +30,45 @@ #include "parsedump.h" -void parseerr -(const char *filename, int lno, FILE *warnto, int *warncount, - const struct pkginfo *pigp, int warnonly, - const char *fmt, ...) +static void +parse_error_msg(const char *filename, int lno, const struct pkginfo *pigp, + const char *type, char *buf) { - va_list al; - char buf1[768], buf2[1000], *p, *q; - - if (warnonly) - sprintf(buf1, _("warning, in file `%.255s' near line %d"), - filename, lno); + if (pigp && pigp->name) + sprintf(buf, _("%s, in file '%.255s' near line %d package '%.255s':\n "), + type, filename, lno, pigp->name); else - sprintf(buf1, _("parse error, in file `%.255s' near line %d"), - filename, lno); + sprintf(buf, _("%s, in file '%.255s' near line %d:\n "), + type, filename, lno); +} - if (pigp && pigp->name) { - sprintf(buf2, _(" package `%.255s'"), pigp->name); - strcat(buf1,buf2); - } +void +parse_error(const char *filename, int lno, + const struct pkginfo *pigp, const char *fmt, ...) +{ + va_list al; + char buf1[768], buf2[1000], *q; + + parse_error_msg(filename, lno, pigp, _("parse error"), buf1); q = str_escape_fmt(buf2, buf1); - strcpy(q,":\n "); strcat(q,fmt); + strcat(q,fmt); + va_start(al,fmt); - if (!warnonly) ohshitv(buf2,al); + ohshitv(buf2, al); +} + +void +parse_warn(const char *filename, int lno, FILE *warnto, int *warncount, + const struct pkginfo *pigp, const char *fmt, ...) +{ + va_list al; + char buf1[768], buf2[1000], *q; + + parse_error_msg(filename, lno, pigp, _("warning"), buf1); + q = str_escape_fmt(buf2, buf1); + strcat(q, fmt); + + va_start(al, fmt); if (warncount) (*warncount)++; if (warnto) { strcat(q,"\n"); @@ -230,19 +246,30 @@ const char *parseversion(struct versionrevision *rversion, const char *string) { return NULL; } -void parsemustfield -(const char *filename, int lno, - FILE *warnto, int *warncount, - const struct pkginfo *pigp, int warnonly, - const char **value, const char *what) +void +parse_must_have_field(const char *filename, int lno, + const struct pkginfo *pigp, + const char *value, const char *what) +{ + if (!value) + parse_error(filename, lno, pigp, _("missing %s"), what); + else if (!*value) + parse_error(filename, lno, pigp, _("empty value for %s"), what); +} + +void +parse_ensure_have_field(const char *filename, int lno, + FILE *warnto, int *warncount, + const struct pkginfo *pigp, + const char **value, const char *what) { static const char *empty = ""; + if (!*value) { - parseerr(filename, lno, warnto, warncount, pigp, warnonly, _("missing %s"), what); - *value= empty; + parse_warn(filename, lno, warnto, warncount, pigp, _("missing %s"), what); + *value = empty; } else if (!**value) { - parseerr(filename, lno, warnto, warncount, pigp, warnonly, - _("empty value for %s"),what); + parse_warn(filename, lno, warnto, warncount, pigp, _("empty value for %s"), what); } } -- 2.39.5