1 .\" -*- mode: nroff -*-
6 This file is part of groff, the GNU roff type-setting system.
8 Copyright (C) 2010-2014 Free Software Foundation, Inc.
9 written by Joachim Walsdorff <Joachim.Walsdorff@urz.uni-heidelberg.de>.
11 groff is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 groff is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 .mso hdtbl.tmac\" load table macros
29 .\" ******************************************************************
30 .\" ** Some macros and the page setup used by the examples **
31 .\" ******************************************************************
33 .\" ******************************************************************
34 .\" ** some of the following macros use system commands **
35 .\" ** and are therefore `unsafe': they need the `-U' argument **
36 .\" ** when calling groff/troff **
37 .\" ******************************************************************
39 .\" ******************************************************************
40 .\" ** Header macro for the examples **
41 .\" ******************************************************************
43 . nr *w* (17 * \w
\a\\$*
\a / 10 + 4n)
53 "width=(\\n[*w*]+4n)<?\n[.l]"
61 .\" ******************************************************************
62 .\" ** Utility macro for the date, requires UNIX date. **
63 .\" ** after return string *date contains the date in the **
64 .\" ** standard form of the Unix date-command, **
65 .\" ** for example "Sun Dec 5 22:27:57 2004" **
66 .\" ******************************************************************
68 . pso sh -c "echo -n .ds *date\ ;date"
73 .\" ******************************************************************
74 .\" ** Utility macro for time measurement, requires UNIX date **
75 .\" ** .time s[tart]|[end] **
76 .\" ** .time start: **
77 .\" ** reg *time gets the start-time (seconds) **
78 .\" ** .time [end]: **
79 .\" ** reg *time gets the difference of the **
80 .\" ** end- and start-time (seconds) **
81 .\" ******************************************************************
86 . pso sh -c "echo -n .nr *time 0+;date +%s"
88 . pso sh -c "echo -n .nr *time -;date +%s"
89 . nr *time 0-\\n[*time]
90 . tm elapsed time: \\n[*time] seconds
95 .\" ******************************************************************
96 .\" ** Perform n-times all the arbitrary arguments **
97 .\" ** .PN n a2 a3 ... **
98 .\" ** PN is nestable **
99 .\" ******************************************************************
102 . nr PN\\n[*pn] (\\$1 + 1) 1
105 . while \\n-[PN\\n[*pn]] \
112 .\" Utility macro: .d2x decimal_number [base [string_name]]
114 .\" Convert `decimal_number' to another base `base' (in the
115 .\" range 1..16) and store the result in string `string_name'.
116 .\" If `base' is missing or empty, convert to a hexadecimal
117 .\" number. If `string_name' is missing or empty, return value
118 .\" in string `hex#', otherwise return the value in both
119 .\" `string_name' and `hex#'.
121 .\" The base value 1 is handled specially: The returned
122 .\" string contains the character `|' `decimal_number' times
123 .\" (for example, input value 4 yields `||||').
144 . tm \\n[.F]:\\n[.c]: invalid or missing first argument
145 . tm1 " usage: `.d2x decimal_number [base [string_name]]'
155 . nr dec# (-\\n[dec#])
159 . tm \\n[.F]:\\n[.c]: invalid base `\\$2'
161 . ie ((\\$2 < 1) : (\\$2 > 16)) \
162 . tm \\n[.F]:\\n[.c]: invalid base `\\$2'
171 . ie (\\n[b#] == 1) \{\
177 . while (\\n[dec#] - \\n[xb#]) \{\
178 . nr xb# (\\n[xb#] * \\n[b#])
182 . while (\\n+[i#] < \\n[j#]) \{\
183 . nr ** (\\n[dec#] / \\n[xb#])
184 . as hex# \\*[d2x-\\n[**]]\"
185 . nr dec# (\\n[dec#] - (\\n[xb#] * \\n[**]))
186 . nr xb# (\\n[xb#] / \\n[b#])
190 . \" strip leading zero, if any
194 . substring hex# 1 -1
197 . ds hex# -\\*[hex#]\"
201 . tm \\n[.F]:\\n[.c]: invalid string name `\\$3'
203 . ds \\$3 \\*[hex#]\"
208 .\" Utility macro: .random#
209 .\" .random-seed seed1 seed2
211 .\" Return pseudo-random numbers in the range 0..0xFFFFFF,
212 .\" represented as the concatenation of `#' and six
213 .\" hexadecimal digits, in the string `#random'. The
214 .\" macro `random-seed' can be used to set seed values,
215 .\" which should be integers in the range 1..2147483562 and
216 .\" 1..2147483398 for `seed1' and `seed2', respectively
217 .\" (the macro applies a modulo operation to assure this
218 .\" range). If `random-seed' isn't called the registers
219 .\" `seconds', `minutes', `hours', `dy', `mo', `year', and
220 .\" `$$' are used to compute it.
222 .\" The used generator is presented in L'Ecuyer's 1988 paper
223 .\" `Efficient and Portable Combined Random Number
224 .\" Generators', which combines two Multiplicative Linear
225 .\" Congruential Generators (MLCGs) to achieve a period of
234 .ds random-s1 \n[minutes]\n[seconds]\n[$$]\n[hours]\"
236 .substring random-s1 0 8
238 .nr random-s1 (\*[random-s1] % 2147483562)
239 .nr random-s2 \n[dy]\n[year]\n[mo]
243 . if !(\\n[.$] == 2) \{\
244 . tm1 "random-seed: Invalid number of arguments.
245 . tm1 " usage: `.random-seed seed1 seed2'
249 . nr random-s1 (\\$1 % 2147483562)
250 . nr random-s2 (\\$2 % 2147483398)
255 . nr * (\\n[random-s1] / 53668)
256 . nr random-s1 (40014 * (\\n[random-s1] - (\\n[*] * 53668)) \
258 . if !\\n[random-s1] \
259 . nr random-s1 +2147483563
261 . nr * (\\n[random-s2] / 52774)
262 . nr random-s2 (40692 * (\\n[random-s2] - (\\n[*] * 52774)) \
264 . if !\\n[random-s2] \
265 . nr random-s2 +2147483399
267 . nr * (\\n[random-s1] - \\n[random-s2])
271 . \" reduce the result to the leftmost 24 bits
272 . nr * (\\n[*] / 128)
275 . ds hex# 000000\\*[hex#]\"
277 . ds #random #\\*[hex#]\"
281 .\" ******************************************************************
282 .\" ** minimal Page setup **
283 .\" ******************************************************************
290 .nr l 6.6i \" set text width
292 .nr o 2c \" set offset
294 .nr p 29.7c \" set paper length (A4)
296 .nr tH 1i \" set top margin
299 .ds t*HM //arbitrary text for page header, except on the first page//\"
300 .ds t*BM //arbitrary text for page footer, except on the last page/\\n[%]/\"
308 . sp |.5i \" print header in top margin
317 . sp |(\\n[p]u - .5i) \" print footer in bottom margin
324 . rm BM \" no page number at bottom of last page
333 .\" Some packages (-mm) define their own .SP macro.
334 .\" Use ours if another one isn't already available.
335 .if !d SP .als SP t*SP