? multipage_boxed_tbl.patch
Index: om.tmac
===================================================================
RCS file: /sources/groff/groff/contrib/mom/om.tmac,v
retrieving revision 1.76
diff -u -r1.76 om.tmac
--- om.tmac	13 Sep 2013 06:38:30 -0000	1.76
+++ om.tmac	13 Sep 2013 16:21:51 -0000
@@ -9379,8 +9379,9 @@
 .          rr float-depth:\\n[loop-count]
 .       \}
 .       ev
-.       vs \\n[#DOC_LEAD]u
 .       SHIM
+\# Invoke table header hook.
+\# Will print table header for multipage tables
 .       rr defer
 .       rr loop-count
 .       rr defer-count
@@ -9388,10 +9389,7 @@
 .       rm float-adj:top
 .       rm float-adj:bottom
 .    \}
-.    if \\n[#TABLE] \{\
-.       rs
-.       sp
-.    \}
+.    tbl@top-hook
 .END
 \#
 \# ====================================================================
@@ -9494,6 +9492,9 @@
 .          rr #OVERFLOW_RIGHT
 .       \}
 .    \}
+\# Table bottom hook, draws the table borders in
+\# multipage boxed tables.
+.    tbl@bottom-hook
 .    ch MN_OVERFLOW_TRAP
 .    nr #L_MARGIN_DIFF \\n[#L_MARGIN]-\\n[#DOC_L_MARGIN]
 .    if !\\n[#FN_DEFER] \{\
@@ -15816,21 +15817,108 @@
 .  sp -1
 .  vpt 1
 ..
+\#
+\# Table Module
+\#
+.
+.nr tbl*have-header 0
+.
 \# Boxed tables don't play nice with vertical spacing.
 \# Compensation is applied in FLOAT.
 .MAC TS END
 .    nr #TABLE 1
-.    if '\\n[.z]'FLOAT*DIV' \{\
-.       if '\\$1'BOXED' \{\
+.    ie '\\n[.z]'FLOAT*DIV' \{\
+.       if '\\$1'BOXED' \
 .          if !\\n[.d] .nr boxed-table 1
+.    \}
+.    el \{\
+.       if '\\$1'H'      .di tbl*header-div
+.       if '\\$1'HEADER' .di tbl*header-div
+.    \}
+.END
+.
+.MAC tbl@top-hook END
+.    ie \\n[tbl*have-header] \{\
+.       tbl*print-header
+\# FIXME: The following lines are from -ms - they ensure that
+\# the header will fit on the page (up to the next trap).
+\# Unfortunately we are in the HEADER trap and \n[.t] is 0.
+\#.       ie \\n[.t]>\\n[tbl*header-ht]+1v .tbl*print-header
+\#.       el .sp \\n[.t]u
+.    \}
+.    el .if \\n[#TABLE] \{\
+.       rs
+.       sp
+.    \}
+.END
+.
+.MAC tbl*print-header END
+\# FIXME: should we switch to some environment?
+\# How could the environment affect the preformatted diversion?
+\#.    ev nf
+.    tbl*header-div
+\#.    ev
+.    mk #T
+.END
+.
+.MAC TH END
+.    ie '\\n[.z]'tbl*header-div' \{\
+.       nr T. 0
+.       T#
+.       br
+.       di
+.       ie (\\n[dn]-\\n[.v])>\\n[.t] \{\
+.          @error ridiculously long table header
+.          ds@need \\n[dn]
+.          tbl*print-header
+.       \}
+.       el \{\
+.          nr tbl*header-ht \\n[dn]
+.          ds@need \\n[dn]u+1v
+.          tbl*print-header
+.          nr tbl*have-header 1
 .       \}
 .    \}
+.    el .@error .TH without .TS H
 .END
 .
+\# Give TH a verbose Mom-like alias
+.ALIAS TH END_TABLE_HEADER
+.
+\# From -ms: I have no idea what it does!
+\# But I think it's for recovering from unterminated tables
+\#.MAC @div-end!tbl*header-div END
+\#.    TH
+\#.    TE
+\#.END
+.
 .MAC TE END
 .    if '\\n[.z]'FLOAT*DIV' .nr bx-tbl-depth \\n[.d]
+.    if '\\n[.z]'tbl*header-div' .@error .TS H but no .TH before .TE
+.    nr tbl*have-header 0
 .    rr #TABLE
 .END
+.
+.MAC tbl@bottom-hook END
+.    if \\n[tbl*have-header] \{\
+.       nr T. 1
+.       T#
+.    \}
+.END
+.
+.ds T&
+.
+\# Copied/modified from -ms:
+\# Move vertically until there is enough space for \$1
+.MAC ds@need END
+.    if '\\n(.z'' \{\
+.       while \\n[.t]<=(\\$1)&(\\n[nl]>\\n[#PAGE_TOP]) \{\
+.          rs
+'          sp \\n[.t]u
+.       \}
+.    \}
+.END
+.
 \#
 \# FLOAT
 \# -----
