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