aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/man.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 /man.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 'man.c')
-rw-r--r--man.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/man.c b/man.c
index a1a0ecd4..975a82f8 100644
--- a/man.c
+++ b/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.71 2010/05/16 00:04:46 kristaps Exp $ */
+/* $Id: man.c,v 1.72 2010/05/16 10:59:36 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -74,11 +74,11 @@ static int man_node_append(struct man *,
static void man_node_free(struct man_node *);
static void man_node_unlink(struct man *,
struct man_node *);
-static int man_ptext(struct man *, int, char *);
-static int man_pmacro(struct man *, int, char *);
+static int man_ptext(struct man *, int, char *, int);
+static int man_pmacro(struct man *, int, char *, int);
static void man_free1(struct man *);
static void man_alloc1(struct man *);
-static int macrowarn(struct man *, int, const char *);
+static int macrowarn(struct man *, int, const char *, int);
const struct man_node *
@@ -148,12 +148,15 @@ man_endparse(struct man *m)
int
-man_parseln(struct man *m, int ln, char *buf)
+man_parseln(struct man *m, int ln, char *buf, int offs)
{
- return(('.' == *buf || '\'' == *buf) ?
- man_pmacro(m, ln, buf) :
- man_ptext(m, ln, buf));
+ if (MAN_HALT & m->flags)
+ return(0);
+
+ return(('.' == buf[offs] || '\'' == buf[offs]) ?
+ man_pmacro(m, ln, buf, offs) :
+ man_ptext(m, ln, buf, offs));
}
@@ -363,31 +366,33 @@ man_node_delete(struct man *m, struct man_node *p)
static int
-man_ptext(struct man *m, int line, char *buf)
+man_ptext(struct man *m, int line, char *buf, int offs)
{
int i;
/* Ignore bogus comments. */
- if ('\\' == buf[0] && '.' == buf[1] && '\"' == buf[2])
- return(man_pwarn(m, line, 0, WBADCOMMENT));
+ if ('\\' == buf[offs] &&
+ '.' == buf[offs + 1] &&
+ '"' == buf[offs + 2])
+ return(man_pwarn(m, line, offs, WBADCOMMENT));
/* Literal free-form text whitespace is preserved. */
if (MAN_LITERAL & m->flags) {
- if ( ! man_word_alloc(m, line, 0, buf))
+ if ( ! man_word_alloc(m, line, offs, buf + offs))
return(0);
goto descope;
}
/* Pump blank lines directly into the backend. */
- for (i = 0; ' ' == buf[i]; i++)
+ for (i = offs; ' ' == buf[i]; i++)
/* Skip leading whitespace. */ ;
if ('\0' == buf[i]) {
/* Allocate a blank entry. */
- if ( ! man_word_alloc(m, line, 0, ""))
+ if ( ! man_word_alloc(m, line, offs, ""))
return(0);
goto descope;
}
@@ -414,7 +419,7 @@ man_ptext(struct man *m, int line, char *buf)
buf[i] = '\0';
}
- if ( ! man_word_alloc(m, line, 0, buf))
+ if ( ! man_word_alloc(m, line, offs, buf + offs))
return(0);
/*
@@ -423,10 +428,7 @@ man_ptext(struct man *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 |= MAN_EOS;
@@ -449,23 +451,23 @@ descope:
if ( ! man_unscope(m, m->last->parent, WERRMAX))
return(0);
- return(man_body_alloc(m, line, 0, m->last->tok));
+ return(man_body_alloc(m, line, offs, m->last->tok));
}
static int
-macrowarn(struct man *m, int ln, const char *buf)
+macrowarn(struct man *m, int ln, const char *buf, int offs)
{
if ( ! (MAN_IGN_MACRO & m->pflags))
- return(man_verr(m, ln, 0, "unknown macro: %s%s",
+ return(man_verr(m, ln, offs, "unknown macro: %s%s",
buf, strlen(buf) > 3 ? "..." : ""));
- return(man_vwarn(m, ln, 0, "unknown macro: %s%s",
+ return(man_vwarn(m, ln, offs, "unknown macro: %s%s",
buf, strlen(buf) > 3 ? "..." : ""));
}
int
-man_pmacro(struct man *m, int ln, char *buf)
+man_pmacro(struct man *m, int ln, char *buf, int offs)
{
int i, j, ppos;
enum mant tok;
@@ -474,10 +476,12 @@ man_pmacro(struct man *m, int ln, char *buf)
/* Comments and empties are quickly ignored. */
- if ('\0' == buf[1])
+ offs++;
+
+ if ('\0' == buf[offs])
return(1);
- i = 1;
+ i = offs;
/*
* Skip whitespace between the control character and initial
@@ -522,7 +526,7 @@ man_pmacro(struct man *m, int ln, char *buf)
}
if (MAN_MAX == (tok = man_hash_find(mac))) {
- if ( ! macrowarn(m, ln, mac))
+ if ( ! macrowarn(m, ln, mac, ppos))
goto err;
return(1);
}
@@ -628,7 +632,7 @@ out:
if ( ! man_unscope(m, m->last->parent, WERRMAX))
return(0);
- return(man_body_alloc(m, ln, 0, m->last->tok));
+ return(man_body_alloc(m, ln, offs, m->last->tok));
err: /* Error out. */