Commit 94e7bbe8 authored by Rusty Russell's avatar Rusty Russell

tools/ccanlint: slight neatening of license logic.

Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 4802b4be
...@@ -10,15 +10,7 @@ ...@@ -10,15 +10,7 @@
#include <stdio.h> #include <stdio.h>
#include <err.h> #include <err.h>
#include <ccan/str/str.h> #include <ccan/str/str.h>
#include <ccan/tal/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_has_license_flavour - returns true if line contains a <flavour> license
...@@ -27,21 +19,19 @@ static char *xstrdup(const char *s) { ...@@ -27,21 +19,19 @@ static char *xstrdup(const char *s) {
* @note ("LGPLv2.0","LGPL") returns true * @note ("LGPLv2.0","LGPL") returns true
* @note ("LGPLv2.0","GPL") returns false * @note ("LGPLv2.0","GPL") returns false
*/ */
static bool line_has_license_flavour(const char *line, const char *flavour) { static bool line_has_license_flavour(const char *line, const char *shortname)
char *strtok_line, *strtok_tmp, *token; {
char **toks = tal_strsplit(NULL, line, " \t-:", STR_NO_EMPTY);
size_t i;
bool ret = false; bool ret = false;
const size_t flavour_len = strlen(flavour);
strtok_line = strtok_tmp = xstrdup(line); for (i = 0; toks[i] != NULL; i++) {
while((token = strtok(strtok_tmp, " \t-:")) != NULL) { if (strstarts(toks[i], shortname)) {
if (!strncmp(token, flavour, flavour_len)) {
ret = true; ret = true;
break; break;
} }
strtok_tmp = NULL;
} }
free(strtok_line); tal_free(toks);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment