2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2011-01-26 21:04:26 +05:30
|
|
|
* Copyright (c) 2008-2011 Juan Romero Pardines.
|
2009-08-17 22:37:20 +05:30
|
|
|
* 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 <errno.h>
|
|
|
|
#include <fnmatch.h>
|
2010-11-13 07:48:58 +05:30
|
|
|
#include <assert.h>
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
#include <xbps_api.h>
|
2010-12-24 10:01:37 +05:30
|
|
|
#include "strlcpy.h"
|
2009-11-24 16:35:39 +05:30
|
|
|
#include "defs.h"
|
2011-01-22 17:10:19 +05:30
|
|
|
#include "../xbps-repo/defs.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-01-26 21:04:26 +05:30
|
|
|
struct object_info {
|
|
|
|
const char *key;
|
|
|
|
const char *descr;
|
|
|
|
};
|
2009-11-25 10:02:04 +05:30
|
|
|
|
2011-01-26 21:04:26 +05:30
|
|
|
static const struct object_info obj_info[] = {
|
2011-05-27 21:02:42 +05:30
|
|
|
{
|
|
|
|
.key = "repository",
|
|
|
|
.descr = "Repository: "
|
|
|
|
},
|
2011-01-26 21:04:26 +05:30
|
|
|
{
|
|
|
|
.key = "filename",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Binary package: "
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "filename-size",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Binary package size"
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "filename-sha256",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Binary package SHA256: "
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "archive-compression-type",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Binary package compression type: "
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "pkgname",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Package: "
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "installed_size",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Installed size"
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "maintainer",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Maintainer: "
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "architecture",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Architecture: "
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "version",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Version: "
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
2011-05-26 14:24:48 +05:30
|
|
|
{
|
|
|
|
.key = "homepage",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Upstream URL: "
|
2011-05-26 14:24:48 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "license",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "License(s): "
|
2011-05-26 14:24:48 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "build_date",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Package build date: "
|
2011-05-26 14:24:48 +05:30
|
|
|
},
|
2011-01-26 21:04:26 +05:30
|
|
|
{
|
|
|
|
.key = "preserve",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Preserve files"
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "replaces",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Replaces these packages"
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "provides",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Provides virtual packages"
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "conflicts",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Conflicts with"
|
2011-02-04 22:30:47 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "hold",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Hold update"
|
2011-02-04 22:30:47 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "update-first",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Always update first"
|
2011-02-04 22:30:47 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "virtual-prefer",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Virtual packages enabled"
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "conf_files",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Configuration files"
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = "short_desc",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "Description: "
|
|
|
|
},
|
2011-01-26 21:04:26 +05:30
|
|
|
{
|
|
|
|
.key = "long_desc",
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = "",
|
2011-01-26 21:04:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
.key = NULL,
|
2011-05-27 21:02:42 +05:30
|
|
|
.descr = NULL
|
2011-01-26 21:04:26 +05:30
|
|
|
}
|
|
|
|
};
|
2009-11-25 10:02:04 +05:30
|
|
|
|
2009-11-24 16:17:04 +05:30
|
|
|
void
|
2011-05-27 21:02:42 +05:30
|
|
|
show_pkg_info(prop_dictionary_t dict)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-01-26 21:04:26 +05:30
|
|
|
const struct object_info *oip;
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_object_t obj;
|
2011-01-19 03:40:07 +05:30
|
|
|
char size[8];
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
assert(dict != NULL);
|
|
|
|
assert(prop_dictionary_count(dict) != 0);
|
|
|
|
|
2011-01-26 21:04:26 +05:30
|
|
|
for (oip = obj_info; oip->key != NULL; oip++) {
|
|
|
|
obj = prop_dictionary_get(dict, oip->key);
|
|
|
|
switch (prop_object_type(obj)) {
|
|
|
|
case PROP_TYPE_STRING:
|
2011-05-27 21:02:42 +05:30
|
|
|
printf("%s%s\n", oip->descr,
|
2011-01-26 21:04:26 +05:30
|
|
|
prop_string_cstring_nocopy(obj));
|
|
|
|
break;
|
|
|
|
case PROP_TYPE_NUMBER:
|
|
|
|
printf("%s: ", oip->descr);
|
|
|
|
if (xbps_humanize_number(size,
|
|
|
|
(int64_t)prop_number_unsigned_integer_value(obj)) == -1)
|
|
|
|
printf("%ju\n",
|
|
|
|
prop_number_unsigned_integer_value(obj));
|
|
|
|
else
|
|
|
|
printf("%s\n", size);
|
|
|
|
break;
|
|
|
|
case PROP_TYPE_BOOL:
|
|
|
|
printf("%s: %s\n", oip->descr,
|
|
|
|
prop_bool_true(obj) ? "yes" : "no");
|
|
|
|
break;
|
|
|
|
case PROP_TYPE_ARRAY:
|
2011-05-27 21:02:42 +05:30
|
|
|
printf("%s:\n", oip->descr);
|
2011-01-26 21:04:26 +05:30
|
|
|
(void)xbps_callback_array_iter_in_dict(dict, oip->key,
|
2011-05-27 21:02:42 +05:30
|
|
|
list_strings_sep_in_array, __UNCONST(" "));
|
2011-01-26 21:04:26 +05:30
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-25 07:45:56 +05:30
|
|
|
int
|
|
|
|
show_pkg_files(prop_dictionary_t filesd)
|
|
|
|
{
|
|
|
|
prop_array_t array;
|
|
|
|
prop_object_iterator_t iter = NULL;
|
|
|
|
prop_object_t obj;
|
2010-01-13 21:27:50 +05:30
|
|
|
const char *file, *array_str;
|
2009-11-25 07:45:56 +05:30
|
|
|
int i = 0;
|
|
|
|
|
2010-01-13 21:27:50 +05:30
|
|
|
/* This will print links, conf_files and files respectively. */
|
|
|
|
for (i = 0; i < 3; i++) {
|
2009-11-25 07:45:56 +05:30
|
|
|
if (i == 0)
|
2010-01-13 21:27:50 +05:30
|
|
|
array_str = "links";
|
|
|
|
else if (i == 1)
|
2009-11-25 07:45:56 +05:30
|
|
|
array_str = "conf_files";
|
|
|
|
else
|
|
|
|
array_str = "files";
|
|
|
|
|
|
|
|
array = prop_dictionary_get(filesd, array_str);
|
|
|
|
if (array == NULL || prop_array_count(array) == 0)
|
|
|
|
continue;
|
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
iter = xbps_array_iter_from_dict(filesd, array_str);
|
2009-11-25 07:45:56 +05:30
|
|
|
if (iter == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
2009-11-25 07:45:56 +05:30
|
|
|
printf("%s\n", file);
|
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-24 21:07:30 +05:30
|
|
|
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;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
int
|
|
|
|
show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done)
|
|
|
|
{
|
2010-11-24 21:07:30 +05:30
|
|
|
struct repo_search_data *rsd = arg;
|
2010-01-14 05:36:54 +05:30
|
|
|
const char *pkgver, *pkgname, *desc;
|
2010-11-24 21:07:30 +05:30
|
|
|
char *tmp = NULL;
|
|
|
|
size_t i;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
(void)loop_done;
|
|
|
|
|
|
|
|
assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY);
|
2010-11-24 21:07:30 +05:30
|
|
|
assert(rsd->pattern != NULL);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-01-14 05:36:54 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
2009-11-28 10:22:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc);
|
|
|
|
|
2010-11-24 21:07:30 +05:30
|
|
|
if ((xbps_pkgpattern_match(pkgver, rsd->pattern) == 1) ||
|
|
|
|
(xbps_pkgpattern_match(desc, rsd->pattern) == 1) ||
|
|
|
|
(strcmp(pkgname, rsd->pattern) == 0) ||
|
|
|
|
(strstr(pkgver, rsd->pattern)) || (strstr(desc, rsd->pattern))) {
|
2010-12-04 15:01:17 +05:30
|
|
|
tmp = calloc(1, rsd->pkgver_len + 1);
|
2010-11-24 21:07:30 +05:30
|
|
|
if (tmp == NULL)
|
|
|
|
return errno;
|
|
|
|
|
2010-12-24 10:01:37 +05:30
|
|
|
strlcpy(tmp, pkgver, rsd->pkgver_len + 1);
|
2010-11-24 21:07:30 +05:30
|
|
|
for (i = strlen(tmp); i < rsd->pkgver_len; i++)
|
|
|
|
tmp[i] = ' ';
|
|
|
|
|
|
|
|
printf(" %s %s\n", tmp, desc);
|
|
|
|
free(tmp);
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
list_strings_in_array(prop_object_t obj, void *arg, bool *loop_done)
|
|
|
|
{
|
|
|
|
(void)arg;
|
|
|
|
(void)loop_done;
|
|
|
|
|
|
|
|
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
2011-01-25 22:22:04 +05:30
|
|
|
print_package_line(prop_string_cstring_nocopy(obj), false);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
list_strings_sep_in_array(prop_object_t obj, void *arg, bool *loop_done)
|
|
|
|
{
|
|
|
|
const char *sep = arg;
|
|
|
|
|
|
|
|
(void)loop_done;
|
|
|
|
|
|
|
|
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
|
|
|
printf("%s%s\n", sep ? sep : "", prop_string_cstring_nocopy(obj));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-12-03 22:06:07 +05:30
|
|
|
|
|
|
|
void
|
2011-01-25 22:22:04 +05:30
|
|
|
print_package_line(const char *str, bool reset)
|
2010-12-03 22:06:07 +05:30
|
|
|
{
|
|
|
|
static size_t cols;
|
|
|
|
static bool first;
|
|
|
|
|
2011-01-25 22:22:04 +05:30
|
|
|
if (reset) {
|
|
|
|
cols = 0;
|
|
|
|
first = false;
|
|
|
|
return;
|
|
|
|
}
|
2010-12-03 22:06:07 +05:30
|
|
|
cols += strlen(str) + 4;
|
|
|
|
if (cols <= 80) {
|
|
|
|
if (first == false) {
|
|
|
|
printf(" ");
|
|
|
|
first = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("\n ");
|
|
|
|
cols = strlen(str) + 4;
|
|
|
|
}
|
|
|
|
printf("%s ", str);
|
|
|
|
}
|