summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-10-18 19:03:36 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-10-18 19:03:36 +0000
commitaae27a21d3c4cec6e6fabd12fb23027c5ef5f244 (patch)
tree7506c9be8ca503ee5629e83925232b4c93a140e7
parent8b811fac9808f46457e2e037bbd37d0e07ea798d (diff)
downloadmandoc-aae27a21d3c4cec6e6fabd12fb23027c5ef5f244.tar.gz
mandoc-aae27a21d3c4cec6e6fabd12fb23027c5ef5f244.tar.zst
mandoc-aae27a21d3c4cec6e6fabd12fb23027c5ef5f244.zip
Made sure devices and formats recognise that -man and -mdoc have different syntax for scaling widths: -mdoc assumes no unit means that the value is a string literal while -man instead uses the default vertical/horizontal scale.
-rw-r--r--man_html.c12
-rw-r--r--man_term.c18
-rw-r--r--mdoc_html.c12
-rw-r--r--mdoc_term.c31
-rw-r--r--term.c56
-rw-r--r--term.h6
6 files changed, 63 insertions, 72 deletions
diff --git a/man_html.c b/man_html.c
index 2aee4bf1..579c861b 100644
--- a/man_html.c
+++ b/man_html.c
@@ -1,4 +1,4 @@
-/* $Id: man_html.c,v 1.10 2009/10/13 10:57:25 kristaps Exp $ */
+/* $Id: man_html.c,v 1.11 2009/10/18 19:03:36 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -222,7 +222,7 @@ a2width(const struct man_node *n, struct roffsu *su)
if (MAN_TEXT != n->type)
return(0);
- if (a2roffsu(n->string, su))
+ if (a2roffsu(n->string, su, SCALE_BU))
return(1);
return(0);
@@ -325,11 +325,9 @@ man_br_pre(MAN_ARGS)
SCALE_VS_INIT(&su, 1);
- if (MAN_sp == n->tok) {
- su.scale = 1;
- if (n->child)
- a2roffsu(n->child->string, &su);
- } else if (MAN_br == n->tok)
+ if (MAN_sp == n->tok && n->child)
+ a2roffsu(n->child->string, &su, SCALE_VS);
+ else if (MAN_br == n->tok)
su.scale = 0;
bufcat_su(h, "height", &su);
diff --git a/man_term.c b/man_term.c
index 7010ccd4..48a6f9c4 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.39 2009/10/18 13:34:16 kristaps Exp $ */
+/* $Id: man_term.c,v 1.40 2009/10/18 19:03:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
+#include "out.h"
#include "man.h"
#include "term.h"
#include "chars.h"
@@ -183,25 +184,28 @@ terminal_man(void *arg, const struct man *man)
static int
arg2height(const struct man_node *n)
{
- int r;
+ struct roffsu su;
assert(MAN_TEXT == n->type);
assert(n->string);
+ if ( ! a2roffsu(n->string, &su, SCALE_VS))
+ SCALE_VS_INIT(&su, strlen(n->string));
- if ((r = a2height(n->string)) < 0)
- return(1);
-
- return(r);
+ return(term_vspan(&su));
}
static int
arg2width(const struct man_node *n)
{
+ struct roffsu su;
assert(MAN_TEXT == n->type);
assert(n->string);
- return(a2width(n->string));
+ if ( ! a2roffsu(n->string, &su, SCALE_BU))
+ SCALE_HS_INIT(&su, strlen(n->string) + 2);
+
+ return(term_hspan(&su));
}
diff --git a/mdoc_html.c b/mdoc_html.c
index 0697d35d..535d44e1 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.31 2009/10/18 11:14:04 kristaps Exp $ */
+/* $Id: mdoc_html.c,v 1.32 2009/10/18 19:03:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -327,10 +327,10 @@ static void
a2width(const char *p, struct roffsu *su)
{
- if (a2roffsu(p, su))
- return;
- su->unit = SCALE_EM;
- su->scale = (int)strlen(p);
+ if ( ! a2roffsu(p, su, SCALE_MAX)) {
+ su->unit = SCALE_EM;
+ su->scale = (int)strlen(p);
+ }
}
@@ -351,7 +351,7 @@ a2offs(const char *p, struct roffsu *su)
SCALE_HS_INIT(su, INDENT);
else if (0 == strcmp(p, "indent-two"))
SCALE_HS_INIT(su, INDENT * 2);
- else if ( ! a2roffsu(p, su)) {
+ else if ( ! a2roffsu(p, su, SCALE_MAX)) {
su->unit = SCALE_EM;
su->scale = (int)strlen(p);
}
diff --git a/mdoc_term.c b/mdoc_term.c
index 0e0d1f39..e3d0f1dc 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.91 2009/10/18 13:34:17 kristaps Exp $ */
+/* $Id: mdoc_term.c,v 1.92 2009/10/18 19:03:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
+#include "out.h"
#include "term.h"
#include "mdoc.h"
#include "chars.h"
@@ -475,31 +476,27 @@ print_head(DECL_ARGS)
static size_t
arg2height(const struct mdoc_node *n)
{
- int r;
+ struct roffsu su;
assert(MDOC_TEXT == n->type);
assert(n->string);
+ if ( ! a2roffsu(n->string, &su, SCALE_VS))
+ SCALE_VS_INIT(&su, strlen(n->string));
- if ((r = a2height(n->string)) < 0)
- return(1);
-
- return((size_t)r);
+ return(term_vspan(&su));
}
static size_t
arg2width(const struct mdoc_argv *arg, int pos)
{
- int r;
+ struct roffsu su;
assert(arg->value[pos]);
- if ('\0' == arg->value[pos][0])
- return(2);
-
- if ((r = a2width(arg->value[pos])) >= 0)
- return((size_t)r);
+ if ( ! a2roffsu(arg->value[pos], &su, SCALE_MAX))
+ SCALE_HS_INIT(&su, strlen(arg->value[pos]) + 2);
- return(strlen(arg->value[pos]) + 2);
+ return(term_hspan(&su));
}
@@ -548,7 +545,7 @@ arg_listtype(const struct mdoc_node *n)
static size_t
arg2offs(const struct mdoc_argv *arg)
{
- int r;
+ struct roffsu su;
if ('\0' == arg->value[0][0])
return(0);
@@ -558,10 +555,10 @@ arg2offs(const struct mdoc_argv *arg)
return(INDENT + 1);
else if (0 == strcmp(arg->value[0], "indent-two"))
return((INDENT + 1) * 2);
- else if ((r = a2width(arg->value[0])) >= 0)
- return((size_t)r);
+ else if ( ! a2roffsu(arg->value[0], &su, SCALE_MAX))
+ SCALE_HS_INIT(&su, strlen(arg->value[0]));
- return(strlen(arg->value[0]));
+ return(term_hspan(&su));
}
diff --git a/term.c b/term.c
index 93f40395..b04f8db3 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.106 2009/10/18 13:34:17 kristaps Exp $ */
+/* $Id: term.c,v 1.107 2009/10/18 19:03:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -21,11 +21,11 @@
#include <string.h>
#include "chars.h"
+#include "out.h"
#include "term.h"
#include "man.h"
#include "mdoc.h"
#include "main.h"
-#include "out.h"
/* FIXME: accomodate non-breaking, non-collapsing white-space. */
/* FIXME: accomodate non-breaking, collapsing white-space. */
@@ -561,82 +561,74 @@ encode(struct termp *p, char c)
}
-int
-a2height(const char *p)
+size_t
+term_vspan(const struct roffsu *su)
{
- struct roffsu su;
double r;
- if ( ! a2roffsu(p, &su))
- return(-1);
-
- switch (su.unit) {
+ switch (su->unit) {
case (SCALE_CM):
- r = su.scale * 2;
+ r = su->scale * 2;
break;
case (SCALE_IN):
- r = su.scale * 6;
+ r = su->scale * 6;
break;
case (SCALE_PC):
- r = su.scale;
+ r = su->scale;
break;
case (SCALE_PT):
- r = su.scale / 8;
+ r = su->scale / 8;
break;
case (SCALE_MM):
- r = su.scale / 1000;
+ r = su->scale / 1000;
break;
case (SCALE_VS):
- r = su.scale;
+ r = su->scale;
break;
default:
- r = su.scale - 1;
+ r = su->scale - 1;
break;
}
if (r < 0.0)
r = 0.0;
- return(/* LINTED */(int)
+ return(/* LINTED */(size_t)
r);
}
-int
-a2width(const char *p)
+size_t
+term_hspan(const struct roffsu *su)
{
- struct roffsu su;
double r;
- if ( ! a2roffsu(p, &su))
- return(-1);
-
- switch (su.unit) {
+ switch (su->unit) {
case (SCALE_CM):
- r = (4 * su.scale) + 2; /* FIXME: double-check. */
+ r = (4 * su->scale) + 2; /* FIXME: double-check. */
break;
case (SCALE_IN):
- r = (10 * su.scale) + 2; /* FIXME: double-check. */
+ r = (10 * su->scale) + 2; /* FIXME: double-check. */
break;
case (SCALE_PC):
- r = (10 * su.scale) / 6; /* FIXME: double-check. */
+ r = (10 * su->scale) / 6; /* FIXME: double-check. */
break;
case (SCALE_PT):
- r = (10 * su.scale) / 72; /* FIXME: double-check. */
+ r = (10 * su->scale) / 72; /* FIXME: double-check. */
break;
case (SCALE_MM):
- r = su.scale / 1000; /* FIXME: double-check. */
+ r = su->scale / 1000; /* FIXME: double-check. */
break;
case (SCALE_VS):
- r = su.scale * 2 - 1; /* FIXME: double-check. */
+ r = su->scale * 2 - 1; /* FIXME: double-check. */
break;
default:
- r = su.scale + 2;
+ r = su->scale;
break;
}
if (r < 0.0)
r = 0.0;
- return((int)/* LINTED */
+ return((size_t)/* LINTED */
r);
}
diff --git a/term.h b/term.h
index ee761bd8..f0d82016 100644
--- a/term.h
+++ b/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.48 2009/10/18 13:34:17 kristaps Exp $ */
+/* $Id: term.h,v 1.49 2009/10/18 19:03:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -53,8 +53,8 @@ void term_vspace(struct termp *);
void term_word(struct termp *, const char *);
void term_flushln(struct termp *);
-int a2width(const char *);
-int a2height(const char *);
+size_t term_hspan(const struct roffsu *);
+size_t term_vspan(const struct roffsu *);
__END_DECLS