From e012cb8b2706ff0d54c6b3b68fa79354484752dc Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Tue, 13 Oct 2009 10:57:25 +0000 Subject: Moved output definitions into main.h. Pushed terminal_{mdoc,man} into {mdoc,man}_term.c. --- Makefile | 2 +- html.c | 3 ++- main.c | 14 ++------------ main.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ man_html.c | 3 ++- man_term.c | 36 ++++++++++++++++++++++++++++-------- mdoc_html.c | 3 ++- mdoc_term.c | 19 +++++++++++++++++-- term.c | 34 ++-------------------------------- tree.c | 3 ++- 10 files changed, 105 insertions(+), 59 deletions(-) create mode 100644 main.h 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 8001cf6c..623fa975 100644 --- a/html.c +++ b/html.c @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.63 2009/10/13 10:21:24 kristaps Exp $ */ +/* $Id: html.c,v 1.64 2009/10/13 10:57:25 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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 79c5f1f3..134a8b84 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.45 2009/10/13 10:21:24 kristaps Exp $ */ +/* $Id: main.c,v 1.46 2009/10/13 10:57:25 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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..a8d995ad --- /dev/null +++ b/main.h @@ -0,0 +1,47 @@ +/* $Id: main.h,v 1.1 2009/10/13 10:57:25 kristaps Exp $ */ +/* + * Copyright (c) 2009 Kristaps Dzonsons + * + * 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 244a7c5e..2aee4bf1 100644 --- a/man_html.c +++ b/man_html.c @@ -1,4 +1,4 @@ -/* $Id: man_html.c,v 1.9 2009/10/09 07:10:37 kristaps Exp $ */ +/* $Id: man_html.c,v 1.10 2009/10/13 10:57:25 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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 5f6923ec..a95420af 100644 --- a/man_term.c +++ b/man_term.c @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.35 2009/10/08 23:00:15 kristaps Exp $ */ +/* $Id: man_term.c,v 1.36 2009/10/13 10:57:25 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -23,8 +23,10 @@ #include #include -#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 e48685fc..218f3961 100644 --- a/mdoc_html.c +++ b/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.28 2009/10/10 10:05:12 kristaps Exp $ */ +/* $Id: mdoc_html.c,v 1.29 2009/10/13 10:57:25 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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 722ca98a..46e02f86 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.88 2009/10/10 11:05:23 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.89 2009/10/13 10:57:25 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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 9ac3039f..e945b95f 100644 --- a/term.c +++ b/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.104 2009/10/10 11:05:23 kristaps Exp $ */ +/* $Id: term.c,v 1.105 2009/10/13 10:57:25 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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 *); @@ -53,32 +49,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 d0aee4ab..2d75ae1d 100644 --- a/tree.c +++ b/tree.c @@ -1,4 +1,4 @@ -/* $Id: tree.c,v 1.15 2009/09/16 09:41:24 kristaps Exp $ */ +/* $Id: tree.c,v 1.16 2009/10/13 10:57:25 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -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); -- cgit v1.2.3-56-ge451