summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--main.c3
-rw-r--r--main.h5
-rw-r--r--term.c63
-rw-r--r--term.h2
-rw-r--r--term_ps.c45
6 files changed, 88 insertions, 40 deletions
diff --git a/Makefile b/Makefile
index 3ff9892b..77905c77 100644
--- a/Makefile
+++ b/Makefile
@@ -69,13 +69,15 @@ MANSRCS = man_macro.c man.c man_hash.c man_validate.c \
MAINLNS = main.ln mdoc_term.ln chars.ln term.ln tree.ln \
compat.ln man_term.ln html.ln mdoc_html.ln \
- man_html.ln out.ln
+ man_html.ln out.ln term_ps.ln
MAINOBJS = main.o mdoc_term.o chars.o term.o tree.o compat.o \
- man_term.o html.o mdoc_html.o man_html.o out.o
+ man_term.o html.o mdoc_html.o man_html.o out.o \
+ term_ps.o
MAINSRCS = main.c mdoc_term.c chars.c term.c tree.c compat.c \
- man_term.c html.c mdoc_html.c man_html.c out.c
+ man_term.c html.c mdoc_html.c man_html.c out.c \
+ term_ps.c
LLNS = llib-llibmdoc.ln llib-llibman.ln llib-lmandoc.ln \
llib-llibmandoc.ln llib-llibroff.ln
@@ -223,6 +225,8 @@ compat.ln compat.o: compat.c
term.ln term.o: term.c term.h man.h mdoc.h chars.h
+term_ps.ln term_ps.o: term_ps.c term.h main.h
+
html.ln html.o: html.c html.h chars.h
mdoc_html.ln mdoc_html.o: mdoc_html.c html.h mdoc.h
diff --git a/main.c b/main.c
index 19c47a25..ef3eceab 100644
--- a/main.c
+++ b/main.c
@@ -591,9 +591,11 @@ fdesc(struct curparse *curp)
break;
case (OUTT_ASCII):
curp->outdata = ascii_alloc(curp->outopts);
+ curp->outfree = ascii_free;
break;
case (OUTT_PS):
curp->outdata = ps_alloc();
+ curp->outfree = ps_free;
break;
default:
break;
@@ -616,7 +618,6 @@ fdesc(struct curparse *curp)
case (OUTT_PS):
curp->outman = terminal_man;
curp->outmdoc = terminal_mdoc;
- curp->outfree = terminal_free;
break;
default:
break;
diff --git a/main.h b/main.h
index 49083fe3..05bd1d4f 100644
--- a/main.h
+++ b/main.h
@@ -42,10 +42,13 @@ void tree_mdoc(void *, const struct mdoc *);
void tree_man(void *, const struct man *);
void *ascii_alloc(char *);
+void ascii_free(void *);
+
void *ps_alloc(void);
+void ps_free(void *);
+
void terminal_mdoc(void *, const struct mdoc *);
void terminal_man(void *, const struct man *);
-void terminal_free(void *);
__END_DECLS
diff --git a/term.c b/term.c
index 14cb756c..b9955af3 100644
--- a/term.c
+++ b/term.c
@@ -45,8 +45,6 @@
#define PS_CHAR_BOTMARG 24
#define PS_CHAR_BOT (PS_CHAR_BOTMARG + 36)
-static struct termp *alloc(char *, enum termenc, enum termtype);
-static void term_free(struct termp *);
static void spec(struct termp *, const char *, size_t);
static void res(struct termp *, const char *, size_t);
static void buffera(struct termp *, const char *, size_t);
@@ -62,28 +60,44 @@ static void pageopen(struct termp *);
void *
ascii_alloc(char *outopts)
{
+ struct termp *p;
+ const char *toks[2];
+ char *v;
- return(alloc(outopts, TERMENC_ASCII, TERMTYPE_CHAR));
-}
+ if (NULL == (p = term_alloc(TERMENC_ASCII)))
+ return(NULL);
+ p->type = TERMTYPE_CHAR;
-void *
-ps_alloc(void)
-{
+ toks[0] = "width";
+ toks[1] = NULL;
+
+ while (outopts && *outopts)
+ switch (getsubopt(&outopts, UNCONST(toks), &v)) {
+ case (0):
+ p->defrmargin = (size_t)atoi(v);
+ break;
+ default:
+ break;
+ }
- return(alloc(NULL, TERMENC_ASCII, TERMTYPE_PS));
+ /* Enforce a lower boundary. */
+ if (p->defrmargin < 58)
+ p->defrmargin = 58;
+
+ return(p);
}
void
-terminal_free(void *arg)
+ascii_free(void *arg)
{
term_free((struct termp *)arg);
}
-static void
+void
term_free(struct termp *p)
{
@@ -91,6 +105,7 @@ term_free(struct termp *p)
free(p->buf);
if (p->symtab)
chars_free(p->symtab);
+
free(p);
}
@@ -290,16 +305,10 @@ advance(struct termp *p, size_t len)
}
-static struct termp *
-alloc(char *outopts, enum termenc enc, enum termtype type)
+struct termp *
+term_alloc(enum termenc enc)
{
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) {
@@ -307,25 +316,9 @@ alloc(char *outopts, enum termenc enc, enum termtype type)
exit(EXIT_FAILURE);
}
- p->type = type;
p->tabwidth = 5;
p->enc = enc;
-
- width = 80;
-
- while (outopts && *outopts)
- switch (getsubopt(&outopts, UNCONST(toks), &v)) {
- case (0):
- width = (size_t)atoi(v);
- break;
- default:
- break;
- }
-
- /* Enforce some lower boundary. */
- if (width < 60)
- width = 60;
- p->defrmargin = width - 2;
+ p->defrmargin = 78;
return(p);
}
diff --git a/term.h b/term.h
index 364b44ef..7b61a4ef 100644
--- a/term.h
+++ b/term.h
@@ -81,6 +81,8 @@ struct termp {
size_t pspage; /* -Tps: current page */
};
+struct termp *term_alloc(enum termenc);
+void term_free(struct termp *);
void term_newln(struct termp *);
void term_vspace(struct termp *);
void term_word(struct termp *, const char *);
diff --git a/term_ps.c b/term_ps.c
new file mode 100644
index 00000000..c6977e1c
--- /dev/null
+++ b/term_ps.c
@@ -0,0 +1,45 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include "out.h"
+#include "main.h"
+#include "term.h"
+
+void *
+ps_alloc(void)
+{
+ struct termp *p;
+
+ if (NULL == (p = term_alloc(TERMENC_ASCII)))
+ return(NULL);
+
+ p->type = TERMTYPE_PS;
+ return(p);
+}
+
+
+void
+ps_free(void *arg)
+{
+
+ term_free((struct termp *)arg);
+}