3 * Popt tables for all rpm modes.
7 const char *__progname;
14 #define POPT_SHOWVERSION -999
15 #define POPT_SHOWRC -998
16 #define POPT_QUERYTAGS -997
17 #define POPT_PREDEFINE -996
19 #define POPT_RCFILE -995
22 static int _debug = 0;
24 extern int _rpmds_nopromote;
26 extern int _fps_debug;
28 extern int _fsm_debug;
30 extern int _fsm_threads;
32 extern int _hdr_debug;
34 extern int _print_pkts;
36 extern int _psm_debug;
38 extern int _psm_threads;
40 extern int _rpmal_debug;
42 extern int _rpmdb_debug;
44 extern int _rpmds_debug;
46 /* XXX avoid -lrpmbuild linkage. */
49 extern int _rpmfi_debug;
51 extern int _rpmgi_debug;
53 extern int _rpmps_debug;
55 extern int _rpmsq_debug;
57 extern int _rpmte_debug;
59 extern int _rpmts_debug;
61 extern int _rpmts_stats;
65 const char * rpmcliPipeOutput = NULL;
67 const char * rpmcliRcfile = NULL;
69 const char * rpmcliRootDir = "/";
71 rpmQueryFlags rpmcliQueryFlags;
75 extern int _rpmio_debug;
77 static int rpmcliInitialized = -1;
80 * Display rpm version.
82 static void printVersion(FILE * fp)
84 fprintf(fp, _("RPM version %s\n"), rpmEVR);
88 * Make sure that config files have been read.
89 * @warning Options like --rcfile and --verbose must precede callers option.
91 void rpmcliConfigured(void)
94 if (rpmcliInitialized < 0)
95 rpmcliInitialized = rpmReadConfigFiles(rpmcliRcfile, NULL);
96 if (rpmcliInitialized)
102 static void rpmcliAllArgCallback( poptContext con,
103 enum poptCallbackReason reason,
104 const struct poptOption * opt, const char * arg,
108 /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
109 if (opt->arg == NULL)
112 rpmSetVerbosity(RPMMESS_QUIET);
115 rpmIncreaseVerbosity();
118 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
121 /* XXX Predefine macro if not initialized yet. */
122 if (rpmcliInitialized < 0)
123 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
125 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
126 (void) rpmDefineMacro(rpmCLIMacroContext, arg, RMIL_CMDLINE);
130 { const char *val = rpmExpand(arg, NULL);
131 fprintf(stdout, "%s\n", val);
135 case POPT_SHOWVERSION:
136 printVersion(stdout);
141 (void) rpmShowRC(stdout);
145 rpmDisplayQueryTags(stdout);
148 #if defined(POPT_RCFILE)
149 case POPT_RCFILE: /* XXX FIXME: noop for now */
152 case RPMCLI_POPT_NODIGEST:
153 rpmcliQueryFlags |= VERIFY_DIGEST;
156 case RPMCLI_POPT_NOSIGNATURE:
157 rpmcliQueryFlags |= VERIFY_SIGNATURE;
160 case RPMCLI_POPT_NOHDRCHK:
161 rpmcliQueryFlags |= VERIFY_HDRCHK;
168 struct poptOption rpmcliFtsPoptTable[] = {
169 { "comfollow", '\0', POPT_BIT_SET, &ftsOpts, FTS_COMFOLLOW,
170 N_("FTS_COMFOLLOW: follow command line symlinks"), NULL },
171 { "logical", '\0', POPT_BIT_SET, &ftsOpts, FTS_LOGICAL,
172 N_("FTS_LOGICAL: logical walk"), NULL },
173 { "nochdir", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOCHDIR,
174 N_("FTS_NOCHDIR: don't change directories"), NULL },
175 { "nostat", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOSTAT,
176 N_("FTS_NOSTAT: don't get stat info"), NULL },
177 { "physical", '\0', POPT_BIT_SET, &ftsOpts, FTS_PHYSICAL,
178 N_("FTS_PHYSICAL: physical walk"), NULL },
179 { "seedot", '\0', POPT_BIT_SET, &ftsOpts, FTS_SEEDOT,
180 N_("FTS_SEEDOT: return dot and dot-dot"), NULL },
181 { "xdev", '\0', POPT_BIT_SET, &ftsOpts, FTS_XDEV,
182 N_("FTS_XDEV: don't cross devices"), NULL },
183 { "whiteout", '\0', POPT_BIT_SET, &ftsOpts, FTS_WHITEOUT,
184 N_("FTS_WHITEOUT: return whiteout information"), NULL },
188 struct poptOption rpmcliAllPoptTable[] = {
190 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
191 rpmcliAllArgCallback, 0, NULL, NULL },
193 { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
196 { "predefine", 'D', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_PREDEFINE,
197 N_("predefine MACRO with value EXPR"),
198 N_("'MACRO EXPR'") },
199 { "define", 'D', POPT_ARG_STRING, 0, 'D',
200 N_("define MACRO with value EXPR"),
201 N_("'MACRO EXPR'") },
202 { "eval", 'E', POPT_ARG_STRING, 0, 'E',
203 N_("print macro expansion of EXPR"),
205 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
206 N_("read <FILE:...> instead of default file(s)"),
209 { "nodigest", '\0', 0, 0, RPMCLI_POPT_NODIGEST,
210 N_("don't verify package digest(s)"), NULL },
211 { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
212 N_("don't verify database header(s) when retrieved"), NULL },
213 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
214 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
215 N_("disable use of libio(3) API"), NULL},
217 { "nosignature", '\0', 0, 0, RPMCLI_POPT_NOSIGNATURE,
218 N_("don't verify package signature(s)"), NULL },
220 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
221 N_("send stdout to CMD"),
223 #if !defined(POPT_RCFILE)
224 { "rcfile", '\0', POPT_ARG_STRING, &rpmcliRcfile, 0,
225 N_("read <FILE:...> instead of default file(s)"),
228 { "rcfile", '\0', 0, NULL, POPT_RCFILE,
229 N_("read <FILE:...> instead of default file(s)"),
232 { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
233 N_("use ROOT as top level directory"),
236 { "querytags", '\0', 0, 0, POPT_QUERYTAGS,
237 N_("display known query tags"), NULL },
238 { "showrc", '\0', 0, NULL, POPT_SHOWRC,
239 N_("display final rpmrc and macro configuration"), NULL },
240 { "quiet", '\0', 0, NULL, 'q',
241 N_("provide less detailed output"), NULL},
242 { "verbose", 'v', 0, NULL, 'v',
243 N_("provide more detailed output"), NULL},
244 { "version", '\0', 0, NULL, POPT_SHOWVERSION,
245 N_("print the version of rpm being used"), NULL },
247 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
248 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
249 N_("disable use of libio(3) API"), NULL},
252 { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
255 { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
257 { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
258 N_("debug payload file state machine"), NULL},
259 { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1,
260 N_("use threads for file state machine"), NULL},
261 { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
264 { "poptdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_popt_debug, -1,
265 N_("debug option/argument processing"), NULL},
267 { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
269 { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
270 N_("debug package state machine"), NULL},
271 { "psmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_threads, -1,
272 N_("use threads for package state machine"), NULL},
273 { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
275 { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
277 { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
279 { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
281 { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
283 { "rpmgidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
285 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
286 N_("debug rpmio I/O"), NULL},
287 { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
289 { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1,
291 { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
293 { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
295 { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
297 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
298 N_("debug URL cache handling"), NULL},
304 rpmcliFini(poptContext optCon)
306 optCon = poptFreeContext(optCon);
308 #if HAVE_MCHECK_H && HAVE_MTRACE
309 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
316 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
322 #if HAVE_MCHECK_H && HAVE_MTRACE
323 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
325 setprogname(argv[0]); /* Retrofit glibc __progname */
327 /* XXX glibc churn sanity */
328 if (__progname == NULL) {
329 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
330 else __progname = argv[0];
333 #if defined(ENABLE_NLS)
334 (void) setlocale(LC_ALL, "" );
335 (void) bindtextdomain(PACKAGE, LOCALEDIR);
336 (void) textdomain(PACKAGE);
339 rpmSetVerbosity(RPMMESS_NORMAL);
341 if (optionsTable == NULL) {
342 /* Read rpm configuration (if not already read). */
347 optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
348 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
349 (void) poptReadDefaultConfig(optCon, 1);
350 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
352 /* Process all options, whine if unknown. */
353 while ((rc = poptGetNextOpt(optCon)) > 0) {
354 optArg = poptGetOptArg(optCon);
357 fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
366 fprintf(stderr, "%s: %s: %s\n", __progname,
367 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
372 /* Read rpm configuration (if not already read). */
376 rpmIncreaseVerbosity();
377 rpmIncreaseVerbosity();