summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--html.c1
-rw-r--r--main.c12
-rw-r--r--main.h47
-rw-r--r--man_html.c1
-rw-r--r--man_term.c34
-rw-r--r--mdoc_html.c1
-rw-r--r--mdoc_term.c17
-rw-r--r--term.c32
-rw-r--r--tree.c1
10 files changed, 97 insertions, 51 deletions
diff --git a/Makefile b/Makefile
index 5815bb28..270277d1 100644
--- a/Makefile
+++ b/Makefile
@@ -54,7 +54,7 @@ SRCS = $(MDOCSRCS) $(MAINSRCS) $(MANSRCS)
DATAS = arch.in att.in lib.in msec.in st.in \
vol.in chars.in
HEADS = mdoc.h libmdoc.h man.h libman.h term.h \
- libmandoc.h html.h chars.h out.h
+ libmandoc.h html.h chars.h out.h main.h
GSGMLS = mandoc.1.sgml mdoc.3.sgml mdoc.7.sgml manuals.7.sgml \
mandoc_char.7.sgml man.7.sgml man.3.sgml
SGMLS = index.sgml $(GSGMLS)
diff --git a/html.c b/html.c
index 2c2f65da..3ea9f02e 100644
--- a/html.c
+++ b/html.c
@@ -29,6 +29,7 @@
#include "out.h"
#include "chars.h"
#include "html.h"
+#include "main.h"
#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
diff --git a/main.c b/main.c
index aadd86ac..c94f1072 100644
--- a/main.c
+++ b/main.c
@@ -27,6 +27,7 @@
#include "mdoc.h"
#include "man.h"
+#include "main.h"
#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
@@ -90,17 +91,6 @@ struct curparse {
char *outopts;
};
-extern void *html_alloc(char *);
-extern void html_mdoc(void *, const struct mdoc *);
-extern void html_man(void *, const struct man *);
-extern void html_free(void *);
-extern void *ascii_alloc(void);
-extern void tree_mdoc(void *, const struct mdoc *);
-extern void tree_man(void *, const struct man *);
-extern void terminal_mdoc(void *, const struct mdoc *);
-extern void terminal_man(void *, const struct man *);
-extern void terminal_free(void *);
-
static int foptions(int *, char *);
static int toptions(enum outt *, char *);
static int moptions(enum intt *, char *);
diff --git a/main.h b/main.h
new file mode 100644
index 00000000..589344d7
--- /dev/null
+++ b/main.h
@@ -0,0 +1,47 @@
+/* $Id$ */
+/*
+ * Copyright (c) 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.
+ */
+#ifndef MAIN_H
+#define MAIN_H
+
+__BEGIN_DECLS
+
+struct mdoc;
+struct man;
+
+/*
+ * Definitions for main.c-visible output device functions, e.g., -Thtml
+ * and -Tascii. Note that ascii_alloc() is named as such in
+ * anticipation of latin1_alloc() and so on, all of which map into the
+ * terminal output routines with different character settings.
+ */
+
+void *html_alloc(char *);
+void html_mdoc(void *, const struct mdoc *);
+void html_man(void *, const struct man *);
+void html_free(void *);
+
+void tree_mdoc(void *, const struct mdoc *);
+void tree_man(void *, const struct man *);
+
+void *ascii_alloc(void);
+void terminal_mdoc(void *, const struct mdoc *);
+void terminal_man(void *, const struct man *);
+void terminal_free(void *);
+
+__END_DECLS
+
+#endif /*!MAIN_H*/
diff --git a/man_html.c b/man_html.c
index f2d7cc10..de1cf2d8 100644
--- a/man_html.c
+++ b/man_html.c
@@ -27,6 +27,7 @@
#include "out.h"
#include "html.h"
#include "man.h"
+#include "main.h"
/* TODO: preserve ident widths. */
diff --git a/man_term.c b/man_term.c
index 466d55f5..f54efedf 100644
--- a/man_term.c
+++ b/man_term.c
@@ -23,8 +23,10 @@
#include <stdlib.h>
#include <string.h>
-#include "term.h"
#include "man.h"
+#include "term.h"
+#include "chars.h"
+#include "main.h"
#define INDENT 7
#define HALFINDENT 3
@@ -140,20 +142,38 @@ static int arg_width(const struct man_node *);
void
-man_run(struct termp *p, const struct man *m)
+terminal_man(void *arg, const struct man *man)
{
- struct mtermp mt;
+ struct termp *p;
+ const struct man_node *n;
+ const struct man_meta *m;
+ struct mtermp mt;
+
+ p = (struct termp *)arg;
+
+ if (NULL == p->symtab)
+ switch (p->enc) {
+ case (TERMENC_ASCII):
+ p->symtab = chars_init(CHARS_ASCII);
+ break;
+ default:
+ abort();
+ /* NOTREACHED */
+ }
+
+ n = man_node(man);
+ m = man_meta(man);
- print_head(p, man_meta(m));
+ print_head(p, m);
p->flags |= TERMP_NOSPACE;
mt.fl = 0;
mt.lmargin = INDENT;
mt.offset = INDENT;
- if (man_node(m)->child)
- print_body(p, &mt, man_node(m)->child, man_meta(m));
- print_foot(p, man_meta(m));
+ if (n->child)
+ print_body(p, &mt, n->child, m);
+ print_foot(p, m);
}
diff --git a/mdoc_html.c b/mdoc_html.c
index f418ad7e..89998348 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -29,6 +29,7 @@
#include "out.h"
#include "html.h"
#include "mdoc.h"
+#include "main.h"
#define INDENT 5
#define HALFINDENT 3
diff --git a/mdoc_term.c b/mdoc_term.c
index 08a546f5..4bba41de 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -25,6 +25,8 @@
#include "term.h"
#include "mdoc.h"
+#include "chars.h"
+#include "main.h"
#define INDENT 5
#define HALFINDENT 3
@@ -257,10 +259,23 @@ static void print_foot(DECL_ARGS);
void
-mdoc_run(struct termp *p, const struct mdoc *mdoc)
+terminal_mdoc(void *arg, const struct mdoc *mdoc)
{
const struct mdoc_node *n;
const struct mdoc_meta *m;
+ struct termp *p;
+
+ p = (struct termp *)arg;
+
+ if (NULL == p->symtab)
+ switch (p->enc) {
+ case (TERMENC_ASCII):
+ p->symtab = chars_init(CHARS_ASCII);
+ break;
+ default:
+ abort();
+ /* NOTREACHED */
+ }
n = mdoc_node(mdoc);
m = mdoc_meta(mdoc);
diff --git a/term.c b/term.c
index 91638e25..c12b04b7 100644
--- a/term.c
+++ b/term.c
@@ -24,15 +24,11 @@
#include "term.h"
#include "man.h"
#include "mdoc.h"
+#include "main.h"
/* FIXME: accomodate non-breaking, non-collapsing white-space. */
/* FIXME: accomodate non-breaking, collapsing white-space. */
-extern void man_run(struct termp *,
- const struct man *);
-extern void mdoc_run(struct termp *,
- const struct mdoc *);
-
static struct termp *term_alloc(enum termenc);
static void term_free(struct termp *);
@@ -54,32 +50,6 @@ ascii_alloc(void)
void
-terminal_man(void *arg, const struct man *man)
-{
- struct termp *p;
-
- p = (struct termp *)arg;
- if (NULL == p->symtab)
- p->symtab = chars_init(CHARS_ASCII);
-
- man_run(p, man);
-}
-
-
-void
-terminal_mdoc(void *arg, const struct mdoc *mdoc)
-{
- struct termp *p;
-
- p = (struct termp *)arg;
- if (NULL == p->symtab)
- p->symtab = chars_init(CHARS_ASCII);
-
- mdoc_run(p, mdoc);
-}
-
-
-void
terminal_free(void *arg)
{
diff --git a/tree.c b/tree.c
index 4211f877..dd283f15 100644
--- a/tree.c
+++ b/tree.c
@@ -21,6 +21,7 @@
#include "mdoc.h"
#include "man.h"
+#include "main.h"
static void print_mdoc(const struct mdoc_node *, int);
static void print_man(const struct man_node *, int);