| | @@ -19,7 +19,7 @@ |
| 19 | 19 | module Doc; |
| 20 | 20 | import Out, Rt, Str, Buf, Heap, Scan, Files; |
| 21 | 21 | |
| 22 | | -const Date = "October 12, 2026"; (* raz-lib(3)'s, when the library last changed *) |
| 22 | +const Date = "October 14, 2026"; (* raz-lib(3)'s, when the library last changed *) |
| 23 | 23 | |
| 24 | 24 | var |
| 25 | 25 | sc: Scan.Scanner; (* the text being read, at the current symbol *) |
| | @@ -144,9 +144,24 @@ |
| 144 | 144 | emit(10); |
| 145 | 145 | end; |
| 146 | 146 | |
| 147 | +(* Whether the space at src[p] ends a sentence: a full stop, ? or ! |
| 148 | + comes before it, maybe behind closing brackets or quotes. mdoc wants |
| 149 | + each sentence on a line of its own, so that roff knows where one |
| 150 | + ends and spaces it so. *) |
| 151 | +proc sentenceEnds(start, p: INT): BOOL; |
| 152 | +begin |
| 153 | + DEC(p); |
| 154 | + while (p > start) and ((src[p] = ')') or (src[p] = ']') or (src[p] = '"') or (src[p] = '\'')) do |
| 155 | + DEC(p); |
| 156 | + end; |
| 157 | + return (p >= start) and ((src[p] = '.') or (src[p] = '?') or (src[p] = '!')); |
| 158 | +end; |
| 159 | + |
| 147 | 160 | (* The comment from start to stop, without its brackets, each line |
| 148 | | - indented by four; in mdoc, filled, but for the lines indented past |
| 149 | | - its own, which are code, kept as they are. *) |
| 161 | + indented by four; in mdoc, filled, each sentence starting a line, |
| 162 | + but for the lines indented past its own, which are code, kept as |
| 163 | + they are in a literal display. mdoc's displays don't nest, so the |
| 164 | + filled one ends where the code starts and starts again after. *) |
| 150 | 165 | proc comment(start, stop: INT); |
| 151 | 166 | var i, j, k, m, n, deep, indent: INT; |
| 152 | 167 | begin |
| | @@ -164,23 +179,35 @@ |
| 164 | 179 | n := 0; |
| 165 | 180 | while (i + n < k) and (src[i + n] = ' ') do INC(n); end; |
| 166 | 181 | if man and (n > deep) and (indent < 0) then |
| 182 | + control(".Ed"); |
| 167 | 183 | control(".Bd -literal -offset indent -compact"); |
| 168 | 184 | indent := n; |
| 169 | 185 | elsif man and (n <= deep) and (indent >= 0) then |
| 170 | 186 | control(".Ed"); |
| 187 | + control(".Bd -filled -offset indent -compact"); |
| 171 | 188 | indent := -1; |
| 172 | 189 | end; |
| 173 | 190 | if man and (n = k - i) and (indent < 0) then control(".Pp"); |
| 191 | + elsif man and (indent < 0) then |
| 192 | + m := i + n; |
| 193 | + while m < k do |
| 194 | + if (src[m] = ' ') and sentenceEnds(i + n, m) then |
| 195 | + emit(10); |
| 196 | + while (m + 1 < k) and (src[m + 1] = ' ') do INC(m); end; |
| 197 | + else emit(src[m]); |
| 198 | + end; |
| 199 | + INC(m); |
| 200 | + end; |
| 201 | + emit(10); |
| 174 | 202 | else |
| 175 | 203 | if not man then Out.str(" "); |
| 176 | | - elsif (indent >= 0) and (n > indent) then n := indent; |
| 204 | + elsif n > indent then n := indent; |
| 177 | 205 | end; |
| 178 | 206 | for m := i + n to k - 1 do emit(src[m]); end; |
| 179 | 207 | emit(10); |
| 180 | 208 | end; |
| 181 | 209 | i := k + 1; |
| 182 | 210 | end; |
| 183 | | - if indent >= 0 then control(".Ed"); end; |
| 184 | 211 | if man then control(".Ed"); end; |
| 185 | 212 | end; |
| 186 | 213 | |