Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / contrib / groff / src / preproc / tbl / table.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004, 2007,
3                  2008, 2009
4    Free Software Foundation, Inc.
5      Written by James Clark (jjc@jclark.com)
6
7 This file is part of groff.
8
9 groff is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 groff is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "lib.h"
23
24 #include <stdlib.h>
25 #include <assert.h>
26 #include <ctype.h>
27 #include <errno.h>
28
29 #include "cset.h"
30 #include "cmap.h"
31 #include "stringclass.h"
32 #include "errarg.h"
33 #include "error.h"
34
35 // PREFIX and PREFIX_CHAR must be the same.
36 #define PREFIX "3"
37 #define PREFIX_CHAR '3'
38
39 // LEADER and LEADER_CHAR must be the same.
40 #define LEADER "a"
41 #define LEADER_CHAR 'a'
42
43 struct inc_number {
44   short inc;
45   short val;
46 };
47
48 struct entry_modifier {
49   inc_number point_size;
50   inc_number vertical_spacing;
51   string font;
52   string macro;
53   enum { CENTER, TOP, BOTTOM } vertical_alignment;
54   char zero_width;
55   char stagger;
56
57   entry_modifier();
58   ~entry_modifier();
59 };
60
61 enum format_type {
62   FORMAT_LEFT, 
63   FORMAT_CENTER, 
64   FORMAT_RIGHT, 
65   FORMAT_NUMERIC,
66   FORMAT_ALPHABETIC,
67   FORMAT_SPAN, 
68   FORMAT_VSPAN,
69   FORMAT_HLINE,
70   FORMAT_DOUBLE_HLINE
71 };
72
73 struct entry_format : public entry_modifier {
74   format_type type;
75
76   entry_format(format_type);
77   entry_format();
78   void debug_print() const;
79 };
80
81 class table_entry;
82 struct horizontal_span;
83 struct stuff;
84 struct vertical_rule;
85
86 class table {
87   int nrows;
88   int ncolumns;
89   int linesize;
90   char delim[2];
91   char decimal_point_char;
92   vertical_rule *vrule_list;
93   stuff *stuff_list;
94   horizontal_span *span_list;
95   table_entry *entry_list;
96   table_entry **entry_list_tailp;
97   table_entry ***entry;
98   char **vline;
99   char *row_is_all_lines;
100   string *minimum_width;
101   int *column_separation;
102   char *equal;
103   int left_separation;
104   int right_separation;
105   int total_separation;
106   int allocated_rows;
107   void build_span_list();
108   void compute_expand_width();
109   void do_hspan(int r, int c);
110   void do_vspan(int r, int c);
111   void allocate(int r);
112   void compute_widths();
113   void divide_span(int, int);
114   void sum_columns(int, int, int);
115   void compute_total_separation();
116   void compute_separation_factor();
117   void compute_column_positions();
118   void do_row(int);
119   void init_output();
120   void add_stuff(stuff *);
121   void do_top();
122   void do_bottom();
123   void do_vertical_rules();
124   void build_vrule_list();
125   void add_vertical_rule(int, int, int, int);
126   void define_bottom_macro();
127   int vline_spanned(int r, int c);
128   int row_begins_section(int);
129   int row_ends_section(int);
130   void make_columns_equal();
131   void compute_vrule_top_adjust(int, int, string &);
132   void compute_vrule_bot_adjust(int, int, string &);
133   void determine_row_type();
134   int count_expand_columns();
135 public:
136   unsigned flags;
137   enum {
138     CENTER       = 0x00000001,
139     EXPAND       = 0x00000002,
140     BOX          = 0x00000004,
141     ALLBOX       = 0x00000008,
142     DOUBLEBOX    = 0x00000010,
143     NOKEEP       = 0x00000020,
144     NOSPACES     = 0x00000040,
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;