summaryrefslogtreecommitdiff
path: root/contrib/hdtbl/hdtbl.tmac
blob: 60293c21c1ba69a74ececcf2f0ff6590e8f4ae04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
.\"	-*- roff -*-
.ig

hdtbl.tmac

This file is part of groff, the GNU roff type-setting system.

Copyright (C) 2005, 2006 Free Software Foundation, Inc.
written by Joachim Walsdorff <Joachim.Walsdorff@urz.uni-heidelberg.de>.

groff is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.

groff is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with groff; see the file COPYING.  If not, write to the Free
Software Foundation, 51 Franklin St - Fifth Floor, Boston, MA
02110-1301, USA.

..
.
.
.\"	*****************************************************************
.\"	*		hdtbl - Heidelberger table macros		*
.\"	*			Vers. 0.91 December 2005		*
.\"	*****************************************************************
.
.if (\n[?] == 1) \
.  tm HDroff: Loading table macros file \n[.F].
.
.nr *hdtbl 1
.
.if !\n[*miscs] \
.  mso hdmisc.tmac
.
.wh 0 HM	\"	comment this, if a page header macro exists
.wh -1i BM	\"	comment this, if a bottom margin macro exists
.
.\" replace `HM' with the name of your pageheader macro, e.g., `pg@top' for MS
.am HM
.  t*hm
..
.
.
.\"	*****************************************************************
.\"	*		default values for some arguments		*
.\"	*****************************************************************
.
.ds t*hl s\"
.ds t*vl s\"
.ds t*tal l\"
.ds t*hal b\"
.ds t*val t\"
.ds t*ff \\n[.fam]\"
.ds t*fst \\n[.f]\"
.ds t*fsz 1 1\"
.ds t*fgc red4\"
.ds t*bgc bisque\"
.ds t*bc red4\"
.nr t*cpd .5n
.nr t*csp .5n
.nr t*b .1n
.nr t*cols 1
.
.
.\"			defaults for table captions
.nr t*cptn 0 1
.ds t*cptn "".sp .4" \
            ".pv 1.4 1.4" \
            ".ad l" \
            "\m[\\*[t*fgc]]Table \\n+[t*cptn]:\0\c\k*"\"
.
.
.\"			Running title, running footer
.ds t*HM //arbitrary text for pageheader, except on the first page//\"
.ds t*BM //arbitrary text for pagefooter, except on the last page/\\n[%]/\"
.
.
.\" %beginstrip%
.
.\" for better error messages
.ds nth-1 st
.ds nth-2 nd
.ds nth-3 rd
.
.nr t*numb 0 1	\"	held table diversion #
.
.
.\"	*****************************************************************
.\"	*	The four base macros and the two optional macros	*
.\"	*****************************************************************
.
.\"	TBL:	table start
.\"		predecessor: 	text, TD or ETB
.\"		successor:	CPTN or TR
.de TBL
.  ds t*m\\n[t*#] \\n[.m]\"
.  ie \\n[t*#] \
.    br
.  el \{\
.    ds * \\n[.ev]\"
.    ev t*tbl
.    evc \\*[*]
.    di t*tbl0
.    sp .4
.    nr t*i \\n[.i]
.    ll -\\n[.i]u
.    in 0
.  \}
.  nr t*# +1
.
.  ds width
.  nr t*height\\n[t*#] 0
.
.  getarg cols \\$@\"	from here string `args' contains the rest of \\$@
.  ie "\\*[cols]"" \
.    nr t*cols\\n[t*#] \\n[t*cols]
.  el \
.    nr t*cols\\n[t*#] \\*[cols]
.
.  getarg cpd \\*[args]               \"	cellpadding
.  ie "\\*[cpd]"" \
.    nr t*cpd\\n[t*#] \\n[t*cpd]
.  el \
.    nr t*cpd\\n[t*#] \\*[cpd]
.
.  getarg csp \\*[args]               \"	cellspacing
.  ie "\\*[csp]"" \
.    nr t*csp\\n[t*#] \\n[t*csp]
.  el \
.    nr t*csp\\n[t*#] \\*[csp]
.
.  getarg border \\*[args]            \"	border
.  ie "\\*[border]"=" \
.    nr t*b\\n[t*#] 0-1
.  el \{\
.    ie "\\*[border]"" \
.      nr t*b\\n[t*#] \\n[t*b]
.    el \
.      nr t*b\\n[t*#] \\*[border]
.  \}
.
.  nr b/2\\n[t*#] (\\n[t*b\\n[t*#]] / 2)\"	shortcut
.
.  getarg bc \\*[args]                \"	border color
.  ds t*bc\\n[t*#] \\*[t*bc]\"
.  if !"\\*[bc]"" \{\
.    ie m\\*[bc] \
.      ds t*bc\\n[t*#] \\*[bc]\"
.    el \{\
.      ie "\\*[bc]"=" \
.        ds t*bc\\n[t*#] =\"
.      el \
.        tm \\n[.F]:\\n[.c]: Invalid border color `\\*[bc]'.
.  \}\}
.  ie "\\*[bc]"=" \
.    ds t*bc\\n[t*#]
.  el \{\
.    ie "\\*[bc]"" \
.      ds t*bc\\n[t*#] \\*[t*bc]\"
.    el \
.      ds t*bc\\n[t*#] \\*[bc]\"
.  \}
.
.  getarg width \\*[args]             \"	table/col widths
.  if "\\*[width]"=" \
.    ds width
.
.  nr cscp\\n[t*#] (\\n[t*csp\\n[t*#]] + \\n[t*cpd\\n[t*#]])\"  aux. register
.
.  getarg height \\*[args]            \"	table outline height
.  if !"\\*[height]"" \
.    nr t*height\\n[t*#] (\\*[height] - \
                          ((2 * \\n[cscp\\n[t*#]]) + (3 * \\n[b/2\\n[t*#]])))
.  t*cl \\*[width]                    \"	calculate cellwidths and indents
.  t*args \\n[t*#]                    \"	look for common arguments
.
.  getarg tal \\*[args]               \"	table horizontal alignment
.  if "\\*[tal]"" \
.    ds tal \\*[t*tal]\"
.  ie "\\*[tal]"l" \
.    nr in\\n[t*#] \\n[.i]
.  el \{\
.    ie "\\*[tal]"c" \
.      nr in\\n[t*#] \\n[.l]-\\n[ll\\n[t*#]]/2+\\n[.i]
.    el \{\
.      ie "\\*[tal]"r" \
.        nr in\\n[t*#] \\n[.l]-\\n[ll\\n[t*#]]+\\n[.i]
.      el \{\
.        tmc \\n[.F]:\\n[.c]: Invalid `tal' value `\\*[tal]':
.        tm1 " must be `l', `c' or `r'.
.  \}\}\}
.
.  nr t*r#\\n[t*#] 0 1		      \"	rowindex in TBL
.  mk toptbl\\n[t*#]
.
.  P1 \\*[args]
.\" \\..                              \"	XXX
..
.
.
.\"	CPTN:	optional table caption
.\"		predecessor:	TBL
.\"		successor:	TR
.de CPTN
.  ft 1
.
.  if "\\$0"CPTN" \
.    if \\n[t*r#\\n[t*#]] \{\
.      tmc \\n[.F]:\\n[.c]: Invalid placement of `.CPTN';
.      tm1 " must be called immediately after `.TBL'.
.      return
.    \}
.
.  getarg val \\$@
.  ds args\\n[t*#] "\\*[args]\"
.
.  index "\\*[args]" .TR
.  ie \\n[index] \{\
.    ds *a\\n[t*#] "\\*[args]
.    substring args\\n[t*#] 0 \\n[index]
.    substring *a\\n[t*#] \\n[index]-2 -1
.  \}
.  el \
.    ds *a\\n[t*#]
.
.  ie "\\*[val]"b" \{\
.    de t*cptn\\n[t*#]
.      *CPTN \\*[args\\n[t*#]]
.      rm t*cptn\\n[t*#]
\\..
.  \}
.  el \{\
.    ll (\\n[ll\\n[t*#]]u + \\n[in\\n[t*#]]u)
.    in \\n[in\\n[t*#]]u
.    P1 \\*[t*cptn]
'    in +\\n[*]u
.    P1 \\*[args\\n[t*#]]
.    pv 1 1
.    in
.    mk toptbl\\n[t*#]
.  \}
.
.  P1 \\*[*a\\n[t*#]]
..
.
.als *CPTN CPTN
.
.
.\"	TR:	table row
.\"		predecessor:	TBL, CPTN, text, TD or ETB
.\"		successor:	TD
.de TR
.  ft 1
.  if !\\n[t*#] \
.    tm \\n[.F]:\\n[.c]: Table row (.TR) without preceding table start (.TBL).
.
.  if \\n[t*r#\\n[t*#]] \
.    t*dntr 1 \\n[c#\\*[#t#r]] \\n[t*cols\\n[t*#]] \\*[*#trc*]
.
.  nr t*r#\\n[t*#] +1			\"	row# of this table
.  ds #t#r \\n[t*#]*\\n[t*r#\\n[t*#]]\"
.  nr c#\\*[#t#r] 0 1			\"	clear cellcounter
.  nr dntr\\*[#t#r] 0 1			\"	clear accumulated row height1
.
.  getarg height \\$@
.  ie "\\*[height]"" \
.    nr t*height\\*[#t#r] 0
.  el \
.    nr t*height\\*[#t#r] \\*[height]
.
.  \"	If there is a TR with height `height', the total height of the table
.  \"	is too high by 3/2 b, independent of the numer of TR with `height'.
.  t*args \\*[#t#r] \\n[t*#]
.
.  P1 \\*[args]
..
.
.
.\"	TH:	optional table header cell
.\"		predecessor:	text, TD or TR
.\"		successor:	text, TD, TR, TBL or ETB
.\"								
.\"		cell content bolded and horizontally and vertically centered,
.\"		else like .TD
.de TH
.  ft 1
.  TD val=m hal=c fst=B \\$@
..
.
.
.\"	TD:	table data cell
.\"		predecessor:	text, TD or TR
.\"		successor:	text, TD, TR, TBL or ETB
.de TD
.  ft 1
.  t*dntr 0 \\n[c#\\*[#t#r]]-1 \\\\n[c#\\*[#t#r]] \\*[*#trc*]\"	four backslashes!
.
.  ds *#trc* \\*[#t#r]*\\n[c#\\*[#t#r]]\"
.
.  getarg rowspan \\$@
.  nr rowspan (\\*[rowspan] >? 1)
.
.  getarg colspan \\*[args]
.  nr colspan (\\*[colspan] >? 1)
.
.  t*args \\*[#trc] \\*[#t#r]     \"  look for common arguments
.
.  nr in\\*[#trc] \\n[in\\n[t*#]*\\n[c#\\*[#t#r]]]
.  nr *cl \\n[cll\\n[t*#]*\\n[c#\\*[#t#r]]]
.  nr * 0 1
.  nr *r \\n[t*r#\\n[t*#]]
.
.  while ((\\n[rowspan] - 1) & (\\n+[*] <= \\n[rowspan])) \{\
.    nr rsp\\n[t*#]*\\n[*r]*\\n[c#\\*[#t#r]] \\n[colspan]
.    if (\\n[*] > 1) \
.      nr csp\\n[t*#]*\\n[*r]*\\n[c#\\*[#t#r]] \\n[colspan]
.    nr *r +1
.  \}
.
.  nr * 1 1
.  nr *c \\n[c#\\*[#t#r]]
.
.  if (\\n[colspan] - 1) \{\
.    nr vl\\*[*#trc*] 0-1	\"	no vl flag
.
.    while (\\n+[*] <= \\n[colspan]) \{\
.      nr *c +1
.      nr *cl +(2 * \\n[cscp\\n[t*#]] \
                + \\n[b/2\\n[t*#]] \
                + \\n[cll\\n[t*#]*\\n[*c]])
.      nr c#\\*[#t#r] +1
.    \}
.  \}
.
.  if (\\n[c#\\n[t*#]*\\n[t*r#\\n[t*#]]] > \\n[t*cols\\n[t*#]]) \{\
.    ds * are
.    ds ** columns
.    if (\\n[c#\\*[#t#r]] == 1) \{\
.      ds * is
.      ds ** column
.    \}
.    tmc \\n[.F]:\\n[.c]: There \\*[*] \\n[c#\\*[#t#r]] table \\*[**] (.TD)
.
.    ds * are
.    if (\\n[t*cols\\n[t*#]] == 1) \
.      ds * is
.    tm1 " but only \\n[t*cols\\n[t*#]] \\*[*] expected.
.
.    ds *
.    length * \\n[.F]:\\n[.c]:
.
.    while \\n-[*] \
.      ds * " \\*[*]\"
.
.    tm1 "\\*[*] Remaining .TDs and its contents are ignored.
.
.    di *t*dummy*                \"	bypass superfluous input
.    return
.  \}
.
.  di t*\\*[#trc]                \"	open cell diversion and set locals
.  in 0
.  nr cll\\*[#trc] \\n[*cl]
.  ll \\n[*cl]u
.  nr *cl\\n[t*#] \\n[.l]
.  gcolor \\*[t*fgc\\*[#trc]]
.  ad \\*[t*hal\\*[#trc]]
.  fam \\*[t*ff\\*[#trc]]
.  ft \\*[t*fst\\*[#trc]]
.  pv \\*[t*fsz\\*[#trc]]
.
.  P1 \\*[args]
..
.
.
.\"	ETB:	end of table
.\"		predecessor:	text, TD or ETB
.\"		successor:	text, TD, TR or TBL
.de ETB
.  ie \\n[t*#] \
.    if !\\n[t*r#\\n[t*#]] \{\
.      tmc \\n[.F]:\\n[.c]: Each table (.TBL)
.      tm1 " should contain at least one table row (.TR)!
.    \}
.  el \{\
.    tmc \\n[.F]:\\n[.c]: Table end (.ETB)
.    tm1 " without corresponding tablestart (.TBL)!
.  \}
.
.  ds #t#r \\n[t*#]*\\n[t*r#\\n[t*#]]\"	refresh #t#r
.  t*dntr 2 \\n[c#\\*[#t#r]] \\n[t*cols\\n[t*#]] \\*[*#trc*]
.
.  t*divs                        \"	print this table
.
.  sp \\n[b/2\\n[t*#]]u
.  t*cptn\\n[t*#]
.  nr t*# -1
.
.  ll \\n[*cl\\n[t*#]]u          \"	restore ll outside this table
.  in 0                          \"	reset indent
.  gcolor \\*[t*m\\n[t*#]]       \"	reset previous fgc
.
.  getarg hold \\$@
.  if !\\n[t*#] \{\
.    sp .5
.    di
.    in \\n[t*i]u
.    ie "\\*[hold]"" \{\
.      ie \\n[.t]-\\n[dn] \
.        DI t*tbl0
.      el \{\
.        rn t*tbl0 t*tbl\\n[t*numb]
.        ds t*kept \\*[t*kept] t*tbl\\n[t*numb] \\n[dn]\"
.      \}
.    \}
.    el \{\
.      rn t*tbl0 t*hold\\n+[t*numb]
.      tm \\n[.F]:\\n[.c]: Table t*hold\\n[t*numb] held.
.      ds t*held \\*[t*held] t*hold\\n[t*numb] \\n[dn]\"
.    \}
.
.    ev				\"	restore previous environment
.  \}
.
.  P1 \\*[args]
..
.
.
.\"	*****************************************************************
.\"	*	Following the definition of five utility macros		*
.\"	*	special to hdtbl.					*
.\"	*	Other utility macros common to hdtbl and hdgroff	*
.\"	*	are defined in the file hdmisc.tmac.			*
.\"	*****************************************************************
.
.
.\"	.t*free [n]
.\"		print the next [n] held table[s].
.\"             Don't call it within a table!
.\"		If the table is higher than the remaining space
.\"		on the page, the table is printed on the next page.
.de t*free
.  if "\\$0"CPTN" \
.    if \\n[t*r#\\n[t*#]] \{\
.      tmc \\n[.F]:\\n[.c]: Invalid placement of `.t*free' within a table;
.      tm1 " it must be called outside of any table.
.      return
.    \}
.
.  if "\\*[t*held]"" \{\
.    tm \\n[.F]:\\n[.c]: No held tables.
.    return
.  \}
.
.  nr ** (\\$1 >? 1)
.  while !""\\*[t*held]" \{\
.    pops * t*held
.    popr * t*held
.
.    ie (\\n[.t] - \\n[*]) \{\
.      ev t*tbl
.      DI \\*[*]
.      ev
.    \}
.    el \{\
.      rn \\*[*] t*tbl\\n+[t*numb]
.      ds t*kept \\*[t*kept] t*tbl\\n[t*numb] \\n[*]\"
.    \}
.
.    if !(\\n-[**] - 1) \
.      return
.  \}
..
.
.
.\"	The main utility macro for tables:
.\"		If a table is closed by ETB, this macro is called.  It
.\"		processes one complete table, i.e., all the table cell
.\"		diversions, paints the cell backgrounds, draws
.\"		horizontal and vertical table lines and the table border.
.\"
.\"		Nested tables are processed from inside to outside.
.
.de t*divs
.  ll (\\n[l]u + 1c)			\"	avoid warning `can't break line'
.  nf
.  nr #r 0 1
.
.  nr b/2 \\n[b/2\\n[t*#]]		\"	some abbrevs.
.  nr cscp \\n[cscp\\n[t*#]]
.  nr cscpb \\n[b/2]+\\n[cscp]
.
.  nr topdiv (\\n[.d] + \\n[b/2] - \\n[cscp]) \"	top of cell diversion
.  nr cscpb2 (\\n[b/2] / 2 + \\n[cscp])
.
.  \"	outer loop for rows
.  while (\\n+[#r] <= \\n[t*r#\\n[t*#]]) \{\
.    \"	insert code here for multipage tables
.    nr * (\\n[#r] - 1)
.    nr topdiv +(\\n[dntr\\n[t*#]*\\n[*]] + \\n[cscp] + \\n[cscpb])
.
.    \"	if table still lower than specified table height, increase it.
.    if ((\\n[#r] == \\n[t*r#\\n[t*#]]) & \\n[t*height\\n[t*#]]) \
.      nr dntr\\n[t*#]*\\n[#r] (\\n[cscpb] \
                                + \\n[toptbl\\n[t*#]] \
                                + \\n[t*height\\n[t*#]] \
                                - (\\n[topdiv] >? \\n[dntr\\n[t*#]*\\n[#r]]))
.
.    nr #c 0 1
.    \"	inner loop for cells
.    while (\\n+[#c] <= \\n[t*cols\\n[t*#]]) \{\
.      ds #trc \\n[t*#]*\\n[#r]*\\n[#c]\"
.      if !dt*\\*[#trc] \
.        continue
.
.      sp |\\n[topdiv]u
.      in (\\n[in\\n[t*#]]u + \\n[in\\*[#trc]]u)	\"	cell indent
.      nr $1 \\n[dntr\\n[t*#]*\\n[#r]]	\"	cell height
.
.      \" if spanned rows calculate resulting row height and lower hl position
.      nr * \\n[#r] 1
.      if \\n[rsp\\*[#trc]] \{\
.        nr rsp\\*[#trc] 0-1			\"	set no hl flag
.        nr corr (\\n[dn\\*[#trc]] - \\n[dntr\\n[t*#]*\\n[#r]])
.
.        while \\n[rsp\\n[t*#]*\\n+[*]*\\n[#c]] \{\
.          nr rsp\\n[t*#]*\\n[*]*\\n[#c] 0	\"	clear rsp's in following rows
.          nr ** (\\n[dntr\\n[t*#]*\\n[*]] + \\n[cscp] + \\n[cscpb])
.          nr corr -\\n[**]
.          nr $1 +\\n[**]
.        \}
.
.        if (\\n-[*] == \\n[t*r#\\n[t*#]]) \
.          nr $1 (\\n[t*height\\n[t*#]] \
                  - \\n[.d] \
                  + \\n[toptbl\\n[t*#]] \
                  + (\\n[cscpb] >? \\n[$1]))
.        nr dntr\\n[t*#]*\\n[*] +(\\n[corr] >? 0)
.      \}
.
.      \"	paint cell background
.      nr * (2 * \\n[t*cpd\\n[t*#]] + \\n[cll\\*[#trc]])	\"	backgrond width
.      nr $1 (\\n[$1] >? \\n[dn\\*[#trc]])	\"	cell height
.
.      if !"\\*[t*bgc\\*[#trc]]"=" \{\
.        nop \h'\\n[t*csp\\n[t*#]]u'\
\M[\\*[t*bgc\\*[#trc]]]\
\v'(-.67v - \\n[t*cpd\\n[t*#]]u)'\
\D'P \\n[*]u 0 \
     0 (2u * \\n[t*cpd\\n[t*#]]u + \\n[$1]u) \
     -\\n[*]u 0'\
\M[]
.        sp -1
.      \}
.
.      \"	***   horizontal and vertical single or double lines   ***
.      \"	double- and single lines have the same thickness;
.      \"	the double lines distance is the line thickness.
.      \"	border=n: horizontal/vertical lines n/2 thick, minimum .1n.
.      \"	border=0: no border; horizontal/vertical lines .1n thick.
.      \"	border= : neither border nor hl/vl's.
.
.      nr *t (.1n >? \\n[b/2])		\"	thickness of hl/vl minimum .1n
.      in +\\n[cscp]u
.
.      if (1 + \\n[t*b\\n[t*#]]) \{\
.        if !"\\*[t*bc\\n[t*#]]"=" \{\
.          \"       possibly hl/vl's:
.          \"	draw horizontal line between this and the following table cell
.          if (\\n[t*r#\\n[t*#]] - \\n[#r] + \\n[rsp\\*[#trc]]) \{\
.            if !"\\*[t*hl\\*[#trc]]"=" \{\
.              sp \\n[$1]u
.              nr * (\\n[cscp] + \\n[cscpb] + \\n[cll\\*[#trc]])
.              nop \X'\*[g] 1 setlinecap'\
\h'(-\\n[cscpb2]u - \\n[*t]u)'\
\v'(\\n[cscpb2]u - .67v)'\
\m[\\*[t*bc\\n[t*#]]]\
\D't \\n[*t]u'\c
.
.              ie "\\*[t*hl\\*[#trc]]"d" \
.                nop \v'-\\n[*t]u'\
\D'l \\n[*]u 0'\
\v'(2u * \\n[*t]u)'\
\D'l -\\n[*]u 0'\
\D't 0'
.              el \
.                nop \D'l \\n[*]u 0'\
\D't 0'
.
.              sp (-\\n[$1]u - 1v)
.          \}\}
.
.          nr rsp\\*[#trc] 0
.
.          \" draw vertical line between this and the next (right) cell
.          if (\\n[t*cols\\n[t*#]] - \\n[#c] + \\n[vl\\*[#trc]]) \{\
.            if !"\\*[t*vl\\*[#trc]]"=" \{\
.              nop \X'\*[g] 1 setlinecap'\
\v'(-\\n[cscpb2]u - .67v)'\
\m[\\*[t*bc\\n[t*#]]]\
\h'(\\n[cscpb2]u - \\n[*t]u + \\n[cll\\*[#trc]]u)'\c
.
.              ie "\\*[t*vl\\*[#trc]]"d" \
.                nop \h'-\\n[*t]u'\
\D't \\n[*t]u'\
\D'l 0 (2u * \\n[cscp]u + \\n[$1]u + (\\n[*t]u / 2u))'\
\h'(2u * \\n[*t]u)'\
\D'l 0 -(2u * \\n[cscp]u + \\n[$1]u + (\\n[*t]u / 2u))'\
\D't 0'
.              el \
.                nop \D't \\n[*t]u'\
\D'l 0 (2u * \\n[cscp]u + \\n[$1]u + (\\n[*t]u / 2u))'\
\D't 0'
.              sp -1
.      \}\}\}\}
.
.      nr vl\\*[#trc] 0
.
.      \" vert. cell content alignment
.      nr ** 0
.
.      ie "\\*[t*val\\*[#trc]]"m" \
.        nr ** ((\\n[$1] - \\n[dn\\*[#trc]]) / 2)	\"		val=m
.      el \
.        if "\\*[t*val\\*[#trc]]"b" \
.          nr ** (\\n[$1] - \\n[dn\\*[#trc]])\"	val=b
.
.      sp \\n[**]u		 		\"	vertical content position
.
.      \" finally output the diversion
.      t*\\*[#trc]
.      rm t*\\*[#trc]
.    \}					\"	end of while loop for cols
.  \}					\"	                  and rows
.
.  \" draw the box border
.  in \\n[in\\n[t*#]]u
.  nr ** (\\n[topdiv] + \\n[dntr\\n[t*#]*\\n-[#r]])
.
.  if \\n[t*b\\n[t*#]] \{\
.    sp |(\\n[toptbl\\n[t*#]]u + \\n[b/2]u)
.    nr $1 (\\n[toptbl\\n[t*#]] - \\n[**] - \\n[cscp])
.    nr * (\\n[ll\\n[t*#]] - \\n[t*b\\n[t*#]])
.
.    if !"\\*[t*bc\\n[t*#]]"=" \
.      nop \X'\*[g] 0 setlinejoin 2 setlinecap'\
\v'-.67v'\
\h'-\\n[b/2]u'\
\m[\\*[t*bc\\n[t*#]]]\
\D't \\n[t*b\\n[t*#]]u'\
\D'l \\n[*]u 0'\
\D'l 0 -\\n[$1]u'\
\D'l -\\n[*]u 0'\
\D'l 0 \\n[$1]u'\
\D't 0'
.  \}
.
.  sp |(\\n[**]u + \\n[cscpb]u)
.  fi
..
.
.
.\"	Utility macro:	calculate cellwidths, tablewidth and indents
.de t*cl
.  nr t*cols\\n[t*#] (\\n[.$] >? \\n[t*cols\\n[t*#]])
.  nr ll\\n[t*#] 0 1
.  nr ** (\\n[.l] / \\n[t*cols\\n[t*#]])
.  nr * 0 1
.
.  \" while-loop: calculate
.  while (\\n[t*cols\\n[t*#]] >= \\n+[*]) \{\
.    ie "\\$[\\n[*]]"" \
.      nr $\\n[*] \\n[**]	\"	gross width of cells $\n[*] and
.    el \{\
.      ds * \\$\\n[*]\"			accumulate table width ll\n[t*#]
.      substring * -1 -1
.      ds ** \\$[\\n[*]]\"
.      substring ** 0 -2
.      ie "\\*[*]"%" \
.        nr $\\n[*] (\\*[**] * \\n[.l] / 100)
.      el \
.        nr $\\n[*] \\$[\\n[*]]
.    \}
.
.    nr ll\\n[t*#] +\\n[$\\n[*]]	\"	accumulated tablewidth
.    nr ** \\n[$\\n[*]]
.  \}
.
.  if (\\n[ll\\n[t*#]] > \\n[.l]) \
.    tm \\n[.F]:\\n[.c]: Table width larger than column width.
.
.  nr ** (0 >? \\n[t*b\\n[t*#]])
.  nr * 0 1
.
.  \" second-while loop: calculate
.  while (\\n[t*cols\\n[t*#]] >= \\n+[*]) \{\
.    \" net cellwidths and indents.
.    if \\n[t*b\\n[t*#]] \{\
.      \" avoid multiplication overflow
.      nr #* (1000 * \\n[ll\\n[t*#]] / \\n[t*b\\n[t*#]])
.      nr $\\n[*] (\\n[$\\n[*]] - (1500 * \\n[$\\n[*]] / \\n[#*]))
.    \}
.
.    \"   VVV cellwidth
.    nr cll\\n[t*#]*\\n[*] (\\n[$\\n[*]] \
                            - (2 * \\n[cscp\\n[t*#]]) \
                            - \\n[b/2\\n[t*#]])
.
.    if !\\n[cll\\n[t*#]*\\n[*]] \{\
.      nr *h ((1000 \
               * \\n[ll\\n[t*#]] \
               / (\\n[ll\\n[t*#]] - (3 * \\n[t*b\\n[t*#]] / 2)) \
               * (2 * \\n[cscp\\n[t*#]] + \\n[b/2\\n[t*#]]) \
               / 1000 \
               + 50) / 10 * 10)
.      ds * \\n[*]th
.      nr *** (\\n[*] % 10)
.      if d nth-\\n[***] \
.        ds * \\n[*]\\*[nth-\\n[***]]
.      tmc \\n[.F]:\\n[.c]: The \\*[*] width value (\\$\\n[*]) is too small.
.      tm1 " It should be greater than \\n[*h].
.    \}
.
.    nr in\\n[t*#]*\\n[*] \\n[**]		\"	cell indent
.    nr ** +\\n[$\\n[*]]
.  \}
..
.
.
.\"	Utility macro:	close TD-diversion, make some calculations and set
.\"			some help strings and registers
.de t*dntr
.  nr dn 0				\"	dn must be reset!
.  br					\"	finish last div
.
.  if "\\n[.z]"*t*dummy*" \
.    return
.
.  ds #t#r \\n[t*#]*\\n[t*r#\\n[t*#]]\"		refresh #t#r
.
.  if \\n[c#\\*[#t#r]] \{\
.    di
.    nr dn\\$4 \\n[dn]			\"	height of this cell
.    if !\\n[rsp\\*[#trc]] \{\
.      nr dntr\\*[#t#r] (\\n[dntr\\*[#t#r]] >? \\n[dn])
.      if \\$2 \
.        nr dntr\\*[#t#r] ((\\n[t*height\\*[#t#r]] \
                            - (2 * \\n[cscp\\n[t*#]] + \\n[b/2\\n[t*#]])) \
                            >? \\n[dntr\\*[#t#r]])
.  \}\}
.
.  nr c#\\*[#t#r] +1
.  nr * \\$2
.
.  while (\\n+[*] <= \\$3) \{\
.    nr c#\\*[#t#r] +\\n[csp\\*[#t#r]*\\n[*]]
.    nr csp\\*[#t#r]*\\n[*] 0
.  \}
.
.  ds #trc \\*[#t#r]*\\n[c#\\*[#t#r]]\"
.
.  if (\\$1 & (\\n[c#\\*[#t#r]] <= \\n[t*cols\\n[t*#]])) \{\
.    ds * are
.    ds ** columns
.    if (\\n-[c#\\*[#t#r]] == 1) \{\
.      ds * is
.      ds ** column
.    \}
.    tmc \\n[.F]:\\n[.c]: There \\*[*] only \\n[c#\\*[#t#r]] \\*[**]
.
.    nr * \\n[t*r#\\n[t*#]]
.    ds * \\n[*]th
.    nr *** (\\n[*] % 10)
.    if d nth-\\n[***] \
.      ds * \\n[*]\\*[nth-\\n[***]]
.    tmc " in the \\*[*] row
.
.    ds * are
.    if (\\n[t*cols\\n[t*#]] == 1) \
.      ds * is
.    tm1 " but \\n[t*cols\\n[t*#]] \\*[*] expected.
.  \}
..
.
.
.\"	Utility-macro:	get the arguments common for TBL, TR and TD
.de t*args
.  ds t*bgc\\$1 \\*[t*bgc\\$2]\"
.  ds t*fgc\\$1 \\*[t*fgc\\$2]\"
.  ds t*hl\\$1 \\*[t*hl\\$2]\"
.  ds t*vl\\$1 \\*[t*vl\\$2]\"
.  ds t*hal\\$1 \\*[t*hal\\$2]\"
.  ds t*val\\$1 \\*[t*val\\$2]\"
.  ds t*ff\\$1 \\*[t*ff\\$2]\"
.  ds t*fst\\$1 \\*[t*fst\\$2]\"
.  ds t*fsz\\$1 \\*[t*fsz\\$2]\"
.
.  if "\\*[args]"" \
.    return
.
.  getarg bgc \\*[args]         \"	background color
.  if !"\\*[bgc]"" \
.    ie m\\*[bgc] \
.      ds t*bgc\\$1 \\*[bgc]
.    el \
.      ie "\\*[bgc]"=" \
.        ds t*bgc\\$1 =\"
.      el \
.  tm \\n[.F]:\\n[.c]: Invalid background color `\\*[bgc]'.
.
.  if "\\*[args]"" \
.    return
.
.  getarg fgc \\*[args]         \"	foreground color
.  if !"\\*[fgc]"" \
.    ie m\\*[fgc] \
.      ds t*fgc\\$1 \\*[fgc]\"
.    el \
.      ie "\\*[fgc]"=" \
.        ds t*fgc\\$1 =\"
.      el \
.      tm \\n[.F]:\\n[.c]: Invalid foreground color `\\*[fgc]'.
.
.      if "\\*[args]"" \
.        return
.
.  getarg hl \\*[args]           \" horizontal line between cells ...
.  if !"\\*[hl]"" \
.    ds t*hl\\$1 \\*[hl]\"
.  if "\\*[args]"" \
.    return
.
.  getarg vl \\*[args]           \" vertical line between cells ...
.  if !"\\*[vl]"" \
.    ds t*vl\\$1 \\*[vl]\"
.  if "\\*[args]"" \
.    return
.
.  getarg hal \\*[args]
.  if !"\\*[hal]"" \{\
.    index bcrl \\*[hal]
.    ie \\n[index] \
.      ds t*hal\\$1 \\*[hal]\"
.    el \{\
.      tmc \\n[.F]:\\n[.c]: Invalid `hal' value `\\*[t*hal\\$1]':
.      tm1 " must be `b', `c', `l' or `r'.
.  \}\}
.
.  if "\\*[args]"" \
.    return
.
.  getarg val \\*[args]         \" vertical table cell alignment
.  if !"\\*[val]"" \{\
.    index tmb \\*[val]
.    ie \\n[index] \
.      ds t*val\\$1 \\*[val]\"
.    el \{\
.      tmc \\n[.F]:\\n[.c]: Invalid `val' value `\\*[t*val]':
.      tm1 " must be `t', `m' or `b'.
.  \}\}
.
.  if "\\*[args]"" \
.    return
.
.  getarg ff \\*[args]
.  if !"\\*[ff]"" \
.    ds t*ff\\$1 \\*[ff]\"
.  if "\\*[args]"" \
.    return
.
.  getarg fst \\*[args]
.  if !"\\*[fst]"" \
.    ds t*fst\\$1 \\*[fst]\"
.  if "\\*[args]"" \
.    return
.
.  getarg fsz \\*[args]
.  if !"\\*[fsz]"" \
.    ds t*fsz\\$1 \\*[fsz]\"
..
.
.
.de t*hm
.  ev t*tbl
.  nr ** \\n[.t]
.  while !""\\*[t*kept]" \{\
.    pops * t*kept
.    popr * t*kept
.    if (\\n[*] - \\n[**]) \{\
.      tm \\n[.F]:\\n[.c]: Table \\*[*] higher than page -- ignored!
.      break
.    \}
.
.    if (\\n[*] - \\n[.t]) \{\
.      ds t*kept \\n[*] \\*[t*kept]
.      ds t*kept \\*[*] \\*[t*kept]
.      tmc \\n[.F]:\\n[.c]: Remaining table(s),
.      tm1 " because not all fit onto this page.
.      break
.    \}
.
.    DI \\*[*]
.  \}
.  ev
..
.
.\" EOF