xbps-repo: the 'search' target now accepts multiple patterns as arguments.
This commit is contained in:
parent
5a892023f4
commit
13331f801c
8
NEWS
8
NEWS
@ -1,3 +1,11 @@
|
||||
xbps-0.11.1 (???):
|
||||
|
||||
* libxbps: more paranoid type checking and allocation results, to make
|
||||
sure that out of memory conditions are handled gracefully.
|
||||
|
||||
* xbps-repo(8): the 'search' target accepts multiple patterns, such as:
|
||||
$ xbps-repo search 'foo-[0-9]*' '*blah*' ...
|
||||
|
||||
xbps-0.11.0 (2011-12-20):
|
||||
|
||||
* xbps-bin(8): it is possible now to reinstall a package even if it's
|
||||
|
@ -100,7 +100,6 @@ void unpack_progress_cb(const struct xbps_unpack_cb_data *, void *);
|
||||
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);
|
||||
|
@ -23,9 +23,6 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_STRCASESTR
|
||||
# define _GNU_SOURCE /* for strcasestr(3) */
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
@ -36,7 +33,6 @@
|
||||
#include <strings.h>
|
||||
|
||||
#include <xbps_api.h>
|
||||
#include "compat.h"
|
||||
#include "defs.h"
|
||||
#include "../xbps-repo/defs.h"
|
||||
|
||||
@ -199,42 +195,6 @@ find_longest_pkgver(prop_dictionary_t d)
|
||||
|
||||
return len;
|
||||
}
|
||||
int
|
||||
show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
struct repo_search_data *rsd = arg;
|
||||
const char *pkgver, *pkgname, *desc;
|
||||
char *tmp = NULL;
|
||||
size_t i;
|
||||
|
||||
(void)loop_done;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY);
|
||||
assert(rsd->pattern != NULL);
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc);
|
||||
|
||||
if ((xbps_pkgpattern_match(pkgver, rsd->pattern) == 1) ||
|
||||
(xbps_pkgpattern_match(desc, rsd->pattern) == 1) ||
|
||||
(strcasecmp(pkgname, rsd->pattern) == 0) ||
|
||||
(strcasestr(pkgver, rsd->pattern)) ||
|
||||
(strcasestr(desc, rsd->pattern))) {
|
||||
tmp = calloc(1, rsd->pkgver_len + 1);
|
||||
if (tmp == NULL)
|
||||
return errno;
|
||||
|
||||
strlcpy(tmp, pkgver, rsd->pkgver_len + 1);
|
||||
for (i = strlen(tmp); i < rsd->pkgver_len; i++)
|
||||
tmp[i] = ' ';
|
||||
|
||||
printf(" %s %s\n", tmp, desc);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
list_strings_in_array(prop_object_t obj, void *arg, bool *loop_done)
|
||||
|
@ -33,7 +33,8 @@
|
||||
#include <xbps_api.h>
|
||||
|
||||
struct repo_search_data {
|
||||
char *pattern;
|
||||
int npatterns;
|
||||
char **patterns;
|
||||
size_t pkgver_len;
|
||||
};
|
||||
|
||||
@ -51,6 +52,7 @@ 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 *);
|
||||
int show_pkg_namedesc(prop_object_t, void *, bool *);
|
||||
|
||||
|
||||
#endif /* !_XBPS_REPO_DEFS_H_ */
|
||||
|
@ -79,15 +79,14 @@ repo_list_uri_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||
int
|
||||
repo_search_pkgs_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||
{
|
||||
struct repo_search_data rsd;
|
||||
struct repo_search_data *rsd = arg;
|
||||
(void)done;
|
||||
|
||||
rsd.pattern = arg;
|
||||
rsd.pkgver_len = find_longest_pkgver(rpi->rpi_repod);
|
||||
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);
|
||||
"packages", show_pkg_namedesc, rsd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
struct xbps_handle *xhp;
|
||||
struct xferstat xfer;
|
||||
struct repo_search_data *rsd = NULL;
|
||||
prop_dictionary_t pkgd;
|
||||
const char *rootdir, *cachedir, *conffile, *option;
|
||||
int c, rv = 0;
|
||||
@ -148,10 +149,18 @@ main(int argc, char **argv)
|
||||
* Search for a package by looking at pkgname/short_desc
|
||||
* by using shell style match patterns (fnmatch(3)).
|
||||
*/
|
||||
if (argc != 2)
|
||||
if (argc < 2)
|
||||
usage(xhp);
|
||||
|
||||
rv = xbps_repository_pool_foreach(repo_search_pkgs_cb, argv[1]);
|
||||
rsd = malloc(sizeof(*rsd));
|
||||
if (rsd == NULL) {
|
||||
rv = ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
rsd->npatterns = argc;
|
||||
rsd->patterns = argv;
|
||||
rv = xbps_repository_pool_foreach(repo_search_pkgs_cb, rsd);
|
||||
free(rsd);
|
||||
if (rv == ENOTSUP)
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
|
@ -23,6 +23,14 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_STRCASESTR
|
||||
# define _GNU_SOURCE /* for strcasestr(3) */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
@ -36,10 +44,6 @@
|
||||
#include "../xbps-bin/defs.h"
|
||||
#include "defs.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
int
|
||||
show_pkg_info_from_repolist(const char *pkgname, const char *option)
|
||||
{
|
||||
@ -85,3 +89,42 @@ show_pkg_deps_from_repolist(const char *pkgname)
|
||||
prop_object_release(pkgd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
struct repo_search_data *rsd = arg;
|
||||
const char *pkgver, *pkgname, *desc;
|
||||
char *tmp = NULL;
|
||||
size_t i, x;
|
||||
|
||||
(void)loop_done;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY);
|
||||
assert(rsd->patterns != NULL);
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc);
|
||||
|
||||
for (i = 1; i < (size_t)rsd->npatterns; i++) {
|
||||
if ((xbps_pkgpattern_match(pkgver, rsd->patterns[i]) == 1) ||
|
||||
(xbps_pkgpattern_match(desc, rsd->patterns[i]) == 1) ||
|
||||
(strcasecmp(pkgname, rsd->patterns[i]) == 0) ||
|
||||
(strcasestr(pkgver, rsd->patterns[i])) ||
|
||||
(strcasestr(desc, rsd->patterns[i]))) {
|
||||
tmp = calloc(1, rsd->pkgver_len + 1);
|
||||
if (tmp == NULL)
|
||||
return errno;
|
||||
|
||||
strlcpy(tmp, pkgver, rsd->pkgver_len + 1);
|
||||
for (x = strlen(tmp); x < rsd->pkgver_len; x++)
|
||||
tmp[x] = ' ';
|
||||
|
||||
printf(" %s %s\n", tmp, desc);
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
.Dd December 15, 2011
|
||||
.Dd December 22, 2011
|
||||
.Os Void GNU/Linux
|
||||
.Dt xbps-repo 8
|
||||
.Sh NAME
|
||||
@ -76,7 +76,7 @@ will be shown. The argument expects a decimal number starting from 0,
|
||||
matching the output of the
|
||||
.Ar list
|
||||
target.
|
||||
.It Sy search Ar pattern
|
||||
.It Sy search Ar pattern Ar [patterns ...]
|
||||
Search for packages containing the shell
|
||||
.Em pattern
|
||||
(see
|
||||
@ -86,7 +86,7 @@ in its
|
||||
or
|
||||
.Em description
|
||||
values in repository pool. Please note that patterns are matched in case
|
||||
insensitive mode.
|
||||
insensitive mode. Multiple patterns can be specified as arguments.
|
||||
.It Sy show Ar pkgname
|
||||
Shows information about binary package
|
||||
.Em pkgname .
|
||||
|
Loading…
Reference in New Issue
Block a user