2 * \file build/parseReqs.c
3 * Parse dependency tag from spec file or from auto-dependency generator.
13 /*@observer@*/ /*@unchecked@*/
14 static struct ReqComp {
15 /*@observer@*/ /*@null@*/ const char * token;
17 } ReqComparisons[] = {
18 { "<=", RPMSENSE_LESS | RPMSENSE_EQUAL},
19 { "=<", RPMSENSE_LESS | RPMSENSE_EQUAL},
20 { "<", RPMSENSE_LESS},
22 { "==", RPMSENSE_EQUAL},
23 { "=", RPMSENSE_EQUAL},
25 { ">=", RPMSENSE_GREATER | RPMSENSE_EQUAL},
26 { "=>", RPMSENSE_GREATER | RPMSENSE_EQUAL},
27 { ">", RPMSENSE_GREATER},
32 #define SKIPWHITE(_x) {while(*(_x) && (xisspace(*_x) || *(_x) == ',')) (_x)++;}
33 #define SKIPNONWHITE(_x){while(*(_x) &&!(xisspace(*_x) || *(_x) == ',')) (_x)++;}
35 int parseRCPOT(Spec spec, Package pkg, const char *field, rpmTag tagN,
36 int index, rpmsenseFlags tagflags)
38 const char *r, *re, *v, *ve;
44 case RPMTAG_PROVIDEFLAGS:
45 tagflags |= RPMSENSE_PROVIDES;
48 case RPMTAG_OBSOLETEFLAGS:
49 tagflags |= RPMSENSE_OBSOLETES;
52 case RPMTAG_CONFLICTFLAGS:
53 tagflags |= RPMSENSE_CONFLICTS;
56 case RPMTAG_BUILDCONFLICTS:
57 tagflags |= RPMSENSE_CONFLICTS;
58 h = spec->buildRestrictions;
61 tagflags |= RPMSENSE_PREREQ;
64 case RPMTAG_BUILDPREREQ:
65 tagflags |= RPMSENSE_PREREQ;
66 h = spec->buildRestrictions;
68 case RPMTAG_TRIGGERIN:
69 tagflags |= RPMSENSE_TRIGGERIN;
72 case RPMTAG_TRIGGERPOSTUN:
73 tagflags |= RPMSENSE_TRIGGERPOSTUN;
76 case RPMTAG_TRIGGERUN:
77 tagflags |= RPMSENSE_TRIGGERUN;
80 case RPMTAG_BUILDREQUIRES:
81 tagflags |= RPMSENSE_ANY;
82 h = spec->buildRestrictions;
85 case RPMTAG_REQUIREFLAGS:
86 tagflags |= RPMSENSE_ANY;
92 for (r = field; *r != '\0'; r = re) {
97 Flags = (tagflags & ~RPMSENSE_SENSEMASK);
99 /* Tokens must begin with alphanumeric, _, or / */
100 if (!(xisalnum(r[0]) || r[0] == '_' || r[0] == '/')) {
101 rpmError(RPMERR_BADSPEC,
102 _("line %d: Dependency tokens must begin with alpha-numeric, '_' or '/': %s\n"),
103 spec->lineNum, spec->line);
104 return RPMERR_BADSPEC;
107 /* Don't permit file names as args for certain tags */
109 case RPMTAG_OBSOLETEFLAGS:
110 case RPMTAG_CONFLICTFLAGS:
111 case RPMTAG_BUILDCONFLICTS:
113 rpmError(RPMERR_BADSPEC,_("line %d: File name not permitted: %s\n"),
114 spec->lineNum, spec->line);
115 return RPMERR_BADSPEC;
117 /*@switchbreak@*/ break;
119 /*@switchbreak@*/ break;
124 N = xmalloc((re-r) + 1);
125 strncpy(N, r, (re-r));
134 re = v; /* ==> next token (if no EVR found) starts here */
136 /* Check for possible logical operator */
139 for (rc = ReqComparisons; rc->token != NULL; rc++) {
140 if ((ve-v) != strlen(rc->token) || strncmp(v, rc->token, (ve-v)))
141 /*@innercontinue@*/ continue;
144 rpmError(RPMERR_BADSPEC,
145 _("line %d: Versioned file name not permitted: %s\n"),
146 spec->lineNum, spec->line);
147 return RPMERR_BADSPEC;
151 case RPMTAG_BUILDPREREQ:
153 case RPMTAG_PROVIDEFLAGS:
154 case RPMTAG_OBSOLETEFLAGS:
155 /* Add prereq on rpmlib that has versioned dependencies. */
156 if (!rpmExpandNumeric("%{?_noVersionedDependencies}"))
157 (void) rpmlibNeedsFeature(h, "VersionedDependencies", "3.0.3-1");
158 /*@switchbreak@*/ break;
160 /*@switchbreak@*/ break;
169 /*@innerbreak@*/ break;
174 if (Flags & RPMSENSE_SENSEMASK) {
175 if (*v == '\0' || ve == v) {
176 rpmError(RPMERR_BADSPEC, _("line %d: Version required: %s\n"),
177 spec->lineNum, spec->line);
178 return RPMERR_BADSPEC;
180 EVR = xmalloc((ve-v) + 1);
181 strncpy(EVR, v, (ve-v));
183 re = ve; /* ==> next token after EVR string starts here */
188 (void) addReqProv(spec, h, tagN, N, EVR, Flags, index);