3 * Popt tables for all rpm modes.
12 #define POPT_SHOWVERSION -999
13 #define POPT_SHOWRC -998
14 #define POPT_QUERYTAGS -997
15 #define POPT_PREDEFINE -996
17 #define POPT_RCFILE -995
21 static int _debug = 0;
23 /*@-exportheadervar@*/
25 extern int _rpmds_nopromote;
28 extern int _fps_debug;
31 extern int _fsm_debug;
34 extern int _fsm_threads;
37 extern int _hdr_debug;
40 extern int _psm_debug;
43 extern int _psm_threads;
46 extern int _rpmal_debug;
49 extern int _rpmdb_debug;
52 extern int _rpmds_debug;
54 /* XXX avoid -lrpmbuild linkage. */
59 extern int _rpmfi_debug;
62 extern int _rpmps_debug;
65 extern int _rpmsq_debug;
68 extern int _rpmte_debug;
71 extern int _rpmts_debug;
74 extern int _rpmts_stats;
78 /*@=exportheadervar@*/
81 const char * rpmcliPipeOutput = NULL;
84 const char * rpmcliRcfile = NULL;
87 const char * rpmcliRootDir = "/";
90 rpmQueryFlags rpmcliQueryFlags;
92 /*@-exportheadervar@*/
94 extern int _ftp_debug;
98 extern int _rpmio_debug;
99 /*@=exportheadervar@*/
102 static int rpmcliInitialized = -1;
105 * Display rpm version.
107 static void printVersion(FILE * fp)
108 /*@globals rpmEVR, fileSystem @*/
109 /*@modifies *fp, fileSystem @*/
111 fprintf(fp, _("RPM version %s\n"), rpmEVR);
115 * Make sure that config files have been read.
116 * @warning Options like --rcfile and --verbose must precede callers option.
119 void rpmcliConfigured(void)
120 /*@globals rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
121 fileSystem, internalState @*/
122 /*@modifies rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
123 fileSystem, internalState @*/
126 if (rpmcliInitialized < 0)
127 rpmcliInitialized = rpmReadConfigFiles(rpmcliRcfile, NULL);
128 if (rpmcliInitialized)
135 static void rpmcliAllArgCallback( /*@unused@*/ poptContext con,
136 /*@unused@*/ enum poptCallbackReason reason,
137 const struct poptOption * opt, const char * arg,
138 /*@unused@*/ const void * data)
139 /*@globals rpmcliQueryFlags, rpmCLIMacroContext, rpmGlobalMacroContext,
140 fileSystem, internalState @*/
141 /*@modifies rpmcliQueryFlags, rpmCLIMacroContext, rpmGlobalMacroContext,
142 fileSystem, internalState @*/
145 /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
147 if (opt->arg == NULL)
150 rpmSetVerbosity(RPMMESS_QUIET);
153 rpmIncreaseVerbosity();
156 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
159 /* XXX Predefine macro if not initialized yet. */
160 if (rpmcliInitialized < 0)
161 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
164 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
165 (void) rpmDefineMacro(rpmCLIMacroContext, arg, RMIL_CMDLINE);
170 { const char *val = rpmExpand(arg, NULL);
171 fprintf(stdout, "%s\n", val);
175 case POPT_SHOWVERSION:
176 printVersion(stdout);
178 /*@notreached@*/ break;
181 (void) rpmShowRC(stdout);
183 /*@notreached@*/ break;
185 rpmDisplayQueryTags(stdout);
187 /*@notreached@*/ break;
188 #if defined(POPT_RCFILE)
189 case POPT_RCFILE: /* XXX FIXME: noop for now */
192 case RPMCLI_POPT_NODIGEST:
193 rpmcliQueryFlags |= VERIFY_DIGEST;
196 case RPMCLI_POPT_NOSIGNATURE:
197 rpmcliQueryFlags |= VERIFY_SIGNATURE;
200 case RPMCLI_POPT_NOHDRCHK:
201 rpmcliQueryFlags |= VERIFY_HDRCHK;
207 /*@-bitwisesigned -compmempass @*/
209 struct poptOption rpmcliAllPoptTable[] = {
210 /*@-type@*/ /* FIX: cast? */
211 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
212 rpmcliAllArgCallback, 0, NULL, NULL },
215 { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
218 { "predefine", 'D', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_PREDEFINE,
219 N_("predefine MACRO with value EXPR"),
220 N_("'MACRO EXPR'") },
221 { "define", 'D', POPT_ARG_STRING, 0, 'D',
222 N_("define MACRO with value EXPR"),
223 N_("'MACRO EXPR'") },
224 { "eval", 'E', POPT_ARG_STRING, 0, 'E',
225 N_("print macro expansion of EXPR"),
227 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
228 N_("read <FILE:...> instead of default file(s)"),
231 { "nodigest", '\0', 0, 0, RPMCLI_POPT_NODIGEST,
232 N_("don't verify package digest(s)"), NULL },
233 { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
234 N_("don't verify database header(s) when retrieved"), NULL },
235 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
236 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
237 N_("disable use of libio(3) API"), NULL},
239 { "nosignature", '\0', 0, 0, RPMCLI_POPT_NOSIGNATURE,
240 N_("don't verify package signature(s)"), NULL },
242 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
243 N_("send stdout to CMD"),
245 #if !defined(POPT_RCFILE)
246 { "rcfile", '\0', POPT_ARG_STRING, &rpmcliRcfile, 0,
247 N_("read <FILE:...> instead of default file(s)"),
250 { "rcfile", '\0', 0, NULL, POPT_RCFILE,
251 N_("read <FILE:...> instead of default file(s)"),
254 { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
255 N_("use ROOT as top level directory"),
258 { "querytags", '\0', 0, 0, POPT_QUERYTAGS,
259 N_("display known query tags"), NULL },
260 { "showrc", '\0', 0, NULL, POPT_SHOWRC,
261 N_("display final rpmrc and macro configuration"), NULL },
262 { "quiet", '\0', 0, NULL, 'q',
263 N_("provide less detailed output"), NULL},
264 { "verbose", 'v', 0, NULL, 'v',
265 N_("provide more detailed output"), NULL},
266 { "version", '\0', 0, NULL, POPT_SHOWVERSION,
267 N_("print the version of rpm being used"), NULL },
269 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
270 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
271 N_("disable use of libio(3) API"), NULL},
274 { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
277 { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
279 { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
280 N_("debug payload file state machine"), NULL},
281 { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1,
282 N_("use threads for file state machine"), NULL},
283 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
284 N_("debug protocol data stream"), NULL},
285 { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
288 { "poptdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_popt_debug, -1,
289 N_("debug option/argument processing"), NULL},
291 { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
292 N_("debug package state machine"), NULL},
293 { "psmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_threads, -1,
294 N_("use threads for package state machine"), NULL},
295 { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
297 { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
299 { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
301 { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
303 { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
305 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
306 N_("debug rpmio I/O"), NULL},
307 { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
309 { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1,
311 { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
313 { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
315 { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
317 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
318 N_("debug URL cache handling"), NULL},
322 /*@=bitwisesigned =compmempass @*/
325 rpmcliFini(poptContext optCon)
327 optCon = poptFreeContext(optCon);
329 #if HAVE_MCHECK_H && HAVE_MTRACE
331 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
340 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
346 #if HAVE_MCHECK_H && HAVE_MTRACE
348 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
352 setprogname(argv[0]); /* Retrofit glibc __progname */
354 /* XXX glibc churn sanity */
355 if (__progname == NULL) {
356 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
357 else __progname = argv[0];
361 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
362 (void) setlocale(LC_ALL, "" );
363 (void) bindtextdomain(PACKAGE, LOCALEDIR);
364 (void) textdomain(PACKAGE);
367 rpmSetVerbosity(RPMMESS_NORMAL);
369 if (optionsTable == NULL) {
370 /* Read rpm configuration (if not already read). */
375 /*@-nullpass -temptrans@*/
376 optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
377 /*@=nullpass =temptrans@*/
378 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
379 (void) poptReadDefaultConfig(optCon, 1);
380 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
382 /* Process all options, whine if unknown. */
383 while ((rc = poptGetNextOpt(optCon)) > 0) {
384 optArg = poptGetOptArg(optCon);
388 fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
393 /*@notreached@*/ /*@switchbreak@*/ break;
399 fprintf(stderr, "%s: %s: %s\n", __progname,
400 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
406 /* Read rpm configuration (if not already read). */
410 rpmIncreaseVerbosity();
411 rpmIncreaseVerbosity();