[ccan] [PATCH] ccanlint - avoid e.g. GPL vs LGPL mismatch in license checking
pb-ccan at barker.dropbear.id.au
pb-ccan at barker.dropbear.id.au
Wed Feb 25 14:34:14 AEDT 2015
From: Peter Barker <pb-ccan at barker.dropbear.id.au>
---
tools/ccanlint/tests/license_comment.c | 38 ++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/tools/ccanlint/tests/license_comment.c b/tools/ccanlint/tests/license_comment.c
index 9548d87..88943e1 100644
--- a/tools/ccanlint/tests/license_comment.c
+++ b/tools/ccanlint/tests/license_comment.c
@@ -11,6 +11,40 @@
#include <err.h>
#include <ccan/str/str.h>
+static char *xstrdup(const char *s) {
+ char * ret = strdup(s);
+ if (ret == NULL) {
+ perror("strdup");
+ abort();
+ }
+ return ret;
+}
+
+/**
+ * line_has_license_flavour - returns true if line contains a <flavour> license
+ * @line: line to look for license in
+ * @shortname: license to find
+ * @note ("LGPLv2.0","LGPL") returns true
+ * @note ("LGPLv2.0","GPL") returns false
+ */
+static bool line_has_license_flavour(const char *line, const char *flavour) {
+ char *strtok_line, *strtok_tmp, *token;
+ bool ret = false;
+ const size_t flavour_len = strlen(flavour);
+
+ strtok_line = strtok_tmp = xstrdup(line);
+ while((token = strtok(strtok_tmp, " \t-:")) != NULL) {
+ if (!strncmp(token, flavour, flavour_len)) {
+ ret = true;
+ break;
+ }
+ strtok_tmp = NULL;
+ }
+ free(strtok_line);
+
+ return ret;
+}
+
static void check_license_comment(struct manifest *m,
unsigned int *timeleft, struct score *score)
{
@@ -38,8 +72,8 @@ static void check_license_comment(struct manifest *m,
break;
if (strstr(lines[i], "LICENSE"))
found_license = true;
- if (strstr(lines[i],
- licenses[m->license].shortname))
+ if (line_has_license_flavour(lines[i],
+ licenses[m->license].shortname))
found_flavor = true;
}
if ((!found_license || !found_flavor)
--
1.7.10.4
More information about the ccan
mailing list