tools/doc_extract: trim trailing blank lines on sections.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 7 Dec 2011 02:55:41 +0000 (13:25 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 7 Dec 2011 02:55:41 +0000 (13:25 +1030)
Makes things a bit neater.

tools/doc_extract-core.c

index 8695a7e16fa2e2437c1ca1671b2eada3134f2b76..74643a04b994b61487f63cf7ba9786b37622d238 100644 (file)
@@ -165,6 +165,7 @@ static void add_detabbed_line(struct doc_section *curr, const char *rawline)
 static void trim_lines(struct doc_section *curr)
 {
        unsigned int i, trim = -1;
 static void trim_lines(struct doc_section *curr)
 {
        unsigned int i, trim = -1;
+       int last_non_empty = -1;
 
        /* Get minimum whitespace prefix. */
        for (i = 0; i < curr->num_lines; i++) {
 
        /* Get minimum whitespace prefix. */
        for (i = 0; i < curr->num_lines; i++) {
@@ -183,7 +184,14 @@ static void trim_lines(struct doc_section *curr)
                        curr->lines[i] += prefix;
                else
                        curr->lines[i] += trim;
                        curr->lines[i] += prefix;
                else
                        curr->lines[i] += trim;
+
+               /* All blank?  Potential to trim. */
+               if (curr->lines[i][strspn(curr->lines[i], " \t")] != '\0')
+                       last_non_empty = i;
        }
        }
+
+       /* Remove trailing blank lines. */
+       curr->num_lines = last_non_empty + 1;
 }
 
 struct list_head *extract_doc_sections(char **rawlines)
 }
 
 struct list_head *extract_doc_sections(char **rawlines)