summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2010-10-16 13:38:30 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2010-10-16 13:38:30 +0000
commit67109423dbbc5dceafdb4ed7394ac6ed336210b5 (patch)
tree5816e1ce1de3b3993927f5e66eb1dac8241f11c2
parentd9a3f1256d9f3713dffb2640546f03d48b2192b2 (diff)
Support tbl(1) code embedded into mdoc(7) input files.
Very similar to what i have done in man(7) yesterday. Allows to build cpu(4) on HPPA, wi(4), and phantasia(6). Now we are able to build all tbl code in base.
-rw-r--r--usr.bin/mandoc/mdoc.c21
-rw-r--r--usr.bin/mandoc/mdoc.h13
-rw-r--r--usr.bin/mandoc/mdoc_action.c27
-rw-r--r--usr.bin/mandoc/mdoc_html.c4
-rw-r--r--usr.bin/mandoc/mdoc_macro.c6
-rw-r--r--usr.bin/mandoc/mdoc_term.c23
-rw-r--r--usr.bin/mandoc/mdoc_validate.c4
7 files changed, 83 insertions, 15 deletions
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c
index ffaf2dfbd39..f9d44990df8 100644
--- a/usr.bin/mandoc/mdoc.c
+++ b/usr.bin/mandoc/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.66 2010/09/27 21:25:28 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.67 2010/10/16 13:38:29 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -28,6 +28,10 @@
#include "libmdoc.h"
#include "libmandoc.h"
+#include "out.h"
+#include "term.h"
+#include "tbl.h"
+
const char *const __mdoc_macronames[MDOC_MAX] = {
"Ap", "Dd", "Dt", "Os",
"Sh", "Ss", "Pp", "D1",
@@ -65,7 +69,7 @@ const char *const __mdoc_macronames[MDOC_MAX] = {
/* LINTED */
"Dx", "%Q", "br", "sp",
/* LINTED */
- "%U", "Ta"
+ "%U", "Ta", "TS", "TE"
};
const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
@@ -225,12 +229,22 @@ mdoc_endparse(struct mdoc *m)
int
mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs)
{
+ struct mdoc_node *n;
if (MDOC_HALT & m->flags)
return(0);
m->flags |= MDOC_NEWLINE;
+ n = m->last;
+
+ if (n && MDOC_TS == n->tok && MDOC_BODY == n->type &&
+ strncmp(buf+offs, ".TE", 3)) {
+ n = n->parent;
+ return(tbl_read(n->data.TS, "<mdoc>", ln, buf+offs,
+ strlen(buf+offs)) ? 1 : 0);
+ }
+
/*
* Let the roff nS register switch SYNOPSIS mode early,
* such that the parser knows at all times
@@ -524,6 +538,9 @@ mdoc_node_free(struct mdoc_node *p)
if (MDOC_Bf == p->tok && MDOC_HEAD == p->type)
if (p->data.Bf)
free(p->data.Bf);
+ if (MDOC_TS == p->tok && MDOC_BLOCK == p->type)
+ if (p->data.TS)
+ tbl_free(p->data.TS);
if (p->string)
free(p->string);
diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h
index 79f8e96fb19..99727fdbe50 100644
--- a/usr.bin/mandoc/mdoc.h
+++ b/usr.bin/mandoc/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.33 2010/08/20 00:53:35 schwarze Exp $ */
+/* $Id: mdoc.h,v 1.34 2010/10/16 13:38:29 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -150,6 +150,8 @@ enum mdoct {
MDOC_sp,
MDOC__U,
MDOC_Ta,
+ MDOC_TS,
+ MDOC_TE,
MDOC_MAX
};
@@ -345,10 +347,11 @@ struct mdoc_node {
enum mdoc_endbody end; /* BODY */
union {
- struct mdoc_an An;
- struct mdoc_bd *Bd;
- struct mdoc_bf *Bf;
- struct mdoc_bl *Bl;
+ struct mdoc_an An;
+ struct mdoc_bd *Bd;
+ struct mdoc_bf *Bf;
+ struct mdoc_bl *Bl;
+ struct tbl *TS;
} data;
};
diff --git a/usr.bin/mandoc/mdoc_action.c b/usr.bin/mandoc/mdoc_action.c
index eca8df27be9..b225823ab9b 100644
--- a/usr.bin/mandoc/mdoc_action.c
+++ b/usr.bin/mandoc/mdoc_action.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_action.c,v 1.44 2010/07/31 21:43:07 schwarze Exp $ */
+/* $Id: mdoc_action.c,v 1.45 2010/10/16 13:38:29 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -28,6 +28,10 @@
#include "libmdoc.h"
#include "libmandoc.h"
+#include "out.h"
+#include "term.h"
+#include "tbl.h"
+
/*
* FIXME: this file is deprecated. All future "actions" should be
* pushed into mdoc_validate.c.
@@ -37,7 +41,7 @@
#define PRE_ARGS struct mdoc *m, struct mdoc_node *n
#define NUMSIZ 32
-#define DATESIZ 32
+#define DATESIZE 32
struct actions {
int (*pre)(PRE_ARGS);
@@ -70,6 +74,7 @@ static int post_std(POST_ARGS);
static int pre_bd(PRE_ARGS);
static int pre_dl(PRE_ARGS);
+static int pre_ts(PRE_ARGS);
static const struct actions mdoc_actions[MDOC_MAX] = {
{ NULL, NULL }, /* Ap */
@@ -194,6 +199,8 @@ static const struct actions mdoc_actions[MDOC_MAX] = {
{ NULL, NULL }, /* sp */
{ NULL, NULL }, /* %U */
{ NULL, NULL }, /* Ta */
+ { pre_ts, NULL }, /* TS */
+ { NULL, NULL }, /* TE */
};
#define RSORD_MAX 14
@@ -905,14 +912,14 @@ post_ar(POST_ARGS)
static int
post_dd(POST_ARGS)
{
- char buf[DATESIZ];
+ char buf[DATESIZE];
if (NULL == n->child) {
m->meta.date = time(NULL);
return(post_prol(m, n));
}
- if ( ! concat(m, buf, n->child, DATESIZ))
+ if ( ! concat(m, buf, n->child, DATESIZE))
return(0);
m->meta.date = mandoc_a2time
@@ -974,6 +981,18 @@ pre_bd(PRE_ARGS)
}
+/* ARGSUSED */
+static int
+pre_ts(PRE_ARGS)
+{
+
+ if (MDOC_BLOCK == n->type)
+ n->data.TS = tbl_alloc();
+
+ return(1);
+}
+
+
static int
post_display(POST_ARGS)
{
diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c
index 2295e26a24d..0ea7b2b118c 100644
--- a/usr.bin/mandoc/mdoc_html.c
+++ b/usr.bin/mandoc/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.34 2010/10/01 21:38:26 schwarze Exp $ */
+/* $Id: mdoc_html.c,v 1.35 2010/10/16 13:38:29 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -245,6 +245,8 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = {
{mdoc_sp_pre, NULL}, /* sp */
{mdoc__x_pre, mdoc__x_post}, /* %U */
{NULL, NULL}, /* Ta */
+ {NULL, NULL}, /* TS */
+ {NULL, NULL}, /* TE */
};
diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c
index c888b17265b..4a495a66734 100644
--- a/usr.bin/mandoc/mdoc_macro.c
+++ b/usr.bin/mandoc/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.57 2010/10/01 21:38:26 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.58 2010/10/16 13:38:29 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -184,6 +184,8 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
{ in_line_eoln, 0 }, /* sp */
{ in_line_eoln, 0 }, /* %U */
{ phrase_ta, MDOC_CALLABLE | MDOC_PARSED }, /* Ta */
+ { blk_part_exp, MDOC_EXPLICIT }, /* TS */
+ { blk_exp_close, MDOC_EXPLICIT }, /* TE */
};
const struct mdoc_macro * const mdoc_macros = __mdoc_macros;
@@ -307,6 +309,8 @@ rew_alt(enum mdoct tok)
return(MDOC_So);
case (MDOC_Xc):
return(MDOC_Xo);
+ case (MDOC_TE):
+ return(MDOC_TS);
default:
return(tok);
}
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index b6b21717efa..4851fb6693c 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.109 2010/10/01 21:38:26 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.110 2010/10/16 13:38:29 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -30,6 +30,7 @@
#include "mdoc.h"
#include "chars.h"
#include "main.h"
+#include "tbl.h"
#define INDENT 5
#define HALFINDENT 3
@@ -113,6 +114,7 @@ static int termp_sh_pre(DECL_ARGS);
static int termp_sm_pre(DECL_ARGS);
static int termp_sp_pre(DECL_ARGS);
static int termp_ss_pre(DECL_ARGS);
+static int termp_ts_pre(DECL_ARGS);
static int termp_under_pre(DECL_ARGS);
static int termp_ud_pre(DECL_ARGS);
static int termp_vt_pre(DECL_ARGS);
@@ -242,6 +244,8 @@ static const struct termact termacts[MDOC_MAX] = {
{ termp_sp_pre, NULL }, /* sp */
{ termp_under_pre, termp____post }, /* %U */
{ NULL, NULL }, /* Ta */
+ { termp_ts_pre, NULL }, /* TS */
+ { NULL, NULL }, /* TE */
};
@@ -2090,6 +2094,23 @@ termp_lk_pre(DECL_ARGS)
/* ARGSUSED */
static int
+termp_ts_pre(DECL_ARGS)
+{
+
+ if (MDOC_BLOCK != n->type)
+ return(0);
+
+ if ( ! tbl_close(p, n->data.TS, "<mdoc>", n->line))
+ return(0);
+
+ tbl_write(p, n->data.TS);
+
+ return(0);
+}
+
+
+/* ARGSUSED */
+static int
termp_bk_pre(DECL_ARGS)
{
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index ef91057b64d..a193bd8e78a 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.70 2010/09/27 21:25:28 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.71 2010/10/16 13:38:29 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -264,6 +264,8 @@ const struct valids mdoc_valids[MDOC_MAX] = {
{ pres_pp, posts_sp }, /* sp */
{ NULL, posts_text1 }, /* %U */
{ NULL, NULL }, /* Ta */
+ { NULL, NULL }, /* TS */
+ { NULL, NULL }, /* TE */
};