]> git.ozlabs.org Git - ccan/commitdiff
ccanlint - avoid e.g. GPL vs LGPL mismatch in license checking
authorPeter Barker <pb-ccan@barker.dropbear.id.au>
Wed, 25 Feb 2015 03:34:14 +0000 (14:34 +1100)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 30 Mar 2015 06:46:33 +0000 (17:16 +1030)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tools/ccanlint/tests/license_comment.c

index 9548d87cbb17af759c5e173e8ab0966990168b54..88943e1c3269c9bc62de5271398401be0cc14424 100644 (file)
 #include <err.h>
 #include <ccan/str/str.h>
 
 #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)
 {
 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;
                                        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)
                                        found_flavor = true;
                        }
                        if ((!found_license || !found_flavor)