forked from void-linux/void-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A bit of reorganization in C/shell code.
With these changes: - Added 'sanitize-plist' action to xbps-pkgdb. It takes a plist file as argument and writes another one "sanitized" by proplib. Use it to sanitize the pkgindex plist file. - Split xbps-pkgdb functions to be shared by other files. - Split xbps-digest functions to be shared by other files. - Rename the plist file to register/unregister installed pkgs to regpkgdb.plist, and related stuff in shell scripts. --HG-- extra : convert_revision : 37731b04c6b41aebac629dfa06106175b9b5e59c
- Loading branch information
Juan RP
committed
Dec 19, 2008
1 parent
5f69948
commit 48b2f03
Showing
13 changed files
with
834 additions
and
586 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/*- | ||
* Copyright (c) 2008 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 <string.h> | ||
#include <errno.h> | ||
#include <limits.h> | ||
#include <prop/proplib.h> | ||
|
||
#include "plist_utils.h" | ||
|
||
prop_dictionary_t | ||
xbps_find_pkg_in_dict(prop_dictionary_t dict, const char *key, | ||
const char *pkgname) | ||
{ | ||
prop_array_t array; | ||
prop_object_iterator_t iter; | ||
prop_object_t obj; | ||
const char *dpkgn; | ||
|
||
if (dict == NULL || pkgname == NULL || key == NULL) | ||
return NULL; | ||
|
||
array = prop_dictionary_get(dict, key); | ||
if (array == NULL || prop_object_type(array) != PROP_TYPE_ARRAY) | ||
return NULL; | ||
|
||
iter = prop_array_iterator(array); | ||
if (iter == NULL) | ||
return NULL; | ||
|
||
while ((obj = prop_object_iterator_next(iter))) { | ||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &dpkgn); | ||
if (strcmp(dpkgn, pkgname) == 0) | ||
break; | ||
} | ||
prop_object_iterator_release(iter); | ||
|
||
return obj; | ||
} | ||
|
||
bool | ||
xbps_add_obj_to_array(prop_array_t array, prop_object_t obj) | ||
{ | ||
if (array == NULL || obj == NULL) | ||
return false; | ||
|
||
if (!prop_array_add(array, obj)) { | ||
prop_object_release(array); | ||
return false; | ||
} | ||
|
||
prop_object_release(obj); | ||
return true; | ||
} | ||
|
||
bool | ||
xbps_add_array_to_dict(prop_dictionary_t dict, prop_array_t array, | ||
const char *key) | ||
{ | ||
if (dict == NULL || array == NULL || key == NULL) | ||
return false; | ||
|
||
if (!prop_dictionary_set(dict, key, array)) | ||
return false; | ||
|
||
prop_object_release(array); | ||
return true; | ||
} | ||
|
||
void | ||
xbps_list_pkgs_in_dict(prop_dictionary_t dict, const char *key) | ||
{ | ||
prop_array_t array; | ||
prop_object_t obj; | ||
prop_object_iterator_t iter; | ||
const char *pkgname, *version, *short_desc; | ||
|
||
if (dict == NULL || key == NULL) { | ||
printf("%s: NULL dict/key\n", __func__); | ||
exit(1); | ||
} | ||
|
||
array = prop_dictionary_get(dict, key); | ||
if (array == NULL || prop_object_type(array) != PROP_TYPE_ARRAY) { | ||
printf("%s: NULL or incorrect array type\n", __func__); | ||
exit(1); | ||
} | ||
|
||
iter = prop_array_iterator(array); | ||
if (iter == NULL) { | ||
printf("%s: NULL iter\n", __func__); | ||
exit(1); | ||
} | ||
|
||
while ((obj = prop_object_iterator_next(iter))) { | ||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); | ||
prop_dictionary_get_cstring_nocopy(obj, "version", &version); | ||
prop_dictionary_get_cstring_nocopy(obj, "short_desc", | ||
&short_desc); | ||
if (pkgname && version && short_desc) | ||
printf("%s (%s)\t%s\n", pkgname, version, short_desc); | ||
} | ||
|
||
prop_object_iterator_release(iter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*- | ||
* Copyright (c) 2008 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. | ||
*/ | ||
|
||
#ifndef _XBPS_PLIST_UTILS_H_ | ||
#define _XBPS_PLIST_UTILS_H_ | ||
|
||
/* | ||
* Adds an array object with specified key into a dictionary. | ||
* | ||
* Arguments: | ||
* - prop_dictionary_t: dictionary to store the array. | ||
* - prop_array_t: the array to be stored. | ||
* - const char *: the key associated with the array. | ||
* | ||
* Returns true on success, false on failure. | ||
*/ | ||
bool | ||
xbps_add_array_to_dict(prop_dictionary_t, prop_array_t, const char *); | ||
|
||
/* | ||
* Adds an opaque object into an array. | ||
* | ||
* Arguments: | ||
* - prop_array_t: the array storing the object. | ||
* - prop_object_t: the opaque object to be stored. | ||
* | ||
* Returns true on success, false on failure. | ||
*/ | ||
bool | ||
xbps_add_obj_to_array(prop_array_t, prop_object_t); | ||
|
||
/* | ||
* Finds a package's dictionary into the main dictionary. | ||
* | ||
* Arguments: | ||
* - prop_dictionary_t: main dictionary to search the object. | ||
* - 1st const char *key: use a dictionary with that key. | ||
* - 2nd const char *pkgname: string of package name. | ||
* | ||
* Returns the package's dictionary object, otherwise NULL. | ||
*/ | ||
prop_dictionary_t | ||
xbps_find_pkg_in_dict(prop_dictionary_t, const char *, const char *); | ||
|
||
/* | ||
* Lists information about all packages found in a dictionary, by | ||
* using a triplet: pkgname, version and short_desc. | ||
* | ||
* Arguments: | ||
* - prop_dictionary_t: dictionary where to search on. | ||
* - const char *: the key associated with the dictionary. | ||
*/ | ||
void | ||
xbps_list_pkgs_in_dict(prop_dictionary_t, const char *); | ||
|
||
#endif /* !_XBPS_PLIST_UTILS_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.