=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/main.c,v retrieving revision 1.4 retrieving revision 1.5 diff -c -r1.4 -r1.5 *** src/usr.bin/mandoc/main.c 2009/06/18 22:16:56 1.4 --- src/usr.bin/mandoc/main.c 2009/06/18 23:34:53 1.5 *************** *** 1,4 **** ! /* $Id: main.c,v 1.4 2009/06/18 22:16:56 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * --- 1,4 ---- ! /* $Id: main.c,v 1.5 2009/06/18 23:34:53 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * *************** *** 312,318 **** size_t sz; ssize_t ssz; struct stat st; ! int j, i, pos, lnn; struct man *man; struct mdoc *mdoc; --- 312,318 ---- size_t sz; ssize_t ssz; struct stat st; ! int j, i, pos, lnn, comment; struct man *man; struct mdoc *mdoc; *************** *** 342,348 **** /* Fill buf with file blocksize. */ ! for (lnn = 0, pos = 0; ; ) { if (-1 == (ssz = read(curp->fd, blk->buf, sz))) { warn("%s", curp->file); return(0); --- 342,348 ---- /* Fill buf with file blocksize. */ ! for (lnn = pos = comment = 0; ; ) { if (-1 == (ssz = read(curp->fd, blk->buf, sz))) { warn("%s", curp->file); return(0); *************** *** 362,378 **** } if ('\n' != blk->buf[i]) { ln->buf[pos++] = blk->buf[i]; continue; ! } ! /* Check for CPP-escaped newline. */ ! if (pos > 0 && '\\' == ln->buf[pos - 1]) { for (j = pos - 1; j >= 0; j--) if ('\\' != ln->buf[j]) break; - if ( ! ((pos - j) % 2)) { pos--; lnn++; --- 362,395 ---- } if ('\n' != blk->buf[i]) { + if (comment) + continue; ln->buf[pos++] = blk->buf[i]; + + /* Handle in-line `\"' comments. */ + + if (1 == pos || '\"' != ln->buf[pos - 1]) + continue; + + for (j = pos - 2; j >= 0; j--) + if ('\\' != ln->buf[j]) + break; + + if ( ! ((pos - 2 - j) % 2)) + continue; + + comment = 1; + pos -= 2; continue; ! } ! /* Handle escaped `\\n' newlines. */ ! if (pos > 0 && 0 == comment && ! '\\' == ln->buf[pos - 1]) { for (j = pos - 1; j >= 0; j--) if ('\\' != ln->buf[j]) break; if ( ! ((pos - j) % 2)) { pos--; lnn++; *************** *** 382,401 **** ln->buf[pos] = 0; lnn++; - - /* - * If no manual parser has been assigned, then - * try to assign one in pset(), which may do - * nothing at all. After this, parse the manual - * line accordingly. - */ if ( ! (man || mdoc) && ! pset(ln->buf, pos, curp, &man, &mdoc)) return(0); ! pos = 0; if (man && ! man_parseln(man, lnn, ln->buf)) return(0); if (mdoc && ! mdoc_parseln(mdoc, lnn, ln->buf)) --- 399,415 ---- ln->buf[pos] = 0; lnn++; + /* If unset, assign parser in pset(). */ + if ( ! (man || mdoc) && ! pset(ln->buf, pos, curp, &man, &mdoc)) return(0); ! pos = comment = 0; + /* Pass down into parsers. */ + if (man && ! man_parseln(man, lnn, ln->buf)) return(0); if (mdoc && ! mdoc_parseln(mdoc, lnn, ln->buf)) *************** *** 403,409 **** } } ! /* Note that a parser may not have been assigned, yet. */ if ( ! (man || mdoc)) { warnx("%s: not a manual", curp->file); --- 417,423 ---- } } ! /* NOTE a parser may not have been assigned, yet. */ if ( ! (man || mdoc)) { warnx("%s: not a manual", curp->file); *************** *** 415,426 **** if (man && ! man_endparse(man)) return(0); ! /* ! * If an output device hasn't been allocated, see if we should ! * do so now. Note that not all outtypes have functions, so ! * this switch statement may be superfluous, but it's ! * low-overhead enough not to matter very much. ! */ if ( ! (curp->outman && curp->outmdoc)) { switch (curp->outtype) { --- 429,435 ---- if (man && ! man_endparse(man)) return(0); ! /* If unset, allocate output dev now (if applicable). */ if ( ! (curp->outman && curp->outmdoc)) { switch (curp->outtype) { *************** *** 456,472 **** pset(const char *buf, int pos, struct curparse *curp, struct man **man, struct mdoc **mdoc) { /* * Try to intuit which kind of manual parser should be used. If * passed in by command-line (-man, -mdoc), then use that * explicitly. If passed as -mandoc, then try to guess from the ! * line: either skip comments, use -mdoc when finding `.Dt', or * default to -man, which is more lenient. */ ! if (pos >= 3 && 0 == memcmp(buf, ".\\\"", 3)) ! return(1); switch (curp->inttype) { case (INTT_MDOC): --- 465,487 ---- pset(const char *buf, int pos, struct curparse *curp, struct man **man, struct mdoc **mdoc) { + int i; /* * Try to intuit which kind of manual parser should be used. If * passed in by command-line (-man, -mdoc), then use that * explicitly. If passed as -mandoc, then try to guess from the ! * line: either skip dot-lines, use -mdoc when finding `.Dt', or * default to -man, which is more lenient. */ ! if (buf[0] == '.') { ! for (i = 1; buf[i]; i++) ! if (' ' != buf[i] && '\t' != buf[i]) ! break; ! if (0 == buf[i]) ! return(1); ! } switch (curp->inttype) { case (INTT_MDOC):