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