00001
00006 #include "system.h"
00007
00008 #include <rpmcli.h>
00009
00010 #include "debug.h"
00011
00012 #define POPT_SHOWVERSION -999
00013 #define POPT_SHOWRC -998
00014 #define POPT_QUERYTAGS -997
00015 #define POPT_PREDEFINE -996
00016 #ifdef NOTYET
00017 #define POPT_RCFILE -995
00018 #endif
00019
00020
00021 static int _debug = 0;
00022
00023
00024
00025 extern int _rpmds_nopromote;
00026
00027
00028 extern int _fps_debug;
00029
00030
00031 extern int _fsm_debug;
00032
00033
00034 extern int _hdr_debug;
00035
00036
00037 extern int _psm_debug;
00038
00039
00040 extern int _rpmal_debug;
00041
00042
00043 extern int _rpmdb_debug;
00044
00045
00046 extern int _rpmds_debug;
00047
00048
00049 extern int _rpmfi_debug;
00050
00051
00052 extern int _rpmps_debug;
00053
00054
00055 extern int _rpmte_debug;
00056
00057
00058 extern int _rpmts_debug;
00059
00060
00061 extern int noLibio;
00062
00063
00064
00065 const char * rpmcliPipeOutput = NULL;
00066
00067
00068 const char * rpmcliRcfile = NULL;
00069
00070
00071 const char * rpmcliRootDir = "/";
00072
00073
00074 rpmQueryFlags rpmcliQueryFlags;
00075
00076
00077
00078 extern int _ftp_debug;
00079
00080 extern int noLibio;
00081
00082 extern int _rpmio_debug;
00083
00084
00085
00086 static int rpmcliInitialized = -1;
00087
00091 static void printVersion(FILE * fp)
00092
00093
00094 {
00095 fprintf(fp, _("RPM version %s\n"), rpmEVR);
00096 }
00097
00102
00103 void rpmcliConfigured(void)
00104
00105
00106
00107
00108 {
00109
00110 if (rpmcliInitialized < 0)
00111 rpmcliInitialized = rpmReadConfigFiles(rpmcliRcfile, NULL);
00112 if (rpmcliInitialized)
00113 exit(EXIT_FAILURE);
00114 }
00115
00118
00119 static void rpmcliAllArgCallback( poptContext con,
00120 enum poptCallbackReason reason,
00121 const struct poptOption * opt, const char * arg,
00122 const void * data)
00123
00124
00125
00126
00127 {
00128
00129
00130
00131 if (opt->arg == NULL)
00132 switch (opt->val) {
00133 case 'q':
00134 rpmSetVerbosity(RPMMESS_QUIET);
00135 break;
00136 case 'v':
00137 rpmIncreaseVerbosity();
00138 break;
00139 case POPT_PREDEFINE:
00140 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00141 break;
00142 case 'D':
00143
00144 if (rpmcliInitialized < 0)
00145 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00146 rpmcliConfigured();
00147
00148 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00149 (void) rpmDefineMacro(rpmCLIMacroContext, arg, RMIL_CMDLINE);
00150
00151 break;
00152 case 'E':
00153 rpmcliConfigured();
00154 { const char *val = rpmExpand(arg, NULL);
00155 fprintf(stdout, "%s\n", val);
00156 val = _free(val);
00157 }
00158 break;
00159 case POPT_SHOWVERSION:
00160 printVersion(stdout);
00161 exit(EXIT_SUCCESS);
00162 break;
00163 case POPT_SHOWRC:
00164 rpmcliConfigured();
00165 (void) rpmShowRC(stdout);
00166 exit(EXIT_SUCCESS);
00167 break;
00168 case POPT_QUERYTAGS:
00169 rpmDisplayQueryTags(stdout);
00170 exit(EXIT_SUCCESS);
00171 break;
00172 #if defined(POPT_RCFILE)
00173 case POPT_RCFILE:
00174 break;
00175 #endif
00176 case RPMCLI_POPT_NODIGEST:
00177 rpmcliQueryFlags |= VERIFY_DIGEST;
00178 break;
00179
00180 case RPMCLI_POPT_NOSIGNATURE:
00181 rpmcliQueryFlags |= VERIFY_SIGNATURE;
00182 break;
00183
00184 case RPMCLI_POPT_NOHDRCHK:
00185 rpmcliQueryFlags |= VERIFY_HDRCHK;
00186 break;
00187 }
00188
00189 }
00190
00191
00192
00193 struct poptOption rpmcliAllPoptTable[] = {
00194
00195 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
00196 rpmcliAllArgCallback, 0, NULL, NULL },
00197
00198
00199 { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
00200 NULL, NULL },
00201
00202 { "predefine", 'D', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_PREDEFINE,
00203 N_("predefine MACRO with value EXPR"),
00204 N_("'MACRO EXPR'") },
00205 { "define", 'D', POPT_ARG_STRING, 0, 'D',
00206 N_("define MACRO with value EXPR"),
00207 N_("'MACRO EXPR'") },
00208 { "eval", 'E', POPT_ARG_STRING, 0, 'E',
00209 N_("print macro expansion of EXPR"),
00210 N_("'EXPR'") },
00211 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
00212 N_("read <FILE:...> instead of default file(s)"),
00213 N_("<FILE:...>") },
00214
00215 { "nodigest", '\0', 0, 0, RPMCLI_POPT_NODIGEST,
00216 N_("don't verify package digest(s)"), NULL },
00217 { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
00218 N_("don't verify database header(s) when retrieved"), NULL },
00219 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00220 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00221 N_("disable use of libio(3) API"), NULL},
00222 #endif
00223 { "nosignature", '\0', 0, 0, RPMCLI_POPT_NOSIGNATURE,
00224 N_("don't verify package signature(s)"), NULL },
00225
00226 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
00227 N_("send stdout to CMD"),
00228 N_("CMD") },
00229 #if !defined(POPT_RCFILE)
00230 { "rcfile", '\0', POPT_ARG_STRING, &rpmcliRcfile, 0,
00231 N_("read <FILE:...> instead of default file(s)"),
00232 N_("<FILE:...>") },
00233 #else
00234 { "rcfile", '\0', 0, NULL, POPT_RCFILE,
00235 N_("read <FILE:...> instead of default file(s)"),
00236 N_("<FILE:...>") },
00237 #endif
00238 { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
00239 N_("use ROOT as top level directory"),
00240 N_("ROOT") },
00241
00242 { "querytags", '\0', 0, 0, POPT_QUERYTAGS,
00243 N_("display known query tags"), NULL },
00244 { "showrc", '\0', 0, NULL, POPT_SHOWRC,
00245 N_("display final rpmrc and macro configuration"), NULL },
00246 { "quiet", '\0', 0, NULL, 'q',
00247 N_("provide less detailed output"), NULL},
00248 { "verbose", 'v', 0, NULL, 'v',
00249 N_("provide more detailed output"), NULL},
00250 { "version", '\0', 0, NULL, POPT_SHOWVERSION,
00251 N_("print the version of rpm being used"), NULL },
00252
00253 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00254 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00255 N_("disable use of libio(3) API"), NULL},
00256 #endif
00257
00258 { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
00259 NULL, NULL},
00260
00261 { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
00262 NULL, NULL},
00263 { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
00264 N_("debug payload file state machine"), NULL},
00265 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
00266 N_("debug protocol data stream"), NULL},
00267 { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
00268 NULL, NULL},
00269 #ifdef DYING
00270 { "poptdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_popt_debug, -1,
00271 N_("debug option/argument processing"), NULL},
00272 #endif
00273 { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
00274 N_("debug package state machine"), NULL},
00275 { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
00276 NULL, NULL},
00277 { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
00278 NULL, NULL},
00279 { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
00280 NULL, NULL},
00281 { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
00282 NULL, NULL},
00283 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
00284 N_("debug rpmio I/O"), NULL},
00285 { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
00286 NULL, NULL},
00287 { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
00288 NULL, NULL},
00289 { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
00290 NULL, NULL},
00291 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
00292 N_("debug URL cache handling"), NULL},
00293
00294 POPT_TABLEEND
00295 };
00296
00297
00298 poptContext
00299 rpmcliFini(poptContext optCon)
00300 {
00301 optCon = poptFreeContext(optCon);
00302
00303 #if HAVE_MCHECK_H && HAVE_MTRACE
00304
00305 muntrace();
00306
00307 #endif
00308
00309 return NULL;
00310 }
00311
00312
00313 poptContext
00314 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
00315 {
00316 const char * optArg;
00317 poptContext optCon;
00318 int rc;
00319
00320 #if HAVE_MCHECK_H && HAVE_MTRACE
00321
00322 mtrace();
00323
00324 #endif
00325
00326 setprogname(argv[0]);
00327
00328
00329 if (__progname == NULL) {
00330 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
00331 else __progname = argv[0];
00332 }
00333
00334
00335 #if !defined(__LCLINT__)
00336 (void) setlocale(LC_ALL, "" );
00337
00338 (void) bindtextdomain(PACKAGE, LOCALEDIR);
00339 (void) textdomain(PACKAGE);
00340 #endif
00341
00342 rpmSetVerbosity(RPMMESS_NORMAL);
00343
00344 if (optionsTable == NULL) {
00345
00346 rpmcliConfigured();
00347 return NULL;
00348 }
00349
00350
00351 optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
00352
00353 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
00354 (void) poptReadDefaultConfig(optCon, 1);
00355 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
00356
00357
00358 while ((rc = poptGetNextOpt(optCon)) > 0) {
00359 optArg = poptGetOptArg(optCon);
00360 switch (rc) {
00361 default:
00362
00363 fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
00364 __progname, rc);
00365
00366 exit(EXIT_FAILURE);
00367
00368 break;
00369 }
00370 }
00371
00372 if (rc < -1) {
00373
00374 fprintf(stderr, "%s: %s: %s\n", __progname,
00375 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00376 poptStrerror(rc));
00377
00378 exit(EXIT_FAILURE);
00379 }
00380
00381
00382 rpmcliConfigured();
00383
00384 if (_debug) {
00385 rpmIncreaseVerbosity();
00386 rpmIncreaseVerbosity();
00387 }
00388
00389 return optCon;
00390 }
00391