diff --git a/NEWS b/NEWS index 2da90ca7..802b5403 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,15 @@ -xbps-0.10.2 (???): +xbps-0.11.0 (???): + + * xbps-bin(8)/xbps-repo(8): new flag '-o' (option). This can be used + in the 'show' target to print only a set of objects stored in package's + properties dictionary, example: + + $ xbps-bin -olicense show xbps + Simplified BSD + $ xbps-bin -oversion,build_date show xbps + 0.10.1 + Wednesday 26 October, 2011, 14:37:31 UTC + $ * libxbpps: when fetching new pkg-index.plist from a repository, make sure that it's a plist file and can be internalized; otherwise diff --git a/bin/xbps-bin/defs.h b/bin/xbps-bin/defs.h index 9ad412cd..1bcf176f 100644 --- a/bin/xbps-bin/defs.h +++ b/bin/xbps-bin/defs.h @@ -66,7 +66,7 @@ int show_pkg_deps(const char *); int show_pkg_reverse_deps(const char *); /* from show-info-files.c */ -int show_pkg_info_from_metadir(const char *); +int show_pkg_info_from_metadir(const char *, const char *); int show_pkg_files_from_metadir(const char *); /* from find-files.c */ @@ -84,12 +84,13 @@ void transaction_cb(struct xbps_transaction_cb_data *); void transaction_err_cb(struct xbps_transaction_cb_data *); /* From util.c */ -int show_pkg_files(prop_dictionary_t); -void show_pkg_info(prop_dictionary_t); -int show_pkg_namedesc(prop_object_t, void *, bool *); -int list_strings_in_array(prop_object_t, void *, bool *); -int list_strings_sep_in_array(prop_object_t, void *, bool *); -size_t find_longest_pkgver(prop_dictionary_t); -void print_package_line(const char *, bool); +int show_pkg_files(prop_dictionary_t); +void show_pkg_info(prop_dictionary_t); +void show_pkg_info_one(prop_dictionary_t, const char *); +int show_pkg_namedesc(prop_object_t, void *, bool *); +int list_strings_in_array(prop_object_t, void *, bool *); +int list_strings_sep_in_array(prop_object_t, void *, bool *); +size_t find_longest_pkgver(prop_dictionary_t); +void print_package_line(const char *, bool); #endif /* !_XBPS_BIN_DEFS_H_ */ diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index 1d3defde..483af818 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -185,17 +185,17 @@ main(int argc, char **argv) struct xferstat xfer; struct list_pkgver_cb lpc; struct sigaction sa; - const char *rootdir, *cachedir, *confdir; + const char *rootdir, *cachedir, *confdir, *option; int i , c, flags, rv; bool yes, purge, debug, force_rm_with_deps, recursive_rm; bool install_auto, install_manual, show_download_pkglist_url; - rootdir = cachedir = confdir = NULL; + rootdir = cachedir = confdir = option = NULL; flags = rv = 0; yes = purge = force_rm_with_deps = recursive_rm = debug = false; install_auto = install_manual = show_download_pkglist_url = false; - while ((c = getopt(argc, argv, "AC:c:dDFfMpRr:Vvy")) != -1) { + while ((c = getopt(argc, argv, "AC:c:dDFfMo:pRr:Vvy")) != -1) { switch (c) { case 'A': install_auto = true; @@ -221,6 +221,9 @@ main(int argc, char **argv) case 'M': install_manual = true; break; + case 'o': + option = optarg; + break; case 'p': purge = true; break; @@ -375,7 +378,7 @@ main(int argc, char **argv) if (argc != 2) usage(xhp); - rv = show_pkg_info_from_metadir(argv[1]); + rv = show_pkg_info_from_metadir(argv[1], option); if (rv != 0) { printf("Package %s not installed.\n", argv[1]); goto out; diff --git a/bin/xbps-bin/show-info-files.c b/bin/xbps-bin/show-info-files.c index 22e7bc49..0eb0cf2b 100644 --- a/bin/xbps-bin/show-info-files.c +++ b/bin/xbps-bin/show-info-files.c @@ -35,7 +35,7 @@ #include "defs.h" int -show_pkg_info_from_metadir(const char *pkgname) +show_pkg_info_from_metadir(const char *pkgname, const char *option) { prop_dictionary_t d; @@ -43,7 +43,11 @@ show_pkg_info_from_metadir(const char *pkgname) if (d == NULL) return EINVAL; - show_pkg_info(d); + if (option == NULL) + show_pkg_info(d); + else + show_pkg_info_one(d, option); + prop_object_release(d); return 0; } diff --git a/bin/xbps-bin/util.c b/bin/xbps-bin/util.c index e1232231..796e8387 100644 --- a/bin/xbps-bin/util.c +++ b/bin/xbps-bin/util.c @@ -40,13 +40,86 @@ #include "defs.h" #include "../xbps-repo/defs.h" +static void +print_value_obj(const char *keyname, prop_object_t obj, bool raw) +{ + const char *value; + size_t i; + char size[8]; + + switch (prop_object_type(obj)) { + case PROP_TYPE_STRING: + if (!raw) + printf("%s: ", keyname); + printf("%s\n", prop_string_cstring_nocopy(obj)); + break; + case PROP_TYPE_NUMBER: + if (!raw) + printf("%s: ", keyname); + if (xbps_humanize_number(size, + (int64_t)prop_number_unsigned_integer_value(obj)) == -1) + printf("%ju\n", + prop_number_unsigned_integer_value(obj)); + else + printf("%s\n", size); + break; + case PROP_TYPE_BOOL: + if (!raw) + printf("%s: ", keyname); + printf("%s\n", prop_bool_true(obj) ? "yes" : "no"); + break; + case PROP_TYPE_ARRAY: + if (!raw) + printf("%s:\n", keyname); + for (i = 0; i < prop_array_count(obj); i++) { + prop_array_get_cstring_nocopy(obj, i, &value); + printf("%s%s%s", !raw ? "\t" : "", value, + !raw ? "\n" : " "); + } + if (raw) + printf("\n"); + break; + default: + xbps_warn_printf("unknown obj type (key %s)\n", + keyname); + break; + } +} + +void +show_pkg_info_one(prop_dictionary_t d, const char *keys) +{ + prop_object_t obj; + char *key, *p, *saveptr; + + assert(prop_object_type(d) == PROP_TYPE_DICTIONARY); + assert(keys != NULL); + + if (strchr(keys, ',') == NULL) { + obj = prop_dictionary_get(d, keys); + if (obj == NULL) + return; + print_value_obj(keys, obj, true); + return; + } + key = strdup(keys); + assert(key != NULL); + for ((p = strtok_r(key, ",", &saveptr)); p; + (p = strtok_r(NULL, ",", &saveptr))) { + obj = prop_dictionary_get(d, p); + if (obj == NULL) + continue; + print_value_obj(p, obj, true); + } + free(key); +} + void show_pkg_info(prop_dictionary_t dict) { prop_array_t all_keys; prop_object_t obj, keysym; const char *keyname; - char size[8]; size_t i; assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); @@ -57,38 +130,11 @@ show_pkg_info(prop_dictionary_t dict) keysym = prop_array_get(all_keys, i); keyname = prop_dictionary_keysym_cstring_nocopy(keysym); obj = prop_dictionary_get_keysym(dict, keysym); + /* ignore run_depends, it's shown via 'show-deps' */ + if (strcmp(keyname, "run_depends") == 0) + break; - switch (prop_object_type(obj)) { - case PROP_TYPE_STRING: - printf("%s: %s\n", keyname, - prop_string_cstring_nocopy(obj)); - break; - case PROP_TYPE_NUMBER: - printf("%s: ", keyname); - if (xbps_humanize_number(size, - (int64_t)prop_number_unsigned_integer_value(obj)) == -1) - printf("%ju\n", - prop_number_unsigned_integer_value(obj)); - else - printf("%s\n", size); - break; - case PROP_TYPE_BOOL: - printf("%s: %s\n", keyname, - prop_bool_true(obj) ? "yes" : "no"); - break; - case PROP_TYPE_ARRAY: - /* ignore run_depends, it's shown via 'show-deps' */ - if (strcmp(keyname, "run_depends") == 0) - break; - printf("%s:\n", keyname); - (void)xbps_callback_array_iter_in_dict(dict, keyname, - list_strings_sep_in_array, __UNCONST("\t")); - break; - default: - xbps_warn_printf("unknown obj type (key %s)\n", - keyname); - break; - } + print_value_obj(keyname, obj, false); } } diff --git a/bin/xbps-bin/xbps-bin.8 b/bin/xbps-bin/xbps-bin.8 index 14e491ad..717c16d7 100644 --- a/bin/xbps-bin/xbps-bin.8 +++ b/bin/xbps-bin/xbps-bin.8 @@ -1,4 +1,4 @@ -.TH "XBPS\-BIN" "8" "17/10/2011" "\ \&" "\ \&" +.TH "XBPS\-BIN" "8" "29/10/2011" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- @@ -88,6 +88,14 @@ option takes effect in the \fIautoupdate\fR, \fIinstall\fR and \fIupdate\fR targ and target packages and its required dependencies will be matched. .RE .PP +\fB-o\fR \fIkey[,key2...]\fR +.RS 4 +Used currently in the +\fIshow\fR +target\&. Prints the value of specified key(s) from package's properties dictionary. +Multiple keys can be specified delimited by the comma character. +.RE +.PP \fB\-p\fR .RS 4 Used currently in the diff --git a/bin/xbps-repo/defs.h b/bin/xbps-repo/defs.h index 41ba9ef9..82ec4c12 100644 --- a/bin/xbps-repo/defs.h +++ b/bin/xbps-repo/defs.h @@ -36,7 +36,7 @@ int repo_genindex(const char *); /* From repository.c */ -int show_pkg_info_from_repolist(const char *); +int show_pkg_info_from_repolist(const char *, const char *); int show_pkg_deps_from_repolist(const char *); int repository_sync(void); diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index 374abf19..2cbe7fa8 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -90,13 +90,13 @@ main(int argc, char **argv) struct xbps_handle *xhp; struct xferstat xfer; prop_dictionary_t pkgd; - const char *rootdir, *cachedir, *confdir; + const char *rootdir, *cachedir, *confdir, *option; int c, rv = 0; bool debug = false; - rootdir = cachedir = confdir = NULL; + rootdir = cachedir = confdir = option = NULL; - while ((c = getopt(argc, argv, "C:c:dr:V")) != -1) { + while ((c = getopt(argc, argv, "C:c:do:r:V")) != -1) { switch (c) { case 'C': confdir = optarg; @@ -107,6 +107,9 @@ main(int argc, char **argv) case 'd': debug = true; break; + case 'o': + option = optarg; + break; case 'r': /* To specify the root directory */ rootdir = optarg; @@ -186,7 +189,7 @@ main(int argc, char **argv) if (argc != 2) usage(xhp); - rv = show_pkg_info_from_repolist(argv[1]); + rv = show_pkg_info_from_repolist(argv[1], option); if (rv == ENOENT) { xbps_printf("Unable to locate package " "`%s' in repository pool.\n", argv[1]); diff --git a/bin/xbps-repo/repository.c b/bin/xbps-repo/repository.c index 6a3bdc8b..6d5c0507 100644 --- a/bin/xbps-repo/repository.c +++ b/bin/xbps-repo/repository.c @@ -100,7 +100,7 @@ out: } int -show_pkg_info_from_repolist(const char *pkgname) +show_pkg_info_from_repolist(const char *pkgname, const char *option) { prop_dictionary_t pkgd; @@ -111,7 +111,11 @@ show_pkg_info_from_repolist(const char *pkgname) return errno; } - show_pkg_info(pkgd); + if (option) + show_pkg_info_one(pkgd, option); + else + show_pkg_info(pkgd); + prop_object_release(pkgd); return 0; diff --git a/bin/xbps-repo/xbps-repo.8 b/bin/xbps-repo/xbps-repo.8 index 860bacf0..ad674bff 100644 --- a/bin/xbps-repo/xbps-repo.8 +++ b/bin/xbps-repo/xbps-repo.8 @@ -1,4 +1,4 @@ -.TH "XBPS\-REPO" "8" "17/10/2011" "\ \&" "\ \&" +.TH "XBPS\-REPO" "8" "28/10/2011" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- @@ -38,6 +38,14 @@ directory to store downloaded binary packages from remote repositories\&. By def Enables extra debugging output to be shown to stderr. .RE .PP +\fB-o\fR \fIkey[,key2...]\fR +.RS 4 +Used currently in the +\fIshow\fR +target\&. Prints the value of specified key(s) from package's properties dictionary. +Multiple keys can be specified delimited by the comma character. +.RE +.PP \fB\-r\fR \fIrootdir\fR .RS 4 Sets the diff --git a/include/xbps_api.h b/include/xbps_api.h index 51a0077b..bcbacc57 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -56,7 +56,7 @@ #define XBPS_PKGINDEX_VERSION "1.2" #define XBPS_API_VERSION "20111027-1" -#define XBPS_VERSION "0.10.2" +#define XBPS_VERSION "0.11.0" /** * @def XBPS_RELVER