From 77409586432c3f97e647f275003486ab04742c95 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 5 Feb 2009 14:46:09 +0100 Subject: [PATCH] Split repo commands into the new xbps-repo bin. - Remove lib/info.c that doesn't belong in the lib and add it into the bins. - Every binary now uses its own directory on bin/. This is in preparation for future changes for correct behaviour of the library and binaries. --HG-- extra : convert_revision : 880d16378bf940c4f5478de0362afe883cd5fd2c --- .gitignore | 10 +- bin/Makefile | 49 +++---- bin/xbps-bin/Makefile | 24 +++ bin/xbps-bin/main.c | 170 ++++++++++++++++++++++ bin/xbps-cmpver/Makefile | 24 +++ bin/{xbps-cmpver.c => xbps-cmpver/main.c} | 2 +- bin/xbps-digest/Makefile | 25 ++++ bin/{xbps-digest.c => xbps-digest/main.c} | 2 +- bin/xbps-pkgdb/Makefile | 24 +++ bin/{xbps-pkgdb.c => xbps-pkgdb/main.c} | 0 bin/xbps-repo/Makefile | 24 +++ bin/{xbps-bin.c => xbps-repo/main.c} | 95 ++---------- lib/info.c => bin/xbps-repo/util.c | 63 ++++---- bin/xbps-repo/util.h | 28 ++++ bin/xbps-src/Makefile | 18 +++ bin/{xbps-src.sh => xbps-src/main.sh} | 0 include/plist.h | 47 +----- lib/Makefile | 2 +- vars.mk | 4 +- 19 files changed, 412 insertions(+), 199 deletions(-) create mode 100644 bin/xbps-bin/Makefile create mode 100644 bin/xbps-bin/main.c create mode 100644 bin/xbps-cmpver/Makefile rename bin/{xbps-cmpver.c => xbps-cmpver/main.c} (99%) create mode 100644 bin/xbps-digest/Makefile rename bin/{xbps-digest.c => xbps-digest/main.c} (98%) create mode 100644 bin/xbps-pkgdb/Makefile rename bin/{xbps-pkgdb.c => xbps-pkgdb/main.c} (100%) create mode 100644 bin/xbps-repo/Makefile rename bin/{xbps-bin.c => xbps-repo/main.c} (75%) rename lib/info.c => bin/xbps-repo/util.c (88%) create mode 100644 bin/xbps-repo/util.h create mode 100644 bin/xbps-src/Makefile rename bin/{xbps-src.sh => xbps-src/main.sh} (100%) diff --git a/.gitignore b/.gitignore index c5ebe8969e6..3aa47864537 100644 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,12 @@ destdir/ srcdistdir/ builddir/ packages/ -bin/xbps-bin -bin/xbps-cmpver -bin/xbps-digest -bin/xbps-pkgdb +bin/xbps-bin/xbps-bin +bin/xbps-cmpver/xbps-cmpver +bin/xbps-digest/xbps-digest +bin/xbps-repo/xbps-repo +bin/xbps-src/xbps-src +bin/xbps-pkgdb/xbps-pkgdb *.o *.so* *.bak diff --git a/bin/Makefile b/bin/Makefile index 22c393e6d88..1166c826089 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,37 +1,26 @@ include ../vars.mk -EXTRA_CFLAGS = -funroll-all-loops -ftree-loop-linear -LDFLAGS += -L../lib -L$(PREFIX)/lib -lxbps +SUBDIRS = xbps-bin +SUBDIRS += xbps-cmpver +SUBDIRS += xbps-digest +SUBDIRS += xbps-pkgdb +SUBDIRS += xbps-repo +SUBDIRS += xbps-src -BINS = xbps-bin xbps-cmpver xbps-digest xbps-pkgdb - -all: $(BINS) .PHONY: all +all: + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir; \ + done -xbps-bin: xbps-bin.o - $(CC) $(LDFLAGS) $^ -o $@ - -xbps-cmpver: xbps-cmpver.o - $(CC) $(LDFLAGS) $^ -o $@ - -xbps-digest: xbps-digest.o - $(CC) $(EXTRA_CFLAGS) $(LDFLAGS) $^ -o $@ - -xbps-pkgdb: xbps-pkgdb.o - $(CC) $(LDFLAGS) $^ -o $@ +.PHONY: install +install: + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir install; \ + done .PHONY: clean -clean: clean-bins clean-objs - -clean-bins: - -rm -f $(BINS) - -clean-objs: - -rm -f *.o - -install: $(BINS) - install -d $(SBINDIR) - install -m 755 $(BINS) $(SBINDIR) - install -m 755 xbps-src.sh $(SBINDIR)/xbps-src - sed -i -e "s|@@XBPS_INSTALL_PREFIX@@|$(PREFIX)|g" $(SBINDIR)/xbps-src - +clean: + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir clean; \ + done diff --git a/bin/xbps-bin/Makefile b/bin/xbps-bin/Makefile new file mode 100644 index 00000000000..aa1a060fc2c --- /dev/null +++ b/bin/xbps-bin/Makefile @@ -0,0 +1,24 @@ +TOPDIR = ../.. +include $(TOPDIR)/vars.mk + +OBJS = main.o +BIN = xbps-bin + +all: $(BIN) +.PHONY: all + +$(BIN): $(OBJS) + $(CC) $(LDFLAGS) $^ -o $@ + +.PHONY: clean +clean: clean-bins clean-objs + +clean-bins: + -rm -f $(BIN) + +clean-objs: + -rm -f *.o + +install: $(BIN) + install -d $(SBINDIR) + install -m 755 $(BIN) $(SBINDIR) diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c new file mode 100644 index 00000000000..8edafef8b04 --- /dev/null +++ b/bin/xbps-bin/main.c @@ -0,0 +1,170 @@ +/*- + * Copyright (c) 2008-2009 Juan Romero Pardines. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static void usage(void); +static int list_pkgs_in_dict(prop_object_t, void *, bool *); + +static void +usage(void) +{ + printf("Usage: xbps-bin [options] [action] [arguments]\n\n" + " Available actions:\n" + " install, list, remove, show\n" + " Actions with arguments:\n" + " install\t\n" + " remove\t\n" + " show\t\n" + " Options shared by all actions:\n" + " -r\t\t\n" + "\n" + " Examples:\n" + " $ xbps-bin install klibc\n" + " $ xbps-bin -r /path/to/root install klibc\n" + " $ xbps-bin list\n" + " $ xbps-bin remove klibc\n" + " $ xbps-bin show klibc\n"); + exit(EXIT_FAILURE); +} + +static int +list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done) +{ + const char *pkgname, *version, *short_desc; + + assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY); + + prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); + prop_dictionary_get_cstring_nocopy(obj, "version", &version); + prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc); + if (pkgname && version && short_desc) { + printf("%s (%s)\t%s\n", pkgname, version, short_desc); + return 0; + } + + return EINVAL; +} + +int +main(int argc, char **argv) +{ + prop_dictionary_t dict; + char *plist, *root = NULL; + int c, rv = 0; + + while ((c = getopt(argc, argv, "r:")) != -1) { + switch (c) { + case 'r': + /* To specify the root directory */ + root = optarg; + xbps_set_rootdir(root); + break; + case '?': + default: + usage(); + } + } + + argc -= optind; + argv += optind; + + if (argc < 1) + usage(); + + if (strcasecmp(argv[0], "list") == 0) { + /* Lists packages currently registered in database. */ + if (argc != 1) + usage(); + + plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB); + if (plist == NULL) + exit(EXIT_FAILURE); + + dict = prop_dictionary_internalize_from_file(plist); + if (dict == NULL) { + printf("No packages currently registered.\n"); + free(plist); + exit(EXIT_SUCCESS); + } + + if (!xbps_callback_array_iter_in_dict(dict, "packages", + list_pkgs_in_dict, NULL)) { + prop_object_release(dict); + free(plist); + exit(EXIT_FAILURE); + } + prop_object_release(dict); + free(plist); + + } else if ((strcasecmp(argv[0], "install") == 0) || + (strcasecmp(argv[0], "remove") == 0)) { + /* Installs a binary package and required deps. */ + if (argc != 2) + usage(); + + if (geteuid() != 0) { + printf("ERROR: root permissions are needed to install" + "and remove binary packages.\n"); + exit(EXIT_FAILURE); + } + + /* Install into root directory by default. */ + if (strcasecmp(argv[0], "install") == 0) { + rv = xbps_install_binary_pkg(argv[1], root); + if (rv) { + printf("ERROR: unable to install %s.\n", argv[1]); + exit(rv); + } + printf("Package %s installed successfully.\n", argv[1]); + } else { + rv = xbps_remove_binary_pkg(argv[1], root); + if (rv) { + if (rv == ENOENT) + printf("Package %s is not installed.\n", + argv[1]); + else + printf("ERROR: unable to remove %s.\n", + argv[1]); + exit(rv); + } + printf("Package %s removed successfully.\n", argv[1]); + } + + } else { + usage(); + } + + exit(EXIT_SUCCESS); +} diff --git a/bin/xbps-cmpver/Makefile b/bin/xbps-cmpver/Makefile new file mode 100644 index 00000000000..49ffad1937d --- /dev/null +++ b/bin/xbps-cmpver/Makefile @@ -0,0 +1,24 @@ +TOPDIR = ../.. +include $(TOPDIR)/vars.mk + +OBJS = main.o +BIN = xbps-cmpver + +all: $(BIN) +.PHONY: all + +$(BIN): $(OBJS) + $(CC) $(LDFLAGS) $^ -o $@ + +.PHONY: clean +clean: clean-bins clean-objs + +clean-bins: + -rm -f $(BIN) + +clean-objs: + -rm -f *.o + +install: $(BIN) + install -d $(SBINDIR) + install -m 755 $(BIN) $(SBINDIR) diff --git a/bin/xbps-cmpver.c b/bin/xbps-cmpver/main.c similarity index 99% rename from bin/xbps-cmpver.c rename to bin/xbps-cmpver/main.c index 6169a737652..8668a9249b3 100644 --- a/bin/xbps-cmpver.c +++ b/bin/xbps-cmpver/main.c @@ -1,4 +1,4 @@ -/* +/* * Compare package and version strings * @ 2008 * Author: pancake diff --git a/bin/xbps-digest/Makefile b/bin/xbps-digest/Makefile new file mode 100644 index 00000000000..ebc7eb14592 --- /dev/null +++ b/bin/xbps-digest/Makefile @@ -0,0 +1,25 @@ +TOPDIR = ../.. +include $(TOPDIR)/vars.mk + +EXTRA_CFLAGS = -funroll-all-loops -ftree-loop-linear +OBJS = main.o +BIN = xbps-digest + +all: $(BIN) +.PHONY: all + +$(BIN): $(OBJS) + $(CC) $(EXTRA_CFLAGS) $(LDFLAGS) $^ -o $@ + +.PHONY: clean +clean: clean-bins clean-objs + +clean-bins: + -rm -f $(BIN) + +clean-objs: + -rm -f *.o + +install: $(BIN) + install -d $(SBINDIR) + install -m 755 $(BIN) $(SBINDIR) diff --git a/bin/xbps-digest.c b/bin/xbps-digest/main.c similarity index 98% rename from bin/xbps-digest.c rename to bin/xbps-digest/main.c index d7e8481dc9c..97528f18570 100644 --- a/bin/xbps-digest.c +++ b/bin/xbps-digest/main.c @@ -58,7 +58,7 @@ main(int argc, char **argv) for (i = 1; i < argc; i++) { if ((fd = open(argv[i], O_RDONLY)) == -1) { printf("xbps-digest: cannot open %s (%s)\n", argv[i], - strerror(errno)); + strerror(errno)); exit(EXIT_FAILURE); } diff --git a/bin/xbps-pkgdb/Makefile b/bin/xbps-pkgdb/Makefile new file mode 100644 index 00000000000..23acf719d1e --- /dev/null +++ b/bin/xbps-pkgdb/Makefile @@ -0,0 +1,24 @@ +TOPDIR = ../.. +include $(TOPDIR)/vars.mk + +OBJS = main.o +BIN = xbps-pkgdb + +all: $(BIN) +.PHONY: all + +$(BIN): $(OBJS) + $(CC) $(LDFLAGS) $^ -o $@ + +.PHONY: clean +clean: clean-bins clean-objs + +clean-bins: + -rm -f $(BIN) + +clean-objs: + -rm -f *.o + +install: $(BIN) + install -d $(SBINDIR) + install -m 755 $(BIN) $(SBINDIR) diff --git a/bin/xbps-pkgdb.c b/bin/xbps-pkgdb/main.c similarity index 100% rename from bin/xbps-pkgdb.c rename to bin/xbps-pkgdb/main.c diff --git a/bin/xbps-repo/Makefile b/bin/xbps-repo/Makefile new file mode 100644 index 00000000000..f6246cd86fd --- /dev/null +++ b/bin/xbps-repo/Makefile @@ -0,0 +1,24 @@ +TOPDIR = ../.. +include $(TOPDIR)/vars.mk + +OBJS = util.o main.o +BIN = xbps-repo + +all: $(BIN) +.PHONY: all + +$(BIN): $(OBJS) + $(CC) $(LDFLAGS) $^ -o $@ + +.PHONY: clean +clean: clean-bins clean-objs + +clean-bins: + -rm -f $(BIN) + +clean-objs: + -rm -f *.o + +install: $(BIN) + install -d $(SBINDIR) + install -m 755 $(BIN) $(SBINDIR) diff --git a/bin/xbps-bin.c b/bin/xbps-repo/main.c similarity index 75% rename from bin/xbps-bin.c rename to bin/xbps-repo/main.c index 81da5df228e..d4b0930a2fc 100644 --- a/bin/xbps-bin.c +++ b/bin/xbps-repo/main.c @@ -33,6 +33,7 @@ #include #include +#include "util.h" typedef struct repository_info { const char *index_version; @@ -51,30 +52,24 @@ static char *plist; static void usage(void) { - printf("Usage: xbps-bin [options] [action] [arguments]\n\n" + printf("Usage: xbps-repo [options] [action] [arguments]\n\n" " Available actions:\n" - " install, list, remove, repo-add, repo-list, repo-rm, search, show\n" + " add, list, remove, search, show\n" " Actions with arguments:\n" - " install\t\n" - " remove\t\n" - " repo-add\t\n" - " repo-rm\t\n" + " add\t\n" + " remove\t\n" " search\t\n" " show\t\n" " Options shared by all actions:\n" " -r\t\t\n" "\n" " Examples:\n" - " $ xbps-bin install klibc\n" - " $ xbps-bin -r /path/to/root install klibc\n" - " $ xbps-bin list\n" - " $ xbps-bin remove klibc\n" - " $ xbps-bin repo-add /path/to/directory\n" - " $ xbps-bin repo-add http://www.location.org/xbps-repo\n" - " $ xbps-bin repo-list\n" - " $ xbps-bin repo-rm /path/to/directory\n" - " $ xbps-bin search klibc\n" - " $ xbps-bin show klibc\n"); + " $ xbps-repo add /path/to/directory\n" + " $ xbps-repo add http://www.location.org/xbps-repo\n" + " $ xbps-repo list\n" + " $ xbps-repo remove /path/to/directory\n" + " $ xbps-repo search klibc\n" + " $ xbps-repo show klibc\n"); exit(EXIT_FAILURE); } @@ -175,7 +170,7 @@ main(int argc, char **argv) prop_dictionary_t dict; repo_info_t *rinfo = NULL; char dpkgidx[PATH_MAX], *root = NULL; - int c, rv = 0; + int c; while ((c = getopt(argc, argv, "r:")) != -1) { switch (c) { @@ -196,7 +191,7 @@ main(int argc, char **argv) if (argc < 1) usage(); - if (strcasecmp(argv[0], "repo-add") == 0) { + if (strcasecmp(argv[0], "add") == 0) { /* Adds a new repository to the pool. */ if (argc != 2) usage(); @@ -249,7 +244,7 @@ main(int argc, char **argv) free(rinfo); free(plist); - } else if (strcasecmp(argv[0], "repo-list") == 0) { + } else if (strcasecmp(argv[0], "list") == 0) { /* Lists all repositories registered in pool. */ if (argc != 1) usage(); @@ -260,7 +255,8 @@ main(int argc, char **argv) prop_object_release(dict); free(plist); - } else if (strcasecmp(argv[0], "repo-rm") == 0) { + } else if ((strcasecmp(argv[0], "rm") == 0) || + (strcasecmp(argv[0], "remove") == 0)) { /* Remove a repository from the pool. */ if (argc != 2) usage(); @@ -306,65 +302,6 @@ main(int argc, char **argv) prop_object_release(dict); free(plist); - } else if (strcasecmp(argv[0], "list") == 0) { - /* Lists packages currently registered in database. */ - if (argc != 1) - usage(); - - plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB); - if (plist == NULL) - exit(EXIT_FAILURE); - - dict = prop_dictionary_internalize_from_file(plist); - if (dict == NULL) { - printf("No packages currently registered.\n"); - free(plist); - exit(EXIT_SUCCESS); - } - - if (!xbps_callback_array_iter_in_dict(dict, "packages", - xbps_list_pkgs_in_dict, NULL)) { - prop_object_release(dict); - free(plist); - exit(EXIT_FAILURE); - } - prop_object_release(dict); - free(plist); - - } else if ((strcasecmp(argv[0], "install") == 0) || - (strcasecmp(argv[0], "remove") == 0)) { - /* Installs a binary package and required deps. */ - if (argc != 2) - usage(); - - if (geteuid() != 0) { - printf("ERROR: root permissions are needed to install" - "and remove binary packages.\n"); - exit(EXIT_FAILURE); - } - - /* Install into root directory by default. */ - if (strcasecmp(argv[0], "install") == 0) { - rv = xbps_install_binary_pkg(argv[1], root); - if (rv) { - printf("ERROR: unable to install %s.\n", argv[1]); - exit(rv); - } - printf("Package %s installed successfully.\n", argv[1]); - } else { - rv = xbps_remove_binary_pkg(argv[1], root); - if (rv) { - if (rv == ENOENT) - printf("Package %s is not installed.\n", - argv[1]); - else - printf("ERROR: unable to remove %s.\n", - argv[1]); - exit(rv); - } - printf("Package %s removed successfully.\n", argv[1]); - } - } else { usage(); } diff --git a/lib/info.c b/bin/xbps-repo/util.c similarity index 88% rename from lib/info.c rename to bin/xbps-repo/util.c index 6929aaad45b..d75bffa605a 100644 --- a/lib/info.c +++ b/bin/xbps-repo/util.c @@ -32,9 +32,14 @@ #include #include +#include "util.h" -void -xbps_show_pkg_info(prop_dictionary_t dict) +static void show_pkg_info(prop_dictionary_t); +static int show_pkg_namedesc(prop_object_t, void *, bool *); +static int list_strings_in_array2(prop_object_t, void *, bool *); + +static void +show_pkg_info(prop_dictionary_t dict) { prop_object_t obj; const char *sep = NULL; @@ -86,7 +91,7 @@ xbps_show_pkg_info(prop_dictionary_t dict) printf("Dependencies:\n\t"); sep = " "; xbps_callback_array_iter_in_dict(dict, "run_depends", - xbps_list_strings_in_array2, (void *)sep); + list_strings_in_array2, (void *)sep); printf("\n\n"); } @@ -94,7 +99,7 @@ xbps_show_pkg_info(prop_dictionary_t dict) if (obj && prop_object_type(obj) == PROP_TYPE_ARRAY) { printf("Configuration files:\n\t"); xbps_callback_array_iter_in_dict(dict, "conf_files", - xbps_list_strings_in_array2, NULL); + list_strings_in_array2, NULL); printf("\n"); } @@ -102,7 +107,7 @@ xbps_show_pkg_info(prop_dictionary_t dict) if (obj && prop_object_type(obj) == PROP_TYPE_ARRAY) { printf("Permanent directories:\n\t"); xbps_callback_array_iter_in_dict(dict, "keep_dirs", - xbps_list_strings_in_array2, NULL); + list_strings_in_array2, NULL); printf("\n"); } @@ -115,25 +120,6 @@ xbps_show_pkg_info(prop_dictionary_t dict) printf(" %s\n", prop_string_cstring_nocopy(obj)); } -int -xbps_show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done) -{ - const char *pkgname, *desc, *ver, *string = arg; - - assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY); - assert(string != NULL); - - prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); - prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc); - prop_dictionary_get_cstring_nocopy(obj, "version", &ver); - assert(ver != NULL); - - if ((strstr(pkgname, string) || strstr(desc, string))) - printf(" %s-%s - %s\n", pkgname, ver, desc); - - return 0; -} - int xbps_search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done) { @@ -159,7 +145,7 @@ xbps_search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done) printf("From %s repository ...\n", repofile); xbps_callback_array_iter_in_dict(dict, "packages", - xbps_show_pkg_namedesc, arg); + show_pkg_namedesc, arg); prop_object_release(dict); free(plist); @@ -210,7 +196,7 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done) } printf("Repository: %s\n", repoloc); - xbps_show_pkg_info(pkgdict); + show_pkg_info(pkgdict); *loop_done = true; prop_object_release(dict); free(plist); @@ -218,26 +204,27 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done) return 0; } -int -xbps_list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done) +static int +show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done) { - const char *pkgname, *version, *short_desc; + const char *pkgname, *desc, *ver, *string = arg; assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY); + assert(string != NULL); prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); - prop_dictionary_get_cstring_nocopy(obj, "version", &version); - prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc); - if (pkgname && version && short_desc) { - printf("%s (%s)\t%s\n", pkgname, version, short_desc); - return 0; - } + prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc); + prop_dictionary_get_cstring_nocopy(obj, "version", &ver); + assert(ver != NULL); - return EINVAL; + if ((strstr(pkgname, string) || strstr(desc, string))) + printf(" %s-%s - %s\n", pkgname, ver, desc); + + return 0; } -int -xbps_list_strings_in_array2(prop_object_t obj, void *arg, bool *loop_done) +static int +list_strings_in_array2(prop_object_t obj, void *arg, bool *loop_done) { static uint16_t count; const char *sep; diff --git a/bin/xbps-repo/util.h b/bin/xbps-repo/util.h new file mode 100644 index 00000000000..7a838b96cfd --- /dev/null +++ b/bin/xbps-repo/util.h @@ -0,0 +1,28 @@ +/*- + * Copyright (c) 2008 Juan Romero Pardines. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +int xbps_search_string_in_pkgs(prop_object_t, void *, bool *); +int xbps_show_pkg_info_from_repolist(prop_object_t, void *, bool *); +int xbps_list_strings_in_array(prop_object_t, void *, bool *); diff --git a/bin/xbps-src/Makefile b/bin/xbps-src/Makefile new file mode 100644 index 00000000000..6a2b9baba79 --- /dev/null +++ b/bin/xbps-src/Makefile @@ -0,0 +1,18 @@ +TOPDIR = ../.. +include $(TOPDIR)/vars.mk + +BIN = xbps-src + +.PHONY: all +all: + sed -e "s|@@XBPS_INSTALL_PREFIX@@|$(PREFIX)|g" main.sh > xbps-src + +.PHONY: clean +clean: clean-bins + +clean-bins: + -rm -f $(BIN) + +install: $(BIN) + install -d $(SBINDIR) + install -m 755 $(BIN) $(SBINDIR) diff --git a/bin/xbps-src.sh b/bin/xbps-src/main.sh similarity index 100% rename from bin/xbps-src.sh rename to bin/xbps-src/main.sh diff --git a/include/plist.h b/include/plist.h index c000a9f6db3..da2b421b6f5 100644 --- a/include/plist.h +++ b/include/plist.h @@ -26,30 +26,8 @@ #ifndef _XBPS_PLIST_H_ #define _XBPS_PLIST_H_ -/* - * Adds an opaque object with specified key into a dictionary. - * - * Arguments: - * - prop_dictionary_t: dictionary to store the object. - * - prop_object_t: the object to be stored. - * - const char *: the key associated with the object. - * - * Returns true on success, false on failure. - */ -bool -xbps_add_obj_to_dict(prop_dictionary_t, prop_object_t, const char *); - -/* - * Adds an opaque object into an array. - * - * Arguments: - * - prop_array_t: the array storing the object. - * - prop_object_t: the opaque object to be stored. - * - * Returns true on success, false on failure. - */ -bool -xbps_add_obj_to_array(prop_array_t, prop_object_t); +bool xbps_add_obj_to_dict(prop_dictionary_t, prop_object_t, const char *); +bool xbps_add_obj_to_array(prop_array_t, prop_object_t); /* * Executes a function callback to process all objects that are @@ -131,27 +109,8 @@ bool xbps_unregister_repository(const char *); bool xbps_remove_pkg_dict_from_file(const char *, const char *); -/* - * Shows information of a package by looking at its dictionary. - * All known objects on it will be showed up. - * - * Arguments: - * - prop_dictionary_t: the package dictionary. - */ -void xbps_show_pkg_info(prop_dictionary_t); - -/* - * Internal functions. - */ -int xbps_list_pkgs_in_dict(prop_object_t, void *, bool *); -int xbps_list_strings_in_array(prop_object_t, void *, bool *); -int xbps_list_strings_in_array2(prop_object_t, void *, bool *); -int xbps_remove_string_from_array(prop_object_t, void *, bool *); -int xbps_show_pkg_info_from_repolist(prop_object_t obj, void *, bool *); -int xbps_show_pkg_namedesc(prop_object_t, void *, bool *); -int xbps_search_string_in_pkgs(prop_object_t, void *, bool *); - /* Utils */ +int xbps_remove_string_from_array(prop_object_t, void *, bool *); void xbps_set_rootdir(const char *); char * xbps_append_full_path(bool, const char *, const char *); int xbps_check_is_installed_pkg(const char *); diff --git a/lib/Makefile b/lib/Makefile index a5cff148cc8..edf506d2168 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -9,7 +9,7 @@ LIBXBPS = libxbps.so LIBXBPS_LDFLAGS = -larchive -lprop -shared -Wl,-soname,$(LIBXBPS).$(MAJOR) OBJECTS = cmpver.o depends.o humanize_number.o install.o plist.o -OBJECTS += sha256.o util.o repository.o fexec.o info.o remove.o +OBJECTS += sha256.o util.o repository.o fexec.o remove.o all: $(LIBXBPS) .PHONY: all diff --git a/vars.mk b/vars.mk index 3f267c4a0bf..8e84b7445e4 100644 --- a/vars.mk +++ b/vars.mk @@ -3,7 +3,9 @@ PREFIX ?= /usr/local SBINDIR ?= $(PREFIX)/sbin LIBDIR ?= $(PREFIX)/lib +TOPDIR ?= .. -CPPFLAGS += -I../include +LDFLAGS += -L$(TOPDIR)/lib -L$(PREFIX)/lib -lxbps +CPPFLAGS += -I$(TOPDIR)/include CFLAGS += -Wstack-protector -fstack-protector-all CFLAGS += -O2 -Wall -Werror -fPIC -DPIC