aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-03-28 23:52:13 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-03-28 23:52:13 +0000
commit916061ed728b162eb71037e2bfb56d6497d21361 (patch)
treebcacd728a2ca2b4b8c76c42c4b516e0052933c27 /mdoc.c
parent38f00ffdcbcf2be5ad01776afecc32d1c141f46c (diff)
downloadmandoc-916061ed728b162eb71037e2bfb56d6497d21361.tar.gz
mandoc-916061ed728b162eb71037e2bfb56d6497d21361.tar.zst
mandoc-916061ed728b162eb71037e2bfb56d6497d21361.zip
Have libman and libmdoc use mandoc_getcontrol() to determine whether a
macro has been invoked. libroff is next.
Diffstat (limited to 'mdoc.c')
-rw-r--r--mdoc.c67
1 files changed, 25 insertions, 42 deletions
diff --git a/mdoc.c b/mdoc.c
index b76c03a6..ea3fda26 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.187 2011/03/22 14:33:05 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.188 2011/03/28 23:52:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -297,7 +297,7 @@ mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs)
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, char *buf, int offs)
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 *buf, int offs)
/* 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 *buf, int offs)
*/
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 *buf, int offs)
/* 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);