summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-12-03 22:06:40 +1030
committerRusty Russell <rusty@rustcorp.com.au>2012-12-03 22:06:40 +1030
commit5f551788224a3cf0988ae490a807b20292822f20 (patch)
treea3e743b7d061022bd493fe7fd43490f4d76b65d4
parent756407b43540926c39181e5c61425d5daf1970db (diff)
ccanlint: remove redundant num_lines in struct ccan_file.
We can use tal_count. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--tools/ccanlint/file_analysis.c5
-rw-r--r--tools/ccanlint/tests/headers_idempotent.c14
-rw-r--r--tools/ccanlint/tests/no_trailing_whitespace.c2
-rw-r--r--tools/ccanlint/tests/reduce_features.c2
-rw-r--r--tools/manifest.c2
-rw-r--r--tools/manifest.h1
6 files changed, 12 insertions, 14 deletions
diff --git a/tools/ccanlint/file_analysis.c b/tools/ccanlint/file_analysis.c
index f5ebd1ce..8fbb7186 100644
--- a/tools/ccanlint/file_analysis.c
+++ b/tools/ccanlint/file_analysis.c
@@ -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;
diff --git a/tools/ccanlint/tests/headers_idempotent.c b/tools/ccanlint/tests/headers_idempotent.c
index d7c89091..55fa9974 100644
--- a/tools/ccanlint/tests/headers_idempotent.c
+++ b/tools/ccanlint/tests/headers_idempotent.c
@@ -64,7 +64,7 @@ static void handle_idem(struct manifest *m, struct score *score)
if (fprintf(out, "#ifndef %s\n#define %s\n", name, name) < 0)
err(1, "Writing %s", tmpname);
- for (i = 0; i < e->file->num_lines; i++)
+ for (i = 0; e->file->lines[i]; i++)
if (fprintf(out, "%s\n", e->file->lines[i]) < 0)
err(1, "Writing %s", tmpname);
@@ -86,11 +86,11 @@ static void check_idem(struct ccan_file *f, struct score *score)
const char *line, *sym;
line_info = get_ccan_line_info(f);
- if (f->num_lines < 3)
+ if (tal_count(f->lines) < 4)
/* FIXME: We assume small headers probably uninteresting. */
return;
- for (i = 0; i < f->num_lines; i++) {
+ for (i = 0; f->lines[i]; i++) {
if (line_info[i].type == DOC_LINE
|| line_info[i].type == COMMENT_LINE)
continue;
@@ -104,11 +104,11 @@ static void check_idem(struct ccan_file *f, struct score *score)
}
/* No code at all? Don't complain. */
- if (i == f->num_lines)
+ if (!f->lines[i])
return;
first_preproc_line = i;
- for (i = first_preproc_line+1; i < f->num_lines; i++) {
+ for (i = first_preproc_line+1; f->lines[i]; i++) {
if (line_info[i].type == DOC_LINE
|| line_info[i].type == COMMENT_LINE)
continue;
@@ -122,7 +122,7 @@ static void check_idem(struct ccan_file *f, struct score *score)
}
/* No code at all? Weird. */
- if (i == f->num_lines)
+ if (!f->lines[i])
return;
/* We expect a condition on this line. */
@@ -158,7 +158,7 @@ static void check_idem(struct ccan_file *f, struct score *score)
}
/* Rest of code should all be covered by that conditional. */
- for (i++; i < f->num_lines; i++) {
+ for (i++; f->lines[i]; i++) {
unsigned int val = 0;
if (line_info[i].type == DOC_LINE
|| line_info[i].type == COMMENT_LINE)
diff --git a/tools/ccanlint/tests/no_trailing_whitespace.c b/tools/ccanlint/tests/no_trailing_whitespace.c
index bba51d8c..60ecee79 100644
--- a/tools/ccanlint/tests/no_trailing_whitespace.c
+++ b/tools/ccanlint/tests/no_trailing_whitespace.c
@@ -34,7 +34,7 @@ static void check_trailing_whitespace(struct manifest *m,
foreach_ptr(list, &m->c_files, &m->h_files) {
list_for_each(list, f, list) {
char **lines = get_ccan_file_lines(f);
- for (i = 0; i < f->num_lines; i++) {
+ for (i = 0; f->lines[i]; i++) {
char *err = get_trailing_whitespace(score,
lines[i]);
if (err)
diff --git a/tools/ccanlint/tests/reduce_features.c b/tools/ccanlint/tests/reduce_features.c
index 54c26f97..b46c85fc 100644
--- a/tools/ccanlint/tests/reduce_features.c
+++ b/tools/ccanlint/tests/reduce_features.c
@@ -83,7 +83,7 @@ static struct htable_option *get_used_options(struct manifest *m)
info = get_ccan_line_info(f);
struct pp_conditions *prev = NULL;
- for (i = 0; i < f->num_lines; i++) {
+ for (i = 0; f->lines[i]; i++) {
if (info[i].cond && info[i].cond != prev) {
num += add_options(opts, info[i].cond);
prev = info[i].cond;
diff --git a/tools/manifest.c b/tools/manifest.c
index b94016e1..927a2185 100644
--- a/tools/manifest.c
+++ b/tools/manifest.c
@@ -57,8 +57,6 @@ char **get_ccan_file_lines(struct ccan_file *f)
f->lines = tal_strsplit(f, get_ccan_file_contents(f), "\n",
STR_EMPTY_OK);
- /* FIXME: is f->num_lines necessary? */
- f->num_lines = tal_count(f->lines) - 1;
return f->lines;
}
diff --git a/tools/manifest.h b/tools/manifest.h
index 945574de..86e1f205 100644
--- a/tools/manifest.h
+++ b/tools/manifest.h
@@ -64,7 +64,6 @@ struct ccan_file {
size_t contents_size;
/* Use get_ccan_file_lines / get_ccan_line_info to fill these. */
- unsigned int num_lines;
char **lines;
struct line_info *line_info;