Annotation of mandoc/term_ascii.c, Revision 1.2
1.2 ! kristaps 1: /* $Id: term_ascii.c,v 1.1 2010/06/08 15:00:17 kristaps Exp $ */
1.1 kristaps 2: /*
3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
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>
1.2 ! kristaps 27: #include <unistd.h>
1.1 kristaps 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:
39:
40: void *
41: ascii_alloc(char *outopts)
42: {
43: struct termp *p;
44: const char *toks[2];
45: char *v;
46:
47: if (NULL == (p = term_alloc(TERMENC_ASCII)))
48: return(NULL);
49:
50: p->type = TERMTYPE_CHAR;
51: p->letter = ascii_letter;
52: p->begin = ascii_begin;
53: p->end = ascii_end;
54: p->endline = ascii_endline;
55: p->advance = ascii_advance;
56:
57: toks[0] = "width";
58: toks[1] = NULL;
59:
60: while (outopts && *outopts)
61: switch (getsubopt(&outopts, UNCONST(toks), &v)) {
62: case (0):
63: p->defrmargin = (size_t)atoi(v);
64: break;
65: default:
66: break;
67: }
68:
69: /* Enforce a lower boundary. */
70: if (p->defrmargin < 58)
71: p->defrmargin = 58;
72:
73: return(p);
74: }
75:
76:
77: void
78: ascii_free(void *arg)
79: {
80:
81: term_free((struct termp *)arg);
82: }
83:
84:
85: /* ARGSUSED */
86: static void
87: ascii_letter(struct termp *p, char c)
88: {
89:
90: /* Just push onto the screen. */
91: putchar(c);
92: }
93:
94:
95: static void
96: ascii_begin(struct termp *p)
97: {
98:
99: (*p->headf)(p, p->argf);
100: }
101:
102:
103: static void
104: ascii_end(struct termp *p)
105: {
106:
107: (*p->footf)(p, p->argf);
108: }
109:
110:
111: /* ARGSUSED */
112: static void
113: ascii_endline(struct termp *p)
114: {
115:
116: putchar('\n');
117: }
118:
119:
120: /* ARGSUSED */
121: static void
122: ascii_advance(struct termp *p, size_t len)
123: {
124: size_t i;
125:
126: /* Just print whitespace on the terminal. */
127: for (i = 0; i < len; i++)
128: putchar(' ');
129: }
CVSweb