xref: /csrg-svn/contrib/groff-1.08/tbl/table.h (revision 69482)
1*69482Sbostic // -*- C++ -*-
2*69482Sbostic /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3*69482Sbostic      Written by James Clark (jjc@jclark.com)
4*69482Sbostic 
5*69482Sbostic This file is part of groff.
6*69482Sbostic 
7*69482Sbostic groff is free software; you can redistribute it and/or modify it under
8*69482Sbostic the terms of the GNU General Public License as published by the Free
9*69482Sbostic Software Foundation; either version 2, or (at your option) any later
10*69482Sbostic version.
11*69482Sbostic 
12*69482Sbostic groff is distributed in the hope that it will be useful, but WITHOUT ANY
13*69482Sbostic WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*69482Sbostic FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15*69482Sbostic for more details.
16*69482Sbostic 
17*69482Sbostic You should have received a copy of the GNU General Public License along
18*69482Sbostic with groff; see the file COPYING.  If not, write to the Free Software
19*69482Sbostic Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20*69482Sbostic 
21*69482Sbostic #include <stdio.h>
22*69482Sbostic #include <stdlib.h>
23*69482Sbostic #include <assert.h>
24*69482Sbostic #include <ctype.h>
25*69482Sbostic #include <errno.h>
26*69482Sbostic 
27*69482Sbostic #include "cset.h"
28*69482Sbostic #include "cmap.h"
29*69482Sbostic #include "stringclass.h"
30*69482Sbostic #include "errarg.h"
31*69482Sbostic #include "error.h"
32*69482Sbostic #include "lib.h"
33*69482Sbostic 
34*69482Sbostic struct inc_number {
35*69482Sbostic   short inc;
36*69482Sbostic   short val;
37*69482Sbostic };
38*69482Sbostic 
39*69482Sbostic struct entry_modifier {
40*69482Sbostic   inc_number point_size;
41*69482Sbostic   inc_number vertical_spacing;
42*69482Sbostic   string font;
43*69482Sbostic   enum { CENTER, TOP, BOTTOM } vertical_alignment;
44*69482Sbostic   char zero_width;
45*69482Sbostic   char stagger;
46*69482Sbostic 
47*69482Sbostic   entry_modifier();
48*69482Sbostic   ~entry_modifier();
49*69482Sbostic };
50*69482Sbostic 
51*69482Sbostic enum format_type {
52*69482Sbostic   FORMAT_LEFT,
53*69482Sbostic   FORMAT_CENTER,
54*69482Sbostic   FORMAT_RIGHT,
55*69482Sbostic   FORMAT_NUMERIC,
56*69482Sbostic   FORMAT_ALPHABETIC,
57*69482Sbostic   FORMAT_SPAN,
58*69482Sbostic   FORMAT_VSPAN,
59*69482Sbostic   FORMAT_HLINE,
60*69482Sbostic   FORMAT_DOUBLE_HLINE
61*69482Sbostic };
62*69482Sbostic 
63*69482Sbostic struct entry_format : entry_modifier {
64*69482Sbostic   format_type type;
65*69482Sbostic 
66*69482Sbostic   entry_format(format_type);
67*69482Sbostic   entry_format();
68*69482Sbostic   void debug_print() const;
69*69482Sbostic };
70*69482Sbostic 
71*69482Sbostic struct table_entry;
72*69482Sbostic struct horizontal_span;
73*69482Sbostic struct stuff;
74*69482Sbostic struct vertical_rule;
75*69482Sbostic 
76*69482Sbostic class table {
77*69482Sbostic   unsigned flags;
78*69482Sbostic   int nrows;
79*69482Sbostic   int ncolumns;
80*69482Sbostic   int linesize;
81*69482Sbostic   char delim[2];
82*69482Sbostic   char decimal_point_char;
83*69482Sbostic   vertical_rule *vrule_list;
84*69482Sbostic   stuff *stuff_list;
85*69482Sbostic   horizontal_span *span_list;
86*69482Sbostic   table_entry *entry_list;
87*69482Sbostic   table_entry ***entry;
88*69482Sbostic   char **vline;
89*69482Sbostic   char *row_is_all_lines;
90*69482Sbostic   string *minimum_width;
91*69482Sbostic   int *column_separation;
92*69482Sbostic   char *equal;
93*69482Sbostic   int left_separation;
94*69482Sbostic   int right_separation;
95*69482Sbostic   int allocated_rows;
96*69482Sbostic   void build_span_list();
97*69482Sbostic   void do_hspan(int r, int c);
98*69482Sbostic   void do_vspan(int r, int c);
99*69482Sbostic   void allocate(int r);
100*69482Sbostic   void compute_widths();
101*69482Sbostic   void divide_span(int, int);
102*69482Sbostic   void sum_columns(int, int);
103*69482Sbostic   void compute_separation_factor();
104*69482Sbostic   void compute_column_positions();
105*69482Sbostic   void do_row(int);
106*69482Sbostic   void init_output();
107*69482Sbostic   void add_stuff(stuff *);
108*69482Sbostic   void do_top();
109*69482Sbostic   void do_bottom();
110*69482Sbostic   void do_vertical_rules();
111*69482Sbostic   void build_vrule_list();
112*69482Sbostic   void add_vertical_rule(int, int, int, int);
113*69482Sbostic   void define_bottom_macro();
114*69482Sbostic   int vline_spanned(int r, int c);
115*69482Sbostic   int row_begins_section(int);
116*69482Sbostic   int row_ends_section(int);
117*69482Sbostic   void make_columns_equal();
118*69482Sbostic   void compute_vrule_top_adjust(int, int, string &);
119*69482Sbostic   void compute_vrule_bot_adjust(int, int, string &);
120*69482Sbostic   void determine_row_type();
121*69482Sbostic public:
122*69482Sbostic   /* used by flags */
123*69482Sbostic   enum {
124*69482Sbostic     CENTER = 01,
125*69482Sbostic     EXPAND = 02,
126*69482Sbostic     BOX = 04,
127*69482Sbostic     ALLBOX = 010,
128*69482Sbostic     DOUBLEBOX = 020,
129*69482Sbostic     NOKEEP = 040
130*69482Sbostic     };
131*69482Sbostic   table(int nc, unsigned flags, int linesize, char decimal_point_char);
132*69482Sbostic   ~table();
133*69482Sbostic 
134*69482Sbostic   void add_text_line(int r, const string &, const char *, int);
135*69482Sbostic   void add_single_hline(int r);
136*69482Sbostic   void add_double_hline(int r);
137*69482Sbostic   void add_entry(int r, int c, const string &, const entry_format *,
138*69482Sbostic 		 const char *, int lineno);
139*69482Sbostic   void add_vlines(int r, const char *);
140*69482Sbostic   void check();
141*69482Sbostic   void print();
142*69482Sbostic   void set_minimum_width(int c, const string &w);
143*69482Sbostic   void set_column_separation(int c, int n);
144*69482Sbostic   void set_equal_column(int c);
145*69482Sbostic   void set_delim(char c1, char c2);
146*69482Sbostic   void print_single_hline(int r);
147*69482Sbostic   void print_double_hline(int r);
148*69482Sbostic   int get_nrows();
149*69482Sbostic };
150*69482Sbostic 
151*69482Sbostic void set_troff_location(const char *, int);
152