xbps-{bin,repo}: use static const tables to parse objs in XBPS_PKGPROPS files.

This commit is contained in:
Juan RP 2011-01-26 16:34:26 +01:00
parent ac6fe51340
commit bc259ae720
4 changed files with 170 additions and 104 deletions

View File

@ -55,8 +55,8 @@ void fetch_file_progress_cb(void *);
/* From util.c */
int show_pkg_files(prop_dictionary_t);
void show_pkg_info(prop_dictionary_t);
void show_pkg_info_only_repo(prop_dictionary_t);
void show_pkg_info(prop_dictionary_t, bool);
void show_pkg_info_only_repo(prop_dictionary_t);
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 *);

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2010 Juan Romero Pardines.
* Copyright (c) 2008-2011 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -43,7 +43,7 @@ show_pkg_info_from_metadir(const char *pkgname)
if (d == NULL)
return errno;
show_pkg_info(d);
show_pkg_info(d, false);
prop_object_release(d);
return 0;

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2010 Juan Romero Pardines.
* Copyright (c) 2008-2011 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,111 +36,177 @@
#include "defs.h"
#include "../xbps-repo/defs.h"
void
show_pkg_info_only_repo(prop_dictionary_t dict)
{
prop_object_t obj;
char size[8];
int rv;
obj = prop_dictionary_get(dict, "filename");
if (prop_object_type(obj) == PROP_TYPE_STRING) {
printf("Filename: %s", prop_string_cstring_nocopy(obj));
obj = prop_dictionary_get(dict, "filename-size");
if (prop_object_type(obj) == PROP_TYPE_NUMBER) {
rv = xbps_humanize_number(size,
(int64_t)prop_number_unsigned_integer_value(obj));
if (rv == -1)
printf(" (size: %ju)\n",
prop_number_unsigned_integer_value(obj));
else
printf(" (size: %s)\n", size);
} else
printf("\n");
}
obj = prop_dictionary_get(dict, "filename-sha256");
if (prop_object_type(obj) == PROP_TYPE_STRING)
printf("SHA256: %s\n", prop_string_cstring_nocopy(obj));
}
void
show_pkg_info(prop_dictionary_t dict)
{
prop_object_t obj;
struct object_info {
const char *key;
const char *descr;
const char *sep;
prop_type_t type;
bool from_repo;
};
static const struct object_info obj_info[] = {
{
.key = "filename",
.descr = "Binary package:",
.sep = NULL,
.type = PROP_TYPE_STRING,
.from_repo = true
},
{
.key = "filename-size",
.descr = "Binary package size",
.sep = NULL,
.type = PROP_TYPE_NUMBER,
.from_repo = true
},
{
.key = "filename-sha256",
.descr = "Binary package SHA256:",
.sep = NULL,
.type = PROP_TYPE_STRING,
.from_repo = true
},
{
.key = "archive-compression-type",
.descr = "Binary package compression type:",
.sep = NULL,
.type = PROP_TYPE_STRING,
.from_repo = false
},
{
.key = "pkgname",
.descr = "Package:",
.sep = NULL,
.type = PROP_TYPE_STRING,
.from_repo = false
},
{
.key = "installed_size",
.descr = "Installed size",
.sep = NULL,
.type = PROP_TYPE_NUMBER,
.from_repo = false
},
{
.key = "maintainer",
.descr = "Maintainer:",
.sep = NULL,
.type = PROP_TYPE_STRING,
.from_repo = false
},
{
.key = "architecture",
.descr = "Architecture:",
.sep = NULL,
.type = PROP_TYPE_STRING,
.from_repo = false
},
{
.key = "version",
.descr = "Version:",
.sep = NULL,
.type = PROP_TYPE_STRING,
.from_repo = false
},
{
.key = "preserve",
.descr = "Preserve files",
.sep = NULL,
.type = PROP_TYPE_BOOL,
.from_repo = false
},
{
.key = "replaces",
.descr = "Replaces these packages:",
.sep = NULL,
.type = PROP_TYPE_ARRAY,
.from_repo = false
},
{
.key = "provides",
.descr = "Provides virtual packages:",
.sep = NULL,
.type = PROP_TYPE_ARRAY,
.from_repo = false
},
{
.key = "conflicts",
.descr = "Conflicts with:",
.sep = NULL,
.type = PROP_TYPE_ARRAY,
.from_repo = false
},
{
.key = "conf_files",
.descr = "Configuration files:\n",
.sep = " ",
.type = PROP_TYPE_ARRAY,
.from_repo = false
},
{
.key = "short_desc",
.descr = "Description:",
.sep = NULL,
.type = PROP_TYPE_STRING,
.from_repo = false },
{
.key = "long_desc",
.descr = " ",
.sep = NULL,
.type = PROP_TYPE_STRING,
.from_repo = false
},
{
.key = NULL,
.descr = NULL,
.sep = NULL,
.type = PROP_TYPE_UNKNOWN,
.from_repo = false
}
};
void
show_pkg_info(prop_dictionary_t dict, bool only_repo)
{
const struct object_info *oip;
prop_object_t obj;
char size[8];
assert(dict != NULL);
assert(prop_dictionary_count(dict) != 0);
obj = prop_dictionary_get(dict, "archive-compression-type");
if (prop_object_type(obj) == PROP_TYPE_STRING)
printf("Compression type: %s\n",
prop_string_cstring_nocopy(obj));
for (oip = obj_info; oip->key != NULL; oip++) {
if (only_repo && oip->from_repo == false)
continue;
obj = prop_dictionary_get(dict, "pkgname");
if (prop_object_type(obj) == PROP_TYPE_STRING)
printf("Package: %s\n", prop_string_cstring_nocopy(obj));
obj = prop_dictionary_get(dict, "installed_size");
if (prop_object_type(obj) == PROP_TYPE_NUMBER) {
printf("Installed size: ");
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);
obj = prop_dictionary_get(dict, oip->key);
switch (prop_object_type(obj)) {
case PROP_TYPE_STRING:
printf("%s %s\n", oip->descr,
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:
printf("%s ", oip->descr);
(void)xbps_callback_array_iter_in_dict(dict, oip->key,
list_strings_sep_in_array, __UNCONST(oip->sep));
break;
default:
break;
}
}
obj = prop_dictionary_get(dict, "maintainer");
if (prop_object_type(obj) == PROP_TYPE_STRING)
printf("Maintainer: %s\n", prop_string_cstring_nocopy(obj));
obj = prop_dictionary_get(dict, "architecture");
if (prop_object_type(obj) == PROP_TYPE_STRING)
printf("Architecture: %s\n", prop_string_cstring_nocopy(obj));
obj = prop_dictionary_get(dict, "version");
if (prop_object_type(obj) == PROP_TYPE_STRING)
printf("Version: %s\n", prop_string_cstring_nocopy(obj));
obj = prop_dictionary_get(dict, "preserve");
if (prop_object_type(obj) == PROP_TYPE_BOOL)
printf("Preserve files: %s\n",
prop_bool_true(obj) ? "yes" : "no");
obj = prop_dictionary_get(dict, "replaces");
if (prop_object_type(obj) == PROP_TYPE_ARRAY) {
printf("Replaces: ");
(void)xbps_callback_array_iter_in_dict(dict, "replaces",
list_strings_sep_in_array, NULL);
}
obj = prop_dictionary_get(dict, "conflicts");
if (prop_object_type(obj) == PROP_TYPE_ARRAY) {
printf("Conflicts: ");
(void)xbps_callback_array_iter_in_dict(dict, "conflicts",
list_strings_sep_in_array, NULL);
}
obj = prop_dictionary_get(dict, "conf_files");
if (prop_object_type(obj) == PROP_TYPE_ARRAY) {
printf("Configuration files:\n");
sep = " ";
(void)xbps_callback_array_iter_in_dict(dict, "conf_files",
list_strings_sep_in_array, __UNCONST(sep));
printf("\n");
}
obj = prop_dictionary_get(dict, "short_desc");
if (prop_object_type(obj) == PROP_TYPE_STRING)
printf("Description: %s", prop_string_cstring_nocopy(obj));
obj = prop_dictionary_get(dict, "long_desc");
if (prop_object_type(obj) == PROP_TYPE_STRING)
printf(" %s\n", prop_string_cstring_nocopy(obj));
}
int

View File

@ -266,8 +266,8 @@ show_pkg_info_from_repolist(const char *pkgname)
return errno;
}
free(url);
show_pkg_info_only_repo(pkgd);
show_pkg_info(pkg_propsd);
show_pkg_info(pkgd, true);
show_pkg_info(pkg_propsd, false);
prop_object_release(pkg_propsd);
prop_object_release(pkgd);