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_TRIGGERPREIN:
00069         tagflags |= RPMSENSE_TRIGGERPREIN;
00070         h = pkg->header;
00071         break;
00072     case RPMTAG_TRIGGERIN:
00073         tagflags |= RPMSENSE_TRIGGERIN;
00074         h = pkg->header;
00075         break;
00076     case RPMTAG_TRIGGERPOSTUN:
00077         tagflags |= RPMSENSE_TRIGGERPOSTUN;
00078         h = pkg->header;
00079         break;
00080     case RPMTAG_TRIGGERUN:
00081         tagflags |= RPMSENSE_TRIGGERUN;
00082         h = pkg->header;
00083         break;
00084     case RPMTAG_BUILDREQUIRES:
00085         tagflags |= RPMSENSE_ANY;
00086         h = spec->buildRestrictions;
00087         break;
00088     default:
00089     case RPMTAG_REQUIREFLAGS:
00090         tagflags |= RPMSENSE_ANY;
00091         h = pkg->header;
00092         break;
00093     }
00094 
00095 /*@-boundsread@*/
00096     for (r = field; *r != '\0'; r = re) {
00097         SKIPWHITE(r);
00098         if (*r == '\0')
00099             break;
00100 
00101         Flags = (tagflags & ~RPMSENSE_SENSEMASK);
00102 
00103         /* Tokens must begin with alphanumeric, _, or / */
00104         if (!(xisalnum(r[0]) || r[0] == '_' || r[0] == '/')) {
00105             rpmError(RPMERR_BADSPEC,
00106                      _("line %d: Dependency tokens must begin with alpha-numeric, '_' or '/': %s\n"),
00107                      spec->lineNum, spec->line);
00108             return RPMERR_BADSPEC;
00109         }
00110 
00111         re = r;
00112         SKIPNONWHITE(re);
00113         N = xmalloc((re-r) + 1);
00114         strncpy(N, r, (re-r));
00115         N[re-r] = '\0';
00116 
00117         /* Parse EVR */
00118         v = re;
00119         SKIPWHITE(v);
00120         ve = v;
00121         SKIPNONWHITE(ve);
00122 
00123         re = v; /* ==> next token (if no EVR found) starts here */
00124 
00125         /* Check for possible logical operator */
00126         if (ve > v) {
00127           struct ReqComp *rc;
00128           for (rc = ReqComparisons; rc->token != NULL; rc++) {
00129             if ((ve-v) != strlen(rc->token) || strncmp(v, rc->token, (ve-v)))
00130                 /*@innercontinue@*/ continue;
00131 
00132             if (r[0] == '/') {
00133                 rpmError(RPMERR_BADSPEC,
00134                          _("line %d: Versioned file name not permitted: %s\n"),
00135                          spec->lineNum, spec->line);
00136                 return RPMERR_BADSPEC;
00137             }
00138 
00139             switch(tagN) {
00140             case RPMTAG_BUILDPREREQ:
00141             case RPMTAG_PREREQ:
00142             case RPMTAG_PROVIDEFLAGS:
00143             case RPMTAG_OBSOLETEFLAGS:
00144                 /* Add prereq on rpmlib that has versioned dependencies. */
00145                 if (!rpmExpandNumeric("%{?_noVersionedDependencies}"))
00146                     (void) rpmlibNeedsFeature(h, "VersionedDependencies", "3.0.3-1");
00147                 /*@switchbreak@*/ break;
00148             default:
00149                 /*@switchbreak@*/ break;
00150             }
00151             Flags |= rc->sense;
00152 
00153             /* now parse EVR */
00154             v = ve;
00155             SKIPWHITE(v);
00156             ve = v;
00157             SKIPNONWHITE(ve);
00158             /*@innerbreak@*/ break;
00159           }
00160         }
00161 
00162         /*@-branchstate@*/
00163         if (Flags & RPMSENSE_SENSEMASK) {
00164             if (*v == '\0' || ve == v) {
00165                 rpmError(RPMERR_BADSPEC, _("line %d: Version required: %s\n"),
00166                         spec->lineNum, spec->line);
00167                 return RPMERR_BADSPEC;
00168             }
00169             EVR = xmalloc((ve-v) + 1);
00170             strncpy(EVR, v, (ve-v));
00171             EVR[ve-v] = '\0';
00172             re = ve;    /* ==> next token after EVR string starts here */
00173         } else
00174             EVR = NULL;
00175         /*@=branchstate@*/
00176 
00177         (void) addReqProv(spec, h, tagN, N, EVR, Flags, index);
00178 
00179         N = _free(N);
00180         EVR = _free(EVR);
00181 
00182     }
00183 /*@=boundsread@*/
00184 
00185     return 0;
00186 }

Generated on Wed Sep 8 11:07:41 2010 for rpm by  doxygen 1.4.7