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