34
34
#include <dpkg/triglib.h>
37
convert_string(struct parsedb_state *ps, const char *what, int otherwise,
38
const struct pkginfo *pigp,
39
const char *startp, const struct namevalue *ivip,
37
parse_nv_next(struct parsedb_state *ps, const struct pkginfo *pigp,
38
const char *what, const struct namevalue *nv_head,
43
const struct namevalue *nvip = ivip;
41
const char *str_start = *strp, *str_end;
42
const struct namevalue *nv;
44
if (str_start[0] == '\0')
46
45
parse_error(ps, pigp, _("%s is missing"), what);
48
if (strncasecmp(nvip->name, startp, nvip->length))
54
if (otherwise != -1) return otherwise;
55
parse_error(ps, pigp, _("`%.*s' is not allowed for %s"),
56
(int)strnlen(startp, 50), startp, what);
59
ep = startp + nvip->length;
63
parse_error(ps, pigp, _("junk after %s"), what);
64
if (endpp) *endpp= ep;
47
nv = namevalue_find_by_name(nv_head, str_start);
49
parse_error(ps, pigp, _("'%.50s' is not allowed for %s"), str_start, what);
51
str_end = str_start + nv->length;
52
while (isspace(str_end[0]))
60
parse_nv_last(struct parsedb_state *ps, const struct pkginfo *pkg,
61
const char *what, const struct namevalue *nv_head,
66
value = parse_nv_next(ps, pkg, what, nv_head, &str);
68
parse_error(ps, pkg, _("junk after %s"), what);
69
f_name(struct pkginfo *pigp, struct pkginfoperfile *pifp,
74
f_name(struct pkginfo *pigp, struct pkgbin *pifp,
70
75
struct parsedb_state *ps,
71
76
const char *value, const struct fieldinfo *fip)
74
if ((e= illegal_packagename(value,NULL)) != NULL)
80
e = pkg_name_is_illegal(value, NULL);
75
82
parse_error(ps, pigp, _("invalid package name (%.250s)"), e);
76
pigp->name= findpackage(value)->name;
77
/* We use the new name, as findpackage() may have
78
done a tolower for us.
83
/* We use the new name, as pkg_db_find() may have done a tolower for us. */
84
pigp->name = pkg_db_find(value)->name;
82
void f_filecharf(struct pkginfo *pigp, struct pkginfoperfile *pifp,
83
struct parsedb_state *ps,
84
const char *value, const struct fieldinfo *fip) {
88
f_filecharf(struct pkginfo *pigp, struct pkgbin *pifp,
89
struct parsedb_state *ps,
90
const char *value, const struct fieldinfo *fip)
85
92
struct filedetails *fdp, **fdpp;
86
93
char *cpos, *space;
121
128
"(compared to others)"), fip->name);
124
void f_charfield(struct pkginfo *pigp, struct pkginfoperfile *pifp,
125
struct parsedb_state *ps,
126
const char *value, const struct fieldinfo *fip) {
132
f_charfield(struct pkginfo *pigp, struct pkgbin *pifp,
133
struct parsedb_state *ps,
134
const char *value, const struct fieldinfo *fip)
127
136
if (*value) PKGPFIELD(pifp,fip->integer,char*)= nfstrsave(value);
130
void f_boolean(struct pkginfo *pigp, struct pkginfoperfile *pifp,
131
struct parsedb_state *ps,
132
const char *value, const struct fieldinfo *fip) {
140
f_boolean(struct pkginfo *pigp, struct pkgbin *pifp,
141
struct parsedb_state *ps,
142
const char *value, const struct fieldinfo *fip)
138
boolean = convert_string(ps, _("yes/no in boolean field"),
139
-1, pigp, value, booleaninfos, NULL);
149
boolean = parse_nv_last(ps, pigp, _("yes/no in boolean field"),
150
booleaninfos, value);
140
151
PKGPFIELD(pifp, fip->integer, bool) = boolean;
143
void f_section(struct pkginfo *pigp, struct pkginfoperfile *pifp,
144
struct parsedb_state *ps,
145
const char *value, const struct fieldinfo *fip) {
155
f_section(struct pkginfo *pigp, struct pkgbin *pifp,
156
struct parsedb_state *ps,
157
const char *value, const struct fieldinfo *fip)
146
159
if (!*value) return;
147
160
pigp->section= nfstrsave(value);
150
void f_priority(struct pkginfo *pigp, struct pkginfoperfile *pifp,
151
struct parsedb_state *ps,
152
const char *value, const struct fieldinfo *fip) {
164
f_priority(struct pkginfo *pigp, struct pkgbin *pifp,
165
struct parsedb_state *ps,
166
const char *value, const struct fieldinfo *fip)
153
168
if (!*value) return;
154
pigp->priority = convert_string(ps, _("word in `priority' field"),
155
pri_other, pigp, value, priorityinfos, NULL);
169
pigp->priority = parse_nv_last(ps, pigp, _("word in `priority' field"),
170
priorityinfos, value);
156
171
if (pigp->priority == pri_other) pigp->otherpriority= nfstrsave(value);
159
void f_status(struct pkginfo *pigp, struct pkginfoperfile *pifp,
160
struct parsedb_state *ps,
161
const char *value, const struct fieldinfo *fip) {
175
f_status(struct pkginfo *pigp, struct pkgbin *pifp,
176
struct parsedb_state *ps,
177
const char *value, const struct fieldinfo *fip)
164
179
if (ps->flags & pdb_rejectstatus)
165
180
parse_error(ps, pigp,
166
181
_("value for `status' field not allowed in this context"));
167
182
if (ps->flags & pdb_recordavailable)
170
pigp->want = convert_string(ps, _("first (want) word in `status' field"),
171
-1, pigp, value, wantinfos, &ep);
172
pigp->eflag = convert_string(ps, _("second (error) word in `status' field"),
173
-1, pigp, ep, eflaginfos, &ep);
174
pigp->status = convert_string(ps, _("third (status) word in `status' field"),
175
-1, pigp, ep, statusinfos, NULL);
185
pigp->want = parse_nv_next(ps, pigp,
186
_("first (want) word in `status' field"),
188
pigp->eflag = parse_nv_next(ps, pigp,
189
_("second (error) word in `status' field"),
191
pigp->status = parse_nv_last(ps, pigp,
192
_("third (status) word in `status' field"),
178
void f_version(struct pkginfo *pigp, struct pkginfoperfile *pifp,
179
struct parsedb_state *ps,
180
const char *value, const struct fieldinfo *fip) {
197
f_version(struct pkginfo *pigp, struct pkgbin *pifp,
198
struct parsedb_state *ps,
199
const char *value, const struct fieldinfo *fip)
181
201
parse_db_version(ps, pigp, &pifp->version, value,
182
202
_("error in Version string '%.250s'"), value);
185
void f_revision(struct pkginfo *pigp, struct pkginfoperfile *pifp,
186
struct parsedb_state *ps,
187
const char *value, const struct fieldinfo *fip) {
206
f_revision(struct pkginfo *pigp, struct pkgbin *pifp,
207
struct parsedb_state *ps,
208
const char *value, const struct fieldinfo *fip)
188
210
char *newversion;
190
212
parse_warn(ps, pigp,
299
329
struct dependency *dyp, **ldypp;
300
330
struct deppossi *dop, **ldopp;
302
if (!*value) return; /* empty fields are ignored */
332
/* Empty fields are ignored. */
304
336
ldypp= &pifp->depends; while (*ldypp) ldypp= &(*ldypp)->next;
305
for (;;) { /* loop creating new struct dependency's */
338
/* Loop creating new struct dependency's. */
306
340
dyp= nfmalloc(sizeof(struct dependency));
307
dyp->up= NULL; /* Set this to zero for now, as we don't know what our real
308
* struct pkginfo address (in the database) is going to be yet.
341
/* Set this to NULL for now, as we don't know what our real
342
* struct pkginfo address (in the database) is going to be yet. */
310
344
dyp->next= NULL; *ldypp= dyp; ldypp= &dyp->next;
311
345
dyp->list= NULL; ldopp= &dyp->list;
312
346
dyp->type= fip->integer;
313
for (;;) { /* loop creating new struct deppossi's */
348
/* Loop creating new struct deppossi's. */
315
/* skip over package name characters */
351
/* Skip over package name characters. */
316
352
while (*p && !isspace(*p) && *p != '(' && *p != ',' && *p != '|') {
319
355
depnamelength= p - depnamestart ;
320
varbufreset(&depname);
321
varbufaddbuf(&depname, depnamestart, depnamelength);
322
varbufaddc(&depname, '\0');
356
varbuf_reset(&depname);
357
varbuf_add_buf(&depname, depnamestart, depnamelength);
358
varbuf_end_str(&depname);
323
359
if (!depname.buf[0])
324
360
parse_error(ps, pigp,
325
361
_("`%s' field, missing package name, or garbage where "
326
362
"package name expected"), fip->name);
327
emsg = illegal_packagename(depname.buf, NULL);
363
emsg = pkg_name_is_illegal(depname.buf, NULL);
329
365
parse_error(ps, pigp,
330
366
_("`%s' field, invalid package name `%.255s': %s"),
331
367
fip->name, depname.buf, emsg);
332
368
dop= nfmalloc(sizeof(struct deppossi));
334
dop->ed = findpackage(depname.buf);
370
dop->ed = pkg_db_find(depname.buf);
335
371
dop->next= NULL; *ldopp= dop; ldopp= &dop->next;
337
373
/* Don't link this (which is after all only ‘newpig’ from