source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Add mode for -Tlocale.
@ 2011-05-17 14:38 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-05-17 14:38 UTC (permalink / raw)
  To: source

Log Message:
-----------
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().

Modified Files:
--------------
    mdocml:
        main.c
        main.h
        man_term.c
        mdoc_term.c
        term.c
        term.h
        term_ascii.c
        term_ps.c

Revision Data
-------------
Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.192
retrieving revision 1.193
diff -Lterm.c -Lterm.c -u -p -r1.192 -r1.193
--- term.c
+++ term.c
@@ -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
Index: term.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.h,v
retrieving revision 1.83
retrieving revision 1.84
diff -Lterm.h -Lterm.h -u -p -r1.83 -r1.84
--- term.h
+++ term.h
@@ -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 *);
Index: man_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -Lman_term.c -Lman_term.c -u -p -r1.108 -r1.109
--- man_term.c
+++ man_term.c
@@ -156,14 +156,7 @@ terminal_man(void *arg, const struct 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);
Index: term_ascii.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ascii.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -Lterm_ascii.c -Lterm_ascii.c -u -p -r1.13 -r1.14
--- term_ascii.c
+++ term_ascii.c
@@ -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
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.229
retrieving revision 1.230
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.229 -r1.230
--- mdoc_term.c
+++ mdoc_term.c
@@ -264,14 +264,7 @@ terminal_mdoc(void *arg, const struct md
 	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);
Index: term_ps.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ps.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.50 -r1.51
--- term_ps.c
+++ term_ps.c
@@ -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;
Index: main.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lmain.h -Lmain.h -u -p -r1.10 -r1.11
--- main.h
+++ main.h
@@ -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 *);
 
Index: main.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v
retrieving revision 1.161
retrieving revision 1.162
diff -Lmain.c -Lmain.c -u -p -r1.161 -r1.162
--- main.c
+++ main.c
@@ -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 *ar
 		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"))
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-17 14:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-17 14:38 mdocml: Add mode for -Tlocale kristaps

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).