]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/file_analysis.c
tools/ccanlint: compile cleanly with -Wextra.
[ccan] / tools / ccanlint / file_analysis.c
index f5ebd1ce44bff9d8c0555ea5eece1a5dc5a18b95..d2fe2a4c1deb621cda477148fa79b4abbe582954 100644 (file)
@@ -218,9 +218,10 @@ struct line_info *get_ccan_line_info(struct ccan_file *f)
                return f->line_info;
 
        get_ccan_file_lines(f);
-       f->line_info = tal_arr(f->lines, struct line_info, f->num_lines);
+       f->line_info = tal_arr(f->lines, struct line_info,
+                              tal_count(f->lines)-1);
 
-       for (i = 0; i < f->num_lines; continued = continues(f->lines[i++])) {
+       for (i = 0; f->lines[i]; continued = continues(f->lines[i++])) {
                char *p;
                bool still_doc_line;
 
@@ -359,15 +360,9 @@ enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
        return ret;
 }
 
-void score_file_error(struct score *score, struct ccan_file *f, unsigned line,
-                     const char *errorfmt, ...)
+static void score_error_vfmt(struct score *score, const char *source,
+                            const char *errorfmt, va_list ap)
 {
-       va_list ap;
-
-       struct file_error *fe = tal(score, struct file_error);
-       fe->file = f;
-       fe->line = line;
-       list_add_tail(&score->per_file_errors, &fe->list);
 
        if (!score->error)
                score->error = tal_strdup(score, "");
@@ -383,18 +378,46 @@ void score_file_error(struct score *score, struct ccan_file *f, unsigned line,
                return;
        }
 
+       tal_append_fmt(&score->error, "%s:", source);
+       tal_append_vfmt(&score->error, errorfmt, ap);
+       score->error = tal_strcat(score, take(score->error), "\n");
+}
+
+
+
+void score_error(struct score *score, const char *source,
+                const char *errorfmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, errorfmt);
+       score_error_vfmt(score, source, errorfmt, ap);
+       va_end(ap);
+}
+
+void score_file_error(struct score *score, struct ccan_file *f, unsigned line,
+                     const char *errorfmt, ...)
+{
+       va_list ap;
+       char *source;
+
+       struct file_error *fe = tal(score, struct file_error);
+       fe->file = f;
+       fe->line = line;
+       list_add_tail(&score->per_file_errors, &fe->list);
+
        if (line)
-               tal_append_fmt(&score->error, "%s:%u:", f->fullname, line);
+               source = tal_fmt(score, "%s:%u", f->fullname, line);
        else
-               tal_append_fmt(&score->error, "%s:", f->fullname);
+               source = tal_fmt(score, "%s", f->fullname);
 
        va_start(ap, errorfmt);
-       tal_append_vfmt(&score->error, errorfmt, ap);
+       score_error_vfmt(score, source, errorfmt, ap);
        va_end(ap);
-       score->error = tal_strcat(score, take(score->error),"\n");
 }
 
-char *get_or_compile_info(const void *ctx, const char *dir)
+
+char *get_or_compile_info(const void *ctx UNNEEDED, const char *dir)
 {
        struct manifest *m = get_manifest(NULL, dir);