xbps-bin: split main.c into new files: list.c show-orphans.c and unpack_cb.c.
This commit is contained in:
parent
029fd96690
commit
9157f7d148
@ -8,6 +8,7 @@ OBJS += question.o fetch_cb.o state_cb.o
|
||||
OBJS += check.o check_pkg_automatic.o check_pkg_files.o
|
||||
OBJS += check_pkg_rundeps.o check_pkg_symlinks.o
|
||||
OBJS += check_pkg_requiredby.o
|
||||
OBJS += show-orphans.o unpack_cb.o list.o
|
||||
MAN = $(BIN).8
|
||||
|
||||
include $(TOPDIR)/bin/prog.mk
|
||||
|
@ -38,6 +38,11 @@ struct xferstat {
|
||||
struct timeval last;
|
||||
};
|
||||
|
||||
struct list_pkgver_cb {
|
||||
pkg_state_t state;
|
||||
size_t pkgver_len;
|
||||
};
|
||||
|
||||
/* from install.c */
|
||||
int install_new_pkg(const char *);
|
||||
int update_pkg(const char *);
|
||||
@ -69,6 +74,9 @@ int show_pkg_reverse_deps(const char *);
|
||||
int show_pkg_info_from_metadir(const char *, const char *);
|
||||
int show_pkg_files_from_metadir(const char *);
|
||||
|
||||
/* from show-orphans.c */
|
||||
int show_orphans(void);
|
||||
|
||||
/* from find-files.c */
|
||||
int find_files_in_packages(const char *);
|
||||
|
||||
@ -82,6 +90,10 @@ void fetch_file_progress_cb(struct xbps_fetch_cb_data *);
|
||||
/* from state_cb.c */
|
||||
void state_cb(struct xbps_state_cb_data *);
|
||||
|
||||
/* from unpack_cb.c */
|
||||
void unpack_progress_cb_verbose(struct xbps_unpack_cb_data *);
|
||||
void unpack_progress_cb(struct xbps_unpack_cb_data *);
|
||||
|
||||
/* From util.c */
|
||||
int show_pkg_files(prop_dictionary_t);
|
||||
void show_pkg_info(prop_dictionary_t);
|
||||
@ -92,4 +104,8 @@ int list_strings_sep_in_array(prop_object_t, void *, bool *);
|
||||
size_t find_longest_pkgver(prop_dictionary_t);
|
||||
void print_package_line(const char *, bool);
|
||||
|
||||
/* from list.c */
|
||||
int list_pkgs_in_dict(prop_object_t, void *, bool *);
|
||||
int list_manual_pkgs(prop_object_t, void *, bool *);
|
||||
|
||||
#endif /* !_XBPS_BIN_DEFS_H_ */
|
||||
|
94
bin/xbps-bin/list.c
Normal file
94
bin/xbps-bin/list.c
Normal file
@ -0,0 +1,94 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-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 <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "compat.h"
|
||||
|
||||
int
|
||||
list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
struct list_pkgver_cb *lpc = arg;
|
||||
const char *pkgver, *short_desc;
|
||||
char *tmp = NULL;
|
||||
pkg_state_t curstate;
|
||||
size_t i = 0;
|
||||
|
||||
(void)loop_done;
|
||||
|
||||
if (xbps_pkg_state_dictionary(obj, &curstate))
|
||||
return EINVAL;
|
||||
|
||||
if (lpc->state == 0) {
|
||||
/* Only list packages that are fully installed */
|
||||
if (curstate != XBPS_PKG_STATE_INSTALLED)
|
||||
return 0;
|
||||
} else {
|
||||
/* Only list packages with specified state */
|
||||
if (curstate != lpc->state)
|
||||
return 0;
|
||||
}
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc);
|
||||
if (!pkgver && !short_desc)
|
||||
return EINVAL;
|
||||
|
||||
tmp = calloc(1, lpc->pkgver_len + 1);
|
||||
if (tmp == NULL)
|
||||
return errno;
|
||||
|
||||
strlcpy(tmp, pkgver, lpc->pkgver_len + 1);
|
||||
for (i = strlen(tmp); i < lpc->pkgver_len; i++)
|
||||
tmp[i] = ' ';
|
||||
|
||||
printf("%s %s\n", tmp, short_desc);
|
||||
free(tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
list_manual_pkgs(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
const char *pkgver;
|
||||
bool automatic = false;
|
||||
|
||||
(void)arg;
|
||||
(void)loop_done;
|
||||
|
||||
prop_dictionary_get_bool(obj, "automatic-install", &automatic);
|
||||
if (automatic == false) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
printf("%s\n", pkgver);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -38,11 +38,6 @@
|
||||
#include "defs.h"
|
||||
#include "../xbps-repo/defs.h"
|
||||
|
||||
struct list_pkgver_cb {
|
||||
pkg_state_t state;
|
||||
size_t pkgver_len;
|
||||
};
|
||||
|
||||
static void __attribute__((noreturn))
|
||||
usage(struct xbps_handle *xhp)
|
||||
{
|
||||
@ -55,95 +50,6 @@ usage(struct xbps_handle *xhp)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int
|
||||
list_pkgs_in_dict(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
struct list_pkgver_cb *lpc = arg;
|
||||
const char *pkgver, *short_desc;
|
||||
char *tmp = NULL;
|
||||
pkg_state_t curstate;
|
||||
size_t i = 0;
|
||||
|
||||
(void)loop_done;
|
||||
|
||||
if (xbps_pkg_state_dictionary(obj, &curstate))
|
||||
return EINVAL;
|
||||
|
||||
if (lpc->state == 0) {
|
||||
/* Only list packages that are fully installed */
|
||||
if (curstate != XBPS_PKG_STATE_INSTALLED)
|
||||
return 0;
|
||||
} else {
|
||||
/* Only list packages with specified state */
|
||||
if (curstate != lpc->state)
|
||||
return 0;
|
||||
}
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc);
|
||||
if (!pkgver && !short_desc)
|
||||
return EINVAL;
|
||||
|
||||
tmp = calloc(1, lpc->pkgver_len + 1);
|
||||
if (tmp == NULL)
|
||||
return errno;
|
||||
|
||||
strlcpy(tmp, pkgver, lpc->pkgver_len + 1);
|
||||
for (i = strlen(tmp); i < lpc->pkgver_len; i++)
|
||||
tmp[i] = ' ';
|
||||
|
||||
printf("%s %s\n", tmp, short_desc);
|
||||
free(tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
list_manual_packages(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
const char *pkgver;
|
||||
bool automatic = false;
|
||||
|
||||
(void)arg;
|
||||
(void)loop_done;
|
||||
|
||||
prop_dictionary_get_bool(obj, "automatic-install", &automatic);
|
||||
if (automatic == false) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
printf("%s\n", pkgver);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
show_orphans(void)
|
||||
{
|
||||
prop_array_t orphans;
|
||||
prop_object_iterator_t iter;
|
||||
prop_object_t obj;
|
||||
const char *pkgver;
|
||||
|
||||
orphans = xbps_find_pkg_orphans(NULL);
|
||||
if (orphans == NULL)
|
||||
return EINVAL;
|
||||
|
||||
if (prop_array_count(orphans) == 0)
|
||||
return 0;
|
||||
|
||||
iter = prop_array_iterator(orphans);
|
||||
if (iter == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
printf("%s\n", pkgver);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __attribute__((noreturn))
|
||||
cleanup(int signum)
|
||||
{
|
||||
@ -153,31 +59,6 @@ cleanup(int signum)
|
||||
exit(signum);
|
||||
}
|
||||
|
||||
static void
|
||||
unpack_progress_cb_verbose(struct xbps_unpack_cb_data *xpd)
|
||||
{
|
||||
if (xpd->entry == NULL || xpd->entry_is_metadata)
|
||||
return;
|
||||
else if (xpd->entry_size <= 0)
|
||||
return;
|
||||
|
||||
printf("Extracted %sfile `%s' (%" PRIi64 " bytes)\n",
|
||||
xpd->entry_is_conf ? "configuration " : "", xpd->entry,
|
||||
xpd->entry_size);
|
||||
}
|
||||
|
||||
static void
|
||||
unpack_progress_cb(struct xbps_unpack_cb_data *xpd)
|
||||
{
|
||||
if (xpd->entry == NULL || xpd->entry_is_metadata)
|
||||
return;
|
||||
else if (xpd->entry_size <= 0)
|
||||
return;
|
||||
|
||||
printf("Extracting `%s'...\n", xpd->entry);
|
||||
printf("\033[1A\033[K");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@ -476,7 +357,7 @@ main(int argc, char **argv)
|
||||
usage(xhp);
|
||||
|
||||
rv = xbps_callback_array_iter_in_dict(xhp->regpkgdb_dictionary,
|
||||
"packages", list_manual_packages, NULL);
|
||||
"packages", list_manual_pkgs, NULL);
|
||||
|
||||
} else if (strcasecmp(argv[0], "show-revdeps") == 0) {
|
||||
/*
|
||||
|
58
bin/xbps-bin/show-orphans.c
Normal file
58
bin/xbps-bin/show-orphans.c
Normal file
@ -0,0 +1,58 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-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 <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
int
|
||||
show_orphans(void)
|
||||
{
|
||||
prop_array_t orphans;
|
||||
prop_object_iterator_t iter;
|
||||
prop_object_t obj;
|
||||
const char *pkgver;
|
||||
|
||||
orphans = xbps_find_pkg_orphans(NULL);
|
||||
if (orphans == NULL)
|
||||
return EINVAL;
|
||||
|
||||
if (prop_array_count(orphans) == 0)
|
||||
return 0;
|
||||
|
||||
iter = prop_array_iterator(orphans);
|
||||
if (iter == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
printf("%s\n", pkgver);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
return 0;
|
||||
}
|
55
bin/xbps-bin/unpack_cb.c
Normal file
55
bin/xbps-bin/unpack_cb.c
Normal file
@ -0,0 +1,55 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-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 <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
void
|
||||
unpack_progress_cb_verbose(struct xbps_unpack_cb_data *xpd)
|
||||
{
|
||||
if (xpd->entry == NULL || xpd->entry_is_metadata)
|
||||
return;
|
||||
else if (xpd->entry_size <= 0)
|
||||
return;
|
||||
|
||||
printf("Extracted %sfile `%s' (%" PRIi64 " bytes)\n",
|
||||
xpd->entry_is_conf ? "configuration " : "", xpd->entry,
|
||||
xpd->entry_size);
|
||||
}
|
||||
|
||||
void
|
||||
unpack_progress_cb(struct xbps_unpack_cb_data *xpd)
|
||||
{
|
||||
if (xpd->entry == NULL || xpd->entry_is_metadata)
|
||||
return;
|
||||
else if (xpd->entry_size <= 0)
|
||||
return;
|
||||
|
||||
printf("Extracting `%s'...\n", xpd->entry);
|
||||
printf("\033[1A\033[K");
|
||||
}
|
Loading…
Reference in New Issue
Block a user