Avoid accidental collisions with POPT_BIT_SET for flags in popt tables.
[platform/upstream/rpm.git] / lib / poptI.c
1 /** \ingroup rpmcli
2  * \file lib/poptI.c
3  *  Popt tables for install modes.
4  */
5
6 #include "system.h"
7
8 #include <rpmcli.h>
9
10 #include "debug.h"
11
12 /*@-redecl@*/
13 extern time_t get_date(const char * p, void * now);     /* XXX expedient lies */
14 /*@=redecl@*/
15
16 /*@unchecked@*/
17 struct rpmInstallArguments_s rpmIArgs;
18
19 #define POPT_RELOCATE           -1016
20 #define POPT_EXCLUDEPATH        -1019
21 #define POPT_ROLLBACK           -1024
22
23 /*@exits@*/ static void argerror(const char * desc)
24         /*@*/
25 {
26     /*@-modfilesys -globs @*/
27     fprintf(stderr, _("%s: %s\n"), __progname, desc);
28     /*@=modfilesys =globs @*/
29     exit(EXIT_FAILURE);
30 }
31
32 /**
33  */
34 static void installArgCallback( /*@unused@*/ poptContext con,
35                 /*@unused@*/ enum poptCallbackReason reason,
36                 const struct poptOption * opt, const char * arg,
37                 /*@unused@*/ const void * data)
38         /*@globals rpmIArgs */
39         /*@modifies rpmIArgs */
40 {
41     struct rpmInstallArguments_s * ia = &rpmIArgs;
42
43 #if 0
44 fprintf(stderr, "*** opt %s %c info 0x%x arg %p val 0x%x arg %p %s\n", opt->longName, opt->shortName, opt->argInfo, opt->arg, opt->val, arg, arg);
45 #endif
46
47     /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
48     /*@-branchstate@*/
49     if (opt->arg == NULL)
50     switch (opt->val) {
51     case POPT_EXCLUDEPATH:
52         if (arg == NULL || *arg != '/') 
53             argerror(_("exclude paths must begin with a /"));
54         ia->relocations = xrealloc(ia->relocations, 
55                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
56         /*@-temptrans@*/
57         ia->relocations[ia->numRelocations].oldPath = arg;
58         /*@=temptrans@*/
59         ia->relocations[ia->numRelocations].newPath = NULL;
60         ia->numRelocations++;
61         break;
62     case POPT_RELOCATE:
63       { char * newPath = NULL;
64         if (arg == NULL || *arg != '/') 
65             argerror(_("relocations must begin with a /"));
66         if (!(newPath = strchr(arg, '=')))
67             argerror(_("relocations must contain a ="));
68         *newPath++ = '\0';
69         if (*newPath != '/') 
70             argerror(_("relocations must have a / following the ="));
71         ia->relocations = xrealloc(ia->relocations, 
72                         sizeof(*ia->relocations) * (ia->numRelocations + 1));
73         /*@-temptrans@*/
74         ia->relocations[ia->numRelocations].oldPath = arg;
75         /*@=temptrans@*/
76         /*@-kepttrans@*/
77         ia->relocations[ia->numRelocations].newPath = newPath;
78         /*@=kepttrans@*/
79         ia->numRelocations++;
80       } break;
81     case POPT_ROLLBACK:
82       { time_t tid;
83         if (arg == NULL)
84             argerror(_("rollback takes a time/date stamp argument"));
85
86         /*@-moduncon@*/
87         tid = get_date(arg, NULL);
88         /*@=moduncon@*/
89
90         if (tid == (time_t)-1 || tid == (time_t)0)
91             argerror(_("malformed rollback time/date stamp argument"));
92         ia->rbtid = tid;
93       } break;
94     }
95     /*@=branchstate@*/
96 }
97
98 /**
99  */
100 /*@-bitwisesigned -compmempass @*/
101 /*@unchecked@*/
102 struct poptOption rpmInstallPoptTable[] = {
103 /*@-type@*/ /* FIX: cast? */
104  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
105         installArgCallback, 0, NULL, NULL },
106 /*@=type@*/
107
108  { "allfiles", '\0', POPT_BIT_SET,
109         &rpmIArgs.transFlags, RPMTRANS_FLAG_ALLFILES,
110   N_("install all files, even configurations which might otherwise be skipped"),
111         NULL},
112  { "allmatches", '\0', POPT_BIT_SET,
113         &rpmIArgs.eraseInterfaceFlags, UNINSTALL_ALLMATCHES,
114         N_("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"),
115         NULL},
116
117  { "apply", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
118         (_noTransScripts|_noTransTriggers|
119                 RPMTRANS_FLAG_APPLYONLY|RPMTRANS_FLAG_PKGCOMMIT),
120         N_("do not execute package scriptlet(s)"), NULL },
121
122  { "badreloc", '\0', POPT_BIT_SET,
123         &rpmIArgs.probFilter, RPMPROB_FILTER_FORCERELOCATE,
124         N_("relocate files in non-relocateable package"), NULL},
125  { "dirstash", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
126         &rpmIArgs.transFlags, RPMTRANS_FLAG_DIRSTASH,
127         N_("save erased package files by renaming into sub-directory"), NULL},
128  { "erase", 'e', POPT_BIT_SET,
129         &rpmIArgs.installInterfaceFlags, INSTALL_ERASE,
130         N_("erase (uninstall) package"), N_("<package>+") },
131  { "excludedocs", '\0', POPT_BIT_SET,
132         &rpmIArgs.transFlags, RPMTRANS_FLAG_NODOCS,
133         N_("do not install documentation"), NULL},
134  { "excludepath", '\0', POPT_ARG_STRING, 0, POPT_EXCLUDEPATH,
135         N_("skip files with leading component <path> "),
136         N_("<path>") },
137  { "force", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
138         (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE),
139         N_("short hand for --replacepkgs --replacefiles"), NULL},
140  { "freshen", 'F', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags,
141         (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL),
142         N_("upgrade package(s) if already installed"),
143         N_("<packagefile>+") },
144  { "hash", 'h', POPT_BIT_SET, &rpmIArgs.installInterfaceFlags, INSTALL_HASH,
145         N_("print hash marks as package installs (good with -v)"), NULL},
146  { "ignorearch", '\0', POPT_BIT_SET,
147         &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREARCH,
148         N_("don't verify package architecture"), NULL},
149  { "ignoreos", '\0', POPT_BIT_SET,
150         &rpmIArgs.probFilter, RPMPROB_FILTER_IGNOREOS,
151         N_("don't verify package operating system"), NULL},
152  { "ignoresize", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
153         (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES),
154         N_("don't check disk space before installing"), NULL},
155  { "includedocs", '\0', 0, &rpmIArgs.incldocs, 0,
156         N_("install documentation"), NULL},
157  { "install", '\0', POPT_BIT_SET,
158         &rpmIArgs.installInterfaceFlags, INSTALL_INSTALL,
159         N_("install package"), N_("<packagefile>+") },
160  { "justdb", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_JUSTDB,
161         N_("update the database, but do not modify the filesystem"), NULL},
162  { "nodeps", '\0', 0, &rpmIArgs.noDeps, 0,
163         N_("do not verify package dependencies"), NULL },
164  { "noorder", '\0', POPT_BIT_SET,
165         &rpmIArgs.installInterfaceFlags, INSTALL_NOORDER,
166         N_("do not reorder package installation to satisfy dependencies"),
167         NULL},
168
169  { "noscripts", '\0', POPT_BIT_SET, &rpmIArgs.transFlags,
170         (_noTransScripts|_noTransTriggers),
171         N_("do not execute package scriptlet(s)"), NULL },
172  { "nopre", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
173         RPMTRANS_FLAG_NOPRE,
174         N_("do not execute %%pre scriptlet (if any)"), NULL },
175  { "nopost", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
176         RPMTRANS_FLAG_NOPOST,
177         N_("do not execute %%post scriptlet (if any)"), NULL },
178  { "nopreun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
179         RPMTRANS_FLAG_NOPREUN,
180         N_("do not execute %%preun scriptlet (if any)"), NULL },
181  { "nopostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN, &rpmIArgs.transFlags,
182         RPMTRANS_FLAG_NOPOSTUN,
183         N_("do not execute %%postun scriptlet (if any)"), NULL },
184
185  { "notriggers", '\0', POPT_BIT_SET, &rpmIArgs.transFlags,
186         _noTransTriggers,
187         N_("do not execute any scriptlet(s) triggered by this package"), NULL},
188  { "notriggerprein", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
189         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPREIN,
190         N_("do not execute any %%triggerprein scriptlet(s)"), NULL},
191  { "notriggerin", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
192         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERIN,
193         N_("do not execute any %%triggerin scriptlet(s)"), NULL},
194  { "notriggerun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
195         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERUN,
196         N_("do not execute any %%triggerun scriptlet(s)"), NULL},
197  { "notriggerpostun", '\0', POPT_BIT_SET|POPT_ARGFLAG_DOC_HIDDEN,
198         &rpmIArgs.transFlags, RPMTRANS_FLAG_NOTRIGGERPOSTUN,
199         N_("do not execute any %%triggerpostun scriptlet(s)"), NULL},
200
201  { "oldpackage", '\0', POPT_BIT_SET,
202         &rpmIArgs.probFilter, RPMPROB_FILTER_OLDPACKAGE,
203         N_("upgrade to an old version of the package (--force on upgrades does this automatically)"),
204         NULL},
205  { "percent", '\0', POPT_BIT_SET,
206         &rpmIArgs.installInterfaceFlags, INSTALL_PERCENT,
207         N_("print percentages as package installs"), NULL},
208  { "prefix", '\0', POPT_ARG_STRING, &rpmIArgs.prefix, 0,
209         N_("relocate the package to <dir>, if relocatable"),
210         N_("<dir>") },
211  { "relocate", '\0', POPT_ARG_STRING, 0, POPT_RELOCATE,
212         N_("relocate files from path <old> to <new>"),
213         N_("<old>=<new>") },
214  { "repackage", '\0', POPT_BIT_SET,
215         &rpmIArgs.transFlags, RPMTRANS_FLAG_REPACKAGE,
216         N_("save erased package files by repackaging"), NULL},
217  { "replacefiles", '\0', POPT_BIT_SET, &rpmIArgs.probFilter,
218         (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
219         N_("install even if the package replaces installed files"), NULL},
220  { "replacepkgs", '\0', POPT_BIT_SET,
221         &rpmIArgs.probFilter, RPMPROB_FILTER_REPLACEPKG,
222         N_("reinstall if the package is already present"), NULL},
223  { "rollback", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_ROLLBACK,
224         N_("deinstall new, reinstall old, package(s), back to <date>"),
225         N_("<date>") },
226  { "test", '\0', POPT_BIT_SET, &rpmIArgs.transFlags, RPMTRANS_FLAG_TEST,
227         N_("don't install, but tell if it would work or not"), NULL},
228  { "upgrade", 'U', POPT_BIT_SET,
229         &rpmIArgs.installInterfaceFlags, (INSTALL_UPGRADE|INSTALL_INSTALL),
230         N_("upgrade package(s)"),
231         N_("<packagefile>+") },
232
233    POPT_TABLEEND
234 };
235 /*@=bitwisesigned =compmempass @*/