Date: Fri, 5 Jul 2013 20:48:47 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254179 - soc2013/mattbw/backend Message-ID: <201307052048.r65KmlZr003280@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mattbw Date: Fri Jul 5 20:48:47 2013 New Revision: 254179 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254179 Log: license conjunctions implemented, first test passes! (next: implement install, refine test) Modified: soc2013/mattbw/backend/licenses.c soc2013/mattbw/backend/licenses.h Modified: soc2013/mattbw/backend/licenses.c ============================================================================== --- soc2013/mattbw/backend/licenses.c Fri Jul 5 20:17:06 2013 (r254178) +++ soc2013/mattbw/backend/licenses.c Fri Jul 5 20:48:47 2013 (r254179) @@ -18,27 +18,59 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include <errno.h> /* errno */ +#include <string.h> /* strdup, strlen, strerror */ + #include "pkg.h" /* struct pkg, etc */ #include "pk-backend.h" /* PkLicenseEnum, PK_* */ +#include "hash_traverse.h" /* HASH_FOR */ #include "licenses.h" /* prototypes */ -/* Retrieves the name of the FIRST license attached to the package. */ -const char * +/* + * Retrieves the name of the license combination attached to the package. The + * name must be free(3)d when finished with. + */ +char * license_name_from_pkg(struct pkg *pkg) { /* TODO: handle conjunctions and disjunctions */ int err; - const char *match; + int sb_err; + lic_t logic; + char *license_dup; + const char *license; + const char *logic_str; struct pkg_license *lic; + struct sbuf *sb; + + pkg_get(pkg, PKG_LICENSE_LOGIC, &logic); + switch (logic) { + case LICENSE_OR: + logic_str = " or "; + break; + case LICENSE_AND: + logic_str = " and "; + break; + default: + logic_str = " "; + break; + } + /* Join all the licenses together with the logic word above. */ lic = NULL; - match = NULL; - do { - err = pkg_licenses(pkg, &lic); - if (err == EPKG_OK) - match = pkg_license_name(lic); - } while (err == EPKG_OK && match == NULL); + sb = sbuf_new_auto(); + for (HASH_FOR(err, pkg_licenses, pkg, &lic)) { + sbuf_cat(sb, logic_str); + sbuf_cat(sb, pkg_license_name(lic)); + } + sb_err = sbuf_finish(sb); + /* Make sure that we remove the initial logic string instance! */ + license = (sb_err + ? strerror(errno) + : (sbuf_data(sb) + strlen(logic_str))); - return match; + license_dup = strdup(license); + sbuf_delete(sb); + return license_dup; } Modified: soc2013/mattbw/backend/licenses.h ============================================================================== --- soc2013/mattbw/backend/licenses.h Fri Jul 5 20:17:06 2013 (r254178) +++ soc2013/mattbw/backend/licenses.h Fri Jul 5 20:48:47 2013 (r254179) @@ -23,6 +23,6 @@ #include "pk-backend.h" -const char *license_name_from_pkg(struct pkg *pkg); +char *license_name_from_pkg(struct pkg *pkg); #endif /* _PKGNG_BACKEND_LICENSES_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307052048.r65KmlZr003280>
