build/parseReqs.c

Go to the documentation of this file.
00001 
00006 #include "system.h"
00007 
00008 #include "rpmbuild.h"
00009 #include "debug.h"
00010 
00013 /*@observer@*/ /*@unchecked@*/
00014 static struct ReqComp {
00015 /*@observer@*/ /*@null@*/ const char * token;
00016     rpmsenseFlags sense;
00017 } ReqComparisons[] = {
00018     { "<=", RPMSENSE_LESS | RPMSENSE_EQUAL},
00019     { "=<", RPMSENSE_LESS | RPMSENSE_EQUAL},
00020     { "<", RPMSENSE_LESS},
00021 
00022     { "==", RPMSENSE_EQUAL},
00023     { "=", RPMSENSE_EQUAL},
00024     
00025     { ">=", RPMSENSE_GREATER | RPMSENSE_EQUAL},
00026     { "=>", RPMSENSE_GREATER | RPMSENSE_EQUAL},
00027     { ">", RPMSENSE_GREATER},
00028 
00029     { NULL, 0 },
00030 };
00031 
00032 #define SKIPWHITE(_x)   {while(*(_x) && (xisspace(*_x) || *(_x) == ',')) (_x)++;}
00033 #define SKIPNONWHITE(_x){while(*(_x) &&!(xisspace(*_x) || *(_x) == ',')) (_x)++;}
00034 
00035 int parseRCPOT(Spec spec, Package pkg, const char *field, rpmTag tagN,
00036                int index, rpmsenseFlags tagflags)
00037 {
00038     const char *r, *re, *v, *ve;
00039     char * N, * EVR;
00040     rpmsenseFlags Flags;
00041     Header h;
00042 
00043     switch (tagN) {
00044     case RPMTAG_PROVIDEFLAGS:
00045         tagflags |= RPMSENSE_PROVIDES;
00046         h = pkg->header;
00047         break;
00048     case RPMTAG_OBSOLETEFLAGS:
00049         tagflags |= RPMSENSE_OBSOLETES;
00050         h = pkg->header;
00051         break;
00052     case RPMTAG_CONFLICTFLAGS:
00053         tagflags |= RPMSENSE_CONFLICTS;
00054         h = pkg->header;
00055         break;
00056     case RPMTAG_BUILDCONFLICTS:
00057         tagflags |= RPMSENSE_CONFLICTS;
00058         h = spec->buildRestrictions;
00059         break;
00060     case RPMTAG_PREREQ:
00061         tagflags |= RPMSENSE_PREREQ;
00062         h = pkg->header;
00063         break;
00064     case RPMTAG_BUILDPREREQ:
00065         tagflags |= RPMSENSE_PREREQ;
00066         h = spec->buildRestrictions;
00067         break;
00068     case RPMTAG_TRIGGERIN:
00069         tagflags |= RPMSENSE_TRIGGERIN;
00070         h = pkg->header;
00071         break;
00072     case RPMTAG_TRIGGERPOSTUN:
00073         tagflags |= RPMSENSE_TRIGGERPOSTUN;
00074         h = pkg->header;
00075         break;
00076     case RPMTAG_TRIGGERUN:
00077         tagflags |= RPMSENSE_TRIGGERUN;
00078         h = pkg->header;
00079         break;
00080     case RPMTAG_BUILDREQUIRES:
00081         tagflags |= RPMSENSE_ANY;
00082         h = spec->buildRestrictions;
00083         break;
00084     default:
00085     case RPMTAG_REQUIREFLAGS:
00086         tagflags |= RPMSENSE_ANY;
00087         h = pkg->header;
00088         break;
00089     }
00090 
00091 /*@-boundsread@*/
00092     for (r = field; *r != '\0'; r = re) {
00093         SKIPWHITE(r);
00094         if (*r == '\0')
00095             break;
00096 
00097         Flags = (tagflags & ~RPMSENSE_SENSEMASK);
00098 
00099         /* Tokens must begin with alphanumeric, _, or / */
00100         if (!(xisalnum(r[0]) || r[0] == '_' || r[0] == '/')) {
00101             rpmError(RPMERR_BADSPEC,
00102                      _("line %d: Dependency tokens must begin with alpha-numeric, '_' or '/': %s\n"),
00103                      spec->lineNum, spec->line);
00104             return RPMERR_BADSPEC;
00105         }
00106 
00107         re = r;
00108         SKIPNONWHITE(re);
00109         N = xmalloc((re-r) + 1);
00110         strncpy(N, r, (re-r));
00111         N[re-r] = '\0';
00112 
00113         /* Parse EVR */
00114         v = re;
00115         SKIPWHITE(v);
00116         ve = v;
00117         SKIPNONWHITE(ve);
00118 
00119         re = v; /* ==> next token (if no EVR found) starts here */
00120 
00121         /* Check for possible logical operator */
00122         if (ve > v) {
00123           struct ReqComp *rc;
00124           for (rc = ReqComparisons; rc->token != NULL; rc++) {
00125             if ((ve-v) != strlen(rc->token) || strncmp(v, rc->token, (ve-v)))
00126                 /*@innercontinue@*/ continue;
00127 
00128             if (r[0] == '/') {
00129                 rpmError(RPMERR_BADSPEC,
00130                          _("line %d: Versioned file name not permitted: %s\n"),
00131                          spec->lineNum, spec->line);
00132                 return RPMERR_BADSPEC;
00133             }
00134 
00135             switch(tagN) {
00136             case RPMTAG_BUILDPREREQ:
00137             case RPMTAG_PREREQ:
00138             case RPMTAG_PROVIDEFLAGS:
00139             case RPMTAG_OBSOLETEFLAGS:
00140                 /* Add prereq on rpmlib that has versioned dependencies. */
00141                 if (!rpmExpandNumeric("%{?_noVersionedDependencies}"))
00142                     (void) rpmlibNeedsFeature(h, "VersionedDependencies", "3.0.3-1");
00143                 /*@switchbreak@*/ break;
00144             default:
00145                 /*@switchbreak@*/ break;
00146             }
00147             Flags |= rc->sense;
00148 
00149             /* now parse EVR */
00150             v = ve;
00151             SKIPWHITE(v);
00152             ve = v;
00153             SKIPNONWHITE(ve);
00154             /*@innerbreak@*/ break;
00155           }
00156         }
00157 
00158         /*@-branchstate@*/
00159         if (Flags & RPMSENSE_SENSEMASK) {
00160             if (*v == '\0' || ve == v) {
00161                 rpmError(RPMERR_BADSPEC, _("line %d: Version required: %s\n"),
00162                         spec->lineNum, spec->line);
00163                 return RPMERR_BADSPEC;
00164             }
00165             EVR = xmalloc((ve-v) + 1);
00166             strncpy(EVR, v, (ve-v));
00167             EVR[ve-v] = '\0';
00168             re = ve;    /* ==> next token after EVR string starts here */
00169         } else
00170             EVR = NULL;
00171         /*@=branchstate@*/
00172 
00173         (void) addReqProv(spec, h, tagN, N, EVR, Flags, index);
00174 
00175         N = _free(N);
00176         EVR = _free(EVR);
00177 
00178     }
00179 /*@=boundsread@*/
00180 
00181     return 0;
00182 }

Generated on Fri Oct 12 08:44:53 2007 for rpm by  doxygen 1.5.2