summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-06-07 10:52:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-06-07 10:52:44 +0000
commitbc3089425f6b3a43c2898c28f960f5a313c05ebe (patch)
tree90e922cb05b24707a53bfbca9db61f220ea19182
parentdb7e43f14579272d3f0f3b85346bfb0e957dacee (diff)
downloadmandoc-bc3089425f6b3a43c2898c28f960f5a313c05ebe.tar.gz
Add -Owidth=width option to mandoc -Tascii. Asked for by joerg@ about a
thousand years ago. Note that this is normalised to >=60.
-rw-r--r--html.c2
-rw-r--r--main.c2
-rw-r--r--main.h5
-rw-r--r--term.c29
4 files changed, 29 insertions, 9 deletions
diff --git a/html.c b/html.c
index 5dca90a1..7dce7473 100644
--- a/html.c
+++ b/html.c
@@ -35,8 +35,6 @@
#include "html.h"
#include "main.h"
-#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
-
struct htmldata {
const char *name;
int flags;
diff --git a/main.c b/main.c
index 7bab2768..e27e2bf1 100644
--- a/main.c
+++ b/main.c
@@ -601,7 +601,7 @@ fdesc(struct curparse *curp)
case (OUTT_LINT):
break;
default:
- curp->outdata = ascii_alloc(80);
+ curp->outdata = ascii_alloc(curp->outopts);
curp->outman = terminal_man;
curp->outmdoc = terminal_mdoc;
curp->outfree = terminal_free;
diff --git a/main.h b/main.h
index 20ed51ec..45c092e9 100644
--- a/main.h
+++ b/main.h
@@ -22,6 +22,9 @@ __BEGIN_DECLS
struct mdoc;
struct man;
+#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
+
+
/*
* Definitions for main.c-visible output device functions, e.g., -Thtml
* and -Tascii. Note that ascii_alloc() is named as such in
@@ -38,7 +41,7 @@ void html_free(void *);
void tree_mdoc(void *, const struct mdoc *);
void tree_man(void *, const struct man *);
-void *ascii_alloc(size_t);
+void *ascii_alloc(char *);
void terminal_mdoc(void *, const struct mdoc *);
void terminal_man(void *, const struct man *);
void terminal_free(void *);
diff --git a/term.c b/term.c
index 03d1ec5b..9506101c 100644
--- a/term.c
+++ b/term.c
@@ -22,6 +22,7 @@
#include <assert.h>
#include <ctype.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -35,7 +36,7 @@
#include "mdoc.h"
#include "main.h"
-static struct termp *term_alloc(enum termenc, size_t);
+static struct termp *term_alloc(char *, enum termenc);
static void term_free(struct termp *);
static void spec(struct termp *, const char *, size_t);
static void res(struct termp *, const char *, size_t);
@@ -46,10 +47,10 @@ static void encode(struct termp *, const char *, size_t);
void *
-ascii_alloc(size_t width)
+ascii_alloc(char *outopts)
{
- return(term_alloc(TERMENC_ASCII, width));
+ return(term_alloc(outopts, TERMENC_ASCII));
}
@@ -75,17 +76,35 @@ term_free(struct termp *p)
static struct termp *
-term_alloc(enum termenc enc, size_t width)
+term_alloc(char *outopts, enum termenc enc)
{
- struct termp *p;
+ struct termp *p;
+ const char *toks[2];
+ char *v;
+ size_t width;
+
+ toks[0] = "width";
+ toks[1] = NULL;
p = calloc(1, sizeof(struct termp));
if (NULL == p) {
perror(NULL);
exit(EXIT_FAILURE);
}
+
p->tabwidth = 5;
p->enc = enc;
+ width = 80;
+
+ while (outopts && *outopts)
+ switch (getsubopt(&outopts, UNCONST(toks), &v)) {
+ case (0):
+ width = atoi(v);
+ break;
+ default:
+ break;
+ }
+
/* Enforce some lower boundary. */
if (width < 60)
width = 60;