Back to index

tetex-bin  3.0
Classes | Defines | Functions | Variables
multi.c File Reference
#include "system.h"
#include "cmds.h"
#include "insertion.h"
#include "makeinfo.h"
#include "multi.h"
#include "xml.h"

Go to the source code of this file.

Classes

struct  env

Defines

#define MAXCOLS   100 /* remove this limit later @@ */
#define CHAR_ADDR(n)   (offset[i] + (n))
#define CHAR_AT(n)   (envs[i].output_paragraph[CHAR_ADDR(n)])

Functions

static unsigned find_template_width (char **params)
static int select_output_environment (int n)
static int setup_output_environment (int env_no, int width)
static int setup_multitable_parameters (void)
static void out_char (int ch)
static void draw_horizontal_separator (void)
void do_multitable (void)
static void nselect_next_environment (void)
static void init_column (void)
static void output_multitable_row (void)
int multitable_item (void)
void cm_tab (void)
void end_multitable (void)

Variables

struct env envs [MAXCOLS]
static int current_env_no
static int current_column_no
static int seen_column_fractions
static int last_column
static int hsep
static int vsep
static int first_row
int after_headitem = 0
int headitem_row = 0

Class Documentation

struct env

Definition at line 57 of file multi.c.

Class Members
int current_indent
int fill_column
int meta_char_pos
int output_column
unsigned char * output_paragraph
int output_paragraph_offset
int paragraph_is_open

Define Documentation

#define CHAR_ADDR (   n)    (offset[i] + (n))
#define CHAR_AT (   n)    (envs[i].output_paragraph[CHAR_ADDR(n)])
#define MAXCOLS   100 /* remove this limit later @@ */

Definition at line 30 of file multi.c.


Function Documentation

void cm_tab ( void  )

Definition at line 581 of file multi.c.

{
  if (!multitable_active)
    error (_("ignoring @tab outside of multitable"));

  current_column_no++;
  
  if (html)
    {
      if (seen_column_fractions)
        add_word_args ("</%s><%s valign=\"top\" width=\"%d%%\">",
            headitem_row ? "th" : "td",
            headitem_row ? "th" : "td",
            envs[current_column_no].fill_column);
      else
        add_word_args ("</%s><%s valign=\"top\">",
            headitem_row ? "th" : "td",
            headitem_row ? "th" : "td");
    }
  /*  else if (docbook)*/ /* 05-08 */
  else if (xml)
    xml_end_multitable_column ();
  else
    nselect_next_environment ();

  init_column ();
}

Here is the call graph for this function:

Definition at line 336 of file multi.c.

{
  int ncolumns;

  if (multitable_active)
    {
      line_error ("Multitables cannot be nested");
      return;
    }

  close_single_paragraph ();

  if (xml)
    {
      xml_no_para = 1;
      if (output_paragraph[output_paragraph_offset-1] == '\n')
        output_paragraph_offset--;
    }

  /* scan the current item function to get the field widths
     and number of columns, and set up the output environment list
     accordingly. */
  ncolumns = setup_multitable_parameters ();
  first_row = 1;

  /* <p> for non-tables browsers.  @multitable implicitly ends the
     current paragraph, so this is ok.  */
  if (html)
    add_html_block_elt ("<p><table summary=\"\">");
  /*  else if (docbook)*/ /* 05-08 */
  else if (xml)
    {
      int *widths = xmalloc (ncolumns * sizeof (int));
      int i;
      for (i=0; i<ncolumns; i++)
       widths[i] = envs[i+1].fill_column;
      xml_begin_multitable (ncolumns, widths);
      free (widths);
    }

  if (hsep)
    draw_horizontal_separator ();

  /* The next @item command will direct stdout into the first column
     and start processing.  @tab will then switch to the next column,
     and @item will flush out the saved output and return to the first
     column.  Environment #1 is the first column.  (Environment #0 is
     the normal output) */

  ++multitable_active;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void draw_horizontal_separator ( void  ) [static]

Definition at line 291 of file multi.c.

{
  int i, j, s;

  if (html)
    {
      add_word ("<hr>");
      return;
    }
  if (xml)
    return;

  for (s = 0; s < envs[0].current_indent; s++)
    out_char (' ');
  if (vsep)
    out_char ('+');
  for (i = 1; i <= last_column; i++) {
    for (j = 0; j <= envs[i].fill_column; j++)
      out_char ('-');
    if (vsep)
      out_char ('+');
  }
  out_char (' ');
  out_char ('\n');
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 612 of file multi.c.

{
  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_args ("<br></%s></tr></table>\n", headitem_row ? "th" : "td");
  /*  else if (docbook)*/ /* 05-08 */
  else if (xml)
    xml_end_multitable ();

#if 0
  printf (_("** Multicolumn output from last row:\n"));
  for (i = 1; i <= last_column; i++) {
    select_output_environment (i);
    printf (_("* column #%d: output = %s\n"), i, output_paragraph);
  }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned find_template_width ( char **  params) [static]

Definition at line 93 of file multi.c.

{
  char *template, *xtemplate;
  unsigned len;
  char *start = *params;
  int brace_level = 0;

  /* The first character should be a {.  */
  if (!params || !*params || **params != '{')
    {
      line_error ("find_template width internal error: passed %s",
                  params ? *params : "null");
      return 0;
    }

  do
    {
      if (**params == '{' && (*params == start || (*params)[-1] != '@'))
        brace_level++;
      else if (**params == '}' && (*params)[-1] != '@')
        brace_level--;
      else if (**params == 0)
        {
          line_error (_("Missing } in @multitable template"));
          return 0;
        }
      (*params)++;
    }
  while (brace_level > 0);
  
  template = substring (start + 1, *params - 1); /* omit braces */
  xtemplate = expansion (template, 0);
  len = strlen (xtemplate);
  
  free (template);
  free (xtemplate);
  
  return len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_column ( void  ) [static]

Definition at line 403 of file multi.c.

{
  /* don't indent 1st paragraph in the item */
  cm_noindent ();

  /* throw away possible whitespace after @item or @tab command */
  skip_whitespace ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 503 of file multi.c.

{
  if (!multitable_active) {
    line_error ("multitable_item internal error: no active multitable");
    xexit (1);
  }

  current_column_no = 1;

  if (html)
    {
      if (!first_row)
        /* <br> for non-tables browsers. */
       add_word_args ("<br></%s></tr>", after_headitem ? "th" : "td");

      if (seen_column_fractions)
        add_word_args ("<tr align=\"left\"><%s valign=\"top\" width=\"%d%%\">",
            headitem_flag ? "th" : "td",
            envs[current_column_no].fill_column);
      else
        add_word_args ("<tr align=\"left\"><%s valign=\"top\">",
            headitem_flag ? "th" : "td");

      if (headitem_flag)
        after_headitem = 1;
      else
        after_headitem = 0;
      first_row = 0;
      headitem_row = headitem_flag;
      headitem_flag = 0;
      return 0;
    }
  /*  else if (docbook)*/ /* 05-08 */
  else if (xml)
    {
      xml_end_multitable_row (first_row);
      if (headitem_flag)
        after_headitem = 1;
      else
        after_headitem = 0;
      first_row = 0;
      headitem_flag = 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 (_("[unexpected] cannot select column #%d in multitable"),
                current_env_no);
    xexit (1);
  }

  init_column ();

  if (headitem_flag)
    hsep = 1;
  else
    hsep = 0;

  if (headitem_flag)
    after_headitem = 1;
  else
    after_headitem = 0;
  headitem_flag = 0;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void nselect_next_environment ( void  ) [static]

Definition at line 390 of file multi.c.

{
  if (current_env_no >= last_column) {
    line_error (_("Too many columns in multitable item (max %d)"), last_column);
    return;
  }
  select_output_environment (current_env_no + 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void out_char ( int  ch) [static]

Definition at line 271 of file multi.c.

{
  if (html || xml)
    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);
    }
}

Here is the call graph for this function:

static void output_multitable_row ( void  ) [static]

Definition at line 413 of file multi.c.

{
  /* 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 ();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int select_output_environment ( int  n) [static]

Definition at line 137 of file multi.c.

Here is the caller graph for this function:

static int setup_multitable_parameters ( void  ) [static]

Definition at line 189 of file multi.c.

{
  char *params = insertion_stack->item_function;
  int nchars;
  float columnfrac;
  char command[200]; /* xx no fixed limits */
  int i = 1;

  /* We implement @hsep and @vsep even though TeX doesn't.
     We don't get mixing of @columnfractions and templates right,
     but TeX doesn't either.  */
  hsep = vsep = 0;

  /* Assume no @columnfractions per default.  */
  seen_column_fractions = 0;

  while (*params) {
    while (whitespace (*params))
      params++;

    if (*params == '@') {
      sscanf (params, "%200s", command);
      nchars = strlen (command);
      params += nchars;
      if (strcmp (command, "@hsep") == 0)
        hsep++;
      else if (strcmp (command, "@vsep") == 0)
        vsep++;
      else if (strcmp (command, "@columnfractions") == 0) {
        seen_column_fractions = 1;
        /* Clobber old environments and create new ones, starting at #1.
           Environment #0 is the normal output, so don't mess with it. */
        for ( ; i <= MAXCOLS; i++) {
          if (sscanf (params, "%f", &columnfrac) < 1)
            goto done;
          /* Unfortunately, can't use %n since m68k-hp-bsd libc (at least)
             doesn't support it.  So skip whitespace (preceding the
             number) and then non-whitespace (the number).  */
          while (*params && (*params == ' ' || *params == '\t'))
            params++;
          /* Hmm, but what about @columnfractions 3foo.  Oh well, 
             it's invalid input anyway.  */
          while (*params && *params != ' ' && *params != '\t'
                 && *params != '\n' && *params != '@')
            params++;

          {
            /* For html/xml/docbook, translate fractions into integer
               percentages, adding .005 to avoid rounding problems.  For
               info, we want the character width.  */
            int width = xml || html ? (columnfrac + .005) * 100
                        : (columnfrac * (fill_column - current_indent) + .5);
            setup_output_environment (i, width);
          }
        }
      }

    } else if (*params == '{') {
      unsigned template_width = find_template_width (&params);

      /* This gives us two spaces between columns.  Seems reasonable.
         How to take into account current_indent here?  */
      setup_output_environment (i++, template_width + 2);
      
    } else {
      warning (_("ignoring stray text `%s' after @multitable"), params);
      break;
    }
  }

done:
  flush_output ();
  inhibit_output_flushing ();

  last_column = i - 1;
  return last_column;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int setup_output_environment ( int  env_no,
int  width 
) [static]

Definition at line 169 of file multi.c.

{
  int old_env = select_output_environment (env_no);

  /* clobber old environment and set width of new one */
  init_paragraph ();

  /* make our change */
  fill_column = width;

  /* Save new environment and restore previous one. */
  select_output_environment (old_env);

  return env_no;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 498 of file multi.c.

Definition at line 72 of file multi.c.

int current_env_no [static]

Definition at line 69 of file multi.c.

struct env envs[MAXCOLS]
int first_row [static]

Definition at line 86 of file multi.c.

Definition at line 499 of file multi.c.

int hsep [static]

Definition at line 83 of file multi.c.

int last_column [static]

Definition at line 79 of file multi.c.

Definition at line 76 of file multi.c.

int vsep [static]

Definition at line 83 of file multi.c.