Back to index

tetex-bin  3.0
Classes | Defines | Functions | Variables
macro.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ITEXT
struct  MACRO_DEF

Defines

#define ME_RECURSE   0x01
#define ME_QUOTE_ARG   0x02

Functions

void execute_macro (MACRO_DEF *def)
MACRO_DEFfind_macro (char *name)
char * expand_macro (MACRO_DEF *def)
ITEXTremember_itext (char *pointer, int offset)
void forget_itext (char *pointer)
void maybe_write_itext (char *pointer, int offset)
void write_region_to_macro_output (char *string, int start, int end)
void append_to_expansion_output (int offset)
void me_append_before_this_command (void)
void me_execute_string (char *execution_string)
void me_execute_string_keep_state (char *execution_string, char *append_string)
char * alias_expand (char *tok)
int enclosure_command (char *tok)
void enclosure_expand (int arg, int start, int end)
void cm_macro (void)
void cm_rmacro (void)
void cm_unmacro (void)
void cm_alias (void)
void cm_definfoenclose (void)
int array_len (char **array)
void free_array (char **array)
char ** get_brace_args (int quote_single)

Variables

FILEmacro_expansion_output_stream
char * macro_expansion_filename
int me_executing_string
int only_macro_expansion

Class Documentation

struct ITEXT

Definition at line 31 of file macro.h.

Class Members
int offset
char * pointer
struct MACRO_DEF

Definition at line 37 of file macro.h.

Class Members
char ** arglist
char * body
int flags
int inhibited
char * name
char * source_file
int source_lineno

Define Documentation

#define ME_QUOTE_ARG   0x02

Definition at line 49 of file macro.h.

#define ME_RECURSE   0x01

Definition at line 48 of file macro.h.


Function Documentation

char* alias_expand ( char *  tok)

Definition at line 1012 of file macro.c.

{
  alias_type *findit = aliases;

  while (findit)
    if (strcmp (findit->alias, tok) == 0)
      {
       free (tok);
       return alias_expand (xstrdup (findit->mapto));
      }
    else
      findit = findit->next;

  return tok;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 930 of file macro.c.

{
  int i;
  ITEXT *itext = NULL;

  for (i = 0; i < itext_size; i++)
    if (itext_info[i] && itext_info[i]->pointer == input_text)
      {
        itext = itext_info[i];
        break;
      }

  if (!itext)
    return;

  if (offset > itext->offset)
    {
      write_region_to_macro_output (input_text, itext->offset, offset);
      remember_itext (input_text, offset);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int array_len ( char **  array)

Definition at line 58 of file macro.c.

{
  int i = 0;

  if (array)
    for (i = 0; array[i]; i++);

  return i;
}

Here is the caller graph for this function:

Definition at line 1053 of file macro.c.

{
  enclosure_type *e = xmalloc (sizeof (enclosure_type));

  skip_whitespace ();
  get_until_in_line (1, ",", &(e->enclose));
  discard_until (",");
  get_until_in_line (0, ",", &(e->before));
  discard_until (",");
  get_until_in_line (0, "\n", &(e->after));

  e->next = enclosures;
  enclosures = e;
}

Here is the call graph for this function:

Definition at line 738 of file macro.c.

{
  int i;
  char *line, *name;
  MACRO_DEF *def;

  if (macro_expansion_output_stream && !executing_string)
    me_append_before_this_command ();

  get_rest_of_line (0, &line);

  for (i = 0; line[i] && !whitespace (line[i]); i++);
  name = xmalloc (i + 1);
  memcpy (name, line, i);
  name[i] = 0;

  def = delete_macro (name);

  if (def)
    {
      free (def->source_file);
      free (def->name);
      free (def->body);

      if (def->arglist)
        {
          int i;

          for (i = 0; def->arglist[i]; i++)
            free (def->arglist[i]);

          free (def->arglist);
        }

      free (def);
    }

  free (line);
  free (name);

  if (macro_expansion_output_stream && !executing_string)
    remember_itext (input_text, input_text_offset);
}

Here is the call graph for this function:

int enclosure_command ( char *  tok)

Definition at line 1072 of file macro.c.

{
  enclosure_type *findit = enclosures;

  while (findit)
    if (strcmp (findit->enclose, tok) == 0)
      {
        enclosure_stack_type *new = xmalloc (sizeof (enclosure_stack_type));
        new->current = findit;
        new->next = enclosure_stack;
        enclosure_stack = new;

        return 1;
      }
    else
      findit = findit->next;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void enclosure_expand ( int  arg,
int  start,
int  end 
)

Definition at line 1094 of file macro.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 415 of file macro.c.

{
  char *execution_string;
  int start_line = line_number, end_line;

  if (macro_expansion_output_stream && !executing_string && !me_inhibit_expansion)
    me_append_before_this_command ();

  execution_string = expand_macro (def);
  if (!execution_string)
    return;

  if (def->body)
    {
      /* Reset the line number to where the macro arguments began.
         This makes line numbers reported in error messages correct in
         case the macro arguments span several lines and the expanded
         arguments invoke other commands.  */
      end_line = line_number;
      line_number = start_line;

      if (macro_expansion_output_stream
          && !executing_string && !me_inhibit_expansion)
        {
          remember_itext (input_text, input_text_offset);
          me_execute_string (execution_string);
        }
      else
        execute_string ("%s", execution_string);

      free (execution_string);
      line_number = end_line;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* expand_macro ( MACRO_DEF def)

Definition at line 385 of file macro.c.

{
  char **arglist;
  int num_args;
  char *execution_string = NULL;
  int start_line = line_number;

  /* Find out how many arguments this macro definition takes. */
  num_args = array_len (def->arglist);

  /* Gather the arguments present on the line if there are any. */
  arglist = get_macro_args (def);

  if (num_args < array_len (arglist))
    {
      free_array (arglist);
      line_error (_("Macro `%s' called on line %d with too many args"),
                  def->name, start_line);
      return execution_string;
    }

  if (def->body)
    execution_string = apply (def->arglist, arglist, def->body);

  free_array (arglist);
  return execution_string;
}

Here is the call graph for this function:

Here is the caller graph for this function:

MACRO_DEF* find_macro ( char *  name)

Definition at line 83 of file macro.c.

{
  int i;
  MACRO_DEF *def;

  def = NULL;
  for (i = 0; macro_list && (def = macro_list[i]); i++)
    {
      if ((!def->inhibited) && (strcmp (def->name, name) == 0))
        break;
    }
  return def;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void forget_itext ( char *  pointer)

Definition at line 840 of file macro.c.

{
  int i;

  for (i = 0; i < itext_size; i++)
    if (itext_info[i] && (itext_info[i]->pointer == pointer))
      {
        free (itext_info[i]);
        itext_info[i] = NULL;
        break;
      }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void free_array ( char **  array)

Definition at line 69 of file macro.c.

{
  if (array)
    {
      int i;
      for (i = 0; array[i]; i++)
        free (array[i]);

      free (array);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char** get_brace_args ( int  quote_single)

Definition at line 160 of file macro.c.

{
  char **arglist, *word;
  int arglist_index, arglist_size;
  int character, escape_seen, start;
  int depth = 1;

  /* There is an arglist in braces here, so gather the args inside of it. */
  skip_whitespace_and_newlines ();
  input_text_offset++;
  arglist = NULL;
  arglist_index = arglist_size = 0;

 get_arg:
  skip_whitespace_and_newlines ();
  start = input_text_offset;
  escape_seen = 0;

  while ((character = curchar ()))
    {
      if (character == '\\')
        {
          input_text_offset += 2;
          escape_seen = 1;
        }
      else if (character == '{')
        {
          depth++;
          input_text_offset++;
        }
      else if ((character == ',' && !quote_single) ||
               ((character == '}') && depth == 1))
        {
          int len = input_text_offset - start;

          if (len || (character != '}'))
            {
              word = xmalloc (1 + len);
              memcpy (word, input_text + start, len);
              word[len] = 0;

              /* Clean up escaped characters. */
              if (escape_seen)
                {
                  int i;
                  for (i = 0; word[i]; i++)
                    if (word[i] == '\\')
                      memmove (word + i, word + i + 1,
                               1 + strlen (word + i + 1));
                }

              if (arglist_index + 2 >= arglist_size)
                arglist = xrealloc
                  (arglist, (arglist_size += 10) * sizeof (char *));

              arglist[arglist_index++] = word;
              arglist[arglist_index] = NULL;
            }

          input_text_offset++;
          if (character == '}')
            break;
          else
            goto get_arg;
        }
      else if (character == '}')
        {
          depth--;
          input_text_offset++;
        }
      else
        {
          input_text_offset++;
          if (character == '\n') line_number++;
        }
    }
  return arglist;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void maybe_write_itext ( char *  pointer,
int  offset 
)

Definition at line 954 of file macro.c.

{
  int i;
  ITEXT *itext = NULL;

  for (i = 0; i < itext_size; i++)
    if (itext_info[i] && (itext_info[i]->pointer == pointer))
      {
        itext = itext_info[i];
        break;
      }

  if (itext && (itext->offset < offset))
    {
      write_region_to_macro_output (itext->pointer, itext->offset, offset);
      remember_itext (pointer, offset);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 856 of file macro.c.

{
  int i;

  for (i = input_text_offset; i && (input_text[i] != COMMAND_PREFIX); i--)
    ;
  maybe_write_itext (input_text, i);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void me_execute_string ( char *  execution_string)

Definition at line 868 of file macro.c.

{
  int saved_escape_html = escape_html;
  int saved_in_paragraph = in_paragraph;
  escape_html = me_executing_string == 0;
  in_paragraph = 0;
  
  pushfile ();
  input_text_offset = 0;
  /* The following xstrdup is so we can relocate input_text at will.  */
  input_text = xstrdup (execution_string);
  input_filename = xstrdup (input_filename);
  input_text_length = strlen (execution_string);

  remember_itext (input_text, 0);

  me_executing_string++;
  reader_loop ();
  free (input_text);
  free (input_filename);
  popfile ();
  me_executing_string--;

  in_paragraph = saved_in_paragraph;
  escape_html = saved_escape_html;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void me_execute_string_keep_state ( char *  execution_string,
char *  append_string 
)

Definition at line 900 of file macro.c.

{
  int op_orig, opcol_orig, popen_orig;
  int fill_orig, newline_orig, indent_orig, meta_pos_orig;

  remember_itext (input_text, input_text_offset);
  op_orig = output_paragraph_offset;
  meta_pos_orig = meta_char_pos;
  opcol_orig = output_column;
  popen_orig = paragraph_is_open;
  fill_orig = filling_enabled;
  newline_orig = last_char_was_newline;
  filling_enabled = 0;
  indent_orig = no_indent;
  no_indent = 1;
  me_execute_string (execution_string);
  if (append_string)
    write_region_to_macro_output (append_string, 0, strlen (append_string));
  output_paragraph_offset = op_orig;
  meta_char_pos = meta_pos_orig;
  output_column = opcol_orig;
  paragraph_is_open = popen_orig;
  filling_enabled = fill_orig;
  last_char_was_newline = newline_orig;
  no_indent = indent_orig;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ITEXT* remember_itext ( char *  pointer,
int  offset 
)

Definition at line 786 of file macro.c.

{
  int i;
  ITEXT *itext = NULL;

  /* If we have no info, initialize a blank list. */
  if (!itext_info)
    {
      itext_info = xmalloc ((itext_size = 10) * sizeof (ITEXT *));
      for (i = 0; i < itext_size; i++)
        itext_info[i] = NULL;
    }

  /* If the pointer is already present in the list, then set the offset. */
  for (i = 0; i < itext_size; i++)
    if ((itext_info[i]) &&
        (itext_info[i]->pointer == pointer))
      {
        itext = itext_info[i];
        itext_info[i]->offset = offset;
        break;
      }

  if (i == itext_size)
    {
      /* Find a blank slot (or create a new one), and remember the
         pointer and offset. */
      for (i = 0; i < itext_size; i++)
        if (itext_info[i] == NULL)
          break;

      /* If not found, then add some slots. */
      if (i == itext_size)
        {
          int j;

          itext_info = xrealloc
            (itext_info, (itext_size += 10) * sizeof (ITEXT *));

          for (j = i; j < itext_size; j++)
            itext_info[j] = NULL;
        }

      /* Now add the pointer and the offset. */
      itext_info[i] = xmalloc (sizeof (ITEXT));
      itext_info[i]->pointer = pointer;
      itext_info[i]->offset = offset;
      itext = itext_info[i];
    }
  return itext;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_region_to_macro_output ( char *  string,
int  start,
int  end 
)

Definition at line 974 of file macro.c.

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 34 of file macro.c.

Definition at line 31 of file macro.c.

Definition at line 37 of file macro.c.

Definition at line 41 of file macro.c.