blob: 157169de6a0b8eaf7bb651f33a168152b9aa7036 [file] [log] [blame]
rscc42a1d32006-02-21 18:37:05 +00001#include "a.h"
2
3/*
4 * 4 - Text filling, centering, and adjusting.
5 * "\ " - unbreakable space
6 * .n register - length of last line
7 * nl register - text baseline position on this page
8 * .h register - baseline high water mark
9 * .k register - current horizontal output position
10 * \p - cause break at end of word, justify
11 * \& - non-printing zero-width filler
12 * tr - output translation
13 * \c - break (but don't) input line in .nf mode
14 * \c - break (but don't) word in .fi mode
15 */
16
17int
18e_space(void)
19{
20 return 0xA0; /* non-breaking space */
21}
22
23int
24e_amp(void)
25{
26 return Uempty;
27}
28
29int
30e_c(void)
31{
32 getrune();
33 bol = 1;
34 return 0;
35}
36
37void
38r_br(int argc, Rune **argv)
39{
40 USED(argc);
41 USED(argv);
42 br();
43}
44
45/* fill mode on */
46void
47r_fi(int argc, Rune **argv)
48{
49 USED(argc);
50 USED(argv);
51 nr(L(".fi"), 1);
rsccbeb0b22006-04-01 19:24:03 +000052/* warn(".fi"); */
rscc42a1d32006-02-21 18:37:05 +000053}
54
55/* no-fill mode */
56void
57r_nf(int argc, Rune **argv)
58{
59 USED(argc);
60 USED(argv);
61 nr(L(".fi"), 0);
62}
63
64/* adjust */
65void
66r_ad(int argc, Rune **argv)
67{
68 int c, n;
69
70 nr(L(".j"), getnr(L(".j"))|1);
71 if(argc < 2)
72 return;
73 c = argv[1][0];
74 switch(c){
75 default:
76 fprint(2, "%L: bad adjust %C\n", c);
77 return;
78 case 'r':
79 n = 2*2|1;
80 break;
81 case 'l':
82 n = 0;
83 break;
84 case 'c':
85 n = 1*2|1;
86 break;
87 case 'b':
88 case 'n':
89 n = 0*2|1;
90 break;
91 case '0':
92 case '1':
93 case '2':
94 case '3':
95 case '4':
96 case '5':
97 n = c-'0';
98 break;
99 }
100 nr(L(".j"), n);
101}
102
103/* no adjust */
104void
105r_na(int argc, Rune **argv)
106{
107 USED(argc);
108 USED(argv);
109
110 nr(L(".j"), getnr(L(".j"))&~1);
111}
112
113/* center next N lines */
114void
115r_ce(int argc, Rune **argv)
116{
117 if(argc < 2)
118 nr(L(".ce"), 1);
119 else
120 nr(L(".ce"), eval(argv[1]));
121 /* XXX set trap */
122}
123
124void
125t4init(void)
126{
127 nr(L(".fi"), 1);
128 nr(L(".j"), 1);
129
130 addreq(L("br"), r_br, 0);
131 addreq(L("fi"), r_fi, 0);
132 addreq(L("nf"), r_nf, 0);
133 addreq(L("ad"), r_ad, -1);
134 addreq(L("na"), r_na, 0);
135 addreq(L("ce"), r_ce, -1);
136
137 addesc(' ', e_space, 0);
138 addesc('p', e_warn, 0);
139 addesc('&', e_amp, 0);
140 addesc('c', e_c, 0);
141}
142