aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-05-16 10:59:36 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-05-16 10:59:36 +0000
commitc634aab3c360afcb672fded79932550136913232 (patch)
tree8817ee774cf6be29b3ab34ebd37331c99412c77e /mdoc.c
parent4d405feb6f8c720cd004dbba9d9a857bd1a4d95f (diff)
downloadmandoc-c634aab3c360afcb672fded79932550136913232.tar.gz
mandoc-c634aab3c360afcb672fded79932550136913232.tar.zst
mandoc-c634aab3c360afcb672fded79932550136913232.zip
Allow roff_parseln() to be re-run.
Allow roff_parseln() to manipulate the line buffer offset. This is used in situations like `.ie n .TH FOO 1' or `.ie n .ie n', where the line buffer offset is recalculated then the roff parser re-run. Fix mdoc_parseln() and man_parseln() to accept the initial line offset. WARNING: backed-out ALL roff macros whilst accomodating for how roff handles multi-line conditionals (in short, re-running the parser).
Diffstat (limited to 'mdoc.c')
-rw-r--r--mdoc.c60
1 files changed, 31 insertions, 29 deletions
diff --git a/mdoc.c b/mdoc.c
index e521e27b..dc35f85e 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.134 2010/05/16 00:04:46 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.135 2010/05/16 10:59:36 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -150,9 +150,10 @@ static struct mdoc_node *node_alloc(struct mdoc *, int, int,
enum mdoct, enum mdoc_type);
static int node_append(struct mdoc *,
struct mdoc_node *);
-static int mdoc_ptext(struct mdoc *, int, char *);
-static int mdoc_pmacro(struct mdoc *, int, char *);
-static int macrowarn(struct mdoc *, int, const char *);
+static int mdoc_ptext(struct mdoc *, int, char *, int);
+static int mdoc_pmacro(struct mdoc *, int, char *, int);
+static int macrowarn(struct mdoc *, int,
+ const char *, int);
const struct mdoc_node *
@@ -284,16 +285,16 @@ mdoc_endparse(struct mdoc *m)
* the macro (mdoc_pmacro()) or text parser (mdoc_ptext()).
*/
int
-mdoc_parseln(struct mdoc *m, int ln, char *buf)
+mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs)
{
if (MDOC_HALT & m->flags)
return(0);
m->flags |= MDOC_NEWLINE;
- return(('.' == *buf || '\'' == *buf) ?
- mdoc_pmacro(m, ln, buf) :
- mdoc_ptext(m, ln, buf));
+ return(('.' == buf[offs] || '\'' == buf[offs]) ?
+ mdoc_pmacro(m, ln, buf, offs) :
+ mdoc_ptext(m, ln, buf, offs));
}
@@ -630,32 +631,34 @@ mdoc_node_delete(struct mdoc *m, struct mdoc_node *p)
* control character.
*/
static int
-mdoc_ptext(struct mdoc *m, int line, char *buf)
+mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
{
int i;
/* Ignore bogus comments. */
- if ('\\' == buf[0] && '.' == buf[1] && '\"' == buf[2])
- return(mdoc_pwarn(m, line, 0, EBADCOMMENT));
+ if ('\\' == buf[offs] &&
+ '.' == buf[offs + 1] &&
+ '"' == buf[offs + 2])
+ return(mdoc_pwarn(m, line, offs, EBADCOMMENT));
/* No text before an initial macro. */
if (SEC_NONE == m->lastnamed)
- return(mdoc_perr(m, line, 0, ETEXTPROL));
+ return(mdoc_perr(m, line, offs, ETEXTPROL));
/* Literal just gets pulled in as-is. */
if (MDOC_LITERAL & m->flags)
- return(mdoc_word_alloc(m, line, 0, buf));
+ return(mdoc_word_alloc(m, line, offs, buf + offs));
/* Check for a blank line, which may also consist of spaces. */
- for (i = 0; ' ' == buf[i]; i++)
+ for (i = offs; ' ' == buf[i]; i++)
/* Skip to first non-space. */ ;
if ('\0' == buf[i]) {
- if ( ! mdoc_pwarn(m, line, 0, ENOBLANK))
+ if ( ! mdoc_pwarn(m, line, offs, ENOBLANK))
return(0);
/*
@@ -663,7 +666,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf)
* blank lines aren't allowed, but enough manuals assume this
* behaviour that we want to work around it.
*/
- if ( ! mdoc_elem_alloc(m, line, 0, MDOC_Pp, NULL))
+ if ( ! mdoc_elem_alloc(m, line, offs, MDOC_Pp, NULL))
return(0);
m->next = MDOC_NEXT_SIBLING;
@@ -694,7 +697,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf)
/* Allocate the whole word. */
- if ( ! mdoc_word_alloc(m, line, 0, buf))
+ if ( ! mdoc_word_alloc(m, line, offs, buf + offs))
return(0);
/*
@@ -703,10 +706,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf)
* sentence. The front-end will know how to interpret this.
*/
- /* FIXME: chain of close delims. */
-
assert(i);
-
if (mandoc_eos(buf, (size_t)i))
m->last->flags |= MDOC_EOS;
@@ -715,12 +715,12 @@ mdoc_ptext(struct mdoc *m, int line, char *buf)
static int
-macrowarn(struct mdoc *m, int ln, const char *buf)
+macrowarn(struct mdoc *m, int ln, const char *buf, int offs)
{
if ( ! (MDOC_IGN_MACRO & m->pflags))
- return(mdoc_verr(m, ln, 0, "unknown macro: %s%s",
+ return(mdoc_verr(m, ln, offs, "unknown macro: %s%s",
buf, strlen(buf) > 3 ? "..." : ""));
- return(mdoc_vwarn(m, ln, 0, "unknown macro: %s%s",
+ return(mdoc_vwarn(m, ln, offs, "unknown macro: %s%s",
buf, strlen(buf) > 3 ? "..." : ""));
}
@@ -730,7 +730,7 @@ macrowarn(struct mdoc *m, int ln, const char *buf)
* character.
*/
int
-mdoc_pmacro(struct mdoc *m, int ln, char *buf)
+mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs)
{
enum mdoct tok;
int i, j, sv;
@@ -738,10 +738,12 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf)
/* Empty lines are ignored. */
- if ('\0' == buf[1])
+ offs++;
+
+ if ('\0' == buf[offs])
return(1);
- i = 1;
+ i = offs;
/* Accept whitespace after the initial control char. */
@@ -770,16 +772,16 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf)
return(mdoc_perr(m, ln, i, EPRINT));
}
- mac[j] = 0;
+ mac[j] = '\0';
if (j == 4 || j < 2) {
- if ( ! macrowarn(m, ln, mac))
+ if ( ! macrowarn(m, ln, mac, sv))
goto err;
return(1);
}
if (MDOC_MAX == (tok = mdoc_hash_find(mac))) {
- if ( ! macrowarn(m, ln, mac))
+ if ( ! macrowarn(m, ln, mac, sv))
goto err;
return(1);
}