From 03a8511e3ba8b2c6cf3dc67fadaeca4aa9fb5221 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 20 Aug 2010 13:16:48 +0300 Subject: Lump much of the common cli-init + finish tasks into cliutils helpers --- rpmqv.c | 76 ++++------------------------------------------------------------- 1 file changed, 4 insertions(+), 72 deletions(-) (limited to 'rpmqv.c') diff --git a/rpmqv.c b/rpmqv.c index dd6b86380..4897eece0 100644 --- a/rpmqv.c +++ b/rpmqv.c @@ -4,15 +4,10 @@ const char *__progname; #define _AUTOHELP #include -#if HAVE_MCHECK_H -#include -#endif - #include #include /* RPMSIGTAG, rpmReadPackageFile .. */ #include #include -#include #include #include #include @@ -123,9 +118,6 @@ int main(int argc, char *argv[]) char * passPhrase = ""; #endif - int arg; - - const char *optArg, *poptCtx; pid_t pipeChild = 0; poptContext optCon; int ec = 0; @@ -134,10 +126,7 @@ int main(int argc, char *argv[]) #ifdef IAM_RPMEIU int i; #endif - -#if HAVE_MCHECK_H && HAVE_MTRACE - mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */ -#endif + setprogname(argv[0]); /* Retrofit glibc __progname */ /* XXX glibc churn sanity */ @@ -146,6 +135,8 @@ int main(int argc, char *argv[]) else __progname = argv[0]; } + optCon = initCli("rpm", optionsTable, argc, argv); + /* Set the major mode based on argv[0] */ #ifdef IAM_RPMQV if (rstreq(__progname, "rpmquery")) bigMode = MODE_QUERY; @@ -170,50 +161,6 @@ int main(int argc, char *argv[]) } #endif -#if defined(ENABLE_NLS) - /* set up the correct locale */ - (void) setlocale(LC_ALL, "" ); - - bindtextdomain(PACKAGE, LOCALEDIR); - textdomain(PACKAGE); -#endif - - rpmSetVerbosity(RPMLOG_NOTICE); /* XXX silly use by showrc */ - - /* Only build has it's own set of aliases, everything else uses rpm */ - poptCtx = "rpm"; - - /* Make a first pass through the arguments, looking for --rcfile */ - /* We need to handle that before dealing with the rest of the arguments. */ - /* XXX popt argv definition should be fixed instead of casting... */ - optCon = poptGetContext(poptCtx, argc, (const char **)argv, optionsTable, 0); - { - char *poptfile = rpmGenPath(rpmConfigDir(), LIBRPMALIAS_FILENAME, NULL); - (void) poptReadConfigFile(optCon, poptfile); - free(poptfile); - } - (void) poptReadDefaultConfig(optCon, 1); - poptSetExecPath(optCon, rpmConfigDir(), 1); - - while ((arg = poptGetNextOpt(optCon)) > 0) { - optArg = poptGetOptArg(optCon); - - switch (arg) { - default: - fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg); - exit(EXIT_FAILURE); - } - } - - if (arg < -1) { - fprintf(stderr, "%s: %s\n", - poptBadOption(optCon, POPT_BADOPTION_NOALIAS), - poptStrerror(arg)); - exit(EXIT_FAILURE); - } - - rpmcliConfigured(); - #ifdef IAM_RPMDB if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) { if (da->init) { @@ -610,19 +557,11 @@ exit: ts = rpmtsFree(ts); - optCon = poptFreeContext(optCon); - rpmFreeMacros(NULL); - rpmFreeMacros(rpmCLIMacroContext); - rpmFreeRpmrc(); - if (pipeChild) { (void) fclose(stdout); (void) waitpid(pipeChild, &status, 0); } - /* keeps memory leak checkers quiet */ - rpmlogClose(); - #ifdef IAM_RPMQV qva->qva_queryFormat = _free(qva->qva_queryFormat); #endif @@ -634,12 +573,5 @@ exit: ia->relocations = _free(ia->relocations); #endif -#if HAVE_MCHECK_H && HAVE_MTRACE - muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */ -#endif - - /* XXX Avoid exit status overflow. Status 255 is special to xargs(1) */ - if (ec > 254) ec = 254; - - return ec; + return finishCli(optCon, ec); } -- cgit v1.2.3