A try at the new rule for block column allocation is now enabled by
[s-roff.git] / src / preproc / tbl / table.h
blob6daf5773c2a4269a8c1cdd98193a2bb8b96a5c65
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 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
11 version.
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
16 for more details.
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. */
22 #include "lib.h"
24 #include <stdlib.h>
25 #include <assert.h>
26 #include <ctype.h>
27 #include <errno.h>
28 #include <stdbool.h>
30 #include "cset.h"
31 #include "cmap.h"
32 #include "stringclass.h"
33 #include "errarg.h"
34 #include "error.h"
36 // PREFIX and PREFIX_CHAR must be the same.
37 #define PREFIX "3"
38 #define PREFIX_CHAR '3'
40 // LEADER and LEADER_CHAR must be the same.
41 #define LEADER "a"
42 #define LEADER_CHAR 'a'
44 struct inc_number {
45 short inc;
46 short val;
49 struct entry_modifier {
50 inc_number point_size;
51 inc_number vertical_spacing;
52 string font;
53 string macro;
54 enum { CENTER, TOP, BOTTOM } vertical_alignment;
55 char zero_width;
56 char stagger;
58 entry_modifier();
59 ~entry_modifier();
62 enum format_type {
63 FORMAT_LEFT,
64 FORMAT_CENTER,
65 FORMAT_RIGHT,
66 FORMAT_NUMERIC,
67 FORMAT_ALPHABETIC,
68 FORMAT_SPAN,
69 FORMAT_VSPAN,
70 FORMAT_HLINE,
71 FORMAT_DOUBLE_HLINE
74 struct entry_format : public entry_modifier {
75 format_type type;
77 entry_format(format_type);
78 entry_format();
79 void debug_print() const;
82 class table_entry;
83 struct horizontal_span;
84 struct stuff;
85 struct vertical_rule;
87 class table {
88 int nrows;
89 int ncolumns;
90 int linesize;
91 char delim[2];
92 char decimal_point_char;
93 vertical_rule *vrule_list;
94 stuff *stuff_list;
95 horizontal_span *span_list;
96 table_entry *entry_list;
97 table_entry **entry_list_tailp;
98 table_entry ***entry;
99 char **vline;
100 char *row_is_all_lines;
101 string *minimum_width;
102 int *column_separation;
103 char *equal;
104 int left_separation;
105 int right_separation;
106 int allocated_rows;
107 void build_span_list();
108 void do_hspan(int r, int c);
109 void do_vspan(int r, int c);
110 void allocate(int r);
111 void compute_widths();
112 void divide_span(int, int);
113 void sum_columns(int, int);
114 void compute_separation_factor();
115 void compute_column_positions();
116 void do_row(int);
117 void init_output();
118 void add_stuff(stuff *);
119 void do_top();
120 void do_bottom();
121 void do_vertical_rules();
122 void build_vrule_list();
123 void add_vertical_rule(int, int, int, int);
124 void define_bottom_macro();
125 int vline_spanned(int r, int c);
126 int row_begins_section(int);
127 int row_ends_section(int);
128 void make_columns_equal();
129 void compute_vrule_top_adjust(int, int, string &);
130 void compute_vrule_bot_adjust(int, int, string &);
131 void determine_row_type();
132 int count_block_columns();
133 public:
134 bool *blockflag;
135 unsigned flags;
136 enum {
137 CENTER = 0x00000001,
138 EXPAND = 0x00000002,
139 BOX = 0x00000004,
140 ALLBOX = 0x00000008,
141 DOUBLEBOX = 0x00000010,
142 NOKEEP = 0x00000020,
143 NOSPACES = 0x00000040,
144 EXPERIMENTAL = 0x80000000, // undocumented; use as a hook for experiments
146 table(int nc, unsigned flags, int linesize, char decimal_point_char);
147 ~table();
149 void add_text_line(int r, const string &, const char *, int);
150 void add_single_hline(int r);
151 void add_double_hline(int r);
152 void add_entry(int r, int c, const string &, const entry_format *,
153 const char *, int lineno);
154 void add_vlines(int r, const char *);
155 void check();
156 void print();
157 void set_minimum_width(int c, const string &w);
158 void set_column_separation(int c, int n);
159 void set_equal_column(int c);
160 void set_delim(char c1, char c2);
161 void print_single_hline(int r);
162 void print_double_hline(int r);
163 int get_nrows();
166 void set_troff_location(const char *, int);
168 extern int compatible_flag;