summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2015-03-30 16:57:38 +1030
committerRusty Russell <rusty@rustcorp.com.au>2015-03-30 17:16:33 +1030
commit94e7bbe83e4071cebe189d8487acb3df7552fb24 (patch)
tree58a198596f90f57eecefb55a1a21aedd7088d3ad
parent4802b4bece8edf21cc64abdc25158d7437a9cfc6 (diff)
tools/ccanlint: slight neatening of license logic.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--tools/ccanlint/tests/license_comment.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/tools/ccanlint/tests/license_comment.c b/tools/ccanlint/tests/license_comment.c
index 88943e1c..abe0204e 100644
--- a/tools/ccanlint/tests/license_comment.c
+++ b/tools/ccanlint/tests/license_comment.c
@@ -10,15 +10,7 @@
#include <stdio.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;
-}
+#include <ccan/tal/str/str.h>
/**
* line_has_license_flavour - returns true if line contains a <flavour> license
@@ -27,21 +19,19 @@ static char *xstrdup(const char *s) {
* @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;
+static bool line_has_license_flavour(const char *line, const char *shortname)
+{
+ char **toks = tal_strsplit(NULL, line, " \t-:", STR_NO_EMPTY);
+ size_t i;
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)) {
+ for (i = 0; toks[i] != NULL; i++) {
+ if (strstarts(toks[i], shortname)) {
ret = true;
break;
}
- strtok_tmp = NULL;
}
- free(strtok_line);
-
+ tal_free(toks);
return ret;
}