xbps-repo: move list/search code into its own file: list.c.
This commit is contained in:
parent
43d85c76b3
commit
afde2a6653
@ -2,7 +2,7 @@ TOPDIR = ../..
|
|||||||
-include $(TOPDIR)/config.mk
|
-include $(TOPDIR)/config.mk
|
||||||
|
|
||||||
BIN = xbps-repo
|
BIN = xbps-repo
|
||||||
OBJS = main.o index.o show.o find-files.o
|
OBJS = main.o index.o show.o find-files.o list.o
|
||||||
OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o
|
OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o
|
||||||
OBJS += ../xbps-bin/state_cb.o ../xbps-bin/list.o
|
OBJS += ../xbps-bin/state_cb.o ../xbps-bin/list.o
|
||||||
MAN = $(BIN).8
|
MAN = $(BIN).8
|
||||||
|
@ -32,19 +32,25 @@
|
|||||||
|
|
||||||
#include <xbps_api.h>
|
#include <xbps_api.h>
|
||||||
|
|
||||||
/* From index.c */
|
|
||||||
int repo_genindex(const char *);
|
|
||||||
|
|
||||||
/* From show.c */
|
|
||||||
int show_pkg_info_from_repolist(const char *, const char *);
|
|
||||||
int show_pkg_deps_from_repolist(const char *);
|
|
||||||
|
|
||||||
/* From find-files.c */
|
|
||||||
int repo_find_files_in_packages(const char *);
|
|
||||||
|
|
||||||
struct repo_search_data {
|
struct repo_search_data {
|
||||||
char *pattern;
|
char *pattern;
|
||||||
size_t pkgver_len;
|
size_t pkgver_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* From index.c */
|
||||||
|
int repo_genindex(const char *);
|
||||||
|
|
||||||
|
/* From find-files.c */
|
||||||
|
int repo_find_files_in_packages(const char *);
|
||||||
|
|
||||||
|
/* From list.c */
|
||||||
|
int repo_pkg_list_cb(struct repository_pool_index *, void *, bool *);
|
||||||
|
int repo_list_uri_cb(struct repository_pool_index *, void *, bool *);
|
||||||
|
int repo_search_pkgs_cb(struct repository_pool_index *, void *, bool *);
|
||||||
|
|
||||||
|
/* From show.c */
|
||||||
|
int show_pkg_info_from_repolist(const char *, const char *);
|
||||||
|
int show_pkg_deps_from_repolist(const char *);
|
||||||
|
|
||||||
|
|
||||||
#endif /* !_XBPS_REPO_DEFS_H_ */
|
#endif /* !_XBPS_REPO_DEFS_H_ */
|
||||||
|
93
bin/xbps-repo/list.c
Normal file
93
bin/xbps-repo/list.c
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2011 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 <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
#include "../xbps-bin/defs.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
repo_pkg_list_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||||
|
{
|
||||||
|
struct list_pkgver_cb lpc;
|
||||||
|
uint16_t idx;
|
||||||
|
char *cp;
|
||||||
|
|
||||||
|
(void)done;
|
||||||
|
if (arg != NULL) {
|
||||||
|
idx = (uint16_t)strtoul(arg, &cp, 0);
|
||||||
|
if (rpi->rpi_index != idx)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
lpc.check_state = false;
|
||||||
|
lpc.state = 0;
|
||||||
|
lpc.pkgver_len = find_longest_pkgver(rpi->rpi_repod);
|
||||||
|
|
||||||
|
printf("From %s repository ...\n", rpi->rpi_uri);
|
||||||
|
(void)xbps_callback_array_iter_in_dict(rpi->rpi_repod,
|
||||||
|
"packages", list_pkgs_in_dict, &lpc);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
repo_list_uri_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||||
|
{
|
||||||
|
const char *pkgidx;
|
||||||
|
uint64_t npkgs;
|
||||||
|
|
||||||
|
(void)arg;
|
||||||
|
(void)done;
|
||||||
|
|
||||||
|
prop_dictionary_get_cstring_nocopy(rpi->rpi_repod,
|
||||||
|
"pkgindex-version", &pkgidx);
|
||||||
|
prop_dictionary_get_uint64(rpi->rpi_repod, "total-pkgs", &npkgs);
|
||||||
|
printf("[%u] %s (index %s, " "%" PRIu64 " packages)\n",
|
||||||
|
rpi->rpi_index, rpi->rpi_uri, pkgidx, npkgs);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
repo_search_pkgs_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||||
|
{
|
||||||
|
struct repo_search_data rsd;
|
||||||
|
(void)done;
|
||||||
|
|
||||||
|
rsd.pattern = arg;
|
||||||
|
rsd.pkgver_len = find_longest_pkgver(rpi->rpi_repod);
|
||||||
|
|
||||||
|
printf("From %s repository ...\n", rpi->rpi_uri);
|
||||||
|
(void)xbps_callback_array_iter_in_dict(rpi->rpi_repod,
|
||||||
|
"packages", show_pkg_namedesc, &rsd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -50,64 +50,6 @@ usage(struct xbps_handle *xhp)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
repo_pkg_list_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
|
||||||
{
|
|
||||||
struct list_pkgver_cb lpc;
|
|
||||||
uint16_t idx;
|
|
||||||
char *cp;
|
|
||||||
|
|
||||||
(void)done;
|
|
||||||
if (arg != NULL) {
|
|
||||||
idx = (uint16_t)strtoul(arg, &cp, 0);
|
|
||||||
if (rpi->rpi_index != idx)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
lpc.check_state = false;
|
|
||||||
lpc.state = 0;
|
|
||||||
lpc.pkgver_len = find_longest_pkgver(rpi->rpi_repod);
|
|
||||||
|
|
||||||
printf("From %s repository ...\n", rpi->rpi_uri);
|
|
||||||
(void)xbps_callback_array_iter_in_dict(rpi->rpi_repod,
|
|
||||||
"packages", list_pkgs_in_dict, &lpc);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
repo_list_uri_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
|
||||||
{
|
|
||||||
const char *pkgidx;
|
|
||||||
uint64_t npkgs;
|
|
||||||
|
|
||||||
(void)arg;
|
|
||||||
(void)done;
|
|
||||||
|
|
||||||
prop_dictionary_get_cstring_nocopy(rpi->rpi_repod,
|
|
||||||
"pkgindex-version", &pkgidx);
|
|
||||||
prop_dictionary_get_uint64(rpi->rpi_repod, "total-pkgs", &npkgs);
|
|
||||||
printf("[%u] %s (index %s, " "%" PRIu64 " packages)\n",
|
|
||||||
rpi->rpi_index, rpi->rpi_uri, pkgidx, npkgs);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
repo_search_pkgs_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
|
||||||
{
|
|
||||||
struct repo_search_data rsd;
|
|
||||||
(void)done;
|
|
||||||
|
|
||||||
rsd.pattern = arg;
|
|
||||||
rsd.pkgver_len = find_longest_pkgver(rpi->rpi_repod);
|
|
||||||
|
|
||||||
printf("From %s repository ...\n", rpi->rpi_uri);
|
|
||||||
(void)xbps_callback_array_iter_in_dict(rpi->rpi_repod,
|
|
||||||
"packages", show_pkg_namedesc, &rsd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user