lib/poptALL.c

Go to the documentation of this file.
00001 
00006 #include "system.h"
00007 const char *__progname;
00008 
00009 #include <rpmcli.h>
00010 #include <rpmlua.h>             /* XXX rpmluaFree() */
00011 #include <fs.h>                 /* XXX rpmFreeFilesystems() */
00012 #include <fts.h>
00013 #include <mire.h>
00014 
00015 #include "debug.h"
00016 
00017 #define POPT_SHOWVERSION        -999
00018 #define POPT_SHOWRC             -998
00019 #define POPT_QUERYTAGS          -997
00020 #define POPT_PREDEFINE          -996
00021 #ifdef  NOTYET
00022 #define POPT_RCFILE             -995
00023 #endif
00024 
00025 /*@access headerTagIndices @*/          /* XXX rpmcliFini */
00026 /*@access headerTagTableEntry @*/       /* XXX rpmcliFini */
00027 
00028 /*@unchecked@*/
00029 static int _debug = 0;
00030 
00031 /*@unchecked@*/
00032 extern int _rsegfault;
00033 
00034 /*@unchecked@*/
00035 extern int _wsegfault;
00036 
00037 /*@-exportheadervar@*/
00038 /*@unchecked@*/
00039 extern int _rpmds_nopromote;
00040 
00041 /*@unchecked@*/
00042 extern int _cpio_debug;
00043 
00044 /*@unchecked@*/
00045 extern int _fps_debug;
00046 
00047 /*@unchecked@*/
00048 extern int _fsm_debug;
00049 
00050 /*@unchecked@*/
00051 extern int _fsm_threads;
00052 
00053 /*@unchecked@*/
00054 extern int _hdr_debug;
00055 
00056 /*@unchecked@*/
00057 extern int _mire_debug;
00058 
00059 /*@unchecked@*/
00060 extern int _print_pkts;
00061 
00062 /*@unchecked@*/
00063 extern int _psm_debug;
00064 
00065 /*@unchecked@*/
00066 extern int _psm_threads;
00067 
00068 /*@unchecked@*/
00069 extern int _rpmal_debug;
00070 
00071 /*@unchecked@*/
00072 extern int _rpmdb_debug;
00073 
00074 /*@unchecked@*/
00075 extern int _rpmds_debug;
00076 
00077 /* XXX avoid -lrpmbuild linkage. */
00078 /*@unchecked@*/
00079        int _rpmfc_debug;
00080 
00081 /*@unchecked@*/
00082 extern int _rpmfi_debug;
00083 
00084 /*@unchecked@*/
00085 extern int _rpmgi_debug;
00086 
00087 /*@unchecked@*/
00088 extern int _rpmps_debug;
00089 
00090 /*@unchecked@*/
00091 extern int _rpmsq_debug;
00092 
00093 /*@unchecked@*/
00094 extern int _rpmsx_debug;
00095 
00096 /*@unchecked@*/
00097 extern int _rpmte_debug;
00098 
00099 /*@unchecked@*/
00100 extern int _rpmts_debug;
00101 
00102 /*@unchecked@*/
00103 extern int _rpmts_stats;
00104 
00105 /*@unchecked@*/
00106 extern int _tar_debug;
00107 
00108 /*@unchecked@*/
00109 extern int noLibio;
00110 /*@=exportheadervar@*/
00111 
00112 /*@unchecked@*/ /*@null@*/
00113 const char * rpmcliPipeOutput = NULL;
00114 
00115 /*@unchecked@*/ /*@null@*/
00116 const char * rpmcliRcfile = NULL;
00117 
00118 /*@unchecked@*/
00119 const char * rpmcliRootDir = "/";
00120 
00121 /*@unchecked@*/
00122 rpmQueryFlags rpmcliQueryFlags;
00123 
00124 /*@unchecked@*/ /*@null@*/
00125 const char * rpmcliTargets = NULL;
00126 
00127 /*@-exportheadervar@*/
00128 /*@unchecked@*/
00129 extern int _ftp_debug;
00130 /*@unchecked@*/
00131 extern int _av_debug;
00132 /*@unchecked@*/
00133 extern int _dav_debug;
00134 
00135 /*@unchecked@*/
00136 extern int noLibio;
00137 
00138 /*@unchecked@*/
00139 extern int _rpmio_debug;
00140 /*@=exportheadervar@*/
00141 
00142 /*@unchecked@*/
00143 static int rpmcliInitialized = -1;
00144 
00148 static void printVersion(FILE * fp)
00149         /*@globals rpmEVR, fileSystem @*/
00150         /*@modifies *fp, fileSystem @*/
00151 {
00152     fprintf(fp, _("RPM version %s\n"), rpmEVR);
00153 }
00154 
00155 void rpmcliConfigured(void)
00156         /*@globals rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
00157                 h_errno, fileSystem, internalState @*/
00158         /*@modifies rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
00159                 fileSystem, internalState @*/
00160 {
00161 
00162     if (rpmcliInitialized < 0) {
00163         char * t = NULL;
00164         if (rpmcliTargets != NULL) {
00165             char *te;
00166             t = xstrdup(rpmcliTargets);
00167             if ((te = strchr(t, ',')) != NULL)
00168                 *te = '\0';
00169         }
00170         rpmcliInitialized = rpmReadConfigFiles(rpmcliRcfile, t);
00171         t = _free(t);
00172     }
00173     if (rpmcliInitialized)
00174         exit(EXIT_FAILURE);
00175 }
00176 
00179 /*@-bounds@*/
00180 static void rpmcliAllArgCallback(poptContext con,
00181                 /*@unused@*/ enum poptCallbackReason reason,
00182                 const struct poptOption * opt, const char * arg,
00183                 /*@unused@*/ const void * data)
00184         /*@globals rpmRcfiles, rpmcliTargets, rpmcliQueryFlags, rpmCLIMacroContext,
00185                 rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00186         /*@modifies con, rpmcliTargets, rpmcliQueryFlags, rpmCLIMacroContext,
00187                 rpmGlobalMacroContext, fileSystem, internalState @*/
00188 {
00189 
00190     /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
00191     /*@-branchstate@*/
00192     if (opt->arg == NULL)
00193     switch (opt->val) {
00194     case 'q':
00195         rpmSetVerbosity(RPMMESS_QUIET);
00196         break;
00197     case 'v':
00198         rpmIncreaseVerbosity();
00199         break;
00200     case POPT_PREDEFINE:
00201         (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00202         break;
00203     case 'D':
00204     {   char *s, *t;
00205         /* XXX Convert '-' in macro name to underscore, skip leading %. */
00206         s = t = xstrdup(arg);
00207         while (*t && !xisspace(*t)) {
00208             if (*t == '-') *t = '_';
00209             t++;
00210         }
00211         t = s;
00212         if (*t == '%') t++;
00213         /* XXX Predefine macro if not initialized yet. */
00214         if (rpmcliInitialized < 0)
00215             (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
00216         rpmcliConfigured();
00217 /*@-type@*/
00218         (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
00219         (void) rpmDefineMacro(rpmCLIMacroContext, t, RMIL_CMDLINE);
00220 /*@=type@*/
00221         s = _free(s);
00222     }   break;
00223     case 'E':
00224         rpmcliConfigured();
00225         {   const char *val = rpmExpand(arg, NULL);
00226             fprintf(stdout, "%s\n", val);
00227             val = _free(val);
00228         }
00229         break;
00230     case POPT_SHOWVERSION:
00231         printVersion(stdout);
00232 /*@i@*/ con = rpmcliFini(con);
00233         exit(EXIT_SUCCESS);
00234         /*@notreached@*/ break;
00235     case POPT_SHOWRC:
00236         rpmcliConfigured();
00237         (void) rpmShowRC(stdout);
00238 /*@i@*/ con = rpmcliFini(con);
00239         exit(EXIT_SUCCESS);
00240         /*@notreached@*/ break;
00241     case POPT_QUERYTAGS:
00242         rpmDisplayQueryTags(stdout);
00243 /*@i@*/ con = rpmcliFini(con);
00244         exit(EXIT_SUCCESS);
00245         /*@notreached@*/ break;
00246 #if defined(POPT_RCFILE)
00247     case POPT_RCFILE:           /* XXX FIXME: noop for now */
00248         break;
00249 #endif
00250     case RPMCLI_POPT_NODIGEST:
00251         rpmcliQueryFlags |= VERIFY_DIGEST;
00252         break;
00253 
00254     case RPMCLI_POPT_NOSIGNATURE:
00255         rpmcliQueryFlags |= VERIFY_SIGNATURE;
00256         break;
00257 
00258     case RPMCLI_POPT_NOHDRCHK:
00259         rpmcliQueryFlags |= VERIFY_HDRCHK;
00260         break;
00261 
00262     case RPMCLI_POPT_TARGETPLATFORM:
00263         if (rpmcliTargets == NULL)
00264             rpmcliTargets = xstrdup(arg);
00265         else {
00266 /*@-modobserver @*/
00267             char * t = (char *) rpmcliTargets;
00268             size_t nb = strlen(t) + (sizeof(",")-1) + strlen(arg) + 1;
00269 /*@i@*/     t = xrealloc(t, nb);
00270             (void) stpcpy( stpcpy(t, ","), arg);
00271             rpmcliTargets = t;
00272 /*@=modobserver @*/
00273         }
00274         break;
00275     }
00276     /*@=branchstate@*/
00277 }
00278 
00279 /*@unchecked@*/
00280 int ftsOpts = 0;
00281 
00282 /*@unchecked@*/
00283 struct poptOption rpmcliFtsPoptTable[] = {
00284  { "comfollow", '\0', POPT_BIT_SET,     &ftsOpts, FTS_COMFOLLOW,
00285         N_("FTS_COMFOLLOW: follow command line symlinks"), NULL },
00286  { "logical", '\0', POPT_BIT_SET,       &ftsOpts, FTS_LOGICAL,
00287         N_("FTS_LOGICAL: logical walk"), NULL },
00288  { "nochdir", '\0', POPT_BIT_SET,       &ftsOpts, FTS_NOCHDIR,
00289         N_("FTS_NOCHDIR: don't change directories"), NULL },
00290  { "nostat", '\0', POPT_BIT_SET,        &ftsOpts, FTS_NOSTAT,
00291         N_("FTS_NOSTAT: don't get stat info"), NULL },
00292  { "physical", '\0', POPT_BIT_SET,      &ftsOpts, FTS_PHYSICAL,
00293         N_("FTS_PHYSICAL: physical walk"), NULL },
00294  { "seedot", '\0', POPT_BIT_SET,        &ftsOpts, FTS_SEEDOT,
00295         N_("FTS_SEEDOT: return dot and dot-dot"), NULL },
00296  { "xdev", '\0', POPT_BIT_SET,          &ftsOpts, FTS_XDEV,
00297         N_("FTS_XDEV: don't cross devices"), NULL },
00298  { "whiteout", '\0', POPT_BIT_SET,      &ftsOpts, FTS_WHITEOUT,
00299         N_("FTS_WHITEOUT: return whiteout information"), NULL },
00300    POPT_TABLEEND
00301 };
00302 
00303 /*@unchecked@*/
00304 int global_depFlags;
00305 
00306 /*@unchecked@*/
00307 struct poptOption rpmcliDepFlagsPoptTable[] = {
00308  { "aid", '\0', POPT_BIT_SET, &global_depFlags, RPMDEPS_FLAG_ADDINDEPS,
00309         N_("add suggested packages to transaction"), NULL },
00310  { "anaconda", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00311         &global_depFlags, RPMDEPS_FLAG_ANACONDA|RPMDEPS_FLAG_DEPLOOPS,
00312         N_("use anaconda \"presentation order\""), NULL},
00313  { "deploops", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00314         &global_depFlags, RPMDEPS_FLAG_DEPLOOPS,
00315         N_("print dependency loops as warning"), NULL},
00316  { "nosuggest", '\0', POPT_BIT_SET,
00317         &global_depFlags, RPMDEPS_FLAG_NOSUGGEST,
00318         N_("do not suggest missing dependency resolution(s)"), NULL},
00319  { "noconflicts", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00320         &global_depFlags, RPMDEPS_FLAG_NOCONFLICTS,
00321         N_("do not check added package conflicts"), NULL},
00322  { "nolinktos", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00323         &global_depFlags, RPMDEPS_FLAG_NOLINKTOS,
00324         N_("ignore added package requires on symlink targets"), NULL},
00325  { "noobsoletes", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00326         &global_depFlags, RPMDEPS_FLAG_NOOBSOLETES,
00327         N_("ignore added package obsoletes"), NULL},
00328  { "noparentdirs", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00329         &global_depFlags, RPMDEPS_FLAG_NOPARENTDIRS,
00330         N_("ignore added package requires on file parent directory"), NULL},
00331  { "norequires", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00332         &global_depFlags, RPMDEPS_FLAG_NOREQUIRES,
00333         N_("do not check added package requires"), NULL},
00334  { "noupgrade", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
00335         &global_depFlags, RPMDEPS_FLAG_NOUPGRADE,
00336         N_("ignore added package upgrades"), NULL},
00337    POPT_TABLEEND
00338 };
00339 
00340 /*@-bitwisesigned -compmempass @*/
00341 /*@unchecked@*/
00342 struct poptOption rpmcliAllPoptTable[] = {
00343 /*@-type@*/ /* FIX: cast? */
00344  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
00345         rpmcliAllArgCallback, 0, NULL, NULL },
00346 /*@=type@*/
00347 
00348  { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
00349         NULL, NULL },
00350 
00351 #if defined(POPT_ARGFLAG_RANDOM)
00352  { "rsegfault", '\0', POPT_ARG_INT|POPT_ARGFLAG_RANDOM|POPT_ARGFLAG_DOC_HIDDEN,
00353         &_rsegfault, 0, NULL, NULL },
00354  { "wsegfault", '\0', POPT_ARG_INT|POPT_ARGFLAG_RANDOM|POPT_ARGFLAG_DOC_HIDDEN,
00355         &_wsegfault, 0, NULL, NULL },
00356 #endif
00357 
00358  { "predefine", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_PREDEFINE,
00359         N_("predefine MACRO with value EXPR"),
00360         N_("'MACRO EXPR'") },
00361  { "define", 'D', POPT_ARG_STRING, 0, 'D',
00362         N_("define MACRO with value EXPR"),
00363         N_("'MACRO EXPR'") },
00364  { "eval", 'E', POPT_ARG_STRING, 0, 'E',
00365         N_("print macro expansion of EXPR"),
00366         N_("'EXPR'") },
00367  { "macros", '\0', POPT_ARG_STRING, &rpmMacrofiles, 0,
00368         N_("read <FILE:...> instead of default file(s)"),
00369         N_("<FILE:...>") },
00370  { "target", '\0', POPT_ARG_STRING, 0,  RPMCLI_POPT_TARGETPLATFORM,
00371         N_("specify target platform"), N_("CPU-VENDOR-OS") },
00372 
00373  { "nodigest", '\0', 0, 0, RPMCLI_POPT_NODIGEST,
00374         N_("don't verify package digest(s)"), NULL },
00375  { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
00376         N_("don't verify database header(s) when retrieved"), NULL },
00377 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00378  { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00379         N_("disable use of libio(3) API"), NULL},
00380 #endif
00381  { "nosignature", '\0', 0, 0, RPMCLI_POPT_NOSIGNATURE,
00382         N_("don't verify package signature(s)"), NULL },
00383 
00384  { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
00385         N_("send stdout to CMD"),
00386         N_("CMD") },
00387 #if !defined(POPT_RCFILE)
00388  { "rcfile", '\0', POPT_ARG_STRING, &rpmcliRcfile, 0,
00389         N_("read <FILE:...> instead of default file(s)"),
00390         N_("<FILE:...>") },
00391 #else
00392  { "rcfile", '\0', 0, NULL, POPT_RCFILE,        
00393         N_("read <FILE:...> instead of default file(s)"),
00394         N_("<FILE:...>") },
00395 #endif
00396  { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
00397         N_("use ROOT as top level directory"),
00398         N_("ROOT") },
00399 
00400  { "querytags", '\0', 0, 0, POPT_QUERYTAGS,
00401         N_("display known query tags"), NULL },
00402  { "showrc", '\0', 0, NULL, POPT_SHOWRC,
00403         N_("display final rpmrc and macro configuration"), NULL },
00404  { "quiet", '\0', 0, NULL, 'q',
00405         N_("provide less detailed output"), NULL},
00406  { "verbose", 'v', 0, NULL, 'v',
00407         N_("provide more detailed output"), NULL},
00408  { "version", '\0', 0, NULL, POPT_SHOWVERSION,
00409         N_("print the version of rpm being used"), NULL },
00410 
00411 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00412  { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00413        N_("disable use of libio(3) API"), NULL},
00414 #endif
00415 
00416  { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
00417         NULL, NULL},
00418 
00419  { "cpiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_cpio_debug, -1,
00420         N_("debug cpio payloads"), NULL},
00421  { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
00422         NULL, NULL},
00423  { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
00424         N_("debug payload file state machine"), NULL},
00425  { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1,
00426         N_("use threads for file state machine"), NULL},
00427  { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
00428         N_("debug FTP/HTTP data stream"), NULL},
00429  { "avdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_av_debug, -1,
00430         N_("debug argv collections"), NULL},
00431  { "davdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_dav_debug, -1,
00432         N_("debug WebDAV data stream"), NULL},
00433  { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
00434         NULL, NULL},
00435  { "miredebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_mire_debug, -1,
00436         NULL, NULL},
00437 #ifdef  DYING
00438  { "poptdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_popt_debug, -1,
00439         N_("debug option/argument processing"), NULL},
00440 #endif
00441  { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
00442         NULL, NULL},
00443  { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
00444         N_("debug package state machine"), NULL},
00445  { "psmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_threads, -1,
00446         N_("use threads for package state machine"), NULL},
00447  { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
00448         NULL, NULL},
00449  { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
00450         NULL, NULL},
00451  { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
00452         NULL, NULL},
00453  { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
00454         NULL, NULL},
00455  { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
00456         NULL, NULL},
00457  { "rpmgidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
00458         NULL, NULL},
00459  { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
00460         N_("debug rpmio I/O"), NULL},
00461  { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
00462         NULL, NULL},
00463  { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1,
00464         NULL, NULL},
00465  { "rpmsxdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsx_debug, -1,
00466         NULL, NULL},
00467  { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
00468         NULL, NULL},
00469  { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
00470         NULL, NULL},
00471  { "tardebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_tar_debug, -1,
00472         N_("debug tar payloads"), NULL},
00473  { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
00474         NULL, NULL},
00475  { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
00476         N_("debug URL cache handling"), NULL},
00477 
00478    POPT_TABLEEND
00479 };
00480 /*@=bitwisesigned =compmempass @*/
00481 
00482 poptContext
00483 rpmcliFini(poptContext optCon)
00484 {
00485     /* keeps memory leak checkers quiet */
00486     rpmFreeMacros(NULL);
00487 /*@i@*/ rpmFreeMacros(rpmCLIMacroContext);
00488     rpmFreeRpmrc();
00489 #ifdef  WITH_LUA
00490     (void) rpmluaFree(NULL);
00491 #endif
00492     rpmFreeFilesystems();
00493 /*@i@*/ urlFreeCache();
00494     rpmlogClose();
00495 /*@i@*/ rpmcliTargets = _free(rpmcliTargets);
00496 
00497     rpmTags->byName = _free(rpmTags->byName);
00498     rpmTags->byValue = _free(rpmTags->byValue);
00499 
00500     optCon = poptFreeContext(optCon);
00501 
00502 #if HAVE_MCHECK_H && HAVE_MTRACE
00503     /*@-noeffect@*/
00504     muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
00505     /*@=noeffect@*/
00506 #endif
00507 
00508     return NULL;
00509 }
00510 
00511 /*@-globstate@*/
00512 poptContext
00513 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
00514 {
00515     const char * optArg;
00516     poptContext optCon;
00517     int rc;
00518 
00519 #if HAVE_MCHECK_H && HAVE_MTRACE
00520     /*@-noeffect@*/
00521     mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
00522     /*@=noeffect@*/
00523 #endif
00524 /*@-globs -mods@*/
00525     setprogname(argv[0]);       /* Retrofit glibc __progname */
00526 
00527     /* XXX glibc churn sanity */
00528     if (__progname == NULL) {
00529         if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
00530         else __progname = argv[0];
00531     }
00532 /*@=globs =mods@*/
00533 
00534 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
00535     (void) setlocale(LC_ALL, "" );
00536     (void) bindtextdomain(PACKAGE, LOCALEDIR);
00537     (void) textdomain(PACKAGE);
00538 #endif
00539 
00540     rpmSetVerbosity(RPMMESS_NORMAL);
00541 
00542     if (optionsTable == NULL) {
00543         /* Read rpm configuration (if not already read). */
00544         rpmcliConfigured();
00545         return NULL;
00546     }
00547 
00548 /*@-nullpass -temptrans@*/
00549     optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
00550 /*@=nullpass =temptrans@*/
00551     (void) poptReadConfigFile(optCon, RPMPOPTFILE);
00552     (void) poptReadDefaultConfig(optCon, 1);
00553     poptSetExecPath(optCon, USRLIBRPM, 1);
00554 
00555     /* Process all options, whine if unknown. */
00556     while ((rc = poptGetNextOpt(optCon)) > 0) {
00557         optArg = poptGetOptArg(optCon);
00558         switch (rc) {
00559         default:
00560 /*@-nullpass@*/
00561             fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
00562                 __progname, rc);
00563 /*@=nullpass@*/
00564             exit(EXIT_FAILURE);
00565 
00566             /*@notreached@*/ /*@switchbreak@*/ break;
00567         }
00568     }
00569 
00570     if (rc < -1) {
00571 /*@-nullpass@*/
00572         fprintf(stderr, "%s: %s: %s\n", __progname,
00573                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00574                 poptStrerror(rc));
00575 /*@=nullpass@*/
00576         exit(EXIT_FAILURE);
00577     }
00578 
00579     /* Read rpm configuration (if not already read). */
00580     rpmcliConfigured();
00581 
00582     if (_debug) {
00583         rpmIncreaseVerbosity();
00584         rpmIncreaseVerbosity();
00585     }
00586 
00587     return optCon;
00588 }
00589 /*@=globstate@*/

Generated on Fri Sep 7 01:07:22 2007 for rpm by  doxygen 1.5.1