pkg_install-20090610:

Improve diagnostic around license handling.
This commit is contained in:
joerg 2009-06-10 20:15:11 +00:00
parent 47e74157b8
commit ba9c59e3bf
2 changed files with 34 additions and 15 deletions

View file

@ -1,4 +1,4 @@
/* $NetBSD: license.c,v 1.4 2009/06/03 16:45:17 ahoka Exp $ */
/* $NetBSD: license.c,v 1.5 2009/06/10 20:15:11 joerg Exp $ */
/*-
* Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>.
@ -156,14 +156,16 @@ acceptable_license(const char *license)
size_t len;
len = strlen(license);
if (strspn(license, license_chars) != len)
if (strspn(license, license_chars) != len) {
warnx("Invalid character in license name at position %zu", len);
return -1;
}
return acceptable_license_internal(license, len);
}
static int
acceptable_pkg_license_internal(const char **licensep, int toplevel)
acceptable_pkg_license_internal(const char **licensep, int toplevel, const char *start)
{
const char *license = *licensep;
int need_parenthesis, is_true = 0;
@ -182,7 +184,7 @@ acceptable_pkg_license_internal(const char **licensep, int toplevel)
for (;;) {
if (*license == '(') {
switch (acceptable_pkg_license_internal(&license, 0)) {
switch (acceptable_pkg_license_internal(&license, 0, start)) {
case -1:
return -1;
case 0:
@ -196,8 +198,10 @@ acceptable_pkg_license_internal(const char **licensep, int toplevel)
license += strspn(license, license_spaces);
} else {
len = strspn(license, license_chars);
if (len == 0)
if (len == 0) {
warnx("Invalid character in license name at position %zu", license - start + 1);
return -1;
}
if (acceptable_license_internal(license, len)) {
if (expr_type != 2)
@ -209,40 +213,53 @@ acceptable_pkg_license_internal(const char **licensep, int toplevel)
license += len;
len = strspn(license, license_spaces);
if (len == 0 && *license && *license != ')')
if (len == 0 && *license && *license != ')') {
warnx("Missing space at position %zu", license - start + 1);
return -1;
}
license += len;
}
if (*license == ')') {
if (!need_parenthesis)
if (!need_parenthesis) {
warnx("Missing open parenthesis at position %zu", license - start + 1);
return -1;
}
*licensep = license + 1;
return is_true;
}
if (*license == '\0') {
if (need_parenthesis)
if (need_parenthesis) {
warnx("Unbalanced parenthesis at position %zu", license - start + 1);
return -1;
}
*licensep = license;
return is_true;
}
if (strncmp(license, "AND", 3) == 0) {
if (expr_type == 1)
if (expr_type == 1) {
warnx("Invalid operator in OR expression at position %zu", license - start + 1);
return -1;
}
expr_type = 2;
license += 3;
} else if (strncmp(license, "OR", 2) == 0) {
if (expr_type == 2)
if (expr_type == 2) {
warnx("Invalid operator in AND expression at position %zu", license - start + 1);
return -1;
}
expr_type = 1;
license += 2;
} else {
warnx("Invalid operator at position %zu", license - start + 1);
return -1;
}
len = strspn(license, license_spaces);
if (len == 0 && *license != '(')
if (len == 0 && *license != '(') {
warnx("Missing space at position %zu", license - start + 1);
return -1;
}
license += len;
}
@ -254,12 +271,14 @@ acceptable_pkg_license(const char *license)
{
int ret;
ret = acceptable_pkg_license_internal(&license, 1);
ret = acceptable_pkg_license_internal(&license, 1, license);
if (ret == -1)
return -1;
license += strspn(license, license_spaces);
if (*license)
if (*license) {
warnx("Trailing garbage in license specification");
return -1;
}
return ret;
}

View file

@ -1,4 +1,4 @@
/* $NetBSD: version.h,v 1.130 2009/05/28 08:59:59 joerg Exp $ */
/* $NetBSD: version.h,v 1.131 2009/06/10 20:15:11 joerg Exp $ */
/*
* Copyright (c) 2001 Thomas Klausner. All rights reserved.
@ -27,6 +27,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
#define PKGTOOLS_VERSION "20090528"
#define PKGTOOLS_VERSION "20090610"
#endif /* _INST_LIB_VERSION_H_ */