summaryrefslogtreecommitdiff
path: root/query.c
diff options
context:
space:
mode:
authorewt <devnull@localhost>1997-05-30 21:14:34 +0000
committerewt <devnull@localhost>1997-05-30 21:14:34 +0000
commiteee6452dc0a625802a3c7272b2b042668d530c9e (patch)
tree5e8c0087880d6f50b2d843792d7b94537f5d445f /query.c
parent381df9002167f7867b721c36a0539149a15c5fa2 (diff)
downloadrpm-eee6452dc0a625802a3c7272b2b042668d530c9e.tar.gz
rpm-eee6452dc0a625802a3c7272b2b042668d530c9e.tar.bz2
rpm-eee6452dc0a625802a3c7272b2b042668d530c9e.zip
moved findPackageByLabel() to rpmdbFindByLabel() and added rpmdbFindByHeader()
CVS patchset: 1671 CVS date: 1997/05/30 21:14:34
Diffstat (limited to 'query.c')
-rw-r--r--query.c96
1 files changed, 1 insertions, 95 deletions
diff --git a/query.c b/query.c
index 4d5f517b9..2fbe32ba6 100644
--- a/query.c
+++ b/query.c
@@ -26,8 +26,6 @@ static char * permsString(int mode);
static void printHeader(Header h, int queryFlags, char * queryFormat);
static void showMatches(rpmdb db, dbiIndexSet matches, int queryFlags,
char * queryFormat);
-static int findMatches(rpmdb db, char * name, char * version, char * release,
- dbiIndexSet * matches);
static void printFileInfo(char * name, unsigned int size, unsigned short mode,
unsigned int mtime, unsigned short rdev,
char * owner, char * group, int uid, int gid,
@@ -487,7 +485,7 @@ int doQuery(char * prefix, enum querysources source, int queryFlags,
break;
case QUERY_PACKAGE:
- rc = findPackageByLabel(db, arg, &matches);
+ rc = rpmdbFindByLabel(db, arg, &matches);
if (rc == 1) {
retcode = 1;
fprintf(stderr, _("package %s is not installed\n"), arg);
@@ -508,98 +506,6 @@ int doQuery(char * prefix, enum querysources source, int queryFlags,
return retcode;
}
-/* 0 found matches */
-/* 1 no matches */
-/* 2 error */
-int findPackageByLabel(rpmdb db, char * arg, dbiIndexSet * matches) {
- char * localarg, * chptr;
- char * release;
- int rc;
-
- if (!strlen(arg)) return 1;
-
- /* did they give us just a name? */
- rc = findMatches(db, arg, NULL, NULL, matches);
- if (rc != 1) return rc;
-
- /* maybe a name and a release */
- localarg = alloca(strlen(arg) + 1);
- strcpy(localarg, arg);
-
- chptr = (localarg + strlen(localarg)) - 1;
- while (chptr > localarg && *chptr != '-') chptr--;
- if (chptr == localarg) return 1;
-
- *chptr = '\0';
- rc = findMatches(db, localarg, chptr + 1, NULL, matches);
- if (rc != 1) return rc;
-
- /* how about name-version-release? */
-
- release = chptr + 1;
- while (chptr > localarg && *chptr != '-') chptr--;
- if (chptr == localarg) return 1;
-
- *chptr = '\0';
- return findMatches(db, localarg, chptr + 1, release, matches);
-}
-
-/* 0 found matches */
-/* 1 no matches */
-/* 2 error */
-int findMatches(rpmdb db, char * name, char * version, char * release,
- dbiIndexSet * matches) {
- int gotMatches;
- int rc;
- int i;
- char * pkgRelease, * pkgVersion;
- int count, type;
- int goodRelease, goodVersion;
- Header h;
-
- if ((rc = rpmdbFindPackage(db, name, matches))) {
- if (rc == -1) return 2; else return 1;
- }
-
- if (!version && !release) return 0;
-
- gotMatches = 0;
-
- /* make sure the version and releases match */
- for (i = 0; i < matches->count; i++) {
- if (matches->recs[i].recOffset) {
- h = rpmdbGetRecord(db, matches->recs[i].recOffset);
- if (!h) {
- fprintf(stderr, _("error: could not read database record\n"));
- dbiFreeIndexRecord(*matches);
- return 2;
- }
-
- headerGetEntry(h, RPMTAG_VERSION, &type, (void **) &pkgVersion,
- &count);
- headerGetEntry(h, RPMTAG_RELEASE, &type, (void **) &pkgRelease,
- &count);
-
- goodRelease = goodVersion = 1;
-
- if (release && strcmp(release, pkgRelease)) goodRelease = 0;
- if (version && strcmp(version, pkgVersion)) goodVersion = 0;
-
- if (goodRelease && goodVersion)
- gotMatches = 1;
- else
- matches->recs[i].recOffset = 0;
- }
- }
-
- if (!gotMatches) {
- dbiFreeIndexRecord(*matches);
- return 1;
- }
-
- return 0;
-}
-
void queryPrintTags(void) {
const struct headerTagTableEntry * t;
int i;