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