From 0587ad80d46d89f36315c37bbd67cf8899708b8d Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Tue, 17 May 2011 14:38:34 +0000 Subject: [PATCH] Add mode for -Tlocale. This mode, with this commit, behaves exactly like -Tascii. While adding this, inline term_alloc() (was a one-liner), remove some switches around the terminal encoding for the symbol table (unnecessary), and split out ascii_alloc() into ascii_init(), which is also called from locale_init(). --- main.c | 14 ++++++++++++-- main.h | 3 ++- man_term.c | 11 ++--------- mdoc_term.c | 11 ++--------- term.c | 14 +------------- term.h | 6 +++--- term_ascii.c | 26 ++++++++++++++++++++------ term_ps.c | 5 +++-- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/main.c b/main.c index bbbb8846..f7edf473 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.161 2011/03/31 10:53:43 kristaps Exp $ */ +/* $Id: main.c,v 1.162 2011/05/17 14:38:34 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -43,6 +43,7 @@ typedef void (*out_free)(void *); enum outt { OUTT_ASCII = 0, /* -Tascii */ + OUTT_LOCALE, /* -Tlocale */ OUTT_TREE, /* -Ttree */ OUTT_HTML, /* -Thtml */ OUTT_XHTML, /* -Txhtml */ @@ -206,9 +207,15 @@ parse(struct curparse *curp, int fd, switch (curp->outtype) { case (OUTT_XHTML): curp->outdata = xhtml_alloc(curp->outopts); + curp->outfree = html_free; break; case (OUTT_HTML): curp->outdata = html_alloc(curp->outopts); + curp->outfree = html_free; + break; + case (OUTT_LOCALE): + curp->outdata = locale_alloc(curp->outopts); + curp->outfree = ascii_free; break; case (OUTT_ASCII): curp->outdata = ascii_alloc(curp->outopts); @@ -232,7 +239,6 @@ parse(struct curparse *curp, int fd, case (OUTT_XHTML): curp->outman = html_man; curp->outmdoc = html_mdoc; - curp->outfree = html_free; break; case (OUTT_TREE): curp->outman = tree_man; @@ -242,6 +248,8 @@ parse(struct curparse *curp, int fd, /* FALLTHROUGH */ case (OUTT_ASCII): /* FALLTHROUGH */ + case (OUTT_LOCALE): + /* FALLTHROUGH */ case (OUTT_PS): curp->outman = terminal_man; curp->outmdoc = terminal_mdoc; @@ -299,6 +307,8 @@ toptions(struct curparse *curp, char *arg) curp->outtype = OUTT_TREE; else if (0 == strcmp(arg, "html")) curp->outtype = OUTT_HTML; + else if (0 == strcmp(arg, "locale")) + curp->outtype = OUTT_LOCALE; else if (0 == strcmp(arg, "xhtml")) curp->outtype = OUTT_XHTML; else if (0 == strcmp(arg, "ps")) diff --git a/main.h b/main.h index bb503eb7..75637b36 100644 --- a/main.h +++ b/main.h @@ -1,4 +1,4 @@ -/* $Id: main.h,v 1.10 2010/07/31 23:52:58 schwarze Exp $ */ +/* $Id: main.h,v 1.11 2011/05/17 14:38:34 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons * @@ -41,6 +41,7 @@ void html_free(void *); void tree_mdoc(void *, const struct mdoc *); void tree_man(void *, const struct man *); +void *locale_alloc(char *); void *ascii_alloc(char *); void ascii_free(void *); diff --git a/man_term.c b/man_term.c index 2fcf8b46..38ceeabd 100644 --- a/man_term.c +++ b/man_term.c @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.108 2011/04/30 22:14:42 kristaps Exp $ */ +/* $Id: man_term.c,v 1.109 2011/05/17 14:38:34 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -156,14 +156,7 @@ terminal_man(void *arg, const struct man *man) p->tabwidth = term_len(p, 5); if (NULL == p->symtab) - switch (p->enc) { - case (TERMENC_ASCII): - p->symtab = mchars_alloc(); - break; - default: - abort(); - /* NOTREACHED */ - } + p->symtab = mchars_alloc(); n = man_node(man); m = man_meta(man); diff --git a/mdoc_term.c b/mdoc_term.c index 5333cb8a..1a5ce4c2 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.229 2011/04/30 22:14:42 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.230 2011/05/17 14:38:34 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze @@ -264,14 +264,7 @@ terminal_mdoc(void *arg, const struct mdoc *mdoc) p->tabwidth = term_len(p, 5); if (NULL == p->symtab) - switch (p->enc) { - case (TERMENC_ASCII): - p->symtab = mchars_alloc(); - break; - default: - abort(); - /* NOTREACHED */ - } + p->symtab = mchars_alloc(); n = mdoc_node(mdoc); m = mdoc_meta(mdoc); diff --git a/term.c b/term.c index bfedefb0..922385ae 100644 --- a/term.c +++ b/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.192 2011/05/17 11:55:08 kristaps Exp $ */ +/* $Id: term.c,v 1.193 2011/05/17 14:38:34 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -69,18 +69,6 @@ term_end(struct termp *p) (*p->end)(p); } - -struct termp * -term_alloc(enum termenc enc) -{ - struct termp *p; - - p = mandoc_calloc(1, sizeof(struct termp)); - p->enc = enc; - return(p); -} - - /* * Flush a line of text. A "line" is loosely defined as being something * that should be followed by a newline, regardless of whether it's diff --git a/term.h b/term.h index 7b0537df..dc3945ec 100644 --- a/term.h +++ b/term.h @@ -1,4 +1,4 @@ -/* $Id: term.h,v 1.83 2011/05/15 00:58:48 kristaps Exp $ */ +/* $Id: term.h,v 1.84 2011/05/17 14:38:34 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * @@ -22,7 +22,8 @@ __BEGIN_DECLS struct termp; enum termenc { - TERMENC_ASCII + TERMENC_ASCII, + TERMENC_LOCALE }; enum termtype { @@ -94,7 +95,6 @@ struct termp { struct termp_ps *ps; }; -struct termp *term_alloc(enum termenc); void term_tbl(struct termp *, const struct tbl_span *); void term_free(struct termp *); void term_newln(struct termp *); diff --git a/term_ascii.c b/term_ascii.c index fd7005f0..5b2ee847 100644 --- a/term_ascii.c +++ b/term_ascii.c @@ -1,4 +1,4 @@ -/* $Id: term_ascii.c,v 1.13 2011/05/14 17:54:42 kristaps Exp $ */ +/* $Id: term_ascii.c,v 1.14 2011/05/17 14:38:34 kristaps Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons * @@ -31,6 +31,7 @@ #include "term.h" #include "main.h" +static struct termp *ascii_init(enum termenc, char *); static double ascii_hspan(const struct termp *, const struct roffsu *); static size_t ascii_width(const struct termp *, int); @@ -40,15 +41,15 @@ static void ascii_end(struct termp *); static void ascii_endline(struct termp *); static void ascii_letter(struct termp *, int); - -void * -ascii_alloc(char *outopts) +static struct termp * +ascii_init(enum termenc enc, char *outopts) { - struct termp *p; const char *toks[2]; char *v; + struct termp *p; - p = term_alloc(TERMENC_ASCII); + p = mandoc_calloc(1, sizeof(struct termp)); + p->enc = enc; p->tabwidth = 5; p->defrmargin = 78; @@ -81,6 +82,19 @@ ascii_alloc(char *outopts) return(p); } +void * +ascii_alloc(char *outopts) +{ + + return(ascii_init(TERMENC_ASCII, outopts)); +} + +void * +locale_alloc(char *outopts) +{ + + return(ascii_init(TERMENC_LOCALE, outopts)); +} /* ARGSUSED */ static size_t diff --git a/term_ps.c b/term_ps.c index 50984dc0..44e492a2 100644 --- a/term_ps.c +++ b/term_ps.c @@ -1,4 +1,4 @@ -/* $Id: term_ps.c,v 1.50 2011/05/15 00:58:48 kristaps Exp $ */ +/* $Id: term_ps.c,v 1.51 2011/05/17 14:38:34 kristaps Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons * @@ -434,7 +434,8 @@ pspdf_alloc(char *outopts) const char *pp; char *v; - p = term_alloc(TERMENC_ASCII); + p = mandoc_calloc(1, sizeof(struct termp)); + p->enc = TERMENC_ASCII; p->ps = mandoc_calloc(1, sizeof(struct termp_ps)); p->advance = ps_advance; -- 2.47.1