Annotation of mandoc/term_ascii.c, Revision 1.5
1.5 ! kristaps 1: /* $Id: term_ascii.c,v 1.4 2010/06/19 20:46:28 kristaps Exp $ */
1.1 kristaps 2: /*
1.4 kristaps 3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
1.1 kristaps 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 *);
1.5 ! kristaps 38: static size_t ascii_width(const struct termp *, char);
1.1 kristaps 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:
1.5 ! kristaps 51: p->tabwidth = 5;
! 52: p->defrmargin = 78;
! 53:
1.1 kristaps 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;
1.5 ! kristaps 60: p->width = ascii_width;
1.1 kristaps 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);
1.5 ! kristaps 79: }
! 80:
! 81:
! 82: static size_t
! 83: ascii_width(const struct termp *p, char c)
! 84: {
! 85:
! 86: return(1);
1.1 kristaps 87: }
88:
89:
90: void
91: ascii_free(void *arg)
92: {
93:
94: term_free((struct termp *)arg);
95: }
96:
97:
98: /* ARGSUSED */
99: static void
100: ascii_letter(struct termp *p, char c)
101: {
102:
103: putchar(c);
104: }
105:
106:
107: static void
108: ascii_begin(struct termp *p)
109: {
110:
111: (*p->headf)(p, p->argf);
112: }
113:
114:
115: static void
116: ascii_end(struct termp *p)
117: {
118:
119: (*p->footf)(p, p->argf);
120: }
121:
122:
123: /* ARGSUSED */
124: static void
125: ascii_endline(struct termp *p)
126: {
127:
128: putchar('\n');
129: }
130:
131:
132: /* ARGSUSED */
133: static void
134: ascii_advance(struct termp *p, size_t len)
135: {
136: size_t i;
137:
138: /* Just print whitespace on the terminal. */
139: for (i = 0; i < len; i++)
140: putchar(' ');
141: }
CVSweb