Commit 5dfeaf27 authored by Rusty Russell's avatar Rusty Russell

Fix handling of one-liner fields.

parent aa722914
...@@ -51,7 +51,7 @@ static bool is_blank(const char *line) ...@@ -51,7 +51,7 @@ static bool is_blank(const char *line)
return line && line[strspn(line, " \t\n")] == '\0'; return line && line[strspn(line, " \t\n")] == '\0';
} }
static bool is_section(const char *line) static bool is_section(const char *line, bool maybe_one_liner)
{ {
unsigned int len; unsigned int len;
...@@ -59,21 +59,29 @@ static bool is_section(const char *line) ...@@ -59,21 +59,29 @@ static bool is_section(const char *line)
if (len == 0) if (len == 0)
return false; return false;
if (line[len] != ':')
return false;
/* If it can be a one-liner, a space is sufficient.*/
if (maybe_one_liner && (line[len+1] == ' ' || line[len+1] == '\t'))
return true;
return line[len] == ':' && is_blank(line+len+1); return line[len] == ':' && is_blank(line+len+1);
} }
static bool end_section(const char *line) static bool end_section(const char *line)
{ {
return !line || is_section(line); return !line || is_section(line, true);
} }
static unsigned int find_section(char **lines, const char *name) static unsigned int find_section(char **lines, const char *name,
bool maybe_one_liner)
{ {
unsigned int i; unsigned int i;
for (i = 0; lines[i]; i++) { for (i = 0; lines[i]; i++) {
if (!is_section(lines[i])) if (!is_section(lines[i], maybe_one_liner))
continue; continue;
if (strncasecmp(lines[i], name, strlen(name)) != 0) if (strncasecmp(lines[i], name, strlen(name)) != 0)
continue; continue;
...@@ -104,12 +112,17 @@ int main(int argc, char *argv[]) ...@@ -104,12 +112,17 @@ int main(int argc, char *argv[])
if (streq(type, "author") if (streq(type, "author")
|| streq(type, "maintainer") || streq(type, "maintainer")
|| streq(type, "licence")) { || streq(type, "licence")) {
line = find_section(lines, type); line = find_section(lines, type, true);
if (lines[line]) { if (lines[line]) {
if (!lines[line+1]) const char *p = strchr(lines[line], ':') + 1;
errx(1, "Malformed %s, end of file", p += strspn(p, " \t\n");
type); if (p[0] == '\0') {
/* Must be on next line. */
if (end_section(lines[line+1]))
errx(1, "Malformed %s", type);
puts(lines[line+1]); puts(lines[line+1]);
} else
puts(p);
} }
} else if (streq(type, "summary")) { } else if (streq(type, "summary")) {
/* Summary comes after - on first line. */ /* Summary comes after - on first line. */
...@@ -128,7 +141,7 @@ int main(int argc, char *argv[]) ...@@ -128,7 +141,7 @@ int main(int argc, char *argv[])
while (!end_section(lines[line])) while (!end_section(lines[line]))
puts(lines[line++]); puts(lines[line++]);
} else if (streq(type, "example")) { } else if (streq(type, "example")) {
line = find_section(lines, type); line = find_section(lines, type, false);
if (lines[line]) { if (lines[line]) {
unsigned int strip; unsigned int strip;
line++; line++;
......
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