From 2745b3f22e169e51509c6a77a688756f59a2b2b9 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 6 Sep 2014 23:24:32 +0000 Subject: Simplify by handling empty request lines at the one logical place in the roff parser instead of in three other places in other parsers. No functional change. --- man.c | 9 +-------- mdoc.c | 11 +---------- read.c | 21 +++++---------------- roff.c | 11 ++++++++++- 4 files changed, 17 insertions(+), 35 deletions(-) diff --git a/man.c b/man.c index d5160212..ef6a2c35 100644 --- a/man.c +++ b/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.138 2014/08/10 23:54:41 schwarze Exp $ */ +/* $Id: man.c,v 1.139 2014/09/06 23:24:32 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze @@ -471,13 +471,6 @@ man_pmacro(struct man *man, int ln, char *buf, int offs) int i, ppos; int bline; - if ('"' == buf[offs]) { - mandoc_msg(MANDOCERR_COMMENT_BAD, man->parse, - ln, offs, NULL); - return(1); - } else if ('\0' == buf[offs]) - return(1); - ppos = offs; /* diff --git a/mdoc.c b/mdoc.c index f9905d49..205a02b0 100644 --- a/mdoc.c +++ b/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.224 2014/08/10 23:54:41 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.225 2014/09/06 23:24:32 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze @@ -793,15 +793,6 @@ mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int offs) char mac[5]; struct mdoc_node *n; - /* Empty post-control lines are ignored. */ - - if ('"' == buf[offs]) { - mandoc_msg(MANDOCERR_COMMENT_BAD, mdoc->parse, - ln, offs, NULL); - return(1); - } else if ('\0' == buf[offs]) - return(1); - sv = offs; /* diff --git a/read.c b/read.c index 26cd6288..7b952aa7 100644 --- a/read.c +++ b/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.83 2014/09/06 22:39:36 schwarze Exp $ */ +/* $Id: read.c,v 1.84 2014/09/06 23:24:32 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -69,9 +69,9 @@ struct mparse { int line; /* line number in the file */ }; +static void choose_parser(struct mparse *); static void resize_buf(struct buf *, size_t); static void mparse_buf_r(struct mparse *, struct buf, int); -static void pset(const char *, int, struct mparse *); static int read_whole_file(struct mparse *, const char *, int, struct buf *, int *); static void mparse_end(struct mparse *); @@ -247,19 +247,10 @@ resize_buf(struct buf *buf, size_t initial) } static void -pset(const char *buf, int pos, struct mparse *curp) +choose_parser(struct mparse *curp) { char *cp, *ep; int format; - int i; - - if ('.' == buf[0] || '\'' == buf[0]) { - for (i = 1; buf[i]; i++) - if (' ' != buf[i] && '\t' != buf[i]) - break; - if ('\0' == buf[i]) - return; - } /* * If neither command line arguments -mdoc or -man select @@ -550,12 +541,10 @@ rerun: */ if ( ! (curp->man || curp->mdoc)) - pset(ln.buf + of, pos - of, curp); + choose_parser(curp); /* - * Lastly, push down into the parsers themselves. One - * of these will have already been set in the pset() - * routine. + * Lastly, push down into the parsers themselves. * If libroff returns ROFF_TBL, then add it to the * currently open parse. Since we only get here if * there does exist data (see tbl_data.c), we're diff --git a/roff.c b/roff.c index 1d8a3991..fac9ffa3 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.227 2014/09/06 22:39:36 schwarze Exp $ */ +/* $Id: roff.c,v 1.228 2014/09/06 23:24:32 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -759,6 +759,15 @@ roff_parseln(struct roff *r, int ln, char **bufp, return(roff_parsetext(bufp, szp, pos, offs)); } + /* Skip empty request lines. */ + + if ((*bufp)[pos] == '"') { + mandoc_msg(MANDOCERR_COMMENT_BAD, r->parse, + ln, pos, NULL); + return(ROFF_IGN); + } else if ((*bufp)[pos] == '\0') + return(ROFF_IGN); + /* * If a scope is open, go to the child handler for that macro, * as it may want to preprocess before doing anything with it. -- cgit v1.2.3-56-ge451