]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/htmlroff/t4.c
ndb/dns: remove single-ip-address assuptions
[plan9front.git] / sys / src / cmd / htmlroff / t4.c
1 #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
17 int
18 e_space(void)
19 {
20         return 0xA0;    /* non-breaking space */
21 }
22
23 int
24 e_amp(void)
25 {
26         return Uempty;
27 }
28
29 int
30 e_c(void)
31 {
32         getrune();
33         bol = 1;
34         return 0;
35 }
36
37 void
38 r_br(int argc, Rune **argv)
39 {
40         USED(argc);
41         USED(argv);
42         br();
43 }
44
45 /* fill mode on */
46 void
47 r_fi(int argc, Rune **argv)
48 {
49         USED(argc);
50         USED(argv);
51         nr(L(".fi"), 1);
52 // warn(".fi");
53 }
54
55 /* no-fill mode */
56 void
57 r_nf(int argc, Rune **argv)
58 {
59         USED(argc);
60         USED(argv);
61         nr(L(".fi"), 0);
62 }
63
64 /* adjust */
65 void
66 r_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 */
104 void
105 r_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 */
114 void
115 r_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
124 void
125 t4init(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