Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

build/reqprov.c

Go to the documentation of this file.
00001 
00006 #include "system.h"
00007 
00008 #include "rpmbuild.h"
00009 #include "debug.h"
00010 
00011 int addReqProv(/*@unused@*/ Spec spec, Header h,
00012                rpmsenseFlags depFlags, const char *depName, const char *depEVR,
00013                 int index)
00014 {
00015     HGE_t hge = (HGE_t)headerGetEntryMinMemory;
00016     HFD_t hfd = headerFreeData;
00017     const char ** names;
00018     rpmTagType dnt;
00019     rpmTag nametag = 0;
00020     rpmTag versiontag = 0;
00021     rpmTag flagtag = 0;
00022     rpmTag indextag = 0;
00023     int len;
00024     rpmsenseFlags extra = RPMSENSE_ANY;
00025     
00026     if (depFlags & RPMSENSE_PROVIDES) {
00027         nametag = RPMTAG_PROVIDENAME;
00028         versiontag = RPMTAG_PROVIDEVERSION;
00029         flagtag = RPMTAG_PROVIDEFLAGS;
00030         extra = depFlags & RPMSENSE_FIND_PROVIDES;
00031     } else if (depFlags & RPMSENSE_OBSOLETES) {
00032         nametag = RPMTAG_OBSOLETENAME;
00033         versiontag = RPMTAG_OBSOLETEVERSION;
00034         flagtag = RPMTAG_OBSOLETEFLAGS;
00035     } else if (depFlags & RPMSENSE_CONFLICTS) {
00036         nametag = RPMTAG_CONFLICTNAME;
00037         versiontag = RPMTAG_CONFLICTVERSION;
00038         flagtag = RPMTAG_CONFLICTFLAGS;
00039     } else if (depFlags & RPMSENSE_PREREQ) {
00040         nametag = RPMTAG_REQUIRENAME;
00041         versiontag = RPMTAG_REQUIREVERSION;
00042         flagtag = RPMTAG_REQUIREFLAGS;
00043         extra = depFlags & _ALL_REQUIRES_MASK;
00044     } else if (depFlags & RPMSENSE_TRIGGER) {
00045         nametag = RPMTAG_TRIGGERNAME;
00046         versiontag = RPMTAG_TRIGGERVERSION;
00047         flagtag = RPMTAG_TRIGGERFLAGS;
00048         indextag = RPMTAG_TRIGGERINDEX;
00049         extra = depFlags & RPMSENSE_TRIGGER;
00050     } else {
00051         nametag = RPMTAG_REQUIRENAME;
00052         versiontag = RPMTAG_REQUIREVERSION;
00053         flagtag = RPMTAG_REQUIREFLAGS;
00054         extra = depFlags & _ALL_REQUIRES_MASK;
00055     }
00056 
00057     depFlags = (depFlags & (RPMSENSE_SENSEMASK | RPMSENSE_MULTILIB)) | extra;
00058 
00059     if (depEVR == NULL)
00060         depEVR = "";
00061     
00062     /* Check for duplicate dependencies. */
00063     if (hge(h, nametag, &dnt, (void **) &names, &len)) {
00064         const char ** versions = NULL;
00065         rpmTagType dvt = RPM_STRING_ARRAY_TYPE;
00066         int *flags = NULL;
00067         int *indexes = NULL;
00068         int duplicate = 0;
00069 
00070         if (flagtag) {
00071             (void) hge(h, versiontag, &dvt, (void **) &versions, NULL);
00072             (void) hge(h, flagtag, NULL, (void **) &flags, NULL);
00073         }
00074         if (indextag)
00075             (void) hge(h, indextag, NULL, (void **) &indexes, NULL);
00076 
00077         while (len > 0) {
00078             len--;
00079             if (strcmp(names[len], depName))
00080                 continue;
00081             if (flagtag && versions != NULL &&
00082                 (strcmp(versions[len], depEVR) ||
00083         ((flags[len] | RPMSENSE_MULTILIB) != (depFlags | RPMSENSE_MULTILIB))))
00084                 continue;
00085             if (indextag && indexes != NULL && indexes[len] != index)
00086                 continue;
00087 
00088             /* This is a duplicate dependency. */
00089             duplicate = 1;
00090 
00091             if (flagtag && isDependsMULTILIB(depFlags) &&
00092                 !isDependsMULTILIB(flags[len]))
00093                     flags[len] |= RPMSENSE_MULTILIB;
00094 
00095             break;
00096         }
00097         names = hfd(names, dnt);
00098         versions = hfd(versions, dvt);
00099         if (duplicate)
00100             return 0;
00101     }
00102 
00103     /* Add this dependency. */
00104     (void) headerAddOrAppendEntry(h, nametag, RPM_STRING_ARRAY_TYPE, &depName, 1);
00105     if (flagtag) {
00106         (void) headerAddOrAppendEntry(h, versiontag,
00107                                RPM_STRING_ARRAY_TYPE, &depEVR, 1);
00108         (void) headerAddOrAppendEntry(h, flagtag,
00109                                RPM_INT32_TYPE, &depFlags, 1);
00110     }
00111     if (indextag)
00112         (void) headerAddOrAppendEntry(h, indextag, RPM_INT32_TYPE, &index, 1);
00113 
00114     return 0;
00115 }
00116 
00117 int rpmlibNeedsFeature(Header h, const char * feature, const char * featureEVR)
00118 {
00119     char * reqname = alloca(sizeof("rpmlib()") + strlen(feature));
00120 
00121     (void) stpcpy( stpcpy( stpcpy(reqname, "rpmlib("), feature), ")");
00122 
00123     /* XXX 1st arg is unused */
00124    return addReqProv(NULL, h, RPMSENSE_RPMLIB|(RPMSENSE_LESS|RPMSENSE_EQUAL),
00125         reqname, featureEVR, 0);
00126 }

Generated at Wed Mar 27 03:56:48 2002 for rpm by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001