]>
git.cameronkatri.com Git - mandoc.git/blob - term_ascii.c
1 /* $Id: term_ascii.c,v 1.6 2010/06/25 19:50:23 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 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>
33 static void ascii_endline(struct termp
*);
34 static void ascii_letter(struct termp
*, char);
35 static void ascii_begin(struct termp
*);
36 static void ascii_advance(struct termp
*, size_t);
37 static void ascii_end(struct termp
*);
38 static size_t ascii_width(const struct termp
*, char);
42 ascii_alloc(char *outopts
)
48 if (NULL
== (p
= term_alloc(TERMENC_ASCII
)))
54 p
->type
= TERMTYPE_CHAR
;
55 p
->letter
= ascii_letter
;
56 p
->begin
= ascii_begin
;
58 p
->endline
= ascii_endline
;
59 p
->advance
= ascii_advance
;
60 p
->width
= ascii_width
;
65 while (outopts
&& *outopts
)
66 switch (getsubopt(&outopts
, UNCONST(toks
), &v
)) {
68 p
->defrmargin
= (size_t)atoi(v
);
74 /* Enforce a lower boundary. */
75 if (p
->defrmargin
< 58)
84 ascii_width(const struct termp
*p
, char c
)
95 term_free((struct termp
*)arg
);
101 ascii_letter(struct termp
*p
, char c
)
109 ascii_begin(struct termp
*p
)
112 (*p
->headf
)(p
, p
->argf
);
117 ascii_end(struct termp
*p
)
120 (*p
->footf
)(p
, p
->argf
);
126 ascii_endline(struct termp
*p
)
135 ascii_advance(struct termp
*p
, size_t len
)
139 /* Just print whitespace on the terminal. */
140 for (i
= 0; i
< len
; i
++)