1 // -*- C++ -*-
2 /* Copyright (C) 1989-2018 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 #include "lf.h"
33 
34 // PREFIX and PREFIX_CHAR must be the same.
35 #define PREFIX "3"
36 #define PREFIX_CHAR '3'
37 
38 // LEADER and LEADER_CHAR must be the same.
39 #define LEADER "a"
40 #define LEADER_CHAR 'a'
41 
42 struct inc_number {
43   short inc;
44   short val;
45 };
46 
47 struct entry_modifier {
48   inc_number point_size;
49   inc_number vertical_spacing;
50   string font;
51   string macro;
52   enum { CENTER, TOP, BOTTOM } vertical_alignment;
53   char zero_width;
54   char stagger;
55 
56   entry_modifier();
57   ~entry_modifier();
58 };
59 
60 enum format_type {
61   FORMAT_LEFT,
62   FORMAT_CENTER,
63   FORMAT_RIGHT,
64   FORMAT_NUMERIC,
65   FORMAT_ALPHABETIC,
66   FORMAT_SPAN,
67   FORMAT_VSPAN,
68   FORMAT_HLINE,
69   FORMAT_DOUBLE_HLINE
70 };
71 
72 struct entry_format : public entry_modifier {
73   format_type type;
74 
75   entry_format(format_type);
76   entry_format();
77   void debug_print() const;
78 };
79 
80 class table_entry;
81 struct horizontal_span;
82 struct stuff;
83 struct vertical_rule;
84 
85 class table {
86   int nrows;
87   int ncolumns;
88   int linesize;
89   char delim[2];
90   char decimal_point_char;
91   vertical_rule *vrule_list;
92   stuff *stuff_list;
93   horizontal_span *span_list;
94   table_entry *entry_list;
95   table_entry **entry_list_tailp;
96   table_entry ***entry;
97   char **vline;
98   char *row_is_all_lines;
99   string *minimum_width;
100   int *column_separation;
101   char *equal;
102   int left_separation;
103   int right_separation;
104   int total_separation;
105   int allocated_rows;
106   void build_span_list();
107   void compute_expand_width();
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, int);
114   void compute_total_separation();
115   void compute_separation_factor();
116   void compute_column_positions();
117   void do_row(int);
118   void init_output();
119   void add_stuff(stuff *);
120   void do_top();
121   void do_bottom();
122   void do_vertical_rules();
123   void build_vrule_list();
124   void add_vertical_rule(int, int, int, int);
125   void define_bottom_macro();
126   int vline_spanned(int r, int c);
127   int row_begins_section(int);
128   int row_ends_section(int);
129   void make_columns_equal();
130   void compute_vrule_top_adjust(int, int, string &);
131   void compute_vrule_bot_adjust(int, int, string &);
132   void determine_row_type();
133   int count_expand_columns();
134 public:
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     NOWARN       = 0x00000080,
145     EXPERIMENTAL = 0x80000000	// undocumented; use as a hook for experiments
146     };
147   char *expand;
148   table(int nc, unsigned flags, int linesize, char decimal_point_char);
149   ~table();
150 
151   void add_text_line(int r, const string &, const char *, int);
152   void add_single_hline(int r);
153   void add_double_hline(int r);
154   void add_entry(int r, int c, const string &, const entry_format *,
155 		 const char *, int lineno);
156   void add_vlines(int r, const char *);
157   void check();
158   void print();
159   void set_minimum_width(int c, const string &w);
160   void set_column_separation(int c, int n);
161   void set_equal_column(int c);
162   void set_expand_column(int c);
163   void set_delim(char c1, char c2);
164   void print_single_hline(int r);
165   void print_double_hline(int r);
166   int get_nrows();
167 };
168 
169 void set_troff_location(const char *, int);
170 
171 extern int compatible_flag;
172