5 #include <rpm/rpmlog.h>
6 #include <rpm/rpmlib.h>
7 #include <rpm/rpmfileutil.h>
8 #include <rpm/rpmmacro.h>
9 #include <rpm/rpmcli.h>
14 void argerror(const char * desc)
16 fprintf(stderr, _("%s: %s\n"), __progname, desc);
20 static void printVersion(FILE * fp)
22 fprintf(fp, _("RPM version %s\n"), rpmEVR);
25 static void printBanner(FILE * fp)
27 fprintf(fp, _("Copyright (C) 1998-2002 - Red Hat, Inc.\n"));
28 fprintf(fp, _("This program may be freely redistributed under the terms of the GNU GPL\n"));
31 void printUsage(poptContext con, FILE * fp, int flags)
38 poptPrintHelp(con, fp, flags);
40 poptPrintUsage(con, fp, flags);
43 poptContext initCli(const char *ctx, struct poptOption *optionsTable,
44 int argc, char *argv[])
50 #if HAVE_MCHECK_H && HAVE_MTRACE
51 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
54 #if defined(ENABLE_NLS)
55 /* set up the correct locale */
56 (void) setlocale(LC_ALL, "" );
58 bindtextdomain(PACKAGE, LOCALEDIR);
62 rpmSetVerbosity(RPMLOG_NOTICE); /* XXX silly use by showrc */
64 /* Make a first pass through the arguments, looking for --rcfile */
65 /* We need to handle that before dealing with the rest of the arguments. */
66 /* XXX popt argv definition should be fixed instead of casting... */
67 optCon = poptGetContext(ctx, argc, (const char **)argv, optionsTable, 0);
69 char *poptfile = rpmGenPath(rpmConfigDir(), LIBRPMALIAS_FILENAME, NULL);
70 (void) poptReadConfigFile(optCon, poptfile);
73 (void) poptReadDefaultConfig(optCon, 1);
74 poptSetExecPath(optCon, rpmConfigDir(), 1);
76 while ((arg = poptGetNextOpt(optCon)) > 0) {
77 optArg = poptGetOptArg(optCon);
81 fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
87 fprintf(stderr, "%s: %s\n",
88 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
98 int finishCli(poptContext optCon, int rc)
100 poptFreeContext(optCon);
102 rpmFreeMacros(rpmCLIMacroContext);
106 #if HAVE_MCHECK_H && HAVE_MTRACE
107 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
110 /* XXX Avoid exit status overflow. Status 255 is special to xargs(1) */
111 return (rc > 254) ? 254 : rc;