169482Sbostic // -*- C++ -*- 269482Sbostic /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. 369482Sbostic Written by James Clark (jjc@jclark.com) 469482Sbostic 569482Sbostic This file is part of groff. 669482Sbostic 769482Sbostic groff is free software; you can redistribute it and/or modify it under 869482Sbostic the terms of the GNU General Public License as published by the Free 969482Sbostic Software Foundation; either version 2, or (at your option) any later 1069482Sbostic version. 1169482Sbostic 1269482Sbostic groff is distributed in the hope that it will be useful, but WITHOUT ANY 1369482Sbostic WARRANTY; without even the implied warranty of MERCHANTABILITY or 1469482Sbostic FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1569482Sbostic for more details. 1669482Sbostic 1769482Sbostic You should have received a copy of the GNU General Public License along 1869482Sbostic with groff; see the file COPYING. If not, write to the Free Software 1969482Sbostic Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 2069482Sbostic 2169482Sbostic #include <stdio.h> 22*69504Sbostic #include <unistd.h> 2369482Sbostic #include <stdlib.h> 2469482Sbostic #include <assert.h> 2569482Sbostic #include <ctype.h> 2669482Sbostic #include <errno.h> 2769482Sbostic 2869482Sbostic #include "cset.h" 2969482Sbostic #include "cmap.h" 3069482Sbostic #include "stringclass.h" 3169482Sbostic #include "errarg.h" 3269482Sbostic #include "error.h" 3369482Sbostic #include "lib.h" 3469482Sbostic 3569482Sbostic struct inc_number { 3669482Sbostic short inc; 3769482Sbostic short val; 3869482Sbostic }; 3969482Sbostic 4069482Sbostic struct entry_modifier { 4169482Sbostic inc_number point_size; 4269482Sbostic inc_number vertical_spacing; 4369482Sbostic string font; 4469482Sbostic enum { CENTER, TOP, BOTTOM } vertical_alignment; 4569482Sbostic char zero_width; 4669482Sbostic char stagger; 4769482Sbostic 4869482Sbostic entry_modifier(); 4969482Sbostic ~entry_modifier(); 5069482Sbostic }; 5169482Sbostic 5269482Sbostic enum format_type { 5369482Sbostic FORMAT_LEFT, 5469482Sbostic FORMAT_CENTER, 5569482Sbostic FORMAT_RIGHT, 5669482Sbostic FORMAT_NUMERIC, 5769482Sbostic FORMAT_ALPHABETIC, 5869482Sbostic FORMAT_SPAN, 5969482Sbostic FORMAT_VSPAN, 6069482Sbostic FORMAT_HLINE, 6169482Sbostic FORMAT_DOUBLE_HLINE 6269482Sbostic }; 6369482Sbostic 6469482Sbostic struct entry_format : entry_modifier { 6569482Sbostic format_type type; 6669482Sbostic 6769482Sbostic entry_format(format_type); 6869482Sbostic entry_format(); 6969482Sbostic void debug_print() const; 7069482Sbostic }; 7169482Sbostic 7269482Sbostic struct table_entry; 7369482Sbostic struct horizontal_span; 7469482Sbostic struct stuff; 7569482Sbostic struct vertical_rule; 7669482Sbostic 7769482Sbostic class table { 7869482Sbostic unsigned flags; 7969482Sbostic int nrows; 8069482Sbostic int ncolumns; 8169482Sbostic int linesize; 8269482Sbostic char delim[2]; 8369482Sbostic char decimal_point_char; 8469482Sbostic vertical_rule *vrule_list; 8569482Sbostic stuff *stuff_list; 8669482Sbostic horizontal_span *span_list; 8769482Sbostic table_entry *entry_list; 8869482Sbostic table_entry ***entry; 8969482Sbostic char **vline; 9069482Sbostic char *row_is_all_lines; 9169482Sbostic string *minimum_width; 9269482Sbostic int *column_separation; 9369482Sbostic char *equal; 9469482Sbostic int left_separation; 9569482Sbostic int right_separation; 9669482Sbostic int allocated_rows; 9769482Sbostic void build_span_list(); 9869482Sbostic void do_hspan(int r, int c); 9969482Sbostic void do_vspan(int r, int c); 10069482Sbostic void allocate(int r); 10169482Sbostic void compute_widths(); 10269482Sbostic void divide_span(int, int); 10369482Sbostic void sum_columns(int, int); 10469482Sbostic void compute_separation_factor(); 10569482Sbostic void compute_column_positions(); 10669482Sbostic void do_row(int); 10769482Sbostic void init_output(); 10869482Sbostic void add_stuff(stuff *); 10969482Sbostic void do_top(); 11069482Sbostic void do_bottom(); 11169482Sbostic void do_vertical_rules(); 11269482Sbostic void build_vrule_list(); 11369482Sbostic void add_vertical_rule(int, int, int, int); 11469482Sbostic void define_bottom_macro(); 11569482Sbostic int vline_spanned(int r, int c); 11669482Sbostic int row_begins_section(int); 11769482Sbostic int row_ends_section(int); 11869482Sbostic void make_columns_equal(); 11969482Sbostic void compute_vrule_top_adjust(int, int, string &); 12069482Sbostic void compute_vrule_bot_adjust(int, int, string &); 12169482Sbostic void determine_row_type(); 12269482Sbostic public: 12369482Sbostic /* used by flags */ 12469482Sbostic enum { 12569482Sbostic CENTER = 01, 12669482Sbostic EXPAND = 02, 12769482Sbostic BOX = 04, 12869482Sbostic ALLBOX = 010, 12969482Sbostic DOUBLEBOX = 020, 13069482Sbostic NOKEEP = 040 13169482Sbostic }; 13269482Sbostic table(int nc, unsigned flags, int linesize, char decimal_point_char); 13369482Sbostic ~table(); 13469482Sbostic 13569482Sbostic void add_text_line(int r, const string &, const char *, int); 13669482Sbostic void add_single_hline(int r); 13769482Sbostic void add_double_hline(int r); 13869482Sbostic void add_entry(int r, int c, const string &, const entry_format *, 13969482Sbostic const char *, int lineno); 14069482Sbostic void add_vlines(int r, const char *); 14169482Sbostic void check(); 14269482Sbostic void print(); 14369482Sbostic void set_minimum_width(int c, const string &w); 14469482Sbostic void set_column_separation(int c, int n); 14569482Sbostic void set_equal_column(int c); 14669482Sbostic void set_delim(char c1, char c2); 14769482Sbostic void print_single_hline(int r); 14869482Sbostic void print_double_hline(int r); 14969482Sbostic int get_nrows(); 15069482Sbostic }; 15169482Sbostic 15269482Sbostic void set_troff_location(const char *, int); 153