/* multi.c -- multitable stuff for makeinfo. $Id: multi.c,v 1.5 2003/05/05 22:19:16 avsm Exp $ Copyright (C) 1996, 97, 98, 99, 2000, 01, 02 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Written by phr@gnu.org (Paul Rubin). */ #include "system.h" #include "insertion.h" #include "makeinfo.h" #include "xml.h" #define MAXCOLS 100 /* remove this limit later @@ */ /* * Output environments. This is a hack grafted onto existing * structure. The "output environment" used to consist of the * global variables `output_paragraph', `fill_column', etc. * Routines like add_char would manipulate these variables. * * Now, when formatting a multitable, we maintain separate environments * for each column. That way we can build up the columns separately * and write them all out at once. The "current" output environment" * is still kept in those global variables, so that the old output * routines don't have to change. But we provide routines to save * and restore these variables in an "environment table". The * `select_output_environment' function switches from one output * environment to another. * * Environment #0 (i.e., element #0 of the table) is the regular * environment that is used when we're not formatting a multitable. * * Environment #N (where N = 1,2,3,...) is the env. for column #N of * the table, when a multitable is active. */ /* contents of an output environment */ /* some more vars may end up being needed here later @@ */ struct env { unsigned char *output_paragraph; int output_paragraph_offset; int meta_char_pos; int output_column; int paragraph_is_open; int current_indent; int fill_column; } envs[MAXCOLS]; /* the environment table */ /* index in environment table of currently selected environment */ static int current_env_no; /* column number of last column in current multitable */ static int last_column; /* flags indicating whether horizontal and vertical separators need to be drawn, separating rows and columns in the current multitable. */ static int hsep, vsep; /* whether this is the first row. */ static int first_row; static void output_multitable_row (); /* Output a row. Calls insert, but also flushes the buffered output when we see a newline, since in multitable every line is a separate paragraph. */ static void out_char (ch) int ch; { if (html) add_char (ch); else { int env = select_output_environment (0); insert (ch); if (ch == '\n') { uninhibit_output_flushing (); flush_output (); inhibit_output_flushing (); } select_output_environment (env); } } void draw_horizontal_separator () { int i, j, s; if (html) { add_word ("
for non-tables browsers. @multitable implicitly ends the current paragraph, so this is ok. */ if (html) add_word ("
"); first_row = 0; return 0; } /* else if (docbook)*/ /* 05-08 */ else if (xml) { xml_end_multitable_row (first_row); first_row = 0; return 0; } first_row = 0; if (current_env_no > 0) { output_multitable_row (); } /* start at column 1 */ select_output_environment (1); if (!output_paragraph) { line_error (_("Cannot select column #%d in multitable"), current_env_no); exit (1); } init_column (); return 0; } static void output_multitable_row () { /* offset in the output paragraph of the next char needing to be output for that column. */ int offset[MAXCOLS]; int i, j, s, remaining; int had_newline = 0; for (i = 0; i <= last_column; i++) offset[i] = 0; /* select the current environment, to make sure the env variables get updated */ select_output_environment (current_env_no); #define CHAR_ADDR(n) (offset[i] + (n)) #define CHAR_AT(n) (envs[i].output_paragraph[CHAR_ADDR(n)]) /* remove trailing whitespace from each column */ for (i = 1; i <= last_column; i++) { if (envs[i].output_paragraph_offset) while (cr_or_whitespace (CHAR_AT (envs[i].output_paragraph_offset - 1))) envs[i].output_paragraph_offset--; if (i == current_env_no) output_paragraph_offset = envs[i].output_paragraph_offset; } /* read the current line from each column, outputting them all pasted together. Do this til all lines are output from all columns. */ for (;;) { remaining = 0; /* first, see if there is any work to do */ for (i = 1; i <= last_column; i++) { if (CHAR_ADDR (0) < envs[i].output_paragraph_offset) { remaining = 1; break; } } if (!remaining) break; for (s = 0; s < envs[0].current_indent; s++) out_char (' '); if (vsep) out_char ('|'); for (i = 1; i <= last_column; i++) { for (s = 0; s < envs[i].current_indent; s++) out_char (' '); for (j = 0; CHAR_ADDR (j) < envs[i].output_paragraph_offset; j++) { if (CHAR_AT (j) == '\n') break; out_char (CHAR_AT (j)); } offset[i] += j + 1; /* skip last text plus skip the newline */ /* Do not output trailing blanks if we're in the last column and there will be no trailing |. */ if (i < last_column && !vsep) for (; j <= envs[i].fill_column; j++) out_char (' '); if (vsep) out_char ('|'); /* draw column separator */ } out_char ('\n'); /* end of line */ had_newline = 1; } /* If completely blank item, get blank line despite no other output. */ if (!had_newline) out_char ('\n'); /* end of line */ if (hsep) draw_horizontal_separator (); /* Now dispose of the buffered output. */ for (i = 1; i <= last_column; i++) { select_output_environment (i); init_paragraph (); } } #undef CHAR_AT #undef CHAR_ADDR /* select a new column in current row of multitable */ void cm_tab () { if (!multitable_active) error (_("ignoring @tab outside of multitable")); if (html) add_word (" | ");
/* else if (docbook)*/ /* 05-08 */
else if (xml)
xml_end_multitable_column ();
else
nselect_next_environment ();
init_column ();
}
/* close a multitable, flushing its output and resetting
whatever needs resetting */
void
end_multitable ()
{
if (!html && !docbook)
output_multitable_row ();
/* Multitables cannot be nested. Otherwise, we'd have to save the
previous output environment number on a stack somewhere, and then
restore to that environment. */
select_output_environment (0);
multitable_active = 0;
uninhibit_output_flushing ();
close_insertion_paragraph ();
if (html)
add_word (" |