| 1 |
.ig |
| 2 |
Copyright 2006 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
Written by Joachim Walsdorff <[email protected]> |
| 5 |
|
| 6 |
This file is part of hdtbl. |
| 7 |
|
| 8 |
hdtbl is distributed with groff, the GNU roff typesetting system. |
| 9 |
|
| 10 |
groff is free software; you can redistribute it and/or modify it under |
| 11 |
the terms of the GNU General Public License as published by the Free |
| 12 |
Software Foundation, either version 3 of the License, or |
| 13 |
(at your option) any later version. |
| 14 |
|
| 15 |
groff is distributed in the hope that it will be useful, but WITHOUT |
| 16 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 18 |
for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 |
.. |
| 23 |
. |
| 24 |
. |
| 25 |
.ds common common.roff\" name for diagnostic messages |
| 26 |
.mso hdtbl.tmac\" load table macros |
| 27 |
. |
| 28 |
.\" ****************************************************************** |
| 29 |
.\" ** Some macros and the page setup used by the examples ** |
| 30 |
.\" ****************************************************************** |
| 31 |
. |
| 32 |
.\" ****************************************************************** |
| 33 |
.\" ** Header macro for the examples ** |
| 34 |
.\" ****************************************************************** |
| 35 |
.de H |
| 36 |
. nr *w* (17 * \w\\$* / 10 + 4n) |
| 37 |
. TBL border=1n \ |
| 38 |
bc=yellow \ |
| 39 |
bgc=red4 \ |
| 40 |
fgc=yellow \ |
| 41 |
csp=0 \ |
| 42 |
fst=TB \ |
| 43 |
"fsz=1.7 1.5" \ |
| 44 |
hal=c \ |
| 45 |
tal=c \ |
| 46 |
"width=(\\n[*w*]+4n)<?\n[.l]" |
| 47 |
. TR .TD |
| 48 |
. t*P1 \\$* |
| 49 |
. ETB |
| 50 |
. SP |
| 51 |
.. |
| 52 |
. |
| 53 |
. |
| 54 |
.\" ****************************************************************** |
| 55 |
.\" ** Perform n-times all the arbitrary arguments ** |
| 56 |
.\" ** .PN n a2 a3 ... ** |
| 57 |
.\" ** PN is nestable ** |
| 58 |
.\" ****************************************************************** |
| 59 |
.de PN |
| 60 |
. nr *pn +1 |
| 61 |
. nr PN\\n[*pn] (\\$1 + 1) 1 |
| 62 |
. shift |
| 63 |
. |
| 64 |
. while \\n-[PN\\n[*pn]] \ |
| 65 |
. t*P1 \\$@ |
| 66 |
. |
| 67 |
. nr *pn -1 |
| 68 |
.. |
| 69 |
. |
| 70 |
. |
| 71 |
.\" Utility macro: .d2x decimal_number [base [string_name]] |
| 72 |
.\" |
| 73 |
.\" Convert 'decimal_number' to another base 'base' (in the |
| 74 |
.\" range 1..16) and store the result in string 'string_name'. |
| 75 |
.\" If 'base' is missing or empty, convert to a hexadecimal |
| 76 |
.\" number. If 'string_name' is missing or empty, return value |
| 77 |
.\" in string 'hex#', otherwise return the value in both |
| 78 |
.\" 'string_name' and 'hex#'. |
| 79 |
.\" |
| 80 |
.\" The base value 1 is handled specially: The returned |
| 81 |
.\" string contains the character '|' 'decimal_number' times |
| 82 |
.\" (for example, input value 4 yields '||||'). |
| 83 |
.ds d2x-0 0\" |
| 84 |
.ds d2x-1 1\" |
| 85 |
.ds d2x-2 2\" |
| 86 |
.ds d2x-3 3\" |
| 87 |
.ds d2x-4 4\" |
| 88 |
.ds d2x-5 5\" |
| 89 |
.ds d2x-6 6\" |
| 90 |
.ds d2x-7 7\" |
| 91 |
.ds d2x-8 8\" |
| 92 |
.ds d2x-9 9\" |
| 93 |
.ds d2x-10 A\" |
| 94 |
.ds d2x-11 B\" |
| 95 |
.ds d2x-12 C\" |
| 96 |
.ds d2x-13 D\" |
| 97 |
.ds d2x-14 E\" |
| 98 |
.ds d2x-15 F\" |
| 99 |
. |
| 100 |
. |
| 101 |
.de d2x |
| 102 |
. if !\B\\$1 \{\ |
| 103 |
. tmc \\*[common]: \\n[.F]:\\n[.c]: d2x: invalid or missing first |
| 104 |
. tm argument |
| 105 |
. tm \\*[common]: usage: '.d2x decimal_number [base [string_name]]' |
| 106 |
. return |
| 107 |
. \} |
| 108 |
. |
| 109 |
. nr i# (-1) 1 |
| 110 |
. nr j# 1 |
| 111 |
. ds hex# |
| 112 |
. nr dec# (\\$1) 1 |
| 113 |
. |
| 114 |
. if !\\$1 \ |
| 115 |
. nr dec# (-\\n[dec#]) |
| 116 |
. |
| 117 |
. ie !"\\$2"" \{\ |
| 118 |
. ie !\B\\$2 \ |
| 119 |
. tm \\*[common]: \\n[.F]:\\n[.c]: d2x: invalid base '\\$2' |
| 120 |
. el \ |
| 121 |
. ie ((\\$2 < 1) : (\\$2 > 16)) \ |
| 122 |
. tm \\*[common]: \\n[.F]:\\n[.c]: d2x: invalid base '\\$2' |
| 123 |
. el \ |
| 124 |
. nr b# \\$2 |
| 125 |
. \}\} |
| 126 |
. el \ |
| 127 |
. nr b# 16 |
| 128 |
. |
| 129 |
. nr xb# 1 |
| 130 |
. |
| 131 |
. ie (\\n[b#] == 1) \{\ |
| 132 |
. nr dec# +1 |
| 133 |
. while \\n-[dec#] \ |
| 134 |
. as hex# |\" |
| 135 |
. \} |
| 136 |
. el \{\ |
| 137 |
. while (\\n[dec#] - \\n[xb#]) \{\ |
| 138 |
. nr xb# (\\n[xb#] * \\n[b#]) |
| 139 |
. nr j# +1 |
| 140 |
. \} |
| 141 |
. |
| 142 |
. while (\\n+[i#] < \\n[j#]) \{\ |
| 143 |
. nr ** (\\n[dec#] / \\n[xb#]) |
| 144 |
. as hex# \\*[d2x-\\n[**]]\" |
| 145 |
. nr dec# (\\n[dec#] - (\\n[xb#] * \\n[**])) |
| 146 |
. nr xb# (\\n[xb#] / \\n[b#]) |
| 147 |
. \} |
| 148 |
. \} |
| 149 |
. |
| 150 |
. \" strip leading zero, if any |
| 151 |
. ds * \\*[hex#]\" |
| 152 |
. substring * 0 0 |
| 153 |
. length len# \\*[hex#] |
| 154 |
. if \\n[len#]>1 .if "\\*[*]"0" \ |
| 155 |
. substring hex# 1 -1 |
| 156 |
. rr len# |
| 157 |
. |
| 158 |
. if (\\$1 < 0) \ |
| 159 |
. ds hex# -\\*[hex#]\" |
| 160 |
. |
| 161 |
. if !"\\$3"" \{\ |
| 162 |
. ie !\A\\$3 \ |
| 163 |
. tm \\*[common]: \\n[.F]:\\n[.c]: d2x: invalid string name '\\$3' |
| 164 |
. el \ |
| 165 |
. ds \\$3 \\*[hex#]\" |
| 166 |
. \} |
| 167 |
.. |
| 168 |
. |
| 169 |
. |
| 170 |
.\" Utility macro: .random# |
| 171 |
.\" .random-seed seed1 seed2 |
| 172 |
.\" |
| 173 |
.\" Return pseudo-random numbers in the range 0..0xFFFFFF, |
| 174 |
.\" represented as the concatenation of '#' and six |
| 175 |
.\" hexadecimal digits, in the string '#random'. The |
| 176 |
.\" macro 'random-seed' can be used to set seed values, |
| 177 |
.\" which should be integers in the range 1..2147483562 and |
| 178 |
.\" 1..2147483398 for 'seed1' and 'seed2', respectively |
| 179 |
.\" (the macro applies a modulo operation to assure this |
| 180 |
.\" range). If 'random-seed' isn't called the registers |
| 181 |
.\" start at some constant, arbitrary values. |
| 182 |
.\" |
| 183 |
.\" The used generator is presented in L'Ecuyer's 1988 paper |
| 184 |
.\" 'Efficient and Portable Combined Random Number |
| 185 |
.\" Generators', which combines two Multiplicative Linear |
| 186 |
.\" Congruential Generators (MLCGs) to achieve a period of |
| 187 |
.\" 2.3*10^18. |
| 188 |
.\" |
| 189 |
.\" Since this just generates example output, |
| 190 |
.\" we don't need good randomness. |
| 191 |
. |
| 192 |
.de random-seed |
| 193 |
. if !(\\n[.$] == 2) \{\ |
| 194 |
. tm \\*[common]: random-seed: Invalid number of arguments. |
| 195 |
. tm \\*[common]: usage: '.random-seed seed1 seed2' |
| 196 |
. return |
| 197 |
. \} |
| 198 |
. |
| 199 |
. nr random-s1 (\\$1 % 2147483562) |
| 200 |
. nr random-s2 (\\$2 % 2147483398) |
| 201 |
.. |
| 202 |
.random-seed 131545532 19201711 |
| 203 |
. |
| 204 |
. |
| 205 |
.de random# |
| 206 |
. nr * (\\n[random-s1] / 53668) |
| 207 |
. nr random-s1 (40014 * (\\n[random-s1] - (\\n[*] * 53668)) \ |
| 208 |
- (\\n[*] * 12211)) |
| 209 |
. if !\\n[random-s1] \ |
| 210 |
. nr random-s1 +2147483563 |
| 211 |
. |
| 212 |
. nr * (\\n[random-s2] / 52774) |
| 213 |
. nr random-s2 (40692 * (\\n[random-s2] - (\\n[*] * 52774)) \ |
| 214 |
- (\\n[*] * 3791)) |
| 215 |
. if !\\n[random-s2] \ |
| 216 |
. nr random-s2 +2147483399 |
| 217 |
. |
| 218 |
. nr * (\\n[random-s1] - \\n[random-s2]) |
| 219 |
. if (\\n[*] < 1) \ |
| 220 |
. nr * +2147483562 |
| 221 |
. |
| 222 |
. \" reduce the result to the leftmost 24 bits |
| 223 |
. nr * (\\n[*] / 128) |
| 224 |
. |
| 225 |
. d2x \\n[*] |
| 226 |
. ds hex# 000000\\*[hex#]\" |
| 227 |
. substring hex# -6 |
| 228 |
. ds #random #\\*[hex#]\" |
| 229 |
.. |
| 230 |
. |
| 231 |
. |
| 232 |
.\" ****************************************************************** |
| 233 |
.\" ** minimal Page setup ** |
| 234 |
.\" ****************************************************************** |
| 235 |
. |
| 236 |
.nr s \n[.ps] |
| 237 |
.nr v \n[.v] |
| 238 |
.nr p \n[.p] |
| 239 |
.nr o \n[.o] |
| 240 |
.nr l 6.6i \" set text width |
| 241 |
.ll \n[t*l]u |
| 242 |
.nr o 2c \" set offset |
| 243 |
.po \n[o]u |
| 244 |
.nr p 29.7c \" set paper length (A4) |
| 245 |
.pl \n[p]u |
| 246 |
.nr tH 1i \" set top margin |
| 247 |
.sp |\n[tH]u |
| 248 |
. |
| 249 |
.ds t*HM //arbitrary text for page header, except on the first page//\" |
| 250 |
.ds t*BM //arbitrary text for page footer, except on the last page/\\n[%]/\" |
| 251 |
. |
| 252 |
.ev 99 |
| 253 |
.lt \n[t*l]u |
| 254 |
.ev |
| 255 |
. |
| 256 |
. |
| 257 |
.de HM |
| 258 |
. sp |.5i \" print header in top margin |
| 259 |
. tl \\*[t*HM] |
| 260 |
. sp |\\n[tH]u |
| 261 |
. ev |
| 262 |
.. |
| 263 |
. |
| 264 |
. |
| 265 |
.de BM |
| 266 |
. ev 99 |
| 267 |
. sp |(\\n[p]u - .5i) \" print footer in bottom margin |
| 268 |
. tl \\*[t*BM] |
| 269 |
. bp |
| 270 |
.. |
| 271 |
. |
| 272 |
. |
| 273 |
.de EM |
| 274 |
. rm BM \" no page number at bottom of last page |
| 275 |
. t*EM |
| 276 |
.. |
| 277 |
. |
| 278 |
. |
| 279 |
.wh 0 HM |
| 280 |
.wh 0-1.5i BM |
| 281 |
.em EM |
| 282 |
. |
| 283 |
.\" Some packages (-mm) define their own .SP macro. |
| 284 |
.\" Use ours if another one isn't already available. |
| 285 |
.if !d SP .als SP t*SP |
| 286 |
. |
| 287 |
.if "\n[.m]"" \ |
| 288 |
. gcolor black |
| 289 |
.if "\n[.M]"" \ |
| 290 |
. fcolor white |
| 291 |
. |
| 292 |
.\" Local Variables: |
| 293 |
.\" mode: nroff |
| 294 |
.\" fill-column: 72 |
| 295 |
.\" End: |
| 296 |
.\" vim: set filetype=groff textwidth=72: |