From db0484ae6e0274a4f76302381615e081968df83f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 19 Dec 2008 23:10:24 +0100 Subject: [PATCH] xbps-bin: add new action "repo-list". --HG-- extra : convert_revision : e0d5fce9503c6544e8ceec56864560b170c0e8c8 --- utils/plist_utils.c | 21 ++++++++++++++++++ utils/plist_utils.h | 9 ++++++++ utils/xbps-bin.c | 52 ++++++++++++++++++++++++++++++++++++++------- 3 files changed, 74 insertions(+), 8 deletions(-) diff --git a/utils/plist_utils.c b/utils/plist_utils.c index 0bfe801569c..9a3741f319d 100644 --- a/utils/plist_utils.c +++ b/utils/plist_utils.c @@ -230,3 +230,24 @@ xbps_list_pkgs_in_dict(prop_dictionary_t dict, const char *key) prop_object_iterator_release(iter); } + +void +xbps_list_strings_in_array(prop_array_t array) +{ + prop_object_iterator_t iter; + prop_object_t obj; + + if (array == NULL) + return; + + iter = prop_array_iterator(array); + if (iter == NULL) + return; + + while ((obj = prop_object_iterator_next(iter))) { + if (prop_object_type(obj) == PROP_TYPE_STRING) + printf("%s\n", prop_string_cstring_nocopy(obj)); + } + + prop_object_iterator_release(iter); +} diff --git a/utils/plist_utils.h b/utils/plist_utils.h index 0aa42c10a22..7b575f70092 100644 --- a/utils/plist_utils.h +++ b/utils/plist_utils.h @@ -87,6 +87,15 @@ xbps_find_string_in_array(prop_array_t, const char *); void xbps_list_pkgs_in_dict(prop_dictionary_t, const char *); +/* + * Lists all string values in an array. + * + * Arguments: + * - prop_array_t: array where to search on. + */ +void +xbps_list_strings_in_array(prop_array_t); + /* * Registers a repository specified by an URI into the pool. * diff --git a/utils/xbps-bin.c b/utils/xbps-bin.c index de41001adcb..49612aed308 100644 --- a/utils/xbps-bin.c +++ b/utils/xbps-bin.c @@ -45,12 +45,19 @@ static void usage(void); static void usage(void) { - printf("Usage: xbps-bin [action] [pkg|url]\n\n" - " Available actions: add-repo, show\n\n" + printf("Usage: xbps-bin [action] [arguments]\n\n" + " Available actions:\n" + " repo-add, repo-list, show\n" + " Action arguments:\n" + " repo-add\t[]\n" + " repo-list\t[none]\n" + " show\t[]\n" + "\n" " Examples:\n" - " $ xbps-bin add-repo /path/to/directory\n" - " $ xbps-bin add-repo http://www.location.org/xbps-repo\n" - " $ xbps-bin show klibc\n"); + " $ xbps-bin repo-list\n" + " $ xbps-bin repo-add /path/to/directory\n" + " $ xbps-bin repo-add http://www.location.org/xbps-repo\n" + " $ xbps-bin show klibc\n"); exit(1); } @@ -87,14 +94,18 @@ int main(int argc, char **argv) { prop_dictionary_t dict; + prop_array_t array; repo_info_t *rinfo = NULL; char pkgindex[PATH_MAX], *tmp; - if (argc != 3) + if (argc < 2) usage(); - /* Adds a new repository to the pool. */ - if (strcmp(argv[1], "add-repo") == 0) { + if (strcmp(argv[1], "repo-add") == 0) { + /* Adds a new repository to the pool. */ + if (argc != 3) + usage(); + tmp = strncpy(pkgindex, argv[2], sizeof(pkgindex)); if (sizeof(*tmp) >= sizeof(pkgindex)) exit(ENAMETOOLONG); @@ -133,6 +144,31 @@ main(int argc, char **argv) rinfo->location_local, rinfo->index_version, rinfo->total_pkgs); free(rinfo); + + } else if (strcmp(argv[1], "repo-list") == 0) { + /* Lists all repositories registered in pool. */ + if (argc != 2) + usage(); + + dict = + prop_dictionary_internalize_from_file(XBPS_REPOLIST_PATH); + if (dict == NULL) { + printf("cannot find repository list file: %s\n", + strerror(errno)); + exit(EINVAL); + } + + array = prop_dictionary_get(dict, "repository-list"); + if (array) + xbps_list_strings_in_array(array); + + } else if (strcmp(argv[1], "show") == 0) { + /* Shows info about a binary package. */ + if (argc != 3) + usage(); + + } else { + usage(); } exit(0);