From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p2SNqEVH029936 for ; Mon, 28 Mar 2011 19:52:14 -0400 (EDT) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.3/8.14.3/Submit) id p2SNqDlF023080; Mon, 28 Mar 2011 19:52:13 -0400 (EDT) Date: Mon, 28 Mar 2011 19:52:13 -0400 (EDT) Message-Id: <201103282352.p2SNqDlF023080@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Have libman and libmdoc use mandoc_getcontrol() to determine X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Have libman and libmdoc use mandoc_getcontrol() to determine whether a macro has been invoked. libroff is next. Modified Files: -------------- mdocml: libmandoc.h mandoc.c mdoc.c Revision Data ------------- Index: mandoc.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.c,v retrieving revision 1.43 retrieving revision 1.44 diff -Lmandoc.c -Lmandoc.c -u -p -r1.43 -r1.44 --- mandoc.c +++ mandoc.c @@ -506,3 +506,28 @@ mandoc_hyph(const char *start, const cha return(1); } +/* + * Find out whether a line is a macro line or not. If it is, adjust the + * current position and return one; if it isn't, return zero and don't + * change the current position. + */ +int +mandoc_getcontrol(const char *cp, int *ppos) +{ + int pos; + + pos = *ppos; + + if ('\\' == cp[pos] && '.' == cp[pos + 1]) + pos += 2; + else if ('.' == cp[pos] || '\'' == cp[pos]) + pos++; + else + return(0); + + while (' ' == cp[pos] || '\t' == cp[pos]) + pos++; + + *ppos = pos; + return(1); +} Index: mdoc.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v retrieving revision 1.187 retrieving revision 1.188 diff -Lmdoc.c -Lmdoc.c -u -p -r1.187 -r1.188 --- mdoc.c +++ mdoc.c @@ -297,7 +297,7 @@ mdoc_parseln(struct mdoc *m, int ln, cha m->flags &= ~MDOC_SYNOPSIS; } - return(('.' == buf[offs] || '\'' == buf[offs]) ? + return(mandoc_getcontrol(buf, &offs) ? mdoc_pmacro(m, ln, buf, offs) : mdoc_ptext(m, ln, buf, offs)); } @@ -661,15 +661,6 @@ mdoc_ptext(struct mdoc *m, int line, cha char *c, *ws, *end; struct mdoc_node *n; - /* Ignore bogus comments. */ - - if ('\\' == buf[offs] && - '.' == buf[offs + 1] && - '"' == buf[offs + 2]) { - mdoc_pmsg(m, line, offs, MANDOCERR_BADCOMMENT); - return(1); - } - /* No text before an initial macro. */ if (SEC_NONE == m->lastnamed) { @@ -796,42 +787,34 @@ static int mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs) { enum mdoct tok; - int i, j, sv; + int i, sv; char mac[5]; struct mdoc_node *n; - /* Empty lines are ignored. */ - - offs++; + /* Empty post-control lines are ignored. */ - if ('\0' == buf[offs]) + if ('"' == buf[offs]) { + mdoc_pmsg(m, ln, offs, MANDOCERR_BADCOMMENT); + return(1); + } else if ('\0' == buf[offs]) return(1); - i = offs; - - /* Accept tabs/whitespace after the initial control char. */ - - if (' ' == buf[i] || '\t' == buf[i]) { - i++; - while (buf[i] && (' ' == buf[i] || '\t' == buf[i])) - i++; - if ('\0' == buf[i]) - return(1); - } - - sv = i; + sv = offs; /* * Copy the first word into a nil-terminated buffer. * Stop copying when a tab, space, or eoln is encountered. */ - j = 0; - while (j < 4 && '\0' != buf[i] && ' ' != buf[i] && '\t' != buf[i]) - mac[j++] = buf[i++]; - mac[j] = '\0'; + i = 0; + while (i < 4 && '\0' != buf[offs] && + ' ' != buf[offs] && '\t' != buf[offs]) + mac[i++] = buf[offs++]; + + mac[i] = '\0'; + + tok = (i > 1 || i < 4) ? mdoc_hash_find(mac) : MDOC_MAX; - tok = (j > 1 || j < 4) ? mdoc_hash_find(mac) : MDOC_MAX; if (MDOC_MAX == tok) { mandoc_vmsg(MANDOCERR_MACRO, m->parse, ln, sv, "%s", buf + sv - 1); @@ -840,21 +823,21 @@ mdoc_pmacro(struct mdoc *m, int ln, char /* Disregard the first trailing tab, if applicable. */ - if ('\t' == buf[i]) - i++; + if ('\t' == buf[offs]) + offs++; /* Jump to the next non-whitespace word. */ - while (buf[i] && ' ' == buf[i]) - i++; + while (buf[offs] && ' ' == buf[offs]) + offs++; /* * Trailing whitespace. Note that tabs are allowed to be passed * into the parser as "text", so we only warn about spaces here. */ - if ('\0' == buf[i] && ' ' == buf[i - 1]) - mdoc_pmsg(m, ln, i - 1, MANDOCERR_EOLNSPACE); + if ('\0' == buf[offs] && ' ' == buf[offs - 1]) + mdoc_pmsg(m, ln, offs - 1, MANDOCERR_EOLNSPACE); /* * If an initial macro or a list invocation, divert directly @@ -862,7 +845,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char */ if (NULL == m->last || MDOC_It == tok || MDOC_El == tok) { - if ( ! mdoc_macro(m, tok, ln, sv, &i, buf)) + if ( ! mdoc_macro(m, tok, ln, sv, &offs, buf)) goto err; return(1); } @@ -901,7 +884,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char /* Normal processing of a macro. */ - if ( ! mdoc_macro(m, tok, ln, sv, &i, buf)) + if ( ! mdoc_macro(m, tok, ln, sv, &offs, buf)) goto err; return(1); Index: libmandoc.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmandoc.h,v retrieving revision 1.16 retrieving revision 1.17 diff -Llibmandoc.h -Llibmandoc.h -u -p -r1.16 -r1.17 --- libmandoc.h +++ libmandoc.h @@ -79,6 +79,7 @@ char *mandoc_getarg(struct mparse *, ch char *mandoc_normdate(struct mparse *, char *, int, int); int mandoc_eos(const char *, size_t, int); int mandoc_hyph(const char *, const char *); +int mandoc_getcontrol(const char *, int *); void mdoc_free(struct mdoc *); struct mdoc *mdoc_alloc(struct regset *, struct mparse *); -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv