]> git.cameronkatri.com Git - mandoc.git/blob - term_ascii.c
Remove "pt" from struct roffsu, as CSS (the only reason it was there) is
[mandoc.git] / term_ascii.c
1 /* $Id: term_ascii.c,v 1.6 2010/06/25 19:50:23 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
4 *
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.
8 *
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.
16 */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <sys/types.h>
22
23 #include <assert.h>
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28
29 #include "out.h"
30 #include "term.h"
31 #include "main.h"
32
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);
39
40
41 void *
42 ascii_alloc(char *outopts)
43 {
44 struct termp *p;
45 const char *toks[2];
46 char *v;
47
48 if (NULL == (p = term_alloc(TERMENC_ASCII)))
49 return(NULL);
50
51 p->tabwidth = 5;
52 p->defrmargin = 78;
53
54 p->type = TERMTYPE_CHAR;
55 p->letter = ascii_letter;
56 p->begin = ascii_begin;
57 p->end = ascii_end;
58 p->endline = ascii_endline;
59 p->advance = ascii_advance;
60 p->width = ascii_width;
61
62 toks[0] = "width";
63 toks[1] = NULL;
64
65 while (outopts && *outopts)
66 switch (getsubopt(&outopts, UNCONST(toks), &v)) {
67 case (0):
68 p->defrmargin = (size_t)atoi(v);
69 break;
70 default:
71 break;
72 }
73
74 /* Enforce a lower boundary. */
75 if (p->defrmargin < 58)
76 p->defrmargin = 58;
77
78 return(p);
79 }
80
81
82 /* ARGSUSED */
83 static size_t
84 ascii_width(const struct termp *p, char c)
85 {
86
87 return(1);
88 }
89
90
91 void
92 ascii_free(void *arg)
93 {
94
95 term_free((struct termp *)arg);
96 }
97
98
99 /* ARGSUSED */
100 static void
101 ascii_letter(struct termp *p, char c)
102 {
103
104 putchar(c);
105 }
106
107
108 static void
109 ascii_begin(struct termp *p)
110 {
111
112 (*p->headf)(p, p->argf);
113 }
114
115
116 static void
117 ascii_end(struct termp *p)
118 {
119
120 (*p->footf)(p, p->argf);
121 }
122
123
124 /* ARGSUSED */
125 static void
126 ascii_endline(struct termp *p)
127 {
128
129 putchar('\n');
130 }
131
132
133 /* ARGSUSED */
134 static void
135 ascii_advance(struct termp *p, size_t len)
136 {
137 size_t i;
138
139 /* Just print whitespace on the terminal. */
140 for (i = 0; i < len; i++)
141 putchar(' ');
142 }