From 62efcbd3fc18b322d1cb236f0ea4cf7dc9099beb Mon Sep 17 00:00:00 2001 From: ewt Date: Tue, 27 Oct 1998 05:41:02 +0000 Subject: [PATCH] 1) split query option parsing into popt subtables 2) moved query code into rpmlib CVS patchset: 2502 CVS date: 1998/10/27 05:41:02 --- Makefile.am | 4 +- Makefile.in | 9 ++--- lib/Makefile.am | 2 +- lib/Makefile.in | 13 ++++--- query.c => lib/query.c | 93 ++++++++++++++++++++++++++++++++++++++++++--- lib/rpmlib.h | 25 +++++++++++++ po/POTFILES.in | 2 +- query.h | 25 ------------- rpm.c | 100 +++++++++++++------------------------------------ 9 files changed, 153 insertions(+), 120 deletions(-) rename query.c => lib/query.c (79%) delete mode 100644 query.h diff --git a/Makefile.am b/Makefile.am index e225bb3..01cbad9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,10 +23,10 @@ config_SCRIPTS = find-provides find-requires mkinstalldirs noinst_HEADERS = \ acconfig.h build.h checksig.h ftp.h \ - install.h query.h system.h url.h \ + install.h system.h url.h \ verify.h -rpm_SOURCES = build.c checksig.c ftp.c install.c query.c rpm.c url.c \ +rpm_SOURCES = build.c checksig.c ftp.c install.c rpm.c url.c \ verify.c rpm_LDADD = -lrpmbuild -lpopt -lrpm @LIBMISC@ diff --git a/Makefile.in b/Makefile.in index d68c359..2f1c33f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -140,10 +140,10 @@ config_SCRIPTS = find-provides find-requires mkinstalldirs noinst_HEADERS = \ acconfig.h build.h checksig.h ftp.h \ - install.h query.h system.h url.h \ + install.h system.h url.h \ verify.h -rpm_SOURCES = build.c checksig.c ftp.c install.c query.c rpm.c url.c \ +rpm_SOURCES = build.c checksig.c ftp.c install.c rpm.c url.c \ verify.c rpm_LDADD = -lrpmbuild -lpopt -lrpm @LIBMISC@ @@ -169,8 +169,7 @@ rpm2cpio_LDFLAGS = rpmconvert_OBJECTS = convertdb.o oldrpmdb.o rpmconvert_DEPENDENCIES = rpmconvert_LDFLAGS = -rpm_OBJECTS = build.o checksig.o ftp.o install.o query.o rpm.o url.o \ -verify.o +rpm_OBJECTS = build.o checksig.o ftp.o install.o rpm.o url.o verify.o rpm_DEPENDENCIES = rpm_LDFLAGS = SCRIPTS = $(bin_SCRIPTS) $(config_SCRIPTS) @@ -197,7 +196,7 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP = --best DEP_FILES = .deps/build.P .deps/checksig.P .deps/convertdb.P \ -.deps/ftp.P .deps/install.P .deps/oldrpmdb.P .deps/query.P .deps/rpm.P \ +.deps/ftp.P .deps/install.P .deps/oldrpmdb.P .deps/rpm.P \ .deps/rpm2cpio.P .deps/url.P .deps/verify.P SOURCES = $(rpm2cpio_SOURCES) $(rpmconvert_SOURCES) $(rpm_SOURCES) OBJECTS = $(rpm2cpio_OBJECTS) $(rpmconvert_OBJECTS) $(rpm_OBJECTS) diff --git a/lib/Makefile.am b/lib/Makefile.am index d83fd4f..cb0dacd 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -16,7 +16,7 @@ librpm_a_SOURCES = \ cpio.c dbindex.c depends.c falloc.c \ formats.c fs.c header.c install.c \ lookup.c macro.c md5.c md5sum.c \ - messages.c misc.c oldheader.c package.c \ + messages.c misc.c oldheader.c package.c query.c \ rebuilddb.c rpmdb.c rpmerr.c rpmlead.c \ rpmrc.c signature.c stringbuf.c tagtable.c \ tread.c uninstall.c verify.c diff --git a/lib/Makefile.in b/lib/Makefile.in index b26a956..91b5cfb 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -133,7 +133,7 @@ librpm_a_SOURCES = \ cpio.c dbindex.c depends.c falloc.c \ formats.c fs.c header.c install.c \ lookup.c macro.c md5.c md5sum.c \ - messages.c misc.c oldheader.c package.c \ + messages.c misc.c oldheader.c package.c query.c \ rebuilddb.c rpmdb.c rpmerr.c rpmlead.c \ rpmrc.c signature.c stringbuf.c tagtable.c \ tread.c uninstall.c verify.c @@ -151,8 +151,8 @@ LDFLAGS = @LDFLAGS@ librpm_a_LIBADD = librpm_a_OBJECTS = cpio.o dbindex.o depends.o falloc.o formats.o fs.o \ header.o install.o lookup.o macro.o md5.o md5sum.o messages.o misc.o \ -oldheader.o package.o rebuilddb.o rpmdb.o rpmerr.o rpmlead.o rpmrc.o \ -signature.o stringbuf.o tagtable.o tread.o uninstall.o verify.o +oldheader.o package.o query.o rebuilddb.o rpmdb.o rpmerr.o rpmlead.o \ +rpmrc.o signature.o stringbuf.o tagtable.o tread.o uninstall.o verify.o CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ @@ -169,9 +169,10 @@ DEP_FILES = .deps/cpio.P .deps/dbindex.P .deps/depends.P .deps/falloc.P \ .deps/formats.P .deps/fs.P .deps/header.P .deps/install.P \ .deps/lookup.P .deps/macro.P .deps/md5.P .deps/md5sum.P \ .deps/messages.P .deps/misc.P .deps/oldheader.P .deps/package.P \ -.deps/rebuilddb.P .deps/rpmdb.P .deps/rpmerr.P .deps/rpmlead.P \ -.deps/rpmrc.P .deps/signature.P .deps/stringbuf.P .deps/tagtable \ -.deps/tagtable.P .deps/tread.P .deps/uninstall.P .deps/verify.P +.deps/query.P .deps/rebuilddb.P .deps/rpmdb.P .deps/rpmerr.P \ +.deps/rpmlead.P .deps/rpmrc.P .deps/signature.P .deps/stringbuf.P \ +.deps/tagtable .deps/tagtable.P .deps/tread.P .deps/uninstall.P \ +.deps/verify.P SOURCES = $(librpm_a_SOURCES) OBJECTS = $(librpm_a_OBJECTS) diff --git a/query.c b/lib/query.c similarity index 79% rename from query.c rename to lib/query.c index 6f48e8d..739e01d 100644 --- a/query.c +++ b/lib/query.c @@ -5,8 +5,7 @@ #endif #include "build/rpmbuild.h" - -#include "query.h" +#include "popt/popt.h" #include "url.h" static char * permsString(int mode); @@ -18,6 +17,88 @@ static void printFileInfo(char * name, unsigned int size, unsigned short mode, char * owner, char * group, int uid, int gid, char * linkto); +#define POPT_QUERYFORMAT 1000 +#define POPT_WHATREQUIRES 1001 +#define POPT_WHATPROVIDES 1002 +#define POPT_QUERYBYNUMBER 1003 +#define POPT_TRIGGEREDBY 1004 +#define POPT_DUMP 1005 + +static void queryArgCallback(poptContext con, enum poptCallbackReason reason, + const struct poptOption * opt, const char * arg, + struct rpmQueryArguments * data); + +struct poptOption rpmQuerySourcePoptTable[] = { + { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA, + queryArgCallback, 0, NULL, NULL }, + { "file", 'f', 0, 0, 'f', "query package owning file", "FILE" }, + { "group", 'g', 0, 0, 'g', "query packages in group", "GROUP" }, + { "package", 'p', 0, 0, 'p', "query a package file" }, + { "triggeredby", '\0', 0, 0, POPT_TRIGGEREDBY, + "query the pacakges triggered by the package", "PACKAGE" }, + { "whatrequires", '\0', 0, 0, POPT_WHATREQUIRES, + "query the packages which require a capability", "CAPABILITY" }, + { "whatprovides", '\0', 0, 0, POPT_WHATPROVIDES, + "query the packages which provide a capability", "CAPABILITY" }, + { 0, 0, 0, 0, 0 } +}; + +struct poptOption rpmQueryPoptTable[] = { + { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA, + queryArgCallback, 0, NULL, NULL }, + { "configfiles", 'c', 0, 0, 'c', "list all configuration files" }, + { "docfiles", 'd', 0, 0, 'd', "list all documetnation files" }, + { "dump", '\0', 0, 0, POPT_DUMP, "dump basic file information" }, + { "list", 'l', 0, 0, 'l', "list files in package" }, + { "qf", '\0', POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN, 0, + POPT_QUERYFORMAT }, + { "querybynumber", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, + POPT_QUERYBYNUMBER }, + { "queryformat", '\0', POPT_ARG_STRING, 0, POPT_QUERYFORMAT, + "use the following query format", "QUERYFORMAT" }, + { "state", 's', 0, 0, 's', "display the states of the listed files" }, + { "verbose", 'v', 0, 0, 'v', "display a verbose filelisting" }, + { 0, 0, 0, 0, 0 } +}; + +static void queryArgCallback(poptContext con, enum poptCallbackReason reason, + const struct poptOption * opt, const char * arg, + struct rpmQueryArguments * data) { + int len; + + switch (opt->val) { + case 'c': data->flags |= QUERY_FOR_CONFIG | QUERY_FOR_LIST; break; + case 'd': data->flags |= QUERY_FOR_DOCS | QUERY_FOR_LIST; break; + case 'l': data->flags |= QUERY_FOR_LIST; break; + case 's': data->flags |= QUERY_FOR_STATE | QUERY_FOR_LIST; break; + case POPT_DUMP: data->flags |= QUERY_FOR_DUMPFILES | QUERY_FOR_LIST; break; + + case 'a': data->source |= QUERY_ALL; data->sourceCount++; break; + case 'f': data->source |= QUERY_PATH; data->sourceCount++; break; + case 'g': data->source |= QUERY_GROUP; data->sourceCount++; break; + case 'p': data->source |= QUERY_RPM; data->sourceCount++; break; + case POPT_WHATPROVIDES: data->source |= QUERY_WHATPROVIDES; + data->sourceCount++; break; + case POPT_WHATREQUIRES: data->source |= QUERY_WHATREQUIRES; + data->sourceCount++; break; + case POPT_QUERYBYNUMBER: data->source |= QUERY_DBOFFSET; + data->sourceCount++; break; + case POPT_TRIGGEREDBY: data->source |= QUERY_TRIGGEREDBY; + data->sourceCount++; break; + + case POPT_QUERYFORMAT: + if (data->queryFormat) { + len = strlen(data->queryFormat) + strlen(arg) + 1; + data->queryFormat = realloc(data->queryFormat, len); + strcat(data->queryFormat, arg); + } else { + data->queryFormat = malloc(strlen(arg) + 1); + strcpy(data->queryFormat, arg); + } + break; + } +} + static int queryHeader(Header h, char * chptr) { char * str; char * error; @@ -328,7 +409,7 @@ static void showMatches(rpmdb db, dbiIndexSet matches, int queryFlags, } } -int doQuery(char * prefix, enum querysources source, int queryFlags, +int rpmQuery(char * prefix, enum rpmQuerySources source, int queryFlags, char * arg, char * queryFormat) { Header h; int offset; @@ -534,18 +615,18 @@ int doQuery(char * prefix, enum querysources source, int queryFlags, return retcode; } -void queryPrintTags(void) { +void rpmDisplayQueryTags(FILE * f) { const struct headerTagTableEntry * t; int i; const struct headerSprintfExtension * ext = rpmHeaderFormats; for (i = 0, t = rpmTagTable; i < rpmTagTableSize; i++, t++) { - fprintf(stdout, "%s\n", t->name + 7); + fprintf(f, "%s\n", t->name + 7); } while (ext->name) { if (ext->type == HEADER_EXT_TAG) - fprintf(stdout, "%s\n", ext->name + 7), ext++; + fprintf(f, "%s\n", ext->name + 7), ext++; else if (ext->type == HEADER_EXT_MORE) ext = ext->u.more; else diff --git a/lib/rpmlib.h b/lib/rpmlib.h index b7b1ed9..ba9ad20 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -518,6 +518,31 @@ int rpmGetFilesystemList(char *** listptr, int * num); int rpmGetFilesystemUsage(char ** filelist, int_32 * fssizes, int numFiles, uint_32 ** usagesPtr, int flags); +enum rpmQuerySources { QUERY_PACKAGE = 0, QUERY_PATH, QUERY_ALL, QUERY_RPM, + QUERY_GROUP, QUERY_WHATPROVIDES, QUERY_WHATREQUIRES, + QUERY_DBOFFSET, QUERY_TRIGGEREDBY }; + +#define QUERY_FOR_LIST (1 << 1) +#define QUERY_FOR_STATE (1 << 2) +#define QUERY_FOR_DOCS (1 << 3) +#define QUERY_FOR_CONFIG (1 << 4) +#define QUERY_FOR_DUMPFILES (1 << 8) + +extern struct poptOption rpmQuerySourcePoptTable[]; +extern struct poptOption rpmQueryPoptTable[]; + +struct rpmQueryArguments { + int flags; + enum rpmQuerySources source; + int sourceCount; /* > 1 is an error */ + char * queryFormat; + int verbose; +}; + +int rpmQuery(char * prefix, enum rpmQuerySources source, int queryFlags, + char * arg, char * queryFormat); +void rpmDisplayQueryTags(FILE * f); + #ifdef __cplusplus } #endif diff --git a/po/POTFILES.in b/po/POTFILES.in index 5e57b2b..5a415af 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -6,7 +6,6 @@ build.c checksig.c ftp.c install.c -query.c rpm.c url.c verify.c @@ -47,6 +46,7 @@ lib/messages.c lib/misc.c lib/oldheader.c lib/package.c +lib/query.c lib/rebuilddb.c lib/rpmdb.c lib/rpmerr.c diff --git a/query.h b/query.h deleted file mode 100644 index 744cdd9..0000000 --- a/query.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef H_QUERY -#define H_QUERY - -#include - -enum querysources { QUERY_PATH, QUERY_PACKAGE, QUERY_ALL, QUERY_RPM, - QUERY_GROUP, QUERY_WHATPROVIDES, QUERY_WHATREQUIRES, - QUERY_DBOFFSET, QUERY_TRIGGEREDBY }; - -#define QUERY_FOR_LIST (1 << 1) -#define QUERY_FOR_STATE (1 << 2) -#define QUERY_FOR_DOCS (1 << 3) -#define QUERY_FOR_CONFIG (1 << 4) -#define QUERY_FOR_DUMPFILES (1 << 8) - -int doQuery(char * prefix, enum querysources source, int queryFlags, - char * arg, char * queryFormat); -void queryPrintTags(void); - -/* 0 found matches */ -/* 1 no matches */ -/* 2 error */ -int findPackageByLabel(rpmdb db, char * arg, dbiIndexSet * matches); - -#endif diff --git a/rpm.c b/rpm.c index 10795fe..4ea6584 100755 --- a/rpm.c +++ b/rpm.c @@ -10,22 +10,17 @@ #include "query.h" #include "verify.h" -#define GETOPT_QUERYFORMAT 1000 -#define GETOPT_WHATREQUIRES 1001 -#define GETOPT_WHATPROVIDES 1002 #define GETOPT_REBUILD 1003 #define GETOPT_RECOMPILE 1004 #define GETOPT_ADDSIGN 1005 #define GETOPT_RESIGN 1006 #define GETOPT_BUILDROOT 1007 -#define GETOPT_QUERYBYNUMBER 1009 #define GETOPT_DBPATH 1010 #define GETOPT_TIMECHECK 1012 #define GETOPT_REBUILDDB 1013 #define GETOPT_INSTALL 1014 #define GETOPT_RMSOURCE 1015 #define GETOPT_RELOCATE 1016 -#define GETOPT_TRIGGEREDBY 1017 #define GETOPT_SHOWRC 1018 #define GETOPT_BUILDPLATFORM 1019 #define GETOPT_BUILDARCH 1020 @@ -44,7 +39,6 @@ static int allMatches; static char * arch; static int badReloc; static int clean; -static int dump; static int excldocs; static int force; static char * ftpPort; @@ -82,6 +76,7 @@ static int test; static int rpm_version; +static struct rpmQueryArguments queryArgs; /* the structure describing the options we take and the defaults */ static struct poptOption optionsTable[] = { { "addsign", '\0', 0, 0, GETOPT_ADDSIGN }, @@ -96,17 +91,12 @@ static struct poptOption optionsTable[] = { { "buildroot", '\0', POPT_ARG_STRING, 0, GETOPT_BUILDROOT }, { "checksig", 'K', 0, 0, 'K' }, { "clean", '\0', 0, &clean, 0 }, - { "configfiles", 'c', 0, 0, 'c' }, { "dbpath", '\0', POPT_ARG_STRING, 0, GETOPT_DBPATH }, - { "docfiles", 'd', 0, 0, 'd' }, - { "dump", '\0', 0, &dump, 0 }, { "erase", 'e', 0, 0, 'e' }, { "excludedocs", '\0', 0, &excldocs, 0}, - { "file", 'f', 0, 0, 'f' }, { "force", '\0', 0, &force, 0 }, { "ftpport", '\0', POPT_ARG_STRING, &ftpPort, 0}, { "ftpproxy", '\0', POPT_ARG_STRING, &ftpProxy, 0}, - { "group", 'g', 0, 0, 'g' }, { "hash", 'h', 0, &showHash, 0 }, { "help", '\0', 0, &help, 0 }, { NULL, 'i', 0, 0, 'i' }, @@ -117,7 +107,6 @@ static struct poptOption optionsTable[] = { /* info and install both using 'i' is dumb */ { "install", '\0', 0, 0, GETOPT_INSTALL }, { "justdb", '\0', 0, &justdb, 0 }, - { "list", 'l', 0, 0, 'l' }, { "nodeps", '\0', 0, &noDeps, 0 }, { "nofiles", '\0', 0, &noFiles, 0 }, { "nolang", '\0', 0, &noLang, 0 }, @@ -127,14 +116,10 @@ static struct poptOption optionsTable[] = { { "noscripts", '\0', 0, &noScripts, 0 }, { "notriggers", '\0', 0, &noTriggers, 0 }, { "oldpackage", '\0', 0, &oldPackage, 0 }, - { "package", 'p', 0, 0, 'p' }, { "percent", '\0', 0, &showPercents, 0 }, { "pipe", '\0', POPT_ARG_STRING, &pipeOutput, 0 }, { "prefix", '\0', POPT_ARG_STRING, &prefix, 0 }, - { "qf", '\0', POPT_ARG_STRING, 0, GETOPT_QUERYFORMAT }, - { "query", 'q', 0, 0, 'q' }, - { "querybynumber", '\0', 0, 0, GETOPT_QUERYBYNUMBER }, - { "queryformat", '\0', POPT_ARG_STRING, 0, GETOPT_QUERYFORMAT }, + { "query", 'q', 0, NULL, 'q' }, { "querytags", '\0', 0, &queryTags, 0 }, { "quiet", '\0', 0, &quiet, 0 }, { "rcfile", '\0', POPT_ARG_STRING, &rcfile, 0 }, @@ -150,19 +135,19 @@ static struct poptOption optionsTable[] = { { "short-circuit", '\0', 0, &shortCircuit, 0 }, { "showrc", '\0', 0, &showrc, GETOPT_SHOWRC }, { "sign", '\0', 0, &signIt, 0 }, - { "state", 's', 0, 0, 's' }, { "tarball", 't', POPT_ARG_STRING, 0, 't' }, { "test", '\0', 0, &test, 0 }, { "timecheck", '\0', POPT_ARG_STRING, 0, GETOPT_TIMECHECK }, - { "triggeredby", '\0', 0, 0, GETOPT_TRIGGEREDBY }, { "upgrade", 'U', 0, 0, 'U' }, { "uninstall", 'u', 0, 0, 'u' }, { "verbose", 'v', 0, 0, 'v' }, { "verify", 'V', 0, 0, 'V' }, { NULL, 'y', 0, 0, 'V' }, { "version", '\0', 0, &rpm_version, 0 }, - { "whatrequires", '\0', 0, 0, GETOPT_WHATREQUIRES }, - { "whatprovides", '\0', 0, 0, GETOPT_WHATPROVIDES }, + { NULL, '\0', POPT_ARG_INCLUDE_TABLE, + rpmQuerySourcePoptTable, 0, (void *) &queryArgs, NULL }, + { NULL, '\0', POPT_ARG_INCLUDE_TABLE, + rpmQueryPoptTable, 0, (void *) &queryArgs, NULL }, { 0, 0, 0, 0, 0 } }; @@ -501,10 +486,9 @@ static void printHelp(void) { int main(int argc, char ** argv) { enum modes bigMode = MODE_UNKNOWN; - enum querysources querySource = QUERY_PACKAGE; + enum rpmQuerySources querySource = QUERY_PACKAGE; enum verifysources verifySource = VERIFY_PACKAGE; int arg, len; - int queryFor = 0; int installFlags = 0, uninstallFlags = 0, interfaceFlags = 0; int buildAmount = 0; int gotDbpath = 0, building = 0, verifyFlags; @@ -512,7 +496,6 @@ int main(int argc, char ** argv) { int checksigFlags = 0; int timeCheck = 0; int addSign = NEW_SIGNATURE; - char * queryFormat = NULL; char buildChar = ' '; char * specFile; char * tce; @@ -538,7 +521,6 @@ int main(int argc, char ** argv) { arch = NULL; badReloc = 0; clean = 0; - dump = 0; excldocs = 0; force = 0; ftpProxy = NULL; @@ -632,6 +614,8 @@ int main(int argc, char ** argv) { rpmSetVerbosity(RPMMESS_NORMAL); /* XXX silly use by showrc */ poptResetContext(optCon); + if (queryArgs.queryFormat) free(queryArgs.queryFormat); + memset(&queryArgs, 0, sizeof(queryArgs)); while ((arg = poptGetNextOpt(optCon)) > 0) { optArg = poptGetOptArg(optCon); @@ -731,22 +715,6 @@ int main(int argc, char ** argv) { installFlags |= RPMINSTALL_UPGRADE; break; - case 's': - queryFor |= QUERY_FOR_LIST | QUERY_FOR_STATE; - break; - - case 'l': - queryFor |= QUERY_FOR_LIST; - break; - - case 'd': - queryFor |= QUERY_FOR_DOCS | QUERY_FOR_LIST; - break; - - case 'c': - queryFor |= QUERY_FOR_CONFIG | QUERY_FOR_LIST; - break; - case 'p': if (querySource != QUERY_PACKAGE && querySource != QUERY_RPM) argerror(_("one type of query/verify may be performed at a " "time")); @@ -778,17 +746,7 @@ int main(int argc, char ** argv) { verifySource = VERIFY_EVERY; break; - case GETOPT_QUERYFORMAT: - if (queryFormat) { - len = strlen(queryFormat) + strlen(optArg) + 1; - queryFormat = realloc(queryFormat, len); - strcat(queryFormat, optArg); - } else { - queryFormat = malloc(strlen(optArg) + 1); - strcpy(queryFormat, optArg); - } - break; - +#ifdef FOO case GETOPT_WHATREQUIRES: if (querySource != QUERY_PACKAGE && querySource != QUERY_WHATREQUIRES) @@ -812,6 +770,7 @@ int main(int argc, char ** argv) { "time")); querySource = QUERY_TRIGGEREDBY; break; +#endif case GETOPT_REBUILD: if (bigMode != MODE_UNKNOWN && bigMode != MODE_REBUILD) @@ -863,14 +822,6 @@ int main(int argc, char ** argv) { gotDbpath = 1; break; - case GETOPT_QUERYBYNUMBER: - if (querySource != QUERY_PACKAGE && querySource != QUERY_RPM) - argerror(_("one type of query may be performed at a " - "time")); - querySource = QUERY_DBOFFSET; - verifySource = VERIFY_RPM; - break; - case GETOPT_TIMECHECK: tce = NULL; timeCheck = strtoul(optArg, &tce, 10); @@ -941,6 +892,13 @@ int main(int argc, char ** argv) { bigMode = MODE_QUERYTAGS; } + if (queryArgs.sourceCount) { + if (querySource != QUERY_PACKAGE || queryArgs.sourceCount > 1) + argerror(_("one type of query/verify may be performed at a " + "time")); + querySource = queryArgs.source; + } + if (buildRootOverride && bigMode != MODE_BUILD && bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) { argerror("--buildroot may only be used during package builds"); @@ -956,10 +914,10 @@ int main(int argc, char ** argv) { bigMode != MODE_RECOMPILE && bigMode != MODE_TARBUILD) argerror(_("--timecheck may only be used during package builds")); - if (bigMode != MODE_QUERY && queryFor) + if (bigMode != MODE_QUERY && queryArgs.flags) argerror(_("unexpected query specifiers")); - if (bigMode != MODE_QUERY && queryFormat) + if (bigMode != MODE_QUERY && queryArgs.queryFormat) argerror(_("unexpected query specifiers")); if (bigMode != MODE_QUERY && bigMode != MODE_VERIFY && @@ -1082,12 +1040,6 @@ int main(int argc, char ** argv) { if (oldPackage && !(installFlags & RPMINSTALL_UPGRADE)) argerror(_("--oldpackage may only be used during upgrades")); - if (bigMode != MODE_QUERY && dump) - argerror(_("--dump may only be used during queries")); - - if (bigMode == MODE_QUERY && dump && !(queryFor & QUERY_FOR_LIST)) - argerror(_("--dump of queries must be used with -l, -c, or -d")); - if ((ftpProxy || ftpPort) && !(bigMode == MODE_INSTALL || ((bigMode == MODE_QUERY && querySource == QUERY_RPM)) || ((bigMode == MODE_VERIFY && querySource == VERIFY_RPM)))) @@ -1165,7 +1117,7 @@ int main(int argc, char ** argv) { if (argc != 2) argerror(_("unexpected arguments to --querytags ")); - queryPrintTags(); + rpmDisplayQueryTags(stdout); break; case MODE_INITDB: @@ -1328,18 +1280,18 @@ int main(int argc, char ** argv) { break; case MODE_QUERY: - if (dump) queryFor |= QUERY_FOR_DUMPFILES; - if (querySource == QUERY_ALL) { if (poptPeekArg(optCon)) argerror(_("extra arguments given for query of all packages")); - ec = doQuery(rootdir, QUERY_ALL, queryFor, NULL, queryFormat); + ec = rpmQuery(rootdir, QUERY_ALL, queryArgs.flags, NULL, + queryArgs.queryFormat); } else { if (!poptPeekArg(optCon)) argerror(_("no arguments given for query")); while ((pkg = poptGetArg(optCon))) - ec = doQuery(rootdir, querySource, queryFor, pkg, queryFormat); + ec = rpmQuery(rootdir, querySource, queryArgs.flags, pkg, + queryArgs.queryFormat); } break; @@ -1368,7 +1320,7 @@ int main(int argc, char ** argv) { } /* keeps memory leak checkers quiet */ - if (queryFormat) free(queryFormat); + if (queryArgs.queryFormat) free(queryArgs.queryFormat); return ec; } -- 2.7.4