=================================================================== RCS file: /cvs/mandoc/Attic/mmain.c,v retrieving revision 1.6 retrieving revision 1.8 diff -u -p -r1.6 -r1.8 --- mandoc/Attic/mmain.c 2009/03/08 11:41:22 1.6 +++ mandoc/Attic/mmain.c 2009/03/08 18:50:40 1.8 @@ -1,4 +1,4 @@ - /* $Id: mmain.c,v 1.6 2009/03/08 11:41:22 kristaps Exp $ */ + /* $Id: mmain.c,v 1.8 2009/03/08 18:50:40 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -30,7 +30,7 @@ #include "mmain.h" -#define MD_LINE_SZ (256) /* Max input line size. */ +#define MD_LINE_SZ (256) /* Input line step-size. */ struct mmain { int warn; /* Warning flags. */ @@ -71,7 +71,7 @@ void mmain_usage(const char *help) { - warnx("usage: %s %s%s[-v] [-Wwarn...] [infile]", __progname, + warnx("usage: %s %s%s[-v] [-foption...] [-Wwarn...] [infile]", __progname, help ? help : "", help ? " " : ""); } @@ -198,7 +198,7 @@ mmain_mdoc(struct mmain *p) /* Allocate the parser. */ - p->mdoc = mdoc_alloc(p, &cb); + p->mdoc = mdoc_alloc(p, p->pflags, &cb); /* Parse the input file. */ @@ -217,14 +217,18 @@ static int optsopt(struct mmain *p, char *arg) { char *v; - char *toks[] = { "ignore-scope", NULL }; + char *toks[] = { "ign-scope", "ign-escape", NULL }; while (*arg) switch (getsubopt(&arg, toks, &v)) { case (0): p->pflags |= MDOC_IGN_SCOPE; break; + case (1): + p->pflags |= MDOC_IGN_ESCAPE; + break; default: + /* FIXME: report? */ return(0); } @@ -254,6 +258,7 @@ optswarn(struct mmain *p, char *arg) p->warn |= MD_WARN_ERR; break; default: + /* FIXME: report? */ return(0); } @@ -264,39 +269,31 @@ optswarn(struct mmain *p, char *arg) static int parse(struct mmain *p) { - ssize_t sz, i; - size_t pos; - char line[MD_LINE_SZ]; - int lnn; + ssize_t sz; + int i, pos, len, lnn; + char *line; - /* - * This is a little more complicated than fgets. TODO: have - * some benchmarks that show it's faster (note that I want to - * check many, many manuals simultaneously, so speed is - * important). Fill a buffer (sized to the block size) with a - * single read, then parse \n-terminated lines into a line - * buffer, which is passed to the parser. Hard-code the line - * buffer to a particular size -- a reasonable assumption. - */ - - for (lnn = 1, pos = 0; ; ) { + for (line = NULL, lnn = 1, len = pos = 0; ; ) { if (-1 == (sz = read(p->fdin, p->buf, p->bufsz))) { warn("%s", p->in); return(0); } else if (0 == sz) break; - for (i = 0; i < sz; i++) { + for (i = 0; i < (int)sz; i++) { + if (pos >= len) { + len += MD_LINE_SZ; + line = realloc(line, len); + if (NULL == line) + err(1, "realloc"); + } + if ('\n' != p->buf[i]) { - if (pos < sizeof(line)) { - line[(int)pos++] = p->buf[(int)i]; - continue; - } - warnx("%s: line %d too long", p->in, lnn); - return(0); + line[pos++] = p->buf[i]; + continue; } - - line[(int)pos] = 0; + + line[pos] = 0; if ( ! mdoc_parseln(p->mdoc, lnn, line)) return(0); @@ -305,6 +302,8 @@ parse(struct mmain *p) } } + if (line) + free(line); return(mdoc_endparse(p->mdoc)); }