5892867d84fd8503b2fd59443308fc336e53bedd
[platform/upstream/groff.git] / src / preproc / tbl / table.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989-2014  Free Software Foundation, Inc.
3      Written by James Clark (jjc@jclark.com)
4
5 This file is part of groff.
6
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "lib.h"
21
22 #include <stdlib.h>
23 #include <assert.h>
24 #include <ctype.h>
25 #include <errno.h>
26
27 #include "cset.h"
28 #include "cmap.h"
29 #include "stringclass.h"
30 #include "errarg.h"
31 #include "error.h"
32
33 // PREFIX and PREFIX_CHAR must be the same.
34 #define PREFIX "3"
35 #define PREFIX_CHAR '3'
36
37 // LEADER and LEADER_CHAR must be the same.
38 #define LEADER "a"
39 #define LEADER_CHAR 'a'
40
41 struct inc_number {
42   short inc;
43   short val;
44 };
45
46 struct entry_modifier {
47   inc_number point_size;
48   inc_number vertical_spacing;
49   string font;
50   string macro;
51   enum { CENTER, TOP, BOTTOM } vertical_alignment;
52   char zero_width;
53   char stagger;
54
55   entry_modifier();
56   ~entry_modifier();
57 };
58
59 enum format_type {
60   FORMAT_LEFT, 
61   FORMAT_CENTER, 
62   FORMAT_RIGHT, 
63   FORMAT_NUMERIC,
64   FORMAT_ALPHABETIC,
65   FORMAT_SPAN, 
66   FORMAT_VSPAN,
67   FORMAT_HLINE,
68   FORMAT_DOUBLE_HLINE
69 };
70
71 struct entry_format : public entry_modifier {
72   format_type type;
73
74   entry_format(format_type);
75   entry_format();
76   void debug_print() const;
77 };
78
79 class table_entry;
80 struct horizontal_span;
81 struct stuff;
82 struct vertical_rule;
83
84 class table {
85   int nrows;
86   int ncolumns;
87   int linesize;
88   char delim[2];
89   char decimal_point_char;
90   vertical_rule *vrule_list;
91   stuff *stuff_list;
92   horizontal_span *span_list;
93   table_entry *entry_list;
94   table_entry **entry_list_tailp;
95   table_entry ***entry;
96   char **vline;
97   char *row_is_all_lines;
98   string *minimum_width;
99   int *column_separation;
100   char *equal;
101   int left_separation;
102   int right_separation;
103   int total_separation;
104   int allocated_rows;
105   void build_span_list();
106   void compute_expand_width();
107   void do_hspan(int r, int c);
108   void do_vspan(int r, int c);
109   void allocate(int r);
110   void compute_widths();
111   void divide_span(int, int);
112   void sum_columns(int, int, int);
113   void compute_total_separation();
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_expand_columns();
133 public:
134   unsigned flags;
135   enum {
136     CENTER       = 0x00000001,
137     EXPAND       = 0x00000002,
138     BOX          = 0x00000004,
139     ALLBOX       = 0x00000008,
140     DOUBLEBOX    = 0x00000010,
141     NOKEEP       = 0x00000020,
142     NOSPACES     = 0x00000040,
143     NOWARN       = 0x00000080,
144     EXPERIMENTAL = 0x80000000   // undocumented; use as a hook for experiments
145     };
146   char *expand;
147   table(int nc, unsigned flags, int linesize, char decimal_point_char);
148   ~table();
149
150   void add_text_line(int r, const string &, const char *, int);
151   void add_single_hline(int r);
152   void add_double_hline(int r);
153   void add_entry(int r, int c, const string &, const entry_format *,
154                  const char *, int lineno);
155   void add_vlines(int r, const char *);
156   void check();
157   void print();
158   void set_minimum_width(int c, const string &w);
159   void set_column_separation(int c, int n);
160   void set_equal_column(int c);
161   void set_expand_column(int c);
162   void set_delim(char c1, char c2);
163   void print_single_hline(int r);
164   void print_double_hline(int r);
165   int get_nrows();
166 };
167
168 void set_troff_location(const char *, int);
169
170 extern int compatible_flag;