aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/htmlroff/t10.c
blob: 4aa745324101a24e39811b8b3be69b94953f5453 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "a.h"

/*
 * 10. Input and Output Conventions and Character Translation.
 */

/* set escape character */
void
r_ec(int argc, Rune **argv)
{
	if(argc == 1)
		backslash = '\\';
	else
		backslash = argv[1][0];
}

/* turn off escape character */
void
r_eo(int argc, Rune **argv)
{
	USED(argc);
	USED(argv);
	backslash = -2;
}

/* continuous underline (same as ul in troff) for the next N lines */
/* set underline font */
void
g_uf(int argc, Rune **argv)
{
	USED(argc);
	USED(argv);
}

/* set control character */
void
r_cc(int argc, Rune **argv)
{
	if(argc == 1)
		dot = '.';
	else
		dot = argv[1][0];
}

/* set no-break control character */
void
r_c2(int argc, Rune **argv)
{
	if(argc == 1)
		tick = '\'';
	else
		tick = argv[1][0];
}

/* output translation */

int
e_bang(void)
{
	Rune *line;
	
	line = readline(CopyMode);
	out(line);
	outrune('\n');
	free(line);
	return 0;
}

int
e_X(void)
{
	int c, c1;
	
	c1 = getrune();
	if(c1 < 0 || c1 == '\n') {
		c = c1;
		c1 = 0;
	} else {
		while((c = getrune()) >= 0 && c != c1 && c != '\n')
			;
	}
	if(c == '\n'){
		warn("newline in %CX'...'", backslash);
		outrune(c);
	}
	if(c < 0)
		warn("eof in %CX'...'", backslash);
	return 0;
}

int
e_quote(void)
{
	int c;

	if(inputmode&ArgMode){
		/* Leave \" around for argument parsing */
		ungetrune('"');
		return '\\';
	}
	while((c = getrune()) >= 0 && c != '\n')
		;
	return '\n';
}

int
e_newline(void)
{
	return 0;
}

int
e_e(void)
{
	return backslash;
}

void
r_comment(Rune *name)
{
	int c;
	
	USED(name);
	while((c = getrune()) >= 0 && c != '\n')
		;
}

void
t10init(void)
{
	addreq(L("ec"), r_ec, -1);
	addreq(L("eo"), r_eo, 0);
	addreq(L("lg"), r_nop, -1);
	addreq(L("cc"), r_cc, -1);
	addreq(L("c2"), r_c2, -1);
	addreq(L("tr"), r_warn, -1);
	addreq(L("ul"), r_nop, -1);
	addraw(L("\\\""), r_comment);
	
	addesc('!', e_bang, 0);
	addesc('X', e_X, 0);
	addesc('\"', e_quote, CopyMode|ArgMode);
	addesc('\n', e_newline, CopyMode|ArgMode|HtmlMode);
	addesc('e', e_e, 0);
}