summaryrefslogtreecommitdiffstats
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
commitb24acbb5f3ae16c8a4e9645043803117dda71323 (patch)
tree1a7428e9636ad90860f62860b0e85c725e8cb556
parentd6c7a4661f77e1989e0da0c6d16c039362c1d97d (diff)
downloadmandoc-b24acbb5f3ae16c8a4e9645043803117dda71323.tar.gz
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.c10
-rw-r--r--man_term.c16
-rw-r--r--mdoc_html.c10
-rw-r--r--mdoc_term.c29
-rw-r--r--term.c54
-rw-r--r--term.h4
6 files changed, 57 insertions, 66 deletions
diff --git a/man_html.c b/man_html.c
index de1cf2d8..f6939321 100644
--- a/man_html.c
+++ b/man_html.c
@@ -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 d3a3e2bd..a29f0af1 100644
--- a/man_term.c
+++ b/man_term.c
@@ -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 d740e9c8..403537cc 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -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 21c0ef7c..5457836d 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -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 d08112a3..5ba6c8ab 100644
--- a/term.c
+++ b/term.c
@@ -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 0a113abd..f4f11610 100644
--- a/term.h
+++ b/term.h
@@ -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