Start rpm commandline compatible wrapper.
1.1 --- a/Makefile Wed Apr 30 18:22:47 2008 -0400
1.2 +++ b/Makefile Tue Jun 03 15:21:22 2008 -0400
1.3 @@ -1,7 +1,7 @@
1.4 CFLAGS = -Wall -Wstrict-prototypes -Wmissing-prototypes -g
1.5 LDLIBS = -lexpat -lz -g -lrpm -lcurl
1.6
1.7 -all : razor test-driver
1.8 +all : razor test-driver rpm-razor
1.9
1.10 razor : razor.o yum.o main.o rpm.o types.o util.o
1.11
1.12 @@ -10,6 +10,8 @@
1.13
1.14 test-driver : razor.o types.o util.o test-driver.o
1.15
1.16 +rpm-razor : rpm-razor.o
1.17 +
1.18 test : test-driver
1.19 ./test-driver test.xml
1.20
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/rpm-razor.c Tue Jun 03 15:21:22 2008 -0400
2.3 @@ -0,0 +1,482 @@
2.4 +/*
2.5 + * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
2.6 + * Copyright (C) 2008 Red Hat, Inc
2.7 + *
2.8 + * This program is free software; you can redistribute it and/or modify
2.9 + * it under the terms of the GNU General Public License as published by
2.10 + * the Free Software Foundation; either version 2 of the License, or
2.11 + * (at your option) any later version.
2.12 + *
2.13 + * This program is distributed in the hope that it will be useful,
2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.16 + * GNU General Public License for more details.
2.17 + *
2.18 + * You should have received a copy of the GNU General Public License along
2.19 + * with this program; if not, write to the Free Software Foundation, Inc.,
2.20 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2.21 + */
2.22 +
2.23 +#include <stdlib.h>
2.24 +#include <string.h>
2.25 +#include <stdio.h>
2.26 +#include "razor.h"
2.27 +
2.28 +enum option_type {
2.29 + OPTION_LAST,
2.30 + OPTION_GROUP,
2.31 + OPTION_BOOL,
2.32 + OPTION_STRING
2.33 +};
2.34 +
2.35 +struct option {
2.36 + enum option_type type;
2.37 + const char *name;
2.38 + char short_name;
2.39 + const char *arg_name;
2.40 + const char *description;
2.41 + void *data;
2.42 +};
2.43 +
2.44 +static int option_all;
2.45 +
2.46 +static const struct option query_options[] = {
2.47 + { OPTION_BOOL, "configfiles", 'c', NULL, "list all configuration files", NULL },
2.48 + { OPTION_BOOL, "docfiles", 'd', NULL, "list all documentation files", NULL },
2.49 + { OPTION_BOOL, "dump", 0, NULL, "dump basic file information", NULL },
2.50 + { OPTION_BOOL, "list", 0, NULL, "list files in package", NULL },
2.51 + { OPTION_STRING, "queryformat", 0, "QUERYFORMAT", "use the following query format", NULL },
2.52 + { OPTION_BOOL, "state", 's', NULL, "display the states of the listed files", NULL },
2.53 + { OPTION_BOOL, "all", 'a', NULL, "query/verify all packages", &option_all },
2.54 + { OPTION_BOOL, "file", 'f', NULL, "query/verify package(s) owning file", NULL },
2.55 + { OPTION_BOOL, "group", 'g', NULL, "query/verify package(s) in group", NULL },
2.56 + { OPTION_BOOL, "package", 'p', NULL, "query/verify a package file", NULL },
2.57 + { OPTION_BOOL, "ftswalk", 'W', NULL, "query/verify package(s) from TOP file tree walk", NULL },
2.58 + { OPTION_BOOL, "pkgid", 0, NULL, "query/verify package(s) with package identifier", NULL },
2.59 + { OPTION_BOOL, "hdrid", 0, NULL, "query/verify package(s) with header identifier", NULL },
2.60 + { OPTION_BOOL, "fileid", 0, NULL, "query/verify package(s) with file identifier", NULL },
2.61 + { OPTION_BOOL, "specfile", 0, NULL, "query a spec file", NULL, },
2.62 + { OPTION_BOOL, "triggeredby", 0, NULL, "query the package(s) triggered by the package", NULL },
2.63 + { OPTION_BOOL, "whatrequires", 0, NULL, "query/verify the package(s) which require a dependency", NULL },
2.64 + { OPTION_BOOL, "whatprovides", 0, NULL, "query/verify the package(s) which provide a dependency", NULL },
2.65 + { OPTION_BOOL, "nomanifest", 0, NULL, "do not process non-package files as manifests", NULL },
2.66 + { }
2.67 +};
2.68 +
2.69 +static const struct option verify_options[] = {
2.70 + { OPTION_BOOL, "nomd5", 0, NULL, "don't verify MD5 digest of files", NULL },
2.71 + { OPTION_BOOL, "nofiles", 0, NULL, "don't verify files in package", NULL },
2.72 + { OPTION_BOOL, "nodeps", 0, NULL, "don't verify package dependencies", NULL },
2.73 + { OPTION_BOOL, "noscript", 0, NULL, "don't execute verify script(s)", NULL, },
2.74 + { OPTION_BOOL, "all", 'a', NULL, "query/verify all packages", NULL },
2.75 + { OPTION_BOOL, "file", 'f', NULL, "query/verify package(s) owning file", NULL },
2.76 + { OPTION_BOOL, "group", 'g', NULL, "query/verify package(s) in group", NULL },
2.77 + { OPTION_BOOL, "package", 'p', NULL, "query/verify a package file", NULL },
2.78 + { OPTION_BOOL, "ftswalk", 'W', NULL, "query/verify package(s) from TOP file tree walk", NULL },
2.79 + { OPTION_BOOL, "pkgid", 0, NULL, "query/verify package(s) with package identifier", NULL },
2.80 + { OPTION_BOOL, "hdrid", 0, NULL, "query/verify package(s) with header identifier", NULL },
2.81 + { OPTION_BOOL, "fileid", 0, NULL, "query/verify package(s) with file identifier", NULL },
2.82 + { OPTION_BOOL, "specfile", 0, NULL, "query a spec file", NULL },
2.83 + { OPTION_BOOL, "triggeredby", 0, NULL, "query the package(s) triggered by the package", NULL },
2.84 + { OPTION_BOOL, "whatrequires", 0, NULL, "query/verify the package(s) which require a dependency", NULL },
2.85 + { OPTION_BOOL, "whatprovides", 0, NULL, "query/verify the package(s) which provide a dependency", NULL },
2.86 + { OPTION_BOOL, "nomanifest", 0, NULL, "do not process non-package files as manifests", NULL },
2.87 + { }
2.88 +};
2.89 +
2.90 +static const struct option ftw_options[] = {
2.91 + { OPTION_BOOL, "comfollow", 0, NULL, "FTS_COMFOLLOW: follow command line symlinks", NULL },
2.92 + { OPTION_BOOL, "logical", 0, NULL, "FTS_LOGICAL: logical walk", NULL },
2.93 + { OPTION_BOOL, "nochdir", 0, NULL, "FTS_NOCHDIR: don't change directories", NULL },
2.94 + { OPTION_BOOL, "nostat", 0, NULL, "FTS_NOSTAT: don't get stat info", NULL },
2.95 + { OPTION_BOOL, "physical", 0, NULL, "FTS_PHYSICAL: physical walk", NULL },
2.96 + { OPTION_BOOL, "seedot", 0, NULL, "FTS_SEEDOT: return dot and dot-dot", NULL },
2.97 + { OPTION_BOOL, "xdev", 0, NULL, "FTS_XDEV: don't cross devices", NULL },
2.98 + { OPTION_BOOL, "whiteout", 0, NULL, "FTS_WHITEOUT: return whiteout information", NULL },
2.99 + { }
2.100 +};
2.101 +
2.102 +static const struct option signature_options[] = {
2.103 + { OPTION_BOOL, "addsign", 0, NULL, "sign package(s) (identical to --resign)", NULL, },
2.104 + { OPTION_BOOL, "checksig", 'K', NULL, "verify package signature(s)", NULL, },
2.105 + { OPTION_BOOL, "delsign", 0, NULL, "delete package signatures", NULL, },
2.106 + { OPTION_BOOL, "import", 0, NULL, "import an armored public key", NULL, },
2.107 + { OPTION_BOOL, "resign", 0, NULL, "sign package(s) (identical to --addsign)", NULL, },
2.108 + { OPTION_BOOL, "nodigest", 0, NULL, "don't verify package digest(s)", NULL, },
2.109 + { OPTION_BOOL, "nosignature", 0, NULL, "don't verify package signature(s)", NULL },
2.110 + { }
2.111 +};
2.112 +
2.113 +static const struct option database_options[] = {
2.114 + { OPTION_BOOL, "initdb", 0, NULL, "initialize database", NULL },
2.115 + { OPTION_BOOL, "rebuilddb", 0, NULL, "rebuild database inverted lists from installed package headers", NULL },
2.116 + { }
2.117 +};
2.118 +
2.119 +static int option_erase, option_install, option_upgrade;
2.120 +
2.121 +static const struct option install_options[] = {
2.122 + { OPTION_BOOL, "aid", 0, NULL, "add suggested packages to transaction", NULL, },
2.123 + { OPTION_BOOL, "allfiles", 0, NULL, "install all files, even configurations which might otherwise be skipped", NULL, },
2.124 + { OPTION_BOOL, "allmatches", 0, NULL, "remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)", NULL, },
2.125 + { OPTION_BOOL, "badreloc", 0, NULL, "relocate files in non-relocatable package", NULL },
2.126 + { OPTION_BOOL, "erase", 'e', "<package>", "erase (uninstall) package", &option_erase },
2.127 + { OPTION_BOOL, "excludedocs", 0, NULL, "do not install documentation", NULL, },
2.128 + { OPTION_BOOL, "excludepath", 0, "<path>", "skip files with leading component <path> ", NULL, },
2.129 + { OPTION_BOOL, "fileconflicts", 0, NULL, "detect file conflicts between packages", NULL, },
2.130 + { OPTION_BOOL, "force", 0, NULL, "short hand for --replacepkgs --replacefiles", NULL },
2.131 + { OPTION_BOOL, "freshen", 'F', "<packagefile>+", "upgrade package(s) if already installed", NULL },
2.132 + { OPTION_BOOL, "hash", 'h', NULL, "print hash marks as package installs (good with -v)", NULL },
2.133 + { OPTION_BOOL, "ignorearch", 0, NULL, "don't verify package architecture", NULL, },
2.134 + { OPTION_BOOL, "ignoreos", 0, NULL, "don't verify package operating system", NULL, },
2.135 + { OPTION_BOOL, "ignoresize", 0, NULL, "don't check disk space before installing", NULL },
2.136 + { OPTION_BOOL, "install", 'i', NULL, "install package(s)", &option_install },
2.137 + { OPTION_BOOL, "justdb", 0, NULL, "update the database, but do not modify the filesystem", NULL, },
2.138 + { OPTION_BOOL, "nodeps", 0, NULL, "do not verify package dependencies", NULL, },
2.139 + { OPTION_BOOL, "nomd5", 0, NULL, "don't verify MD5 digest of files", NULL, },
2.140 + { OPTION_BOOL, "nocontexts", 0, NULL, "don't install file security contexts", NULL, },
2.141 + { OPTION_BOOL, "noorder", 0, NULL, "do not reorder package installation to satisfy dependencies", NULL, },
2.142 + { OPTION_BOOL, "nosuggest", 0, NULL, "do not suggest missing dependency resolution(s)", NULL, },
2.143 + { OPTION_BOOL, "noscripts", 0, NULL, "do not execute package scriptlet(s)", NULL, },
2.144 + { OPTION_BOOL, "notriggers", 0, NULL, "do not execute any scriptlet(s) triggered by this package", NULL, },
2.145 + { OPTION_BOOL, "oldpackage", 0, NULL, "upgrade to an old version of the package (--force on upgrades does this automatically)", NULL },
2.146 + { OPTION_BOOL, "percent", 0, NULL, "print percentages as package installs", NULL, },
2.147 + { OPTION_STRING, "prefix", 0, "<dir>", "relocate the package to <dir>, if relocatable", NULL, },
2.148 + { OPTION_STRING, "relocate", 0, "<old>=<new>", "relocate files from path <old> to <new>", NULL, },
2.149 + { OPTION_BOOL, "repackage", 0, NULL, "save erased package files by repackaging", NULL, },
2.150 + { OPTION_BOOL, "replacefiles", 0, NULL, "ignore file conflicts between packages", NULL, },
2.151 + { OPTION_BOOL, "replacepkgs", 0, NULL, "reinstall if the package is already present", NULL, },
2.152 + { OPTION_BOOL, "test", 0, NULL, "don't install, but tell if it would work or not", NULL },
2.153 + { OPTION_BOOL, "upgrade", 'U', "<packagefile>+", "upgrade package(s)", &option_upgrade },
2.154 + { }
2.155 +};
2.156 +
2.157 +static int option_version;
2.158 +
2.159 +static const struct option common_options[] = {
2.160 + { OPTION_STRING, "define", 'D', "MACRO EXPR", "define MACRO with value EXPR", NULL, },
2.161 + { OPTION_STRING, "eval", 'E', "EXPR", "print macro expansion of EXPR", NULL },
2.162 + { OPTION_STRING, "macros", 0, "<FILE:...>", "read <FILE:...> instead of default file(s)", NULL },
2.163 + { OPTION_BOOL, "nodigest", 0, NULL, "don't verify package digest(s)", NULL, },
2.164 + { OPTION_BOOL, "nosignature", 0, NULL, "don't verify package signature(s)", NULL, },
2.165 + { OPTION_STRING, "rcfile", 0, "<FILE:...>", "read <FILE:...> instead of default file(s)", NULL },
2.166 + { OPTION_STRING, "root", 'r', "ROOT", "use ROOT as top level directory (default: \"/\")", NULL },
2.167 + { OPTION_BOOL, "querytags", 0, NULL, "display known query tags", NULL, },
2.168 + { OPTION_BOOL, "showrc", 0, NULL, "display final rpmrc and macro configuration", NULL, },
2.169 + { OPTION_BOOL, "quiet", 0, NULL, "provide less detailed output", NULL },
2.170 + { OPTION_BOOL, "verbose", 'v', NULL, "provide more detailed output", NULL },
2.171 + { OPTION_BOOL, "version", 0, NULL, "print the version of rpm being used", &option_version },
2.172 + { }
2.173 +};
2.174 +
2.175 +static const struct option alias_options[] = {
2.176 + { OPTION_BOOL, "scripts", 0, NULL, "list install/erase scriptlets from package(s)", NULL, },
2.177 + { OPTION_BOOL, "setperms", 0, NULL, "set permissions of files in a package", NULL, },
2.178 + { OPTION_BOOL, "setugids", 0, NULL, "set user/group ownership of files in a package", NULL, },
2.179 + { OPTION_BOOL, "conflicts", 0, NULL, "list capabilities this package conflicts with", NULL, },
2.180 + { OPTION_BOOL, "obsoletes", 0, NULL, "list other packages removed by installing this package", NULL, },
2.181 + { OPTION_BOOL, "provides", 0, NULL, "list capabilities that this package provides", NULL, },
2.182 + { OPTION_BOOL, "requires", 0, NULL, "list capabilities required by package(s)", NULL, },
2.183 + { OPTION_BOOL, "info", 0, NULL, "list descriptive information from package(s)", NULL, },
2.184 + { OPTION_BOOL, "changelog", 0, NULL, "list change logs for this package", NULL, },
2.185 + { OPTION_BOOL, "xml", 0, NULL, "list metadata in xml", NULL, },
2.186 + { OPTION_BOOL, "triggers", 0, NULL, "list trigger scriptlets from package(s)", NULL, },
2.187 + { OPTION_BOOL, "last", 0, NULL, "list package(s) by install time, most recent first", NULL, },
2.188 + { OPTION_BOOL, "dupes", 0, NULL, "list duplicated packages", NULL, },
2.189 + { OPTION_BOOL, "filesbypkg", 0, NULL, "list all files from each package", NULL, },
2.190 + { OPTION_BOOL, "fileclass", 0, NULL, "list file names with classes", NULL, },
2.191 + { OPTION_BOOL, "filecolor", 0, NULL, "list file names with colors", NULL, },
2.192 + { OPTION_BOOL, "filecontext", 0, NULL, "list file names with security context from header", NULL, },
2.193 + { OPTION_BOOL, "fscontext", 0, NULL, "list file names with security context from file system", NULL, },
2.194 + { OPTION_BOOL, "recontext", 0, NULL, "list file names with security context from policy RE", NULL, },
2.195 + { OPTION_BOOL, "fileprovide", 0, NULL, "list file names with provides", NULL, },
2.196 + { OPTION_BOOL, "filerequire", 0, NULL, "list file names with requires", NULL, },
2.197 + { OPTION_BOOL, "redhatprovides", 0, NULL, "find package name that contains a provided capability (needs rpmdb-redhat package installed)", NULL, },
2.198 + { OPTION_BOOL, "redhatrequires", 0, NULL, "find package name that contains a required capability (needs rpmdb-redhat package installed)", NULL, },
2.199 + { OPTION_STRING, "buildpolicy", 0, "<policy>", "set buildroot <policy> (e.g. compress man pages)", NULL, },
2.200 + { OPTION_BOOL, "with", 0, "<option>", "enable configure <option> for build", NULL, },
2.201 + { OPTION_BOOL, "without", 0, "<option>", "disable configure <option> for build", NULL },
2.202 + { }
2.203 +};
2.204 +
2.205 +static int option_help, option_usage;
2.206 +
2.207 +static const struct option help_options[] = {
2.208 + { OPTION_BOOL, "help", '?', NULL, "Show this help message", &option_help },
2.209 + { OPTION_BOOL, "usage", 0, NULL, "Display brief usage message", &option_usage},
2.210 + { }
2.211 +};
2.212 +
2.213 +static int option_query, option_verify;
2.214 +
2.215 +static const struct option rpm_options[] = {
2.216 + { OPTION_BOOL, "query", 'q', NULL, "Query rpm database", &option_query },
2.217 + { OPTION_BOOL, "verify", 'V', NULL, "Verify rpm database", &option_verify },
2.218 + { OPTION_GROUP, NULL, 0, NULL, "Query options (with -q or --query):", &query_options },
2.219 + { OPTION_GROUP, NULL, 0, NULL, "Verify options (with -V or --verify):", &verify_options },
2.220 + { OPTION_GROUP, NULL, 0, NULL, "File tree walk options (with --ftswalk):", &ftw_options },
2.221 + { OPTION_GROUP, NULL, 0, NULL, "Signature options:", &signature_options },
2.222 + { OPTION_GROUP, NULL, 0, NULL, "Database options:", &database_options },
2.223 + { OPTION_GROUP, NULL, 0, NULL, "Install/Upgrade/Erase options:", &install_options },
2.224 + { OPTION_GROUP, NULL, 0, NULL, "Common options for all rpm modes and executables:", &common_options },
2.225 + { OPTION_GROUP, NULL, 0, NULL, "Options implemented via popt alias/exec:", &alias_options },
2.226 + { OPTION_GROUP, NULL, 0, NULL, "Help options", &help_options },
2.227 + { }
2.228 +};
2.229 +
2.230 +static void
2.231 +command_query(int argc, const char *argv[])
2.232 +{
2.233 + if (argc == 0 && !option_all) {
2.234 + printf("no arguments given for query\n");
2.235 + exit(1);
2.236 + }
2.237 +
2.238 + printf("command query - not implemented\n");
2.239 +}
2.240 +
2.241 +static void
2.242 +command_verify(int argc, const char *argv[])
2.243 +{
2.244 + if (argc == 0) {
2.245 + printf("no arguments given for verify\n");
2.246 + exit(1);
2.247 + }
2.248 +
2.249 + printf("command verify - not implemented\n");
2.250 +}
2.251 +
2.252 +static void
2.253 +command_erase(int argc, const char *argv[])
2.254 +{
2.255 + if (argc == 0) {
2.256 + printf("no packages given for erase\n");
2.257 + exit(1);
2.258 + }
2.259 +
2.260 + printf("command erase - not implemented\n");
2.261 +}
2.262 +
2.263 +static void
2.264 +command_install(int argc, const char *argv[])
2.265 +{
2.266 + if (argc == 0) {
2.267 + printf("no packages given for install\n");
2.268 + exit(1);
2.269 + }
2.270 +
2.271 + printf("command install - not implemented\n");
2.272 +}
2.273 +
2.274 +static void
2.275 +command_update(int argc, const char *argv[])
2.276 +{
2.277 + if (argc == 0) {
2.278 + printf("no packages given for update\n");
2.279 + exit(1);
2.280 + }
2.281 +
2.282 + printf("command update - not implemented\n");
2.283 +}
2.284 +
2.285 +static const struct option *
2.286 +find_option(const struct option *options, const char *s)
2.287 +{
2.288 + const struct option *o;
2.289 + int i;
2.290 +
2.291 + for (i = 0; options[i].type != OPTION_LAST; i++) {
2.292 + switch (options[i].type) {
2.293 + case OPTION_GROUP:
2.294 + o = find_option(options[i].data, s);
2.295 + if (o != NULL)
2.296 + return o;
2.297 + break;
2.298 +
2.299 + case OPTION_BOOL:
2.300 + case OPTION_STRING:
2.301 + if (s[0] == '-' &&
2.302 + s[1] == options[i].short_name && s[2] == '\0')
2.303 + return &options[i];
2.304 + if (s[0] == '-' && s[1] == '-' &&
2.305 + strcmp(options[i].name, s + 2) == 0)
2.306 + return &options[i];
2.307 + break;
2.308 +
2.309 + case OPTION_LAST:
2.310 + break;
2.311 + }
2.312 + }
2.313 +
2.314 + return NULL;
2.315 +}
2.316 +
2.317 +static int
2.318 +parse_options(const struct option *options, int argc, const char **argv)
2.319 +{
2.320 + const struct option *o;
2.321 + int i, j;
2.322 +
2.323 + /* FIXME: Bundling... rpm -Uvh must work :) */
2.324 +
2.325 + for (i = 1, j = 0; i < argc; i++) {
2.326 + if (argv[i][0] != '-') {
2.327 + argv[j++] = argv[i];
2.328 + continue;
2.329 + }
2.330 + o = find_option(options, argv[i]);
2.331 + if (o == NULL) {
2.332 + printf("unknown option: \"%s\"\n", argv[i]);
2.333 + continue;
2.334 + }
2.335 + if (o->data == NULL) {
2.336 + printf("option \"%s\" not supported\n", argv[i]);
2.337 + continue;
2.338 + }
2.339 + switch (o->type) {
2.340 + case OPTION_BOOL:
2.341 + *(int *) o->data = 1;
2.342 + break;
2.343 +
2.344 + case OPTION_STRING:
2.345 + *(const char **) o->data =
2.346 + argv[i] + strlen(o->name) + 3;
2.347 + break;
2.348 +
2.349 + case OPTION_LAST:
2.350 + case OPTION_GROUP:
2.351 + /* Shouldn't happen. */
2.352 + break;
2.353 + }
2.354 + }
2.355 +
2.356 + return j;
2.357 +}
2.358 +
2.359 +static void
2.360 +print_options_help(const struct option *options)
2.361 +{
2.362 + int i;
2.363 +
2.364 + for (i = 0; options[i].type != OPTION_LAST; i++) {
2.365 + switch (options[i].type) {
2.366 + case OPTION_GROUP:
2.367 + printf("%s\n", options[i].description);
2.368 + print_options_help(options[i].data);
2.369 + printf("\n");
2.370 + break;
2.371 +
2.372 + case OPTION_BOOL:
2.373 + case OPTION_STRING:
2.374 + printf(" ");
2.375 + if (options[i].short_name)
2.376 + printf("-%c", options[i].short_name);
2.377 + if (options[i].short_name && options[i].name)
2.378 + printf(", ");
2.379 + if (options[i].name)
2.380 + printf("--%s", options[i].name);
2.381 + if (options[i].arg_name)
2.382 + printf("=%s", options[i].arg_name);
2.383 + if (options[i].description)
2.384 + printf("\t\t%s", options[i].description);
2.385 + printf("\n");
2.386 + break;
2.387 +
2.388 + case OPTION_LAST:
2.389 + break;
2.390 + }
2.391 + }
2.392 +}
2.393 +
2.394 +static void
2.395 +print_options_usage(const struct option *options)
2.396 +{
2.397 + int i;
2.398 +
2.399 + for (i = 0; options[i].type != OPTION_LAST; i++) {
2.400 + switch (options[i].type) {
2.401 + case OPTION_GROUP:
2.402 + print_options_usage(options[i].data);
2.403 + break;
2.404 +
2.405 + case OPTION_BOOL:
2.406 + printf("[");
2.407 + if (options[i].short_name)
2.408 + printf("-%c", options[i].short_name);
2.409 + if (options[i].short_name && options[i].name)
2.410 + printf("|");
2.411 + if (options[i].name)
2.412 + printf("--%s", options[i].name);
2.413 + printf("] ");
2.414 + break;
2.415 +
2.416 + case OPTION_STRING:
2.417 + printf("[");
2.418 + if (options[i].short_name)
2.419 + printf("-%c", options[i].short_name);
2.420 + if (options[i].short_name && options[i].name)
2.421 + printf("|");
2.422 + if (options[i].name)
2.423 + printf("--%s", options[i].name);
2.424 + if (options[i].arg_name)
2.425 + printf("=%s", options[i].arg_name);
2.426 + printf("] ");
2.427 + break;
2.428 +
2.429 +
2.430 + break;
2.431 +
2.432 + case OPTION_LAST:
2.433 + break;
2.434 + }
2.435 + }
2.436 +}
2.437 +
2.438 +int
2.439 +main(int argc, const char *argv[])
2.440 +{
2.441 + argc = parse_options(rpm_options, argc, argv);
2.442 +
2.443 + if (option_version) {
2.444 + printf("razor rpm version hoopla.\n");
2.445 + exit(0);
2.446 + }
2.447 +
2.448 + if (option_help) {
2.449 + printf("Usage: rpm [OPTION...]\n");
2.450 + print_options_help(rpm_options);
2.451 + exit(0);
2.452 + }
2.453 +
2.454 + if (option_usage) {
2.455 + printf("Usage: rpm [OPTION...]\n");
2.456 + print_options_usage(rpm_options);
2.457 + printf("\n");
2.458 + exit(0);
2.459 + }
2.460 +
2.461 + if (option_query + option_verify +
2.462 + option_erase + option_install + option_upgrade > 1) {
2.463 + printf("specify only one of query, verify, erase, install "
2.464 + "or upgrade\n");
2.465 + exit(1);
2.466 + }
2.467 +
2.468 + if (option_query) {
2.469 + command_query(argc, argv);
2.470 + } else if (option_verify) {
2.471 + command_verify(argc, argv);
2.472 + } else if (option_erase) {
2.473 + command_erase(argc, argv);
2.474 + } else if (option_install) {
2.475 + command_install(argc, argv);
2.476 + } else if (option_upgrade) {
2.477 + command_update(argc, argv);
2.478 + } else {
2.479 + print_options_usage(rpm_options);
2.480 + printf("\n");
2.481 + exit(0);
2.482 + }
2.483 +
2.484 + return 0;
2.485 +}