Improvements for xbps-{bin,repo}.
- Indent properly with the longest "pkgver" object while listing or searching for packages. - Also match strings in the short description object while searching for packages in xbps_repo.
This commit is contained in:
parent
d2be842ce5
commit
940e077fb4
13
NEWS
13
NEWS
@ -1,4 +1,15 @@
|
|||||||
xbps-0.6.3 (?)
|
xbps-0.7.0 (?)
|
||||||
|
|
||||||
|
* xbps-{bin,repo}(8): indent uniformly all lines while listing packages
|
||||||
|
in xbps-bin or while searching for packages in xbps-repo.
|
||||||
|
|
||||||
|
* xbps-repo(8): while searching for packages also try to find strings
|
||||||
|
in the short description object.
|
||||||
|
|
||||||
|
* xbps-{bin,repo}(8): added -d arg to enable debugging output to stderr.
|
||||||
|
|
||||||
|
* Cleaned up the API. Still not finished and there's a long way to have this
|
||||||
|
finished and ready for public consumption.
|
||||||
|
|
||||||
* xbps-dgraph: new utility to generate graphviz' dot(1) graphs for package
|
* xbps-dgraph: new utility to generate graphviz' dot(1) graphs for package
|
||||||
metadata properties, such as dependencies, reverse dependencies, etc.
|
metadata properties, such as dependencies, reverse dependencies, etc.
|
||||||
|
@ -36,6 +36,11 @@
|
|||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "../xbps-repo/defs.h"
|
#include "../xbps-repo/defs.h"
|
||||||
|
|
||||||
|
struct list_pkgver_cb {
|
||||||
|
pkg_state_t state;
|
||||||
|
size_t pkgver_len;
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
@ -76,8 +81,11 @@ usage(void)
|
|||||||
static int
|
static int
|
||||||
list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
|
list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
{
|
{
|
||||||
|
struct list_pkgver_cb *lpc = arg;
|
||||||
const char *pkgver, *short_desc;
|
const char *pkgver, *short_desc;
|
||||||
pkg_state_t curstate, *wantstate = (pkg_state_t *)arg;
|
char *tmp = NULL;
|
||||||
|
pkg_state_t curstate, *wantstate = &lpc->state;
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
(void)loop_done;
|
(void)loop_done;
|
||||||
|
|
||||||
@ -96,7 +104,18 @@ list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
|
|||||||
if (!pkgver && !short_desc)
|
if (!pkgver && !short_desc)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
printf("%s\t%s\n", pkgver, short_desc);
|
tmp = malloc(lpc->pkgver_len + 1);
|
||||||
|
if (tmp == NULL)
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
memcpy(tmp, pkgver, lpc->pkgver_len);
|
||||||
|
for (i = strlen(tmp); i < lpc->pkgver_len; i++)
|
||||||
|
tmp[i] = ' ';
|
||||||
|
|
||||||
|
tmp[lpc->pkgver_len + 1] = '\0';
|
||||||
|
printf("%s %s\n", tmp, short_desc);
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +149,7 @@ int
|
|||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dict;
|
prop_dictionary_t dict;
|
||||||
pkg_state_t pkgstate = 0;
|
struct list_pkgver_cb lpc;
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
int i = 0, c, flags = 0, rv = 0;
|
int i = 0, c, flags = 0, rv = 0;
|
||||||
bool yes, purge, with_debug;
|
bool yes, purge, with_debug;
|
||||||
@ -223,11 +242,11 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if (argv[1]) {
|
if (argv[1]) {
|
||||||
if (strcmp(argv[1], "installed") == 0)
|
if (strcmp(argv[1], "installed") == 0)
|
||||||
pkgstate = XBPS_PKG_STATE_INSTALLED;
|
lpc.state = XBPS_PKG_STATE_INSTALLED;
|
||||||
else if (strcmp(argv[1], "unpacked") == 0)
|
else if (strcmp(argv[1], "unpacked") == 0)
|
||||||
pkgstate = XBPS_PKG_STATE_UNPACKED;
|
lpc.state = XBPS_PKG_STATE_UNPACKED;
|
||||||
else if (strcmp(argv[1], "config-files") == 0)
|
else if (strcmp(argv[1], "config-files") == 0)
|
||||||
pkgstate = XBPS_PKG_STATE_CONFIG_FILES;
|
lpc.state = XBPS_PKG_STATE_CONFIG_FILES;
|
||||||
else {
|
else {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"E: invalid state `%s'. Accepted values: "
|
"E: invalid state `%s'. Accepted values: "
|
||||||
@ -238,8 +257,12 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* Find the longest pkgver string to pretty print the output.
|
||||||
|
*/
|
||||||
|
lpc.pkgver_len = find_longest_pkgver(dict);
|
||||||
rv = xbps_callback_array_iter_in_dict(dict, "packages",
|
rv = xbps_callback_array_iter_in_dict(dict, "packages",
|
||||||
list_pkgs_in_dict, &pkgstate);
|
list_pkgs_in_dict, &lpc);
|
||||||
|
|
||||||
} else if (strcasecmp(argv[0], "install") == 0) {
|
} else if (strcasecmp(argv[0], "install") == 0) {
|
||||||
/* Installs a binary package and required deps. */
|
/* Installs a binary package and required deps. */
|
||||||
|
@ -41,5 +41,11 @@ void show_pkg_info_only_repo(prop_dictionary_t);
|
|||||||
int show_pkg_namedesc(prop_object_t, void *, bool *);
|
int show_pkg_namedesc(prop_object_t, void *, bool *);
|
||||||
int list_strings_in_array(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 *);
|
int list_strings_sep_in_array(prop_object_t, void *, bool *);
|
||||||
|
size_t find_longest_pkgver(prop_dictionary_t);
|
||||||
|
|
||||||
|
struct repo_search_data {
|
||||||
|
char *pattern;
|
||||||
|
size_t pkgver_len;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* !_XBPS_REPO_DEFS_H_ */
|
#endif /* !_XBPS_REPO_DEFS_H_ */
|
||||||
|
@ -74,18 +74,23 @@ repo_list_uri_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
|||||||
(void)done;
|
(void)done;
|
||||||
|
|
||||||
printf("%s\n", rpi->rpi_uri);
|
printf("%s\n", rpi->rpi_uri);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
repo_search_pkgs_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
repo_search_pkgs_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||||
{
|
{
|
||||||
char *pattern = arg;
|
struct repo_search_data rsd;
|
||||||
(void)done;
|
(void)done;
|
||||||
|
|
||||||
|
rsd.pattern = arg;
|
||||||
|
rsd.pkgver_len = find_longest_pkgver(rpi->rpi_repod);
|
||||||
|
|
||||||
printf("From %s repository ...\n", rpi->rpi_uri);
|
printf("From %s repository ...\n", rpi->rpi_uri);
|
||||||
(void)xbps_callback_array_iter_in_dict(rpi->rpi_repod,
|
(void)xbps_callback_array_iter_in_dict(rpi->rpi_repod,
|
||||||
"packages", show_pkg_namedesc, pattern);
|
"packages", show_pkg_namedesc, &rsd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,29 +178,64 @@ show_pkg_files(prop_dictionary_t filesd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_find_longest_pkgver_cb(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
|
{
|
||||||
|
size_t *len = arg;
|
||||||
|
const char *pkgver;
|
||||||
|
|
||||||
|
(void)loop_done;
|
||||||
|
|
||||||
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||||
|
if (*len == 0 || strlen(pkgver) > *len)
|
||||||
|
*len = strlen(pkgver);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
find_longest_pkgver(prop_dictionary_t d)
|
||||||
|
{
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
(void)xbps_callback_array_iter_in_dict(d, "packages",
|
||||||
|
_find_longest_pkgver_cb, &len);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
int
|
int
|
||||||
show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done)
|
show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
{
|
{
|
||||||
|
struct repo_search_data *rsd = arg;
|
||||||
const char *pkgver, *pkgname, *desc;
|
const char *pkgver, *pkgname, *desc;
|
||||||
char *pattern = arg;
|
char *tmp = NULL;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
(void)loop_done;
|
(void)loop_done;
|
||||||
|
|
||||||
assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY);
|
assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY);
|
||||||
assert(pattern != NULL);
|
assert(rsd->pattern != NULL);
|
||||||
|
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc);
|
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc);
|
||||||
|
|
||||||
if (xbps_pkgpattern_match(pkgver, pattern) == 1)
|
if ((xbps_pkgpattern_match(pkgver, rsd->pattern) == 1) ||
|
||||||
printf(" %s - %s\n", pkgver, desc);
|
(xbps_pkgpattern_match(desc, rsd->pattern) == 1) ||
|
||||||
else if (strcmp(pkgname, pattern) == 0)
|
(strcmp(pkgname, rsd->pattern) == 0) ||
|
||||||
printf(" %s - %s\n", pkgver, desc);
|
(strstr(pkgver, rsd->pattern)) || (strstr(desc, rsd->pattern))) {
|
||||||
else if (xbps_pkgpattern_match(desc, pattern) == 1)
|
tmp = malloc(rsd->pkgver_len + 1);
|
||||||
printf(" %s - %s\n", pkgver, desc);
|
if (tmp == NULL)
|
||||||
else if (strstr(pkgver, pattern))
|
return errno;
|
||||||
printf(" %s - %s\n", pkgver, desc);
|
|
||||||
|
memcpy(tmp, pkgver, rsd->pkgver_len);
|
||||||
|
for (i = strlen(tmp); i < rsd->pkgver_len; i++)
|
||||||
|
tmp[i] = ' ';
|
||||||
|
|
||||||
|
tmp[rsd->pkgver_len + 1] = '\0';
|
||||||
|
printf(" %s %s\n", tmp, desc);
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user