2 /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2003, 2004
3 Free Software Foundation, Inc.
4 Written by James Clark (jjc@jclark.com)
6 This file is part of groff.
8 groff is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 groff is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License along
19 with groff; see the file COPYING. If not, write to the Free Software
20 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
24 #define BAR_HEIGHT ".25m"
25 #define DOUBLE_LINE_SEP "2p"
26 #define HALF_DOUBLE_LINE_SEP "1p"
28 #define BODY_DEPTH ".25m"
30 const int DEFAULT_COLUMN_SEPARATION
= 3;
32 #define DELIMITER_CHAR "\\[tbl]"
33 #define SEPARATION_FACTOR_REG PREFIX "sep"
34 #define BOTTOM_REG PREFIX "bot"
35 #define RESET_MACRO_NAME PREFIX "init"
36 #define LINESIZE_REG PREFIX "lps"
37 #define TOP_REG PREFIX "top"
38 #define CURRENT_ROW_REG PREFIX "crow"
39 #define LAST_PASSED_ROW_REG PREFIX "passed"
40 #define TRANSPARENT_STRING_NAME PREFIX "trans"
41 #define QUOTE_STRING_NAME PREFIX "quote"
42 #define SECTION_DIVERSION_NAME PREFIX "section"
43 #define SECTION_DIVERSION_FLAG_REG PREFIX "sflag"
44 #define SAVED_VERTICAL_POS_REG PREFIX "vert"
45 #define NEED_BOTTOM_RULE_REG PREFIX "brule"
46 #define KEEP_MACRO_NAME PREFIX "keep"
47 #define RELEASE_MACRO_NAME PREFIX "release"
48 #define SAVED_FONT_REG PREFIX "fnt"
49 #define SAVED_SIZE_REG PREFIX "sz"
50 #define SAVED_FILL_REG PREFIX "fll"
51 #define SAVED_INDENT_REG PREFIX "ind"
52 #define SAVED_CENTER_REG PREFIX "cent"
53 #define TABLE_DIVERSION_NAME PREFIX "table"
54 #define TABLE_DIVERSION_FLAG_REG PREFIX "tflag"
55 #define TABLE_KEEP_MACRO_NAME PREFIX "tkeep"
56 #define TABLE_RELEASE_MACRO_NAME PREFIX "trelease"
57 #define NEEDED_REG PREFIX "needed"
58 #define REPEATED_MARK_MACRO PREFIX "rmk"
59 #define REPEATED_VPT_MACRO PREFIX "rvpt"
60 #define SUPPRESS_BOTTOM_REG PREFIX "supbot"
61 #define SAVED_DN_REG PREFIX "dn"
63 // this must be one character
64 #define COMPATIBLE_REG PREFIX "c"
66 #define LEADER_REG PREFIX LEADER
68 #define BLOCK_WIDTH_PREFIX PREFIX "tbw"
69 #define BLOCK_DIVERSION_PREFIX PREFIX "tbd"
70 #define BLOCK_HEIGHT_PREFIX PREFIX "tbh"
71 #define SPAN_WIDTH_PREFIX PREFIX "w"
72 #define SPAN_LEFT_NUMERIC_WIDTH_PREFIX PREFIX "lnw"
73 #define SPAN_RIGHT_NUMERIC_WIDTH_PREFIX PREFIX "rnw"
74 #define SPAN_ALPHABETIC_WIDTH_PREFIX PREFIX "aw"
75 #define COLUMN_SEPARATION_PREFIX PREFIX "cs"
76 #define ROW_START_PREFIX PREFIX "rs"
77 #define COLUMN_START_PREFIX PREFIX "cl"
78 #define COLUMN_END_PREFIX PREFIX "ce"
79 #define COLUMN_DIVIDE_PREFIX PREFIX "cd"
80 #define ROW_TOP_PREFIX PREFIX "rt"
82 string
block_width_reg(int r
, int c
);
83 string
block_diversion_name(int r
, int c
);
84 string
block_height_reg(int r
, int c
);
85 string
span_width_reg(int start_col
, int end_col
);
86 string
span_left_numeric_width_reg(int start_col
, int end_col
);
87 string
span_right_numeric_width_reg(int start_col
, int end_col
);
88 string
span_alphabetic_width_reg(int start_col
, int end_col
);
89 string
column_separation_reg(int col
);
90 string
row_start_reg(int r
);
91 string
column_start_reg(int c
);
92 string
column_end_reg(int c
);
93 string
column_divide_reg(int c
);
94 string
row_top_reg(int r
);
96 void set_inline_modifier(const entry_modifier
*);
97 void restore_inline_modifier(const entry_modifier
*m
);
98 void set_modifier(const entry_modifier
*);
99 int find_decimal_point(const char *s
, char decimal_point_char
,
102 string an_empty_string
;
103 int location_force_filename
= 0;
105 void printfs(const char *,
106 const string
&arg1
= an_empty_string
,
107 const string
&arg2
= an_empty_string
,
108 const string
&arg3
= an_empty_string
,
109 const string
&arg4
= an_empty_string
,
110 const string
&arg5
= an_empty_string
);
112 void prints(const string
&);
114 inline void prints(char c
)
119 inline void prints(const char *s
)
124 void prints(const string
&s
)
127 fwrite(s
.contents(), 1, s
.length(), stdout
);
130 struct horizontal_span
{
131 horizontal_span
*next
;
134 horizontal_span(int, int, horizontal_span
*);
137 class single_line_entry
;
138 class double_line_entry
;
145 const char *input_filename
;
151 const entry_modifier
*mod
;
154 table_entry(const entry_modifier
*);
155 virtual ~table_entry();
156 virtual int divert(int ncols
, const string
*mw
, int *sep
);
157 virtual void do_width();
158 virtual void do_depth();
159 virtual void print() = 0;
160 virtual void position_vertically() = 0;
161 virtual single_line_entry
*to_single_line_entry();
162 virtual double_line_entry
*to_double_line_entry();
163 virtual simple_entry
*to_simple_entry();
164 virtual int line_type();
165 virtual void note_double_vrule_on_right(int);
166 virtual void note_double_vrule_on_left(int);
169 class simple_entry
: public table_entry
{
171 simple_entry(const entry_modifier
*);
173 void position_vertically();
174 simple_entry
*to_simple_entry();
175 virtual void add_tab();
176 virtual void simple_print(int);
179 class empty_entry
: public simple_entry
{
181 empty_entry(const entry_modifier
*);
185 class text_entry
: public simple_entry
{
188 void print_contents();
190 text_entry(char *, const entry_modifier
*);
194 void text_entry::print_contents()
196 set_inline_modifier(mod
);
198 restore_inline_modifier(mod
);
201 class repeated_char_entry
: public text_entry
{
203 repeated_char_entry(char *s
, const entry_modifier
*m
);
204 void simple_print(int);
207 class simple_text_entry
: public text_entry
{
209 simple_text_entry(char *s
, const entry_modifier
*m
);
213 class left_text_entry
: public simple_text_entry
{
215 left_text_entry(char *s
, const entry_modifier
*m
);
216 void simple_print(int);
220 class right_text_entry
: public simple_text_entry
{
222 right_text_entry(char *s
, const entry_modifier
*m
);
223 void simple_print(int);
227 class center_text_entry
: public simple_text_entry
{
229 center_text_entry(char *s
, const entry_modifier
*m
);
230 void simple_print(int);
234 class numeric_text_entry
: public text_entry
{
237 numeric_text_entry(char *s
, const entry_modifier
*m
, int pos
);
239 void simple_print(int);
242 class alphabetic_text_entry
: public text_entry
{
244 alphabetic_text_entry(char *s
, const entry_modifier
*m
);
246 void simple_print(int);
250 class line_entry
: public simple_entry
{
252 char double_vrule_on_right
;
253 char double_vrule_on_left
;
255 line_entry(const entry_modifier
*);
256 void note_double_vrule_on_right(int);
257 void note_double_vrule_on_left(int);
258 void simple_print(int) = 0;
261 class single_line_entry
: public line_entry
{
263 single_line_entry(const entry_modifier
*m
);
264 void simple_print(int);
265 single_line_entry
*to_single_line_entry();
269 class double_line_entry
: public line_entry
{
271 double_line_entry(const entry_modifier
*m
);
272 void simple_print(int);
273 double_line_entry
*to_double_line_entry();
277 class short_line_entry
: public simple_entry
{
279 short_line_entry(const entry_modifier
*m
);
280 void simple_print(int);
284 class short_double_line_entry
: public simple_entry
{
286 short_double_line_entry(const entry_modifier
*m
);
287 void simple_print(int);
291 class block_entry
: public table_entry
{
294 void do_divert(int alphabetic
, int ncols
, const string
*mw
, int *sep
);
296 block_entry(char *s
, const entry_modifier
*m
);
298 int divert(int ncols
, const string
*mw
, int *sep
);
301 void position_vertically();
305 class left_block_entry
: public block_entry
{
307 left_block_entry(char *s
, const entry_modifier
*m
);
311 class right_block_entry
: public block_entry
{
313 right_block_entry(char *s
, const entry_modifier
*m
);
317 class center_block_entry
: public block_entry
{
319 center_block_entry(char *s
, const entry_modifier
*m
);
323 class alphabetic_block_entry
: public block_entry
{
325 alphabetic_block_entry(char *s
, const entry_modifier
*m
);
327 int divert(int ncols
, const string
*mw
, int *sep
);
330 table_entry::table_entry(const entry_modifier
*m
)
331 : next(0), input_lineno(-1), input_filename(0),
332 start_row(-1), end_row(-1), start_col(-1), end_col(-1), mod(m
)
336 table_entry::~table_entry()
340 int table_entry::divert(int, const string
*, int *)
345 void table_entry::do_width()
349 single_line_entry
*table_entry::to_single_line_entry()
354 double_line_entry
*table_entry::to_double_line_entry()
359 simple_entry
*table_entry::to_simple_entry()
364 void table_entry::do_depth()
368 void table_entry::set_location()
370 set_troff_location(input_filename
, input_lineno
);
373 int table_entry::line_type()
378 void table_entry::note_double_vrule_on_right(int)
382 void table_entry::note_double_vrule_on_left(int)
386 simple_entry::simple_entry(const entry_modifier
*m
) : table_entry(m
)
390 void simple_entry::add_tab()
395 void simple_entry::simple_print(int)
400 void simple_entry::position_vertically()
402 if (start_row
!= end_row
)
403 switch (mod
->vertical_alignment
) {
404 case entry_modifier::TOP
:
405 printfs(".sp |\\n[%1]u\n", row_start_reg(start_row
));
407 case entry_modifier::CENTER
:
408 // Peform the motion in two stages so that the center is rounded
409 // vertically upwards even if net vertical motion is upwards.
410 printfs(".sp |\\n[%1]u\n", row_start_reg(start_row
));
411 printfs(".sp \\n[" BOTTOM_REG
"]u-\\n[%1]u-1v/2u\n",
412 row_start_reg(start_row
));
414 case entry_modifier::BOTTOM
:
415 printfs(".sp |\\n[%1]u+\\n[" BOTTOM_REG
"]u-\\n[%1]u-1v\n",
416 row_start_reg(start_row
));
423 void simple_entry::print()
434 simple_entry
*simple_entry::to_simple_entry()
439 empty_entry::empty_entry(const entry_modifier
*m
)
444 int empty_entry::line_type()
449 text_entry::text_entry(char *s
, const entry_modifier
*m
)
450 : simple_entry(m
), contents(s
)
454 text_entry::~text_entry()
459 repeated_char_entry::repeated_char_entry(char *s
, const entry_modifier
*m
)
464 void repeated_char_entry::simple_print(int)
466 printfs("\\h'|\\n[%1]u'", column_start_reg(start_col
));
467 set_inline_modifier(mod
);
468 printfs("\\l" DELIMITER_CHAR
"\\n[%1]u\\&",
469 span_width_reg(start_col
, end_col
));
471 prints(DELIMITER_CHAR
);
472 restore_inline_modifier(mod
);
475 simple_text_entry::simple_text_entry(char *s
, const entry_modifier
*m
)
480 void simple_text_entry::do_width()
483 printfs(".nr %1 \\n[%1]>?\\w" DELIMITER_CHAR
,
484 span_width_reg(start_col
, end_col
));
486 prints(DELIMITER_CHAR
"\n");
489 left_text_entry::left_text_entry(char *s
, const entry_modifier
*m
)
490 : simple_text_entry(s
, m
)
494 void left_text_entry::simple_print(int)
496 printfs("\\h'|\\n[%1]u'", column_start_reg(start_col
));
500 // The only point of this is to make `\a' ``work'' as in Unix tbl. Grrr.
502 void left_text_entry::add_tab()
504 printfs(" \\n[%1]u", column_end_reg(end_col
));
507 right_text_entry::right_text_entry(char *s
, const entry_modifier
*m
)
508 : simple_text_entry(s
, m
)
512 void right_text_entry::simple_print(int)
514 printfs("\\h'|\\n[%1]u'", column_start_reg(start_col
));
520 void right_text_entry::add_tab()
522 printfs(" \\n[%1]u", column_end_reg(end_col
));
525 center_text_entry::center_text_entry(char *s
, const entry_modifier
*m
)
526 : simple_text_entry(s
, m
)
530 void center_text_entry::simple_print(int)
532 printfs("\\h'|\\n[%1]u'", column_start_reg(start_col
));
538 void center_text_entry::add_tab()
540 printfs(" \\n[%1]u", column_end_reg(end_col
));
543 numeric_text_entry::numeric_text_entry(char *s
, const entry_modifier
*m
, int pos
)
544 : text_entry(s
, m
), dot_pos(pos
)
548 void numeric_text_entry::do_width()
552 printfs(".nr %1 0\\w" DELIMITER_CHAR
,
553 block_width_reg(start_row
, start_col
));
554 set_inline_modifier(mod
);
555 for (int i
= 0; i
< dot_pos
; i
++)
557 restore_inline_modifier(mod
);
558 prints(DELIMITER_CHAR
"\n");
559 printfs(".nr %1 \\n[%1]>?\\n[%2]\n",
560 span_left_numeric_width_reg(start_col
, end_col
),
561 block_width_reg(start_row
, start_col
));
564 printfs(".nr %1 0\n", block_width_reg(start_row
, start_col
));
565 if (contents
[dot_pos
] != '\0') {
567 printfs(".nr %1 \\n[%1]>?\\w" DELIMITER_CHAR
,
568 span_right_numeric_width_reg(start_col
, end_col
));
569 set_inline_modifier(mod
);
570 prints(contents
+ dot_pos
);
571 restore_inline_modifier(mod
);
572 prints(DELIMITER_CHAR
"\n");
576 void numeric_text_entry::simple_print(int)
578 printfs("\\h'|(\\n[%1]u-\\n[%2]u-\\n[%3]u/2u+\\n[%2]u+\\n[%4]u-\\n[%5]u)'",
579 span_width_reg(start_col
, end_col
),
580 span_left_numeric_width_reg(start_col
, end_col
),
581 span_right_numeric_width_reg(start_col
, end_col
),
582 column_start_reg(start_col
),
583 block_width_reg(start_row
, start_col
));
587 alphabetic_text_entry::alphabetic_text_entry(char *s
, const entry_modifier
*m
)
592 void alphabetic_text_entry::do_width()
595 printfs(".nr %1 \\n[%1]>?\\w" DELIMITER_CHAR
,
596 span_alphabetic_width_reg(start_col
, end_col
));
598 prints(DELIMITER_CHAR
"\n");
601 void alphabetic_text_entry::simple_print(int)
603 printfs("\\h'|\\n[%1]u'", column_start_reg(start_col
));
604 printfs("\\h'\\n[%1]u-\\n[%2]u/2u'",
605 span_width_reg(start_col
, end_col
),
606 span_alphabetic_width_reg(start_col
, end_col
));
610 // The only point of this is to make `\a' ``work'' as in Unix tbl. Grrr.
612 void alphabetic_text_entry::add_tab()
614 printfs(" \\n[%1]u", column_end_reg(end_col
));
617 block_entry::block_entry(char *s
, const entry_modifier
*m
)
618 : table_entry(m
), contents(s
)
622 block_entry::~block_entry()
627 void block_entry::position_vertically()
629 if (start_row
!= end_row
)
630 switch(mod
->vertical_alignment
) {
631 case entry_modifier::TOP
:
632 printfs(".sp |\\n[%1]u\n", row_start_reg(start_row
));
634 case entry_modifier::CENTER
:
635 // Peform the motion in two stages so that the center is rounded
636 // vertically upwards even if net vertical motion is upwards.
637 printfs(".sp |\\n[%1]u\n", row_start_reg(start_row
));
638 printfs(".sp \\n[" BOTTOM_REG
"]u-\\n[%1]u-\\n[%2]u/2u\n",
639 row_start_reg(start_row
),
640 block_height_reg(start_row
, start_col
));
642 case entry_modifier::BOTTOM
:
643 printfs(".sp |\\n[%1]u+\\n[" BOTTOM_REG
"]u-\\n[%1]u-\\n[%2]u\n",
644 row_start_reg(start_row
),
645 block_height_reg(start_row
, start_col
));
651 prints(".sp -.5v\n");
654 int block_entry::divert(int ncols
, const string
*mw
, int *sep
)
656 do_divert(0, ncols
, mw
, sep
);
660 void block_entry::do_divert(int alphabetic
, int ncols
, const string
*mw
,
663 printfs(".di %1\n", block_diversion_name(start_row
, start_col
));
664 prints(".if \\n[" SAVED_FILL_REG
"] .fi\n"
668 for (i
= start_col
; i
<= end_col
; i
++)
672 // Every column spanned by this entry has a minimum width.
673 for (int j
= start_col
; j
<= end_col
; j
++) {
676 printfs("+%1n", as_string(sep
[j
- 1]));
679 printfs("(n;%1)", mw
[j
]);
681 printfs(">?\\n[%1]u", span_width_reg(start_col
, end_col
));
684 printfs("(u;\\n[%1]>?(\\n[.l]*%2/%3))",
685 span_width_reg(start_col
, end_col
),
686 as_string(end_col
- start_col
+ 1),
687 as_string(ncols
+ 1));
691 prints(".cp \\n(" COMPATIBLE_REG
"\n");
695 prints(".br\n.di\n.cp 0\n");
696 if (!mod
->zero_width
) {
698 printfs(".nr %1 \\n[%1]>?(\\n[dl]+2n)\n",
699 span_width_reg(start_col
, end_col
));
700 printfs(".nr %1 \\n[%1]>?\\n[dl]\n",
701 span_alphabetic_width_reg(start_col
, end_col
));
704 printfs(".nr %1 \\n[%1]>?\\n[dl]\n", span_width_reg(start_col
, end_col
));
706 printfs(".nr %1 \\n[dn]\n", block_height_reg(start_row
, start_col
));
707 printfs(".nr %1 \\n[dl]\n", block_width_reg(start_row
, start_col
));
708 prints("." RESET_MACRO_NAME
"\n"
709 ".in \\n[" SAVED_INDENT_REG
"]u\n"
711 // the block might have contained .lf commands
712 location_force_filename
= 1;
715 void block_entry::do_width()
717 // do nothing; the action happens in divert
720 void block_entry::do_depth()
722 printfs(".nr " BOTTOM_REG
" \\n[" BOTTOM_REG
"]>?(\\n[%1]+\\n[%2])\n",
723 row_start_reg(start_row
),
724 block_height_reg(start_row
, start_col
));
727 left_block_entry::left_block_entry(char *s
, const entry_modifier
*m
)
732 void left_block_entry::print()
734 printfs(".in +\\n[%1]u\n", column_start_reg(start_col
));
735 printfs(".%1\n", block_diversion_name(start_row
, start_col
));
739 right_block_entry::right_block_entry(char *s
, const entry_modifier
*m
)
744 void right_block_entry::print()
746 printfs(".in +\\n[%1]u+\\n[%2]u-\\n[%3]u\n",
747 column_start_reg(start_col
),
748 span_width_reg(start_col
, end_col
),
749 block_width_reg(start_row
, start_col
));
750 printfs(".%1\n", block_diversion_name(start_row
, start_col
));
754 center_block_entry::center_block_entry(char *s
, const entry_modifier
*m
)
759 void center_block_entry::print()
761 printfs(".in +\\n[%1]u+(\\n[%2]u-\\n[%3]u/2u)\n",
762 column_start_reg(start_col
),
763 span_width_reg(start_col
, end_col
),
764 block_width_reg(start_row
, start_col
));
765 printfs(".%1\n", block_diversion_name(start_row
, start_col
));
769 alphabetic_block_entry::alphabetic_block_entry(char *s
,
770 const entry_modifier
*m
)
775 int alphabetic_block_entry::divert(int ncols
, const string
*mw
, int *sep
)
777 do_divert(1, ncols
, mw
, sep
);
781 void alphabetic_block_entry::print()
783 printfs(".in +\\n[%1]u+(\\n[%2]u-\\n[%3]u/2u)\n",
784 column_start_reg(start_col
),
785 span_width_reg(start_col
, end_col
),
786 span_alphabetic_width_reg(start_col
, end_col
));
787 printfs(".%1\n", block_diversion_name(start_row
, start_col
));
791 line_entry::line_entry(const entry_modifier
*m
)
792 : simple_entry(m
), double_vrule_on_right(0), double_vrule_on_left(0)
796 void line_entry::note_double_vrule_on_right(int is_corner
)
798 double_vrule_on_right
= is_corner
? 1 : 2;
801 void line_entry::note_double_vrule_on_left(int is_corner
)
803 double_vrule_on_left
= is_corner
? 1 : 2;
806 single_line_entry::single_line_entry(const entry_modifier
*m
)
811 int single_line_entry::line_type()
816 void single_line_entry::simple_print(int dont_move
)
818 printfs("\\h'|\\n[%1]u",
819 column_divide_reg(start_col
));
820 if (double_vrule_on_left
) {
821 prints(double_vrule_on_left
== 1 ? "-" : "+");
822 prints(HALF_DOUBLE_LINE_SEP
);
826 prints("\\v'-" BAR_HEIGHT
"'");
827 printfs("\\s[\\n[" LINESIZE_REG
"]]" "\\D'l |\\n[%1]u",
828 column_divide_reg(end_col
+1));
829 if (double_vrule_on_right
) {
830 prints(double_vrule_on_left
== 1 ? "+" : "-");
831 prints(HALF_DOUBLE_LINE_SEP
);
835 prints("\\v'" BAR_HEIGHT
"'");
838 single_line_entry
*single_line_entry::to_single_line_entry()
843 double_line_entry::double_line_entry(const entry_modifier
*m
)
848 int double_line_entry::line_type()
853 void double_line_entry::simple_print(int dont_move
)
856 prints("\\v'-" BAR_HEIGHT
"'");
857 printfs("\\h'|\\n[%1]u",
858 column_divide_reg(start_col
));
859 if (double_vrule_on_left
) {
860 prints(double_vrule_on_left
== 1 ? "-" : "+");
861 prints(HALF_DOUBLE_LINE_SEP
);
864 printfs("\\v'-" HALF_DOUBLE_LINE_SEP
"'"
865 "\\s[\\n[" LINESIZE_REG
"]]"
867 column_divide_reg(end_col
+1));
868 if (double_vrule_on_right
)
869 prints("-" HALF_DOUBLE_LINE_SEP
);
871 printfs("\\v'" DOUBLE_LINE_SEP
"'"
873 column_divide_reg(start_col
));
874 if (double_vrule_on_right
) {
875 prints(double_vrule_on_left
== 1 ? "+" : "-");
876 prints(HALF_DOUBLE_LINE_SEP
);
880 "\\v'-" HALF_DOUBLE_LINE_SEP
"'");
882 prints("\\v'" BAR_HEIGHT
"'");
885 double_line_entry
*double_line_entry::to_double_line_entry()
890 short_line_entry::short_line_entry(const entry_modifier
*m
)
895 int short_line_entry::line_type()
900 void short_line_entry::simple_print(int dont_move
)
905 prints("\\v'-" BAR_HEIGHT
"'");
906 printfs("\\h'|\\n[%1]u'", column_start_reg(start_col
));
907 printfs("\\s[\\n[" LINESIZE_REG
"]]"
910 span_width_reg(start_col
, end_col
));
912 prints("\\v'" BAR_HEIGHT
"'");
917 short_double_line_entry::short_double_line_entry(const entry_modifier
*m
)
922 int short_double_line_entry::line_type()
927 void short_double_line_entry::simple_print(int dont_move
)
932 prints("\\v'-" BAR_HEIGHT
"'");
933 printfs("\\h'|\\n[%2]u'"
934 "\\v'-" HALF_DOUBLE_LINE_SEP
"'"
935 "\\s[\\n[" LINESIZE_REG
"]]"
937 "\\v'" DOUBLE_LINE_SEP
"'"
940 "\\v'-" HALF_DOUBLE_LINE_SEP
"'",
941 span_width_reg(start_col
, end_col
),
942 column_start_reg(start_col
));
944 prints("\\v'" BAR_HEIGHT
"'");
949 void set_modifier(const entry_modifier
*m
)
951 if (!m
->font
.empty())
952 printfs(".ft %1\n", m
->font
);
953 if (m
->point_size
.val
!= 0) {
955 if (m
->point_size
.inc
> 0)
957 else if (m
->point_size
.inc
< 0)
959 printfs("%1\n", as_string(m
->point_size
.val
));
961 if (m
->vertical_spacing
.val
!= 0) {
963 if (m
->vertical_spacing
.inc
> 0)
965 else if (m
->vertical_spacing
.inc
< 0)
967 printfs("%1\n", as_string(m
->vertical_spacing
.val
));
969 if (!m
->macro
.empty())
970 printfs(".%1\n", m
->macro
);
973 void set_inline_modifier(const entry_modifier
*m
)
975 if (!m
->font
.empty())
976 printfs("\\f[%1]", m
->font
);
977 if (m
->point_size
.val
!= 0) {
979 if (m
->point_size
.inc
> 0)
981 else if (m
->point_size
.inc
< 0)
983 printfs("%1]", as_string(m
->point_size
.val
));
989 void restore_inline_modifier(const entry_modifier
*m
)
991 if (!m
->font
.empty())
992 prints("\\f[\\n[" SAVED_FONT_REG
"]]");
993 if (m
->point_size
.val
!= 0)
994 prints("\\s[\\n[" SAVED_SIZE_REG
"]]");
1001 int row
; // occurs before row `row'
1002 char printed
; // has it been printed?
1005 virtual void print(table
*) = 0;
1007 virtual int is_single_line() { return 0; };
1008 virtual int is_double_line() { return 0; };
1011 stuff::stuff(int r
) : next(0), row(r
), printed(0)
1019 struct text_stuff
: public stuff
{
1021 const char *filename
;
1024 text_stuff(const string
&, int r
, const char *fn
, int ln
);
1026 void print(table
*);
1029 text_stuff::text_stuff(const string
&s
, int r
, const char *fn
, int ln
)
1030 : stuff(r
), contents(s
), filename(fn
), lineno(ln
)
1034 text_stuff::~text_stuff()
1038 void text_stuff::print(table
*)
1041 prints(".cp \\n(" COMPATIBLE_REG
"\n");
1042 set_troff_location(filename
, lineno
);
1045 location_force_filename
= 1; // it might have been a .lf command
1048 struct single_hline_stuff
: public stuff
{
1049 single_hline_stuff(int r
);
1050 void print(table
*);
1051 int is_single_line();
1054 single_hline_stuff::single_hline_stuff(int r
) : stuff(r
)
1058 void single_hline_stuff::print(table
*tbl
)
1061 tbl
->print_single_hline(row
);
1064 int single_hline_stuff::is_single_line()
1069 struct double_hline_stuff
: stuff
{
1070 double_hline_stuff(int r
);
1071 void print(table
*);
1072 int is_double_line();
1075 double_hline_stuff::double_hline_stuff(int r
) : stuff(r
)
1079 void double_hline_stuff::print(table
*tbl
)
1082 tbl
->print_double_hline(row
);
1085 int double_hline_stuff::is_double_line()
1090 struct vertical_rule
{
1091 vertical_rule
*next
;
1099 vertical_rule(int sr
, int er
, int c
, int dbl
, vertical_rule
*);
1101 void contribute_to_bottom_macro(table
*);
1105 vertical_rule::vertical_rule(int sr
, int er
, int c
, int dbl
, vertical_rule
*p
)
1106 : next(p
), start_row(sr
), end_row(er
), col(c
), is_double(dbl
)
1110 vertical_rule::~vertical_rule()
1114 void vertical_rule::contribute_to_bottom_macro(table
*tbl
)
1116 printfs(".if \\n[" CURRENT_ROW_REG
"]>=%1",
1117 as_string(start_row
));
1118 if (end_row
!= tbl
->get_nrows() - 1)
1119 printfs("&(\\n[" CURRENT_ROW_REG
"]<%1)",
1120 as_string(end_row
));
1122 printfs(".if %1<=\\n[" LAST_PASSED_ROW_REG
"] .nr %2 \\n[#T]\n",
1123 as_string(start_row
),
1124 row_top_reg(start_row
));
1125 const char *offset_table
[3];
1127 offset_table
[0] = "-" HALF_DOUBLE_LINE_SEP
;
1128 offset_table
[1] = "+" HALF_DOUBLE_LINE_SEP
;
1129 offset_table
[2] = 0;
1132 offset_table
[0] = "";
1133 offset_table
[1] = 0;
1135 for (const char **offsetp
= offset_table
; *offsetp
; offsetp
++) {
1138 if (!bot_adjust
.empty())
1139 printfs("+%1", bot_adjust
);
1141 printfs("\\h'\\n[%1]u%3'\\s[\\n[" LINESIZE_REG
"]]\\D'l 0 |\\n[%2]u-1v",
1142 column_divide_reg(col
),
1143 row_top_reg(start_row
),
1145 if (!bot_adjust
.empty())
1146 printfs("-(%1)", bot_adjust
);
1147 // don't perform the top adjustment if the top is actually #T
1148 if (!top_adjust
.empty())
1149 printfs("+((%1)*(%2>\\n[" LAST_PASSED_ROW_REG
"]))",
1151 as_string(start_row
));
1157 void vertical_rule::print()
1159 printfs("\\*[" TRANSPARENT_STRING_NAME
"]"
1160 ".if %1<=\\*[" QUOTE_STRING_NAME
"]\\n[" LAST_PASSED_ROW_REG
"] "
1161 ".nr %2 \\*[" QUOTE_STRING_NAME
"]\\n[#T]\n",
1162 as_string(start_row
),
1163 row_top_reg(start_row
));
1164 const char *offset_table
[3];
1166 offset_table
[0] = "-" HALF_DOUBLE_LINE_SEP
;
1167 offset_table
[1] = "+" HALF_DOUBLE_LINE_SEP
;
1168 offset_table
[2] = 0;
1171 offset_table
[0] = "";
1172 offset_table
[1] = 0;
1174 for (const char **offsetp
= offset_table
; *offsetp
; offsetp
++) {
1175 prints("\\*[" TRANSPARENT_STRING_NAME
"].sp -1\n"
1176 "\\*[" TRANSPARENT_STRING_NAME
"]\\v'" BODY_DEPTH
);
1177 if (!bot_adjust
.empty())
1178 printfs("+%1", bot_adjust
);
1180 printfs("\\h'\\n[%1]u%3'"
1181 "\\s[\\n[" LINESIZE_REG
"]]"
1182 "\\D'l 0 |\\*[" QUOTE_STRING_NAME
"]\\n[%2]u-1v",
1183 column_divide_reg(col
),
1184 row_top_reg(start_row
),
1186 if (!bot_adjust
.empty())
1187 printfs("-(%1)", bot_adjust
);
1188 // don't perform the top adjustment if the top is actually #T
1189 if (!top_adjust
.empty())
1190 printfs("+((%1)*(%2>\\*[" QUOTE_STRING_NAME
"]\\n["
1191 LAST_PASSED_ROW_REG
"]))",
1193 as_string(start_row
));
1199 table::table(int nc
, unsigned f
, int ls
, char dpc
)
1200 : flags(f
), nrows(0), ncolumns(nc
), linesize(ls
), decimal_point_char(dpc
),
1201 vrule_list(0), stuff_list(0), span_list(0),
1202 entry_list(0), entry_list_tailp(&entry_list
), entry(0),
1203 vline(0), row_is_all_lines(0), left_separation(0), right_separation(0),
1206 minimum_width
= new string
[ncolumns
];
1207 column_separation
= ncolumns
> 1 ? new int[ncolumns
- 1] : 0;
1208 equal
= new char[ncolumns
];
1210 for (i
= 0; i
< ncolumns
; i
++)
1212 for (i
= 0; i
< ncolumns
-1; i
++)
1213 column_separation
[i
] = DEFAULT_COLUMN_SEPARATION
;
1214 delim
[0] = delim
[1] = '\0';
1219 for (int i
= 0; i
< nrows
; i
++) {
1225 while (entry_list
) {
1226 table_entry
*tem
= entry_list
;
1227 entry_list
= entry_list
->next
;
1230 ad_delete(ncolumns
) minimum_width
;
1231 a_delete column_separation
;
1233 while (stuff_list
) {
1234 stuff
*tem
= stuff_list
;
1235 stuff_list
= stuff_list
->next
;
1238 while (vrule_list
) {
1239 vertical_rule
*tem
= vrule_list
;
1240 vrule_list
= vrule_list
->next
;
1243 a_delete row_is_all_lines
;
1245 horizontal_span
*tem
= span_list
;
1246 span_list
= span_list
->next
;
1251 void table::set_delim(char c1
, char c2
)
1257 void table::set_minimum_width(int c
, const string
&w
)
1259 assert(c
>= 0 && c
< ncolumns
);
1260 minimum_width
[c
] = w
;
1263 void table::set_column_separation(int c
, int n
)
1265 assert(c
>= 0 && c
< ncolumns
- 1);
1266 column_separation
[c
] = n
;
1269 void table::set_equal_column(int c
)
1271 assert(c
>= 0 && c
< ncolumns
);
1275 void table::add_stuff(stuff
*p
)
1278 for (pp
= &stuff_list
; *pp
; pp
= &(*pp
)->next
)
1283 void table::add_text_line(int r
, const string
&s
, const char *filename
, int lineno
)
1285 add_stuff(new text_stuff(s
, r
, filename
, lineno
));
1288 void table::add_single_hline(int r
)
1290 add_stuff(new single_hline_stuff(r
));
1293 void table::add_double_hline(int r
)
1295 add_stuff(new double_hline_stuff(r
));
1298 void table::allocate(int r
)
1301 typedef table_entry
**PPtable_entry
; // work around g++ 1.36.1 bug
1302 if (r
>= allocated_rows
) {
1303 if (allocated_rows
== 0) {
1304 allocated_rows
= 16;
1305 if (allocated_rows
<= r
)
1306 allocated_rows
= r
+ 1;
1307 entry
= new PPtable_entry
[allocated_rows
];
1308 vline
= new char*[allocated_rows
];
1311 table_entry
***old_entry
= entry
;
1312 int old_allocated_rows
= allocated_rows
;
1313 allocated_rows
*= 2;
1314 if (allocated_rows
<= r
)
1315 allocated_rows
= r
+ 1;
1316 entry
= new PPtable_entry
[allocated_rows
];
1317 memcpy(entry
, old_entry
, sizeof(table_entry
**)*old_allocated_rows
);
1319 char **old_vline
= vline
;
1320 vline
= new char*[allocated_rows
];
1321 memcpy(vline
, old_vline
, sizeof(char*)*old_allocated_rows
);
1325 assert(allocated_rows
> r
);
1326 while (nrows
<= r
) {
1327 entry
[nrows
] = new table_entry
*[ncolumns
];
1329 for (i
= 0; i
< ncolumns
; i
++)
1330 entry
[nrows
][i
] = 0;
1331 vline
[nrows
] = new char[ncolumns
+1];
1332 for (i
= 0; i
< ncolumns
+1; i
++)
1333 vline
[nrows
][i
] = 0;
1339 void table::do_hspan(int r
, int c
)
1341 assert(r
>= 0 && c
>= 0 && r
< nrows
&& c
< ncolumns
);
1343 error("first column cannot be horizontally spanned");
1346 table_entry
*e
= entry
[r
][c
];
1348 assert(e
->start_row
<= r
&& r
<= e
->end_row
1349 && e
->start_col
<= c
&& c
<= e
->end_col
1350 && e
->end_row
- e
->start_row
> 0
1351 && e
->end_col
- e
->start_col
> 0);
1355 // e can be 0 if we had an empty entry or an error
1358 if (e
->start_row
!= r
) {
1362 error("impossible horizontal span at row %1, column %2", r
+ 1, c
+ 1);
1370 void table::do_vspan(int r
, int c
)
1372 assert(r
>= 0 && c
>= 0 && r
< nrows
&& c
< ncolumns
);
1374 error("first row cannot be vertically spanned");
1377 table_entry
*e
= entry
[r
][c
];
1379 assert(e
->start_row
<= r
&& r
<= e
->end_row
1380 && e
->start_col
<= c
&& c
<= e
->end_col
1381 && e
->end_row
- e
->start_row
> 0
1382 && e
->end_col
- e
->start_col
> 0);
1386 // e can be 0 if we had an empty entry or an error
1389 if (e
->start_col
!= c
) {
1392 error("impossible vertical span at row %1, column %2", r
+ 1, c
+ 1);
1395 for (int i
= c
; i
<= e
->end_col
; i
++) {
1396 assert(entry
[r
][i
] == 0);
1403 int find_decimal_point(const char *s
, char decimal_point_char
,
1406 if (s
== 0 || *s
== '\0')
1409 int in_delim
= 0; // is p within eqn delimiters?
1410 // tbl recognises \& even within eqn delimiters; I don't
1411 for (p
= s
; *p
; p
++)
1416 else if (*p
== delim
[0])
1418 else if (p
[0] == '\\' && p
[1] == '&')
1420 int possible_pos
= -1;
1422 for (p
= s
; *p
; p
++)
1427 else if (*p
== delim
[0])
1429 else if (p
[0] == decimal_point_char
&& csdigit(p
[1]))
1430 possible_pos
= p
- s
;
1431 if (possible_pos
>= 0)
1432 return possible_pos
;
1434 for (p
= s
; *p
; p
++)
1439 else if (*p
== delim
[0])
1441 else if (csdigit(*p
))
1442 possible_pos
= p
+ 1 - s
;
1443 return possible_pos
;
1446 void table::add_entry(int r
, int c
, const string
&str
, const entry_format
*f
,
1447 const char *fn
, int ln
)
1452 e
= new short_line_entry(f
);
1454 else if (str
== "\\=") {
1455 e
= new short_double_line_entry(f
);
1457 else if (str
== "_") {
1458 single_line_entry
*lefte
;
1459 if (c
> 0 && entry
[r
][c
-1] != 0 &&
1460 (lefte
= entry
[r
][c
-1]->to_single_line_entry()) != 0
1461 && lefte
->start_row
== r
1462 && lefte
->mod
->stagger
== f
->stagger
) {
1464 entry
[r
][c
] = lefte
;
1467 e
= new single_line_entry(f
);
1469 else if (str
== "=") {
1470 double_line_entry
*lefte
;
1471 if (c
> 0 && entry
[r
][c
-1] != 0 &&
1472 (lefte
= entry
[r
][c
-1]->to_double_line_entry()) != 0
1473 && lefte
->start_row
== r
1474 && lefte
->mod
->stagger
== f
->stagger
) {
1476 entry
[r
][c
] = lefte
;
1479 e
= new double_line_entry(f
);
1481 else if (str
== "\\^") {
1484 else if (str
.length() > 2 && str
[0] == '\\' && str
[1] == 'R') {
1485 if (str
.search('\n') >= 0)
1486 error_with_file_and_line(fn
, ln
, "bad repeated character");
1488 char *s
= str
.substring(2, str
.length() - 2).extract();
1489 e
= new repeated_char_entry(s
, f
);
1493 int is_block
= str
.search('\n') >= 0;
1497 assert(str
.empty());
1504 e
= new left_block_entry(s
, f
);
1506 e
= new left_text_entry(s
, f
);
1509 e
= new empty_entry(f
);
1515 e
= new center_block_entry(s
, f
);
1517 e
= new center_text_entry(s
, f
);
1520 e
= new empty_entry(f
);
1526 e
= new right_block_entry(s
, f
);
1528 e
= new right_text_entry(s
, f
);
1531 e
= new empty_entry(f
);
1533 case FORMAT_NUMERIC
:
1537 error_with_file_and_line(fn
, ln
, "can't have numeric text block");
1538 e
= new left_block_entry(s
, f
);
1541 int pos
= find_decimal_point(s
, decimal_point_char
, delim
);
1543 e
= new center_text_entry(s
, f
);
1545 e
= new numeric_text_entry(s
, f
, pos
);
1549 e
= new empty_entry(f
);
1551 case FORMAT_ALPHABETIC
:
1555 e
= new alphabetic_block_entry(s
, f
);
1557 e
= new alphabetic_text_entry(s
, f
);
1560 e
= new empty_entry(f
);
1566 if (str
.length() != 0)
1567 error_with_file_and_line(fn
, ln
,
1568 "non-empty data entry for `_' format ignored");
1569 e
= new single_line_entry(f
);
1571 case FORMAT_DOUBLE_HLINE
:
1572 if (str
.length() != 0)
1573 error_with_file_and_line(fn
, ln
,
1574 "non-empty data entry for `=' format ignored");
1575 e
= new double_line_entry(f
);
1582 table_entry
*preve
= entry
[r
][c
];
1586 error_with_file_and_line(fn
, ln
, "row %1, column %2 already spanned",
1591 e
->input_lineno
= ln
;
1592 e
->input_filename
= fn
;
1593 e
->start_row
= e
->end_row
= r
;
1594 e
->start_col
= e
->end_col
= c
;
1595 *entry_list_tailp
= e
;
1596 entry_list_tailp
= &e
->next
;
1602 // add vertical lines for row r
1604 void table::add_vlines(int r
, const char *v
)
1607 for (int i
= 0; i
< ncolumns
+1; i
++)
1613 table_entry
*p
= entry_list
;
1616 for (i
= p
->start_row
; i
<= p
->end_row
; i
++)
1617 for (j
= p
->start_col
; j
<= p
->end_col
; j
++)
1618 assert(entry
[i
][j
] == p
);
1625 location_force_filename
= 1;
1628 determine_row_type();
1630 if (!(flags
& CENTER
))
1631 prints(".if \\n[" SAVED_CENTER_REG
"] \\{");
1632 prints(".in +(u;\\n[.l]-\\n[.i]-\\n[TW]/2>?-\\n[.i])\n"
1633 ".nr " SAVED_INDENT_REG
" \\n[.i]\n");
1634 if (!(flags
& CENTER
))
1637 define_bottom_macro();
1639 for (int i
= 0; i
< nrows
; i
++)
1644 void table::determine_row_type()
1646 row_is_all_lines
= new char[nrows
];
1647 for (int i
= 0; i
< nrows
; i
++) {
1650 int had_non_line
= 0;
1651 for (int c
= 0; c
< ncolumns
; c
++) {
1652 table_entry
*e
= entry
[i
][c
];
1654 if (e
->start_row
== e
->end_row
) {
1655 int t
= e
->line_type();
1679 row_is_all_lines
[i
] = 0;
1680 else if (had_double
)
1681 row_is_all_lines
[i
] = 2;
1682 else if (had_single
)
1683 row_is_all_lines
[i
] = 1;
1685 row_is_all_lines
[i
] = 0;
1689 void table::init_output()
1691 prints(".nr " COMPATIBLE_REG
" \\n(.C\n"
1694 printfs(".nr " LINESIZE_REG
" %1\n", as_string(linesize
));
1696 prints(".nr " LINESIZE_REG
" \\n[.s]\n");
1697 if (!(flags
& CENTER
))
1698 prints(".nr " SAVED_CENTER_REG
" \\n[.ce]\n");
1699 if (compatible_flag
)
1700 prints(".ds " LEADER_REG
" \\a\n");
1701 prints(".de " RESET_MACRO_NAME
"\n"
1713 ".nr " SAVED_INDENT_REG
" \\n[.i]\n"
1714 ".nr " SAVED_FONT_REG
" \\n[.f]\n"
1715 ".nr " SAVED_SIZE_REG
" \\n[.s]\n"
1716 ".nr " SAVED_FILL_REG
" \\n[.u]\n"
1718 ".nr " CURRENT_ROW_REG
" 0-1\n"
1719 ".nr " LAST_PASSED_ROW_REG
" 0-1\n"
1720 ".nr " SECTION_DIVERSION_FLAG_REG
" 0\n"
1721 ".ds " TRANSPARENT_STRING_NAME
"\n"
1722 ".ds " QUOTE_STRING_NAME
"\n"
1723 ".nr " NEED_BOTTOM_RULE_REG
" 1\n"
1724 ".nr " SUPPRESS_BOTTOM_REG
" 0\n"
1726 ".de " REPEATED_MARK_MACRO
"\n"
1728 ".if !'\\n(.z'' \\!." REPEATED_MARK_MACRO
" \"\\$1\"\n"
1730 ".de " REPEATED_VPT_MACRO
"\n"
1732 ".if !'\\n(.z'' \\!." REPEATED_VPT_MACRO
" \"\\$1\"\n"
1734 if (!(flags
& NOKEEP
))
1735 prints(".de " KEEP_MACRO_NAME
"\n"
1736 ".if '\\n[.z]'' \\{.ds " QUOTE_STRING_NAME
" \\\\\n"
1737 ".ds " TRANSPARENT_STRING_NAME
" \\!\n"
1738 ".di " SECTION_DIVERSION_NAME
"\n"
1739 ".nr " SECTION_DIVERSION_FLAG_REG
" 1\n"
1743 ".de " RELEASE_MACRO_NAME
"\n"
1744 ".if \\n[" SECTION_DIVERSION_FLAG_REG
"] \\{"
1746 ".in \\n[" SAVED_INDENT_REG
"]u\n"
1747 ".nr " SAVED_DN_REG
" \\n[dn]\n"
1748 ".ds " QUOTE_STRING_NAME
"\n"
1749 ".ds " TRANSPARENT_STRING_NAME
"\n"
1750 ".nr " SECTION_DIVERSION_FLAG_REG
" 0\n"
1751 ".if \\n[.t]<=\\n[dn] \\{"
1754 ".nr " SUPPRESS_BOTTOM_REG
" 1\n"
1756 ".nr " SUPPRESS_BOTTOM_REG
" 0\n"
1759 ".if \\n[.t]<=\\n[" SAVED_DN_REG
"] "
1760 /* Since we turn off traps, it won't get into an infinite loop
1761 when we try and print it; it will just go off the bottom of the
1763 ".tm warning: page \\n%: table text block will not fit on one page\n"
1766 "." SECTION_DIVERSION_NAME
"\n"
1768 ".rm " SECTION_DIVERSION_NAME
"\n"
1771 ".nr " TABLE_DIVERSION_FLAG_REG
" 0\n"
1772 ".de " TABLE_KEEP_MACRO_NAME
"\n"
1773 ".if '\\n[.z]'' \\{"
1774 ".di " TABLE_DIVERSION_NAME
"\n"
1775 ".nr " TABLE_DIVERSION_FLAG_REG
" 1\n"
1778 ".de " TABLE_RELEASE_MACRO_NAME
"\n"
1779 ".if \\n[" TABLE_DIVERSION_FLAG_REG
"] \\{.br\n"
1781 ".nr " SAVED_DN_REG
" \\n[dn]\n"
1782 ".ne \\n[dn]u+\\n[.V]u\n"
1783 ".ie \\n[.t]<=\\n[" SAVED_DN_REG
"] "
1784 ".tm error: page \\n%: table will not fit on one page; use .TS H/.TH with a supporting macro package\n"
1789 "." TABLE_DIVERSION_NAME
"\n"
1791 ".rm " TABLE_DIVERSION_NAME
"\n"
1799 string
block_width_reg(int r
, int c
)
1801 static char name
[sizeof(BLOCK_WIDTH_PREFIX
)+INT_DIGITS
+1+INT_DIGITS
];
1802 sprintf(name
, BLOCK_WIDTH_PREFIX
"%d,%d", r
, c
);
1803 return string(name
);
1806 string
block_diversion_name(int r
, int c
)
1808 static char name
[sizeof(BLOCK_DIVERSION_PREFIX
)+INT_DIGITS
+1+INT_DIGITS
];
1809 sprintf(name
, BLOCK_DIVERSION_PREFIX
"%d,%d", r
, c
);
1810 return string(name
);
1813 string
block_height_reg(int r
, int c
)
1815 static char name
[sizeof(BLOCK_HEIGHT_PREFIX
)+INT_DIGITS
+1+INT_DIGITS
];
1816 sprintf(name
, BLOCK_HEIGHT_PREFIX
"%d,%d", r
, c
);
1817 return string(name
);
1820 string
span_width_reg(int start_col
, int end_col
)
1822 static char name
[sizeof(SPAN_WIDTH_PREFIX
)+INT_DIGITS
+1+INT_DIGITS
];
1823 sprintf(name
, SPAN_WIDTH_PREFIX
"%d", start_col
);
1824 if (end_col
!= start_col
)
1825 sprintf(strchr(name
, '\0'), ",%d", end_col
);
1826 return string(name
);
1829 string
span_left_numeric_width_reg(int start_col
, int end_col
)
1831 static char name
[sizeof(SPAN_LEFT_NUMERIC_WIDTH_PREFIX
)+INT_DIGITS
+1+INT_DIGITS
];
1832 sprintf(name
, SPAN_LEFT_NUMERIC_WIDTH_PREFIX
"%d", start_col
);
1833 if (end_col
!= start_col
)
1834 sprintf(strchr(name
, '\0'), ",%d", end_col
);
1835 return string(name
);
1838 string
span_right_numeric_width_reg(int start_col
, int end_col
)
1840 static char name
[sizeof(SPAN_RIGHT_NUMERIC_WIDTH_PREFIX
)+INT_DIGITS
+1+INT_DIGITS
];
1841 sprintf(name
, SPAN_RIGHT_NUMERIC_WIDTH_PREFIX
"%d", start_col
);
1842 if (end_col
!= start_col
)
1843 sprintf(strchr(name
, '\0'), ",%d", end_col
);
1844 return string(name
);
1847 string
span_alphabetic_width_reg(int start_col
, int end_col
)
1849 static char name
[sizeof(SPAN_ALPHABETIC_WIDTH_PREFIX
)+INT_DIGITS
+1+INT_DIGITS
];
1850 sprintf(name
, SPAN_ALPHABETIC_WIDTH_PREFIX
"%d", start_col
);
1851 if (end_col
!= start_col
)
1852 sprintf(strchr(name
, '\0'), ",%d", end_col
);
1853 return string(name
);
1856 string
column_separation_reg(int col
)
1858 static char name
[sizeof(COLUMN_SEPARATION_PREFIX
)+INT_DIGITS
];
1859 sprintf(name
, COLUMN_SEPARATION_PREFIX
"%d", col
);
1860 return string(name
);
1863 string
row_start_reg(int row
)
1865 static char name
[sizeof(ROW_START_PREFIX
)+INT_DIGITS
];
1866 sprintf(name
, ROW_START_PREFIX
"%d", row
);
1867 return string(name
);
1870 string
column_start_reg(int col
)
1872 static char name
[sizeof(COLUMN_START_PREFIX
)+INT_DIGITS
];
1873 sprintf(name
, COLUMN_START_PREFIX
"%d", col
);
1874 return string(name
);
1877 string
column_end_reg(int col
)
1879 static char name
[sizeof(COLUMN_END_PREFIX
)+INT_DIGITS
];
1880 sprintf(name
, COLUMN_END_PREFIX
"%d", col
);
1881 return string(name
);
1884 string
column_divide_reg(int col
)
1886 static char name
[sizeof(COLUMN_DIVIDE_PREFIX
)+INT_DIGITS
];
1887 sprintf(name
, COLUMN_DIVIDE_PREFIX
"%d", col
);
1888 return string(name
);
1891 string
row_top_reg(int row
)
1893 static char name
[sizeof(ROW_TOP_PREFIX
)+INT_DIGITS
];
1894 sprintf(name
, ROW_TOP_PREFIX
"%d", row
);
1895 return string(name
);
1898 void init_span_reg(int start_col
, int end_col
)
1900 printfs(".nr %1 \\n(.H\n.nr %2 0\n.nr %3 0\n.nr %4 0\n",
1901 span_width_reg(start_col
, end_col
),
1902 span_alphabetic_width_reg(start_col
, end_col
),
1903 span_left_numeric_width_reg(start_col
, end_col
),
1904 span_right_numeric_width_reg(start_col
, end_col
));
1907 void compute_span_width(int start_col
, int end_col
)
1909 printfs(".nr %1 \\n[%1]>?(\\n[%2]+\\n[%3])\n"
1910 ".if \\n[%4] .nr %1 \\n[%1]>?(\\n[%4]+2n)\n",
1911 span_width_reg(start_col
, end_col
),
1912 span_left_numeric_width_reg(start_col
, end_col
),
1913 span_right_numeric_width_reg(start_col
, end_col
),
1914 span_alphabetic_width_reg(start_col
, end_col
));
1917 // Increase the widths of columns so that the width of any spanning entry
1918 // is not greater than the sum of the widths of the columns that it spans.
1919 // Ensure that the widths of columns remain equal.
1921 void table::divide_span(int start_col
, int end_col
)
1923 assert(end_col
> start_col
);
1924 printfs(".nr " NEEDED_REG
" \\n[%1]-(\\n[%2]",
1925 span_width_reg(start_col
, end_col
),
1926 span_width_reg(start_col
, start_col
));
1928 for (i
= start_col
+ 1; i
<= end_col
; i
++) {
1929 // The column separation may shrink with the expand option.
1930 if (!(flags
& EXPAND
))
1931 printfs("+%1n", as_string(column_separation
[i
- 1]));
1932 printfs("+\\n[%1]", span_width_reg(i
, i
));
1935 printfs(".nr " NEEDED_REG
" \\n[" NEEDED_REG
"]/%1\n",
1936 as_string(end_col
- start_col
+ 1));
1937 prints(".if \\n[" NEEDED_REG
"] \\{");
1938 for (i
= start_col
; i
<= end_col
; i
++)
1939 printfs(".nr %1 +\\n[" NEEDED_REG
"]\n",
1940 span_width_reg(i
, i
));
1942 for (i
= start_col
; i
<= end_col
&& !equal_flag
; i
++)
1946 for (i
= 0; i
< ncolumns
; i
++)
1947 if (i
< start_col
|| i
> end_col
)
1948 printfs(".nr %1 +\\n[" NEEDED_REG
"]\n",
1949 span_width_reg(i
, i
));
1954 void table::sum_columns(int start_col
, int end_col
)
1956 assert(end_col
> start_col
);
1957 printfs(".nr %1 \\n[%2]",
1958 span_width_reg(start_col
, end_col
),
1959 span_width_reg(start_col
, start_col
));
1960 for (int i
= start_col
+ 1; i
<= end_col
; i
++)
1961 printfs("+(%1*\\n[" SEPARATION_FACTOR_REG
"])+\\n[%2]",
1962 as_string(column_separation
[i
- 1]),
1963 span_width_reg(i
, i
));
1967 horizontal_span::horizontal_span(int sc
, int ec
, horizontal_span
*p
)
1968 : next(p
), start_col(sc
), end_col(ec
)
1972 void table::build_span_list()
1975 table_entry
*p
= entry_list
;
1977 if (p
->end_col
!= p
->start_col
) {
1979 for (q
= span_list
; q
; q
= q
->next
)
1980 if (q
->start_col
== p
->start_col
1981 && q
->end_col
== p
->end_col
)
1984 span_list
= new horizontal_span(p
->start_col
, p
->end_col
, span_list
);
1988 // Now sort span_list primarily by order of end_row, and secondarily
1989 // by reverse order of start_row. This ensures that if we divide
1990 // spans using the order in span_list, we will get reasonable results.
1991 horizontal_span
*unsorted
= span_list
;
1994 horizontal_span
**pp
;
1995 for (pp
= &span_list
; *pp
; pp
= &(*pp
)->next
)
1996 if (unsorted
->end_col
< (*pp
)->end_col
1997 || (unsorted
->end_col
== (*pp
)->end_col
1998 && (unsorted
->start_col
> (*pp
)->start_col
)))
2000 horizontal_span
*tem
= unsorted
->next
;
2001 unsorted
->next
= *pp
;
2007 void table::compute_separation_factor()
2009 if (flags
& (ALLBOX
|BOX
|DOUBLEBOX
))
2010 left_separation
= right_separation
= 1;
2012 for (int i
= 0; i
< nrows
; i
++) {
2013 if (vline
[i
][0] > 0)
2014 left_separation
= 1;
2015 if (vline
[i
][ncolumns
] > 0)
2016 right_separation
= 1;
2019 if (flags
& EXPAND
) {
2020 int total_sep
= left_separation
+ right_separation
;
2022 for (i
= 0; i
< ncolumns
- 1; i
++)
2023 total_sep
+= column_separation
[i
];
2024 if (total_sep
!= 0) {
2025 // Don't let the separation factor be negative.
2026 prints(".nr " SEPARATION_FACTOR_REG
" \\n[.l]-\\n[.i]");
2027 for (i
= 0; i
< ncolumns
; i
++)
2028 printfs("-\\n[%1]", span_width_reg(i
, i
));
2029 printfs("/%1>?0\n", as_string(total_sep
));
2034 void table::compute_column_positions()
2036 printfs(".nr %1 0\n", column_divide_reg(0));
2037 printfs(".nr %1 %2*\\n[" SEPARATION_FACTOR_REG
"]\n",
2038 column_start_reg(0),
2039 as_string(left_separation
));
2042 printfs(".nr %1 \\n[%2]+\\n[%3]\n",
2043 column_end_reg(i
-1),
2044 column_start_reg(i
-1),
2045 span_width_reg(i
-1, i
-1));
2048 printfs(".nr %1 \\n[%2]+(%3*\\n[" SEPARATION_FACTOR_REG
"])\n",
2049 column_start_reg(i
),
2050 column_end_reg(i
-1),
2051 as_string(column_separation
[i
-1]));
2052 printfs(".nr %1 \\n[%2]+\\n[%3]/2\n",
2053 column_divide_reg(i
),
2054 column_end_reg(i
-1),
2055 column_start_reg(i
));
2057 printfs(".nr %1 \\n[%2]+(%3*\\n[" SEPARATION_FACTOR_REG
"])\n",
2058 column_divide_reg(ncolumns
),
2059 column_end_reg(i
-1),
2060 as_string(right_separation
));
2061 printfs(".nr TW \\n[%1]\n",
2062 column_divide_reg(ncolumns
));
2063 if (flags
& DOUBLEBOX
) {
2064 printfs(".nr %1 +" DOUBLE_LINE_SEP
"\n", column_divide_reg(0));
2065 printfs(".nr %1 -" DOUBLE_LINE_SEP
"\n", column_divide_reg(ncolumns
));
2069 void table::make_columns_equal()
2071 int first
= -1; // index of first equal column
2073 for (i
= 0; i
< ncolumns
; i
++)
2076 printfs(".nr %1 \\n[%1]", span_width_reg(i
, i
));
2080 printfs(">?\\n[%1]", span_width_reg(i
, i
));
2084 for (i
= first
+ 1; i
< ncolumns
; i
++)
2086 printfs(".nr %1 \\n[%2]\n",
2087 span_width_reg(i
, i
),
2088 span_width_reg(first
, first
));
2092 void table::compute_widths()
2097 prints(".nr " SEPARATION_FACTOR_REG
" 1n\n");
2098 for (i
= 0; i
< ncolumns
; i
++) {
2099 init_span_reg(i
, i
);
2100 if (!minimum_width
[i
].empty())
2101 printfs(".nr %1 %2\n", span_width_reg(i
, i
), minimum_width
[i
]);
2103 for (p
= span_list
; p
; p
= p
->next
)
2104 init_span_reg(p
->start_col
, p
->end_col
);
2106 for (q
= entry_list
; q
; q
= q
->next
)
2107 if (!q
->mod
->zero_width
)
2109 for (i
= 0; i
< ncolumns
; i
++)
2110 compute_span_width(i
, i
);
2111 for (p
= span_list
; p
; p
= p
->next
)
2112 compute_span_width(p
->start_col
, p
->end_col
);
2113 make_columns_equal();
2114 // Note that divide_span keeps equal width columns equal.
2115 for (p
= span_list
; p
; p
= p
->next
)
2116 divide_span(p
->start_col
, p
->end_col
);
2117 for (p
= span_list
; p
; p
= p
->next
)
2118 sum_columns(p
->start_col
, p
->end_col
);
2119 int had_spanning_block
= 0;
2120 int had_equal_block
= 0;
2121 for (q
= entry_list
; q
; q
= q
->next
)
2122 if (q
->divert(ncolumns
, minimum_width
,
2123 (flags
& EXPAND
) ? column_separation
: 0)) {
2124 if (q
->end_col
> q
->start_col
)
2125 had_spanning_block
= 1;
2126 for (i
= q
->start_col
; i
<= q
->end_col
&& !had_equal_block
; i
++)
2128 had_equal_block
= 1;
2130 if (had_equal_block
)
2131 make_columns_equal();
2132 if (had_spanning_block
)
2133 for (p
= span_list
; p
; p
= p
->next
)
2134 divide_span(p
->start_col
, p
->end_col
);
2135 compute_separation_factor();
2136 for (p
= span_list
; p
; p
= p
->next
)
2137 sum_columns(p
->start_col
, p
->end_col
);
2138 compute_column_positions();
2141 void table::print_single_hline(int r
)
2143 prints(".vs " LINE_SEP
">?\\n[.V]u\n"
2145 "\\v'" BODY_DEPTH
"'"
2146 "\\s[\\n[" LINESIZE_REG
"]]");
2148 prints("\\D'l |\\n[TW]u 0'");
2152 while (start_col
< ncolumns
2153 && entry
[r
][start_col
] != 0
2154 && entry
[r
][start_col
]->start_row
!= r
)
2157 for (end_col
= start_col
;
2159 && (entry
[r
][end_col
] == 0
2160 || entry
[r
][end_col
]->start_row
== r
);
2163 if (end_col
<= start_col
)
2165 printfs("\\h'|\\n[%1]u",
2166 column_divide_reg(start_col
));
2167 if ((r
> 0 && vline
[r
-1][start_col
] == 2)
2168 || (r
< nrows
&& vline
[r
][start_col
] == 2))
2169 prints("-" HALF_DOUBLE_LINE_SEP
);
2171 printfs("\\D'l |\\n[%1]u",
2172 column_divide_reg(end_col
));
2173 if ((r
> 0 && vline
[r
-1][end_col
] == 2)
2174 || (r
< nrows
&& vline
[r
][end_col
] == 2))
2175 prints("+" HALF_DOUBLE_LINE_SEP
);
2177 start_col
= end_col
;
2185 void table::print_double_hline(int r
)
2187 prints(".vs " LINE_SEP
"+" DOUBLE_LINE_SEP
2190 "\\v'" BODY_DEPTH
"'"
2191 "\\s[\\n[" LINESIZE_REG
"]]");
2193 prints("\\v'-" DOUBLE_LINE_SEP
"'"
2194 "\\D'l |\\n[TW]u 0'"
2195 "\\v'" DOUBLE_LINE_SEP
"'"
2197 "\\D'l |\\n[TW]u 0'");
2201 while (start_col
< ncolumns
2202 && entry
[r
][start_col
] != 0
2203 && entry
[r
][start_col
]->start_row
!= r
)
2206 for (end_col
= start_col
;
2208 && (entry
[r
][end_col
] == 0
2209 || entry
[r
][end_col
]->start_row
== r
);
2212 if (end_col
<= start_col
)
2214 const char *left_adjust
= 0;
2215 if ((r
> 0 && vline
[r
-1][start_col
] == 2)
2216 || (r
< nrows
&& vline
[r
][start_col
] == 2))
2217 left_adjust
= "-" HALF_DOUBLE_LINE_SEP
;
2218 const char *right_adjust
= 0;
2219 if ((r
> 0 && vline
[r
-1][end_col
] == 2)
2220 || (r
< nrows
&& vline
[r
][end_col
] == 2))
2221 right_adjust
= "+" HALF_DOUBLE_LINE_SEP
;
2222 printfs("\\v'-" DOUBLE_LINE_SEP
"'"
2224 column_divide_reg(start_col
));
2226 prints(left_adjust
);
2228 printfs("\\D'l |\\n[%1]u",
2229 column_divide_reg(end_col
));
2231 prints(right_adjust
);
2233 printfs("\\v'" DOUBLE_LINE_SEP
"'"
2235 column_divide_reg(start_col
));
2237 prints(left_adjust
);
2239 printfs("\\D'l |\\n[%1]u",
2240 column_divide_reg(end_col
));
2242 prints(right_adjust
);
2244 start_col
= end_col
;
2252 void table::compute_vrule_top_adjust(int start_row
, int col
, string
&result
)
2254 if (row_is_all_lines
[start_row
] && start_row
< nrows
- 1) {
2255 if (row_is_all_lines
[start_row
] == 2)
2256 result
= LINE_SEP
">?\\n[.V]u" "+" DOUBLE_LINE_SEP
;
2258 result
= LINE_SEP
">?\\n[.V]u";
2265 for (stuff
*p
= stuff_list
; p
&& p
->row
<= start_row
; p
= p
->next
)
2266 if (p
->row
== start_row
2267 && (p
->is_single_line() || p
->is_double_line()))
2272 table_entry
*e
= entry
[start_row
-1][col
-1];
2273 if (e
&& e
->start_row
== e
->end_row
) {
2274 if (e
->to_double_line_entry() != 0)
2276 else if (e
->to_single_line_entry() != 0)
2281 if (col
< ncolumns
) {
2282 table_entry
*e
= entry
[start_row
-1][col
];
2283 if (e
&& e
->start_row
== e
->end_row
) {
2284 if (e
->to_double_line_entry() != 0)
2286 else if (e
->to_single_line_entry() != 0)
2290 if (row_is_all_lines
[start_row
-1] == 0) {
2291 if (left
> 0 || right
> 0) {
2292 result
+= "-" BODY_DEPTH
"-" BAR_HEIGHT
;
2293 if ((left
== 2 && right
!= 2) || (right
== 2 && left
!= 2))
2294 result
+= "-" HALF_DOUBLE_LINE_SEP
;
2295 else if (left
== 2 && right
== 2)
2296 result
+= "+" HALF_DOUBLE_LINE_SEP
;
2299 else if (row_is_all_lines
[start_row
-1] == 2) {
2300 if ((left
== 2 && right
!= 2) || (right
== 2 && left
!= 2))
2301 result
+= "-" DOUBLE_LINE_SEP
;
2302 else if (left
== 1 || right
== 1)
2303 result
+= "-" HALF_DOUBLE_LINE_SEP
;
2307 void table::compute_vrule_bot_adjust(int end_row
, int col
, string
&result
)
2309 if (row_is_all_lines
[end_row
] && end_row
> 0) {
2315 for (p
= stuff_list
; p
&& p
->row
< end_row
+ 1; p
= p
->next
)
2317 if (p
&& p
->row
== end_row
+ 1 && p
->is_double_line()) {
2318 result
= "-" DOUBLE_LINE_SEP
;
2321 if ((p
!= 0 && p
->row
== end_row
+ 1)
2322 || end_row
== nrows
- 1) {
2326 if (row_is_all_lines
[end_row
+1] == 1)
2328 else if (row_is_all_lines
[end_row
+1] == 2)
2329 result
= LINE_SEP
"+" DOUBLE_LINE_SEP
;
2335 table_entry
*e
= entry
[end_row
+1][col
-1];
2336 if (e
&& e
->start_row
== e
->end_row
) {
2337 if (e
->to_double_line_entry() != 0)
2339 else if (e
->to_single_line_entry() != 0)
2344 if (col
< ncolumns
) {
2345 table_entry
*e
= entry
[end_row
+1][col
];
2346 if (e
&& e
->start_row
== e
->end_row
) {
2347 if (e
->to_double_line_entry() != 0)
2349 else if (e
->to_single_line_entry() != 0)
2353 if (row_is_all_lines
[end_row
+1] == 0) {
2354 if (left
> 0 || right
> 0) {
2355 result
= "1v-" BODY_DEPTH
"-" BAR_HEIGHT
;
2356 if ((left
== 2 && right
!= 2) || (right
== 2 && left
!= 2))
2357 result
+= "+" HALF_DOUBLE_LINE_SEP
;
2358 else if (left
== 2 && right
== 2)
2359 result
+= "-" HALF_DOUBLE_LINE_SEP
;
2362 else if (row_is_all_lines
[end_row
+1] == 2) {
2363 if (left
== 2 && right
== 2)
2364 result
+= "-" DOUBLE_LINE_SEP
;
2365 else if (left
!= 2 && right
!= 2 && (left
== 1 || right
== 1))
2366 result
+= "-" HALF_DOUBLE_LINE_SEP
;
2370 void table::add_vertical_rule(int start_row
, int end_row
, int col
, int is_double
)
2372 vrule_list
= new vertical_rule(start_row
, end_row
, col
, is_double
,
2374 compute_vrule_top_adjust(start_row
, col
, vrule_list
->top_adjust
);
2375 compute_vrule_bot_adjust(end_row
, col
, vrule_list
->bot_adjust
);
2378 void table::build_vrule_list()
2381 if (flags
& ALLBOX
) {
2382 for (col
= 1; col
< ncolumns
; col
++) {
2385 while (start_row
< nrows
&& vline_spanned(start_row
, col
))
2387 if (start_row
>= nrows
)
2389 int end_row
= start_row
;
2390 while (end_row
< nrows
&& !vline_spanned(end_row
, col
))
2393 add_vertical_rule(start_row
, end_row
, col
, 0);
2394 start_row
= end_row
+ 1;
2398 if (flags
& (BOX
|ALLBOX
|DOUBLEBOX
)) {
2399 add_vertical_rule(0, nrows
- 1, 0, 0);
2400 add_vertical_rule(0, nrows
- 1, ncolumns
, 0);
2402 for (int end_row
= 0; end_row
< nrows
; end_row
++)
2403 for (col
= 0; col
< ncolumns
+1; col
++)
2404 if (vline
[end_row
][col
] > 0
2405 && !vline_spanned(end_row
, col
)
2406 && (end_row
== nrows
- 1
2407 || vline
[end_row
+1][col
] != vline
[end_row
][col
]
2408 || vline_spanned(end_row
+1, col
))) {
2410 for (start_row
= end_row
- 1;
2412 && vline
[start_row
][col
] == vline
[end_row
][col
]
2413 && !vline_spanned(start_row
, col
);
2417 add_vertical_rule(start_row
, end_row
, col
, vline
[end_row
][col
] > 1);
2419 for (vertical_rule
*p
= vrule_list
; p
; p
= p
->next
)
2421 for (int r
= p
->start_row
; r
<= p
->end_row
; r
++) {
2422 if (p
->col
> 0 && entry
[r
][p
->col
-1] != 0
2423 && entry
[r
][p
->col
-1]->end_col
== p
->col
-1) {
2424 int is_corner
= r
== p
->start_row
|| r
== p
->end_row
;
2425 entry
[r
][p
->col
-1]->note_double_vrule_on_right(is_corner
);
2427 if (p
->col
< ncolumns
&& entry
[r
][p
->col
] != 0
2428 && entry
[r
][p
->col
]->start_col
== p
->col
) {
2429 int is_corner
= r
== p
->start_row
|| r
== p
->end_row
;
2430 entry
[r
][p
->col
]->note_double_vrule_on_left(is_corner
);
2435 void table::define_bottom_macro()
2439 ".if !\\n[" SUPPRESS_BOTTOM_REG
"] \\{"
2440 "." REPEATED_VPT_MACRO
" 0\n"
2441 ".mk " SAVED_VERTICAL_POS_REG
"\n");
2442 if (flags
& (BOX
|ALLBOX
|DOUBLEBOX
)) {
2443 prints(".if \\n[T.]&\\n[" NEED_BOTTOM_RULE_REG
"] \\{");
2444 print_single_hline(0);
2448 for (vertical_rule
*p
= vrule_list
; p
; p
= p
->next
)
2449 p
->contribute_to_bottom_macro(this);
2450 if (flags
& DOUBLEBOX
)
2451 prints(".if \\n[T.] \\{.vs " DOUBLE_LINE_SEP
">?\\n[.V]u\n"
2452 "\\v'" BODY_DEPTH
"'\\s[\\n[" LINESIZE_REG
"]]"
2453 "\\D'l \\n[TW]u 0'\\s0\n"
2456 ".if \\n[" LAST_PASSED_ROW_REG
"]>=0 "
2457 ".nr " TOP_REG
" \\n[#T]-" DOUBLE_LINE_SEP
"\n"
2459 "\\v'" BODY_DEPTH
"'\\s[\\n[" LINESIZE_REG
"]]"
2460 "\\D'l 0 |\\n[" TOP_REG
"]u-1v'\\s0\n"
2462 "\\v'" BODY_DEPTH
"'\\h'|\\n[TW]u'\\s[\\n[" LINESIZE_REG
"]]"
2463 "\\D'l 0 |\\n[" TOP_REG
"]u-1v'\\s0\n");
2465 prints(".nr " LAST_PASSED_ROW_REG
" \\n[" CURRENT_ROW_REG
"]\n"
2466 ".sp |\\n[" SAVED_VERTICAL_POS_REG
"]u\n"
2467 "." REPEATED_VPT_MACRO
" 1\n"
2473 // is the vertical line before column c in row r horizontally spanned?
2475 int table::vline_spanned(int r
, int c
)
2477 assert(r
>= 0 && r
< nrows
&& c
>= 0 && c
< ncolumns
+ 1);
2478 return (c
!= 0 && c
!= ncolumns
&& entry
[r
][c
] != 0
2479 && entry
[r
][c
]->start_col
!= c
2480 // horizontally spanning lines don't count
2481 && entry
[r
][c
]->to_double_line_entry() == 0
2482 && entry
[r
][c
]->to_single_line_entry() == 0);
2485 int table::row_begins_section(int r
)
2487 assert(r
>= 0 && r
< nrows
);
2488 for (int i
= 0; i
< ncolumns
; i
++)
2489 if (entry
[r
][i
] && entry
[r
][i
]->start_row
!= r
)
2494 int table::row_ends_section(int r
)
2496 assert(r
>= 0 && r
< nrows
);
2497 for (int i
= 0; i
< ncolumns
; i
++)
2498 if (entry
[r
][i
] && entry
[r
][i
]->end_row
!= r
)
2503 void table::do_row(int r
)
2505 if (!(flags
& NOKEEP
) && row_begins_section(r
))
2506 prints("." KEEP_MACRO_NAME
"\n");
2509 for (p
= stuff_list
; p
&& p
->row
< r
; p
= p
->next
)
2511 for (stuff
*p1
= p
; p1
&& p1
->row
== r
; p1
= p1
->next
)
2512 if (!p1
->printed
&& (p1
->is_single_line() || p1
->is_double_line())) {
2516 if (!had_line
&& !row_is_all_lines
[r
])
2517 printfs("." REPEATED_MARK_MACRO
" %1\n", row_top_reg(r
));
2519 for (; p
&& p
->row
== r
; p
= p
->next
)
2522 if (!had_line
&& (p
->is_single_line() || p
->is_double_line())) {
2523 printfs("." REPEATED_MARK_MACRO
" %1\n", row_top_reg(r
));
2527 // Change the row *after* printing the stuff list (which might contain .TH).
2528 printfs("\\*[" TRANSPARENT_STRING_NAME
"].nr " CURRENT_ROW_REG
" %1\n",
2530 if (!had_line
&& row_is_all_lines
[r
])
2531 printfs("." REPEATED_MARK_MACRO
" %1\n", row_top_reg(r
));
2532 // we might have had a .TH, for example, since we last tried
2533 if (!(flags
& NOKEEP
) && row_begins_section(r
))
2534 prints("." KEEP_MACRO_NAME
"\n");
2535 printfs(".mk %1\n", row_start_reg(r
));
2536 prints(".mk " BOTTOM_REG
"\n"
2537 "." REPEATED_VPT_MACRO
" 0\n");
2539 int row_is_blank
= 1;
2540 int first_start_row
= r
;
2541 for (c
= 0; c
< ncolumns
; c
++) {
2542 table_entry
*e
= entry
[r
][c
];
2544 if (e
->end_row
== r
) {
2546 if (e
->start_row
< first_start_row
)
2547 first_start_row
= e
->start_row
;
2554 prints(".nr " BOTTOM_REG
" +1v\n");
2555 if (row_is_all_lines
[r
]) {
2556 prints(".vs " LINE_SEP
);
2557 if (row_is_all_lines
[r
] == 2)
2558 prints("+" DOUBLE_LINE_SEP
);
2559 prints(">?\\n[.V]u\n.ls 1\n");
2561 prints("\\v'" BODY_DEPTH
);
2562 if (row_is_all_lines
[r
] == 2)
2563 prints("-" HALF_DOUBLE_LINE_SEP
);
2565 for (c
= 0; c
< ncolumns
; c
++) {
2566 table_entry
*e
= entry
[r
][c
];
2568 if (e
->end_row
== e
->start_row
)
2569 e
->to_simple_entry()->simple_print(1);
2576 prints(".nr " BOTTOM_REG
" \\n[" BOTTOM_REG
"]>?\\n[.d]\n");
2577 printfs(".sp |\\n[%1]u\n", row_start_reg(r
));
2579 for (int i
= row_is_all_lines
[r
] ? r
- 1 : r
;
2580 i
>= first_start_row
;
2582 simple_entry
*first
= 0;
2583 for (c
= 0; c
< ncolumns
; c
++) {
2584 table_entry
*e
= entry
[r
][c
];
2586 if (e
->end_row
== r
&& e
->start_row
== i
) {
2587 simple_entry
*simple
= e
->to_simple_entry();
2601 first
->position_vertically();
2602 first
->set_location();
2604 first
->simple_print(0);
2605 for (c
= first
->end_col
+ 1; c
< ncolumns
; c
++) {
2606 table_entry
*e
= entry
[r
][c
];
2608 if (e
->end_row
== r
&& e
->start_row
== i
) {
2609 simple_entry
*simple
= e
->to_simple_entry();
2611 if (e
->end_row
!= e
->start_row
) {
2613 simple
->position_vertically();
2616 simple
->simple_print(0);
2623 prints(".nr " BOTTOM_REG
" \\n[" BOTTOM_REG
"]>?\\n[.d]\n");
2624 printfs(".sp |\\n[%1]u\n", row_start_reg(r
));
2627 for (c
= 0; c
< ncolumns
; c
++) {
2628 table_entry
*e
= entry
[r
][c
];
2630 if (e
->end_row
== r
&& e
->to_simple_entry() == 0) {
2631 e
->position_vertically();
2633 prints(".nr " BOTTOM_REG
" \\n[" BOTTOM_REG
"]>?\\n[.d]\n");
2634 printfs(".sp |\\n[%1]u\n", row_start_reg(r
));
2639 prints("." REPEATED_VPT_MACRO
" 1\n"
2640 ".sp |\\n[" BOTTOM_REG
"]u\n"
2641 "\\*[" TRANSPARENT_STRING_NAME
"].nr " NEED_BOTTOM_RULE_REG
" 1\n");
2642 if (r
!= nrows
- 1 && (flags
& ALLBOX
)) {
2643 print_single_hline(r
+ 1);
2644 prints("\\*[" TRANSPARENT_STRING_NAME
"].nr " NEED_BOTTOM_RULE_REG
" 0\n");
2646 if (r
!= nrows
- 1) {
2647 if (p
&& p
->row
== r
+ 1
2648 && (p
->is_single_line() || p
->is_double_line())) {
2650 prints("\\*[" TRANSPARENT_STRING_NAME
"].nr " NEED_BOTTOM_RULE_REG
2653 int printed_one
= 0;
2654 for (vertical_rule
*vr
= vrule_list
; vr
; vr
= vr
->next
)
2655 if (vr
->end_row
== r
) {
2657 prints("." REPEATED_VPT_MACRO
" 0\n");
2663 prints("." REPEATED_VPT_MACRO
" 1\n");
2664 if (!(flags
& NOKEEP
) && row_ends_section(r
))
2665 prints("." RELEASE_MACRO_NAME
"\n");
2669 void table::do_top()
2671 prints(".fc \002\003\n");
2672 if (!(flags
& NOKEEP
) && (flags
& (BOX
|DOUBLEBOX
|ALLBOX
)))
2673 prints("." TABLE_KEEP_MACRO_NAME
"\n");
2674 if (flags
& DOUBLEBOX
) {
2676 ".vs " LINE_SEP
">?\\n[.V]u\n"
2677 "\\v'" BODY_DEPTH
"'\\s[\\n[" LINESIZE_REG
"]]\\D'l \\n[TW]u 0'\\s0\n"
2679 "." REPEATED_MARK_MACRO
" " TOP_REG
"\n"
2680 ".vs " DOUBLE_LINE_SEP
">?\\n[.V]u\n");
2681 printfs("\\v'" BODY_DEPTH
"'"
2682 "\\s[\\n[" LINESIZE_REG
"]]"
2684 "\\D'l |\\n[%2]u 0'"
2687 column_divide_reg(0),
2688 column_divide_reg(ncolumns
));
2692 else if (flags
& (ALLBOX
|BOX
)) {
2693 print_single_hline(0);
2695 //printfs(".mk %1\n", row_top_reg(0));
2698 void table::do_bottom()
2700 // print stuff after last row
2701 for (stuff
*p
= stuff_list
; p
; p
= p
->next
)
2702 if (p
->row
> nrows
- 1)
2704 if (!(flags
& NOKEEP
))
2705 prints("." RELEASE_MACRO_NAME
"\n");
2706 printfs(".mk %1\n", row_top_reg(nrows
));
2707 prints(".nr " NEED_BOTTOM_RULE_REG
" 1\n"
2710 if (!(flags
& NOKEEP
) && (flags
& (BOX
|DOUBLEBOX
|ALLBOX
)))
2711 prints("." TABLE_RELEASE_MACRO_NAME
"\n");
2712 if (flags
& DOUBLEBOX
)
2713 prints(".sp " DOUBLE_LINE_SEP
"\n");
2714 prints("." RESET_MACRO_NAME
"\n"
2716 ".cp \\n(" COMPATIBLE_REG
"\n");
2719 int table::get_nrows()
2724 const char *last_filename
= 0;
2726 void set_troff_location(const char *fn
, int ln
)
2728 if (!location_force_filename
&& last_filename
!= 0
2729 && strcmp(fn
, last_filename
) == 0)
2730 printfs(".lf %1\n", as_string(ln
));
2732 printfs(".lf %1 %2\n", as_string(ln
), fn
);
2734 location_force_filename
= 0;
2738 void printfs(const char *s
, const string
&arg1
, const string
&arg2
,
2739 const string
&arg3
, const string
&arg4
, const string
&arg5
)
2743 while ((c
= *s
++) != '\0') {