diff options
Diffstat (limited to 'contrib/groff/src/preproc/tbl')
-rw-r--r-- | contrib/groff/src/preproc/tbl/Makefile.sub | 1 | ||||
-rw-r--r-- | contrib/groff/src/preproc/tbl/main.cpp | 99 | ||||
-rw-r--r-- | contrib/groff/src/preproc/tbl/table.cpp | 37 | ||||
-rw-r--r-- | contrib/groff/src/preproc/tbl/table.h | 17 | ||||
-rw-r--r-- | contrib/groff/src/preproc/tbl/tbl.man | 50 |
5 files changed, 166 insertions, 38 deletions
diff --git a/contrib/groff/src/preproc/tbl/Makefile.sub b/contrib/groff/src/preproc/tbl/Makefile.sub index 8decd3103a55..bea28b35164d 100644 --- a/contrib/groff/src/preproc/tbl/Makefile.sub +++ b/contrib/groff/src/preproc/tbl/Makefile.sub @@ -1,6 +1,7 @@ PROG=tbl$(EXEEXT) MAN1=tbl.n XLIBS=$(LIBGROFF) +MLIB=$(LIBM) OBJS=\ main.$(OBJEXT) \ table.$(OBJEXT) diff --git a/contrib/groff/src/preproc/tbl/main.cpp b/contrib/groff/src/preproc/tbl/main.cpp index fe3aabf9e664..d79adb0bf831 100644 --- a/contrib/groff/src/preproc/tbl/main.cpp +++ b/contrib/groff/src/preproc/tbl/main.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -17,7 +17,7 @@ for more details. You should have received a copy of the GNU General Public License along with groff; see the file COPYING. If not, write to the Free Software -Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ #include "table.h" @@ -26,11 +26,14 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ extern "C" const char *Version_string; -static int compatible_flag = 0; +int compatible_flag = 0; class table_input { FILE *fp; - enum { START, MIDDLE, REREAD_T, REREAD_TE, REREAD_E, END, ERROR } state; + enum { START, MIDDLE, + REREAD_T, REREAD_TE, REREAD_E, + LEADER_1, LEADER_2, LEADER_3, LEADER_4, + END, ERROR } state; string unget_stack; public: table_input(FILE *); @@ -117,11 +120,15 @@ int table_input::get() } break; case MIDDLE: - // handle line continuation + // handle line continuation and uninterpreted leader character if ((c = getc(fp)) == '\\') { c = getc(fp); if (c == '\n') c = getc(fp); // perhaps state ought to be START now + else if (c == 'a' && compatible_flag) { + state = LEADER_1; + return '\\'; + } else { if (c != EOF) ungetc(c, fp); @@ -152,6 +159,18 @@ int table_input::get() case REREAD_E: state = MIDDLE; return 'E'; + case LEADER_1: + state = LEADER_2; + return '*'; + case LEADER_2: + state = LEADER_3; + return '('; + case LEADER_3: + state = LEADER_4; + return PREFIX_CHAR; + case LEADER_4: + state = MIDDLE; + return LEADER_CHAR; case END: case ERROR: return EOF; @@ -573,6 +592,11 @@ void entry_format::debug_print() const put_string(font, stderr); putc(' ', stderr); } + if (!macro.empty()) { + putc('m', stderr); + put_string(macro, stderr); + putc(' ', stderr); + } switch (vertical_alignment) { case entry_modifier::CENTER: break; @@ -886,6 +910,40 @@ format *process_format(table_input &in, options *opt, } } break; + case 'x': + case 'X': + do { + c = in.get(); + } while (c == ' ' || c == '\t'); + if (c == EOF) { + error("missing macro name"); + break; + } + if (c == '(') { + for (;;) { + c = in.get(); + if (c == EOF || c == ' ' || c == '\t') { + error("missing `)'"); + break; + } + if (c == ')') { + c = in.get(); + break; + } + list->macro += char(c); + } + } + else { + list->macro = c; + char cc = c; + c = in.get(); + if (!csdigit(cc) + && c != EOF && c != ' ' && c != '\t' && c != '.' && c != '\n') { + list->macro += char(c); + c = in.get(); + } + } + break; case 'v': case 'V': c = in.get(); @@ -1184,9 +1242,9 @@ table *process_data(table_input &in, format *f, options *opt) format_index = f->nrows - 1; // A format row that is all lines doesn't use up a data line. while (format_index < f->nrows - 1) { - int c; - for (c = 0; c < ncolumns; c++) { - entry_format *e = f->entry[format_index] + c; + int cnt; + for (cnt = 0; cnt < ncolumns; cnt++) { + entry_format *e = f->entry[format_index] + cnt; if (e->type != FORMAT_HLINE && e->type != FORMAT_DOUBLE_HLINE // Unfortunately tbl treats a span as needing data. @@ -1194,11 +1252,11 @@ table *process_data(table_input &in, format *f, options *opt) ) break; } - if (c < ncolumns) + if (cnt < ncolumns) break; - for (c = 0; c < ncolumns; c++) - tbl->add_entry(current_row, c, input_entry, - f->entry[format_index] + c, current_filename, + for (cnt = 0; cnt < ncolumns; cnt++) + tbl->add_entry(current_row, cnt, input_entry, + f->entry[format_index] + cnt, current_filename, current_lineno); tbl->add_vlines(current_row, f->vline[format_index]); format_index++; @@ -1295,13 +1353,19 @@ table *process_data(table_input &in, format *f, options *opt) } break; case GOT_RIGHT_BRACE: + if ((opt->flags & table::NOSPACES)) { + while (c == ' ') + c = in.get(); + if (c == EOF) + break; + } if (c == '\n' || c == tab_char) state = END; else { input_entry += 'T'; input_entry += '}'; input_entry += c; - state = c == '\n' ? START : MIDDLE; + state = MIDDLE; } break; case MIDDLE: @@ -1428,7 +1492,6 @@ table *process_data(table_input &in, format *f, options *opt) void process_table(table_input &in) { - int c; options *opt = 0; format *form = 0; table *tbl = 0; @@ -1440,7 +1503,7 @@ void process_table(table_input &in) } else { error("giving up on this table"); - while ((c = in.get()) != EOF) + while (in.get() != EOF) ; } delete opt; @@ -1504,10 +1567,8 @@ int main(int argc, char **argv) else { errno = 0; FILE *fp = fopen(argv[i], "r"); - if (fp == 0) { - current_lineno = -1; - error("can't open `%1': %2", argv[i], strerror(errno)); - } + if (fp == 0) + fatal("can't open `%1': %2", argv[i], strerror(errno)); else { current_lineno = 1; current_filename = argv[i]; diff --git a/contrib/groff/src/preproc/tbl/table.cpp b/contrib/groff/src/preproc/tbl/table.cpp index 32068c367ed1..8312386aafee 100644 --- a/contrib/groff/src/preproc/tbl/table.cpp +++ b/contrib/groff/src/preproc/tbl/table.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2003 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2003, 2004 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -17,7 +17,7 @@ for more details. You should have received a copy of the GNU General Public License along with groff; see the file COPYING. If not, write to the Free Software -Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ #include "table.h" @@ -30,7 +30,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ const int DEFAULT_COLUMN_SEPARATION = 3; #define DELIMITER_CHAR "\\[tbl]" -#define PREFIX "3" #define SEPARATION_FACTOR_REG PREFIX "sep" #define BOTTOM_REG PREFIX "bot" #define RESET_MACRO_NAME PREFIX "init" @@ -64,6 +63,8 @@ const int DEFAULT_COLUMN_SEPARATION = 3; // this must be one character #define COMPATIBLE_REG PREFIX "c" +#define LEADER_REG PREFIX LEADER + #define BLOCK_WIDTH_PREFIX PREFIX "tbw" #define BLOCK_DIVERSION_PREFIX PREFIX "tbd" #define BLOCK_HEIGHT_PREFIX PREFIX "tbh" @@ -128,14 +129,14 @@ void prints(const string &s) struct horizontal_span { horizontal_span *next; - short start_col; - short end_col; + int start_col; + int end_col; horizontal_span(int, int, horizontal_span *); }; -struct single_line_entry; -struct double_line_entry; -struct simple_entry; +class single_line_entry; +class double_line_entry; +class simple_entry; class table_entry { friend class table; @@ -145,8 +146,8 @@ friend class table; protected: int start_row; int end_row; - short start_col; - short end_col; + int start_col; + int end_col; const entry_modifier *mod; public: void set_location(); @@ -687,8 +688,8 @@ void block_entry::do_divert(int alphabetic, int ncols, const string *mw, if (alphabetic) prints("-2n"); prints("\n"); - set_modifier(mod); prints(".cp \\n(" COMPATIBLE_REG "\n"); + set_modifier(mod); set_location(); prints(contents); prints(".br\n.di\n.cp 0\n"); @@ -965,6 +966,8 @@ void set_modifier(const entry_modifier *m) prints('-'); printfs("%1\n", as_string(m->vertical_spacing.val)); } + if (!m->macro.empty()) + printfs(".%1\n", m->macro); } void set_inline_modifier(const entry_modifier *m) @@ -1088,7 +1091,7 @@ struct vertical_rule { vertical_rule *next; int start_row; int end_row; - short col; + int col; char is_double; string top_adjust; string bot_adjust; @@ -1693,6 +1696,8 @@ void table::init_output() prints(".nr " LINESIZE_REG " \\n[.s]\n"); if (!(flags & CENTER)) prints(".nr " SAVED_CENTER_REG " \\n[.ce]\n"); + if (compatible_flag) + prints(".ds " LEADER_REG " \\a\n"); prints(".de " RESET_MACRO_NAME "\n" ".ft \\n[.f]\n" ".ps \\n[.s]\n" @@ -2602,8 +2607,14 @@ void table::do_row(int r) if (e) { if (e->end_row == r && e->start_row == i) { simple_entry *simple = e->to_simple_entry(); - if (simple) + if (simple) { + if (e->end_row != e->start_row) { + prints('\n'); + simple->position_vertically(); + prints("\\&"); + } simple->simple_print(0); + } } c = e->end_col; } diff --git a/contrib/groff/src/preproc/tbl/table.h b/contrib/groff/src/preproc/tbl/table.h index 69959b899e4c..4b2497e2158e 100644 --- a/contrib/groff/src/preproc/tbl/table.h +++ b/contrib/groff/src/preproc/tbl/table.h @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002 +/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -17,7 +17,7 @@ for more details. You should have received a copy of the GNU General Public License along with groff; see the file COPYING. If not, write to the Free Software -Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ #include "lib.h" @@ -32,6 +32,14 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "errarg.h" #include "error.h" +// PREFIX and PREFIX_CHAR must be the same. +#define PREFIX "3" +#define PREFIX_CHAR '3' + +// LEADER and LEADER_CHAR must be the same. +#define LEADER "a" +#define LEADER_CHAR 'a' + struct inc_number { short inc; short val; @@ -41,6 +49,7 @@ struct entry_modifier { inc_number point_size; inc_number vertical_spacing; string font; + string macro; enum { CENTER, TOP, BOTTOM } vertical_alignment; char zero_width; char stagger; @@ -69,7 +78,7 @@ struct entry_format : public entry_modifier { void debug_print() const; }; -struct table_entry; +class table_entry; struct horizontal_span; struct stuff; struct vertical_rule; @@ -152,3 +161,5 @@ public: }; void set_troff_location(const char *, int); + +extern int compatible_flag; diff --git a/contrib/groff/src/preproc/tbl/tbl.man b/contrib/groff/src/preproc/tbl/tbl.man index 7f12bf933e00..00dfe4f83009 100644 --- a/contrib/groff/src/preproc/tbl/tbl.man +++ b/contrib/groff/src/preproc/tbl/tbl.man @@ -1,5 +1,6 @@ .ig -Copyright (C) 1989-1995, 2001, 2002 Free Software Foundation, Inc. +Copyright (C) 1989-1995, 2001, 2002, 2003, 2004 + Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -62,11 +63,13 @@ will cause the standard input to be read. .SH OPTIONS .TP .B \-C -Recognize +Enable compatibility mode to +recognize .B .TS and .B .TE even when followed by a character other than space or newline. +Leader characters (\[rs]a) are handled as interpreted. .TP .B \-v Print the version number. @@ -287,6 +290,33 @@ If used multiple times to specify the width for a particular column, the last entry takes effect. . .TP +x,X +This is a GNU tbl extension. +Either of these specifiers may be followed by a macro name +(either one or two characters long), +or long name in parentheses. +A one-letter macro name must be separated by one or more blanks +from whatever follows. +The macro which name can be specified here +must be defined before creating the table. +It is called just before the table's cell text is output. +As implemented currently, this macro is only called if block input is used, +that is, text between `T{' and `T}'. +The macro should contain only simple +.B troff +requests to change the text block formatting, like text adjustment, +hyphenation, size, or font. +The macro is called +.I after +other cell modifications like +.BR b , +.B f +or +.B v +are output. +Thus the macro can overwrite other modification specifiers. +. +.TP e,E Make equally-spaced columns. . @@ -339,6 +369,19 @@ too long as a simple string between tabs. It is started with `T{' and closed with `T}'. The former must end a line, and the latter must start a line, probably followed by other data columns (separated with tabs). +By default, the text block is formatted with the settings which were +active before entering the table, possibly overridden by the +.B v +and +.B w +tbl specifiers. +For example, to make all text blocks ragged-right, insert +.B .na +right before the starting +.B .TS +(and +.B .ad +after the table). .LP To change the data format within a table, use the .B .T& @@ -415,7 +458,8 @@ and use instead of .BR bp . .LP -Using \ea directly in a table to get leaders will not work. +Using \ea directly in a table to get leaders will not work (except in +compatibility mode). This is correct behaviour: \ea is an .B uninterpreted leader. |