Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

lib/poptALL.c

Go to the documentation of this file.
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 /*@unchecked@*/
00021 static int _debug = 0;
00022 
00023 /*@-exportheadervar@*/
00024 /*@unchecked@*/
00025 extern int _rpmds_nopromote;
00026 
00027 /*@unchecked@*/
00028 extern int _fps_debug;
00029 
00030 /*@unchecked@*/
00031 extern int _fsm_debug;
00032 
00033 /*@unchecked@*/
00034 extern int _hdr_debug;
00035 
00036 /*@unchecked@*/
00037 extern int _psm_debug;
00038 
00039 /*@unchecked@*/
00040 extern int _rpmal_debug;
00041 
00042 /*@unchecked@*/
00043 extern int _rpmdb_debug;
00044 
00045 /*@unchecked@*/
00046 extern int _rpmds_debug;
00047 
00048 /*@unchecked@*/
00049 extern int _rpmfi_debug;
00050 
00051 /*@unchecked@*/
00052 extern int _rpmps_debug;
00053 
00054 /*@unchecked@*/
00055 extern int _rpmte_debug;
00056 
00057 /*@unchecked@*/
00058 extern int _rpmts_debug;
00059 
00060 /*@unchecked@*/
00061 extern int noLibio;
00062 /*@=exportheadervar@*/
00063 
00064 /*@unchecked@*/
00065 const char * rpmcliPipeOutput = NULL;
00066 
00067 /*@unchecked@*/
00068 const char * rpmcliRcfile = NULL;
00069 
00070 /*@unchecked@*/
00071 const char * rpmcliRootDir = "/";
00072 
00073 /*@unchecked@*/
00074 rpmQueryFlags rpmcliQueryFlags;
00075 
00076 /*@-exportheadervar@*/
00077 /*@unchecked@*/
00078 extern int _ftp_debug;
00079 /*@unchecked@*/
00080 extern int noLibio;
00081 /*@unchecked@*/
00082 extern int _rpmio_debug;
00083 /*@=exportheadervar@*/
00084 
00085 /*@unchecked@*/
00086 static int rpmcliInitialized = -1;
00087 
00091 static void printVersion(FILE * fp)
00092         /*@globals rpmEVR, fileSystem @*/
00093         /*@modifies *fp, fileSystem @*/
00094 {
00095     fprintf(fp, _("RPM version %s\n"), rpmEVR);
00096 }
00097 
00102 /*@mayexit@*/
00103 void rpmcliConfigured(void)
00104         /*@globals rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
00105                 fileSystem, internalState @*/
00106         /*@modifies rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
00107                 fileSystem, internalState @*/
00108 {
00109 
00110     if (rpmcliInitialized < 0)
00111         rpmcliInitialized = rpmReadConfigFiles(rpmcliRcfile, NULL);
00112     if (rpmcliInitialized)
00113         exit(EXIT_FAILURE);
00114 }
00115 
00118 /*@-bounds@*/
00119 static void rpmcliAllArgCallback( /*@unused@*/ poptContext con,
00120                 /*@unused@*/ enum poptCallbackReason reason,
00121                 const struct poptOption * opt, const char * arg,
00122                 /*@unused@*/ const void * data)
00123         /*@globals rpmcliQueryFlags, rpmCLIMacroContext, rpmGlobalMacroContext,
00124                 fileSystem, internalState @*/
00125         /*@modifies rpmcliQueryFlags, rpmCLIMacroContext, rpmGlobalMacroContext,
00126                 fileSystem, internalState @*/
00127 {
00128 
00129     /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
00130     /*@-branchstate@*/
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         /* XXX Predefine macro if not initialized yet. */
00144         if (rpmcliInitialized < 0)
00145             (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00146         rpmcliConfigured();
00147 /*@-type@*/
00148         (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00149         (void) rpmDefineMacro(rpmCLIMacroContext, arg, RMIL_CMDLINE);
00150 /*@=type@*/
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         /*@notreached@*/ break;
00163     case POPT_SHOWRC:
00164         rpmcliConfigured();
00165         (void) rpmShowRC(stdout);
00166         exit(EXIT_SUCCESS);
00167         /*@notreached@*/ break;
00168     case POPT_QUERYTAGS:
00169         rpmDisplayQueryTags(stdout);
00170         exit(EXIT_SUCCESS);
00171         /*@notreached@*/ break;
00172 #if defined(POPT_RCFILE)
00173     case POPT_RCFILE:           /* XXX FIXME: noop for now */
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     /*@=branchstate@*/
00189 }
00190 
00191 /*@-bitwisesigned -compmempass @*/
00192 /*@unchecked@*/
00193 struct poptOption rpmcliAllPoptTable[] = {
00194 /*@-type@*/ /* FIX: cast? */
00195  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
00196         rpmcliAllArgCallback, 0, NULL, NULL },
00197 /*@=type@*/
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, &macrofiles, 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 /*@=bitwisesigned =compmempass @*/
00297 
00298 poptContext
00299 rpmcliFini(poptContext optCon)
00300 {
00301     optCon = poptFreeContext(optCon);
00302 
00303 #if HAVE_MCHECK_H && HAVE_MTRACE
00304     /*@-noeffect@*/
00305     muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
00306     /*@=noeffect@*/
00307 #endif
00308 
00309     return NULL;
00310 }
00311 
00312 /*@-globstate@*/
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     /*@-noeffect@*/
00322     mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
00323     /*@=noeffect@*/
00324 #endif
00325 /*@-globs -mods@*/
00326     setprogname(argv[0]);       /* Retrofit glibc __progname */
00327 
00328     /* XXX glibc churn sanity */
00329     if (__progname == NULL) {
00330         if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
00331         else __progname = argv[0];
00332     }
00333 /*@=globs =mods@*/
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         /* Read rpm configuration (if not already read). */
00346         rpmcliConfigured();
00347         return NULL;
00348     }
00349 
00350 /*@-nullpass -temptrans@*/
00351     optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
00352 /*@=nullpass =temptrans@*/
00353     (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
00354     (void) poptReadDefaultConfig(optCon, 1);
00355     poptSetExecPath(optCon, RPMCONFIGDIR, 1);
00356 
00357     /* Process all options, whine if unknown. */
00358     while ((rc = poptGetNextOpt(optCon)) > 0) {
00359         optArg = poptGetOptArg(optCon);
00360         switch (rc) {
00361         default:
00362 /*@-nullpass@*/
00363             fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
00364                 __progname, rc);
00365 /*@=nullpass@*/
00366             exit(EXIT_FAILURE);
00367 
00368             /*@notreached@*/ /*@switchbreak@*/ break;
00369         }
00370     }
00371 
00372     if (rc < -1) {
00373 /*@-nullpass@*/
00374         fprintf(stderr, "%s: %s: %s\n", __progname,
00375                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00376                 poptStrerror(rc));
00377 /*@=nullpass@*/
00378         exit(EXIT_FAILURE);
00379     }
00380 
00381     /* Read rpm configuration (if not already read). */
00382     rpmcliConfigured();
00383 
00384     if (_debug) {
00385         rpmIncreaseVerbosity();
00386         rpmIncreaseVerbosity();
00387     }
00388 
00389     return optCon;
00390 }
00391 /*@=globstate@*/

Generated on Tue Sep 17 15:56:39 2002 for rpm by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002