]>
git.cameronkatri.com Git - mandoc.git/blob - term_ascii.c
5b2ee847aca070d405092ad4ba3e6a53eed3b291
1 /* $Id: term_ascii.c,v 1.14 2011/05/17 14:38:34 kristaps Exp $ */
3 * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
34 static struct termp
*ascii_init(enum termenc
, char *);
35 static double ascii_hspan(const struct termp
*,
36 const struct roffsu
*);
37 static size_t ascii_width(const struct termp
*, int);
38 static void ascii_advance(struct termp
*, size_t);
39 static void ascii_begin(struct termp
*);
40 static void ascii_end(struct termp
*);
41 static void ascii_endline(struct termp
*);
42 static void ascii_letter(struct termp
*, int);
45 ascii_init(enum termenc enc
, char *outopts
)
51 p
= mandoc_calloc(1, sizeof(struct termp
));
57 p
->advance
= ascii_advance
;
58 p
->begin
= ascii_begin
;
60 p
->endline
= ascii_endline
;
61 p
->hspan
= ascii_hspan
;
62 p
->letter
= ascii_letter
;
63 p
->type
= TERMTYPE_CHAR
;
64 p
->width
= ascii_width
;
69 while (outopts
&& *outopts
)
70 switch (getsubopt(&outopts
, UNCONST(toks
), &v
)) {
72 p
->defrmargin
= (size_t)atoi(v
);
78 /* Enforce a lower boundary. */
79 if (p
->defrmargin
< 58)
86 ascii_alloc(char *outopts
)
89 return(ascii_init(TERMENC_ASCII
, outopts
));
93 locale_alloc(char *outopts
)
96 return(ascii_init(TERMENC_LOCALE
, outopts
));
101 ascii_width(const struct termp
*p
, int c
)
109 ascii_free(void *arg
)
112 term_free((struct termp
*)arg
);
118 ascii_letter(struct termp
*p
, int c
)
127 ascii_begin(struct termp
*p
)
130 (*p
->headf
)(p
, p
->argf
);
135 ascii_end(struct termp
*p
)
138 (*p
->footf
)(p
, p
->argf
);
144 ascii_endline(struct termp
*p
)
153 ascii_advance(struct termp
*p
, size_t len
)
157 /* Just print whitespace on the terminal. */
158 for (i
= 0; i
< len
; i
++)
165 ascii_hspan(const struct termp
*p
, const struct roffsu
*su
)
170 * Approximate based on character width. These are generated
171 * entirely by eyeballing the screen, but appear to be correct.
182 r
= (10 * su
->scale
) / 6;
185 r
= (10 * su
->scale
) / 72;
188 r
= su
->scale
/ 1000;
191 r
= su
->scale
* 2 - 1;