aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_term.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-05-09 16:05:13 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-05-09 16:05:13 +0000
commit128e414f1c82f7607806f15487777c93565529c7 (patch)
tree0c2afcf4c556067e826293406d196cb217f2f013 /mdoc_term.c
parent4771cf7dd2f8f8540c825480ff001d5ce820fc07 (diff)
downloadmandoc-128e414f1c82f7607806f15487777c93565529c7.tar.gz
mandoc-128e414f1c82f7607806f15487777c93565529c7.tar.zst
mandoc-128e414f1c82f7607806f15487777c93565529c7.zip
Allow literal contexts to have unbound line lengths (from Ingo Schwarze's mandoc TODO by way of Jason McIntyre).
Diffstat (limited to 'mdoc_term.c')
-rw-r--r--mdoc_term.c79
1 files changed, 56 insertions, 23 deletions
diff --git a/mdoc_term.c b/mdoc_term.c
index 7c1c6661..d407ec96 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.117 2010/04/08 08:17:55 kristaps Exp $ */
+/* $Id: mdoc_term.c,v 1.118 2010/05/09 16:05:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -22,6 +22,7 @@
#include <assert.h>
#include <ctype.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -58,6 +59,7 @@ static int arg_hasattr(int, const struct mdoc_node *);
static int arg_getattrs(const int *, int *, size_t,
const struct mdoc_node *);
static int arg_getattr(int, const struct mdoc_node *);
+static int arg_disptype(const struct mdoc_node *);
static int arg_listtype(const struct mdoc_node *);
static void print_bvspace(struct termp *,
const struct mdoc_node *,
@@ -478,6 +480,35 @@ a2width(const struct mdoc_argv *arg, int pos)
static int
+arg_disptype(const struct mdoc_node *n)
+{
+ int i, len;
+
+ assert(MDOC_BLOCK == n->type);
+
+ len = (int)(n->args ? n->args->argc : 0);
+
+ for (i = 0; i < len; i++)
+ switch (n->args->argv[i].arg) {
+ case (MDOC_Centred):
+ /* FALLTHROUGH */
+ case (MDOC_Ragged):
+ /* FALLTHROUGH */
+ case (MDOC_Filled):
+ /* FALLTHROUGH */
+ case (MDOC_Unfilled):
+ /* FALLTHROUGH */
+ case (MDOC_Literal):
+ return(n->args->argv[i].arg);
+ default:
+ break;
+ }
+
+ return(-1);
+}
+
+
+static int
arg_listtype(const struct mdoc_node *n)
{
int i, len;
@@ -1126,7 +1157,7 @@ termp_an_post(DECL_ARGS)
return;
}
- if (arg_getattr(MDOC_Split, n) > -1) {
+ if (arg_hasattr(MDOC_Split, n)) {
p->flags &= ~TERMP_NOSPLIT;
p->flags |= TERMP_SPLIT;
} else {
@@ -1598,6 +1629,7 @@ static int
termp_bd_pre(DECL_ARGS)
{
int i, type;
+ size_t sv;
const struct mdoc_node *nn;
if (MDOC_BLOCK == n->type) {
@@ -1608,26 +1640,11 @@ termp_bd_pre(DECL_ARGS)
nn = n->parent;
- for (type = -1, i = 0; i < (int)nn->args->argc; i++) {
- switch (nn->args->argv[i].arg) {
- case (MDOC_Centred):
- /* FALLTHROUGH */
- case (MDOC_Ragged):
- /* FALLTHROUGH */
- case (MDOC_Filled):
- /* FALLTHROUGH */
- case (MDOC_Unfilled):
- /* FALLTHROUGH */
- case (MDOC_Literal):
- type = nn->args->argv[i].arg;
- break;
- case (MDOC_Offset):
- p->offset += a2offs(&nn->args->argv[i]);
- break;
- default:
- break;
- }
- }
+ type = arg_disptype(nn);
+ assert(-1 != type);
+
+ if (-1 != (i = arg_getattr(MDOC_Offset, nn)))
+ p->offset += a2offs(&nn->args->argv[i]);
/*
* If -ragged or -filled are specified, the block does nothing
@@ -1637,10 +1654,12 @@ termp_bd_pre(DECL_ARGS)
* lines are allowed.
*/
- assert(type > -1);
if (MDOC_Literal != type && MDOC_Unfilled != type)
return(1);
+ sv = p->rmargin;
+ p->rmargin = 100000; /* FIXME */
+
for (nn = n->child; nn; nn = nn->next) {
p->flags |= TERMP_NOSPACE;
print_mdoc_node(p, pair, m, nn);
@@ -1652,6 +1671,7 @@ termp_bd_pre(DECL_ARGS)
term_flushln(p);
}
+ p->rmargin = sv;
return(0);
}
@@ -1660,11 +1680,24 @@ termp_bd_pre(DECL_ARGS)
static void
termp_bd_post(DECL_ARGS)
{
+ int type;
+ size_t sv;
if (MDOC_BODY != n->type)
return;
+
+ type = arg_disptype(n->parent);
+ assert(-1 != type);
+
+ sv = p->rmargin;
+
+ if (MDOC_Literal == type || MDOC_Unfilled == type)
+ p->rmargin = 100000; /* FIXME */
+
p->flags |= TERMP_NOSPACE;
term_flushln(p);
+
+ p->rmargin = sv;
}