Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Typedefs | Functions | Variables
chew.c File Reference
#include "ansidecl.h"
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  buffer
struct  dict_struct

Defines

#define DEF_SIZE   5000
#define STACK   50
#define NO_PARAMS   1

Typedefs

typedef struct buffer string_type
typedef void(* stinst_type )()
typedef intword_type
typedef struct dict_struct

Functions

static void init_string_with_size (string_type *buffer, unsigned int size)
static void init_string (string_type *buffer)
static int find (string_type *str, char *what)
static void write_buffer (string_type *buffer, FILE *f)
static void delete_string (string_type *buffer)
static char * addr (string_type *buffer, unsigned int idx)
static char at (string_type *buffer, unsigned int pos)
static void catchar (string_type *buffer, int ch)
static void overwrite_string (string_type *dst, string_type *src)
static void catbuf (string_type *buffer, char *buf, unsigned int len)
static void cattext (string_type *buffer, char *string)
static void catstr (string_type *dst, string_type *src)
static unsigned int skip_white_and_stars (string_type *src, unsigned int idx)
static void die (char *msg)
static void check_range ()
static void icheck_range ()
static void exec (dict_type *word)
static void call ()
static void remchar ()
static void strip_trailing_newlines ()
static void push_number ()
static void push_text ()
static void remove_noncomments (string_type *src, string_type *dst)
static void print_stack_level ()
static void paramstuff ()
static void translatecomments ()
static void outputdots ()
static void courierize ()
static void bulletize ()
static void do_fancy_stuff ()
static int iscommand (string_type *ptr, unsigned int idx)
static int copy_past_newline (string_type *ptr, unsigned int idx, string_type *dst)
static void icopy_past_newline ()
static void kill_bogus_lines ()
static void indent ()
static void get_stuff_in_command ()
static void swap ()
static void other_dup ()
static void drop ()
static void idrop ()
static void icatstr ()
static void skip_past_newline ()
static void internalmode ()
static void maybecatstr ()
char * nextword (char *string, char **word)
dict_type * lookup_word (char *word)
static void perform ()
dict_type * newentry (char *word)
unsigned int add_to_definition (dict_type *entry, stinst_type word)
void add_intrinsic (char *name, void(*)() func)
void add_var (char *name)
void compile (char *string)
static void bang ()
static void atsign ()
static void hello ()
static void stdout_ ()
static void stderr_ ()
static void print ()
static void read_in (string_type *str, FILE *file)
static void usage ()
static void chew_exit ()
int main (int ac, av)

Variables

int internal_wanted
int internal_mode
int warning
string_type stack [STACK]
string_typetos
unsigned int idx = 0
string_typeptr
stinst_typepc
stinst_type sstack [STACK]
stinst_typessp = &sstack[0]
long istack [STACK]
longisp = &istack[0]
dict_type * root

Class Documentation

struct buffer

Definition at line 102 of file chew.c.

Class Members
bfd_vma base
signed char data
int n_fetch
int n_used
char * ptr
unsigned long size
unsigned long write_idx
struct dict_struct

Definition at line 282 of file chew.c.

Collaboration diagram for dict_struct:
Class Members
stinst_type * code
int code_end
int code_length
struct dict_struct * next
int var
char * word

Define Documentation

#define DEF_SIZE   5000

Definition at line 92 of file chew.c.

#define NO_PARAMS   1
#define STACK   50

Definition at line 93 of file chew.c.


Typedef Documentation

Definition at line 292 of file chew.c.

typedef void(* stinst_type)()

Definition at line 273 of file chew.c.

typedef int* word_type

Definition at line 280 of file chew.c.


Function Documentation

void add_intrinsic ( char *  name,
void (*) ()  func 
)

Definition at line 1294 of file chew.c.

{
  dict_type *new = newentry (name);
  add_to_definition (new, func);
  add_to_definition (new, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int add_to_definition ( dict_type *  entry,
stinst_type  word 
)

Definition at line 1277 of file chew.c.

{
  if (entry->code_end == entry->code_length)
    {
      entry->code_length += 2;
      entry->code =
       (stinst_type *) realloc ((char *) (entry->code),
                             entry->code_length * sizeof (word_type));
    }
  entry->code[entry->code_end] = word;

  return entry->code_end++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void add_var ( char *  name)

Definition at line 1304 of file chew.c.

{
  dict_type *new = newentry (name);
  add_to_definition (new, push_number);
  add_to_definition (new, (stinst_type) (&(new->var)));
  add_to_definition (new, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* addr ( string_type buffer,
unsigned int  idx 
) [static]

Definition at line 175 of file chew.c.

{
  return buffer->ptr + idx;
}

Here is the caller graph for this function:

static char at ( string_type buffer,
unsigned int  pos 
) [static]

Definition at line 183 of file chew.c.

{
  if (pos >= buffer->write_idx)
    return 0;
  return buffer->ptr[pos];
}
static void atsign ( ) [static]

Definition at line 1389 of file chew.c.

{
  isp[0] = *(long *) (isp[0]);
  pc++;
}

Here is the caller graph for this function:

static void bang ( ) [static]

Definition at line 1380 of file chew.c.

{
  *(long *) ((isp[0])) = isp[-1];
  isp -= 2;
  icheck_range ();
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void bulletize ( ) [static]

Definition at line 726 of file chew.c.

{
  unsigned int idx = 0;
  int on = 0;
  string_type out;
  init_string (&out);

  while (at (tos, idx))
    {
      if (at (tos, idx) == '@'
         && at (tos, idx + 1) == '*')
       {
         cattext (&out, "*");
         idx += 2;
       }
      else if (at (tos, idx) == '\n'
              && at (tos, idx + 1) == 'o'
              && isspace ((unsigned char) at (tos, idx + 2)))
       {
         if (!on)
           {
             cattext (&out, "\n@itemize @bullet\n");
             on = 1;

           }
         cattext (&out, "\n@item\n");
         idx += 3;
       }
      else
       {
         catchar (&out, at (tos, idx));
         if (on && at (tos, idx) == '\n'
             && at (tos, idx + 1) == '\n'
             && at (tos, idx + 2) != 'o')
           {
             cattext (&out, "@end itemize");
             on = 0;
           }
         idx++;

       }
    }
  if (on)
    {
      cattext (&out, "@end itemize\n");
    }

  delete_string (tos);
  *tos = out;
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void call ( ) [static]

Definition at line 366 of file chew.c.

{
  stinst_type *oldpc = pc;
  dict_type *e;
  e = (dict_type *) (pc[1]);
  exec (e);
  pc = oldpc + 2;
}

Here is the call graph for this function:

static void catbuf ( string_type buffer,
char *  buf,
unsigned int  len 
) [static]

Definition at line 218 of file chew.c.

{
  if (buffer->write_idx + len >= buffer->size)
    {
      while (buffer->write_idx + len >= buffer->size)
       buffer->size *= 2;
      buffer->ptr = realloc (buffer->ptr, buffer->size);
    }
  memcpy (buffer->ptr + buffer->write_idx, buf, len);
  buffer->write_idx += len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void catchar ( string_type buffer,
int  ch 
) [static]

Definition at line 193 of file chew.c.

{
  if (buffer->write_idx == buffer->size)
    {
      buffer->size *= 2;
      buffer->ptr = realloc (buffer->ptr, buffer->size);
    }

  buffer->ptr[buffer->write_idx++] = ch;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void catstr ( string_type dst,
string_type src 
) [static]

Definition at line 242 of file chew.c.

{
  catbuf (dst, src->ptr, src->write_idx);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void cattext ( string_type buffer,
char *  string 
) [static]

Definition at line 234 of file chew.c.

{
  catbuf (buffer, string, (unsigned int) strlen (string));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void check_range ( ) [static]

Definition at line 303 of file chew.c.

{
  if (tos < stack)
    die ("underflow in string stack");
  if (tos >= stack + STACK)
    die ("overflow in string stack");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void chew_exit ( ) [static]

Definition at line 1467 of file chew.c.

{
  exit (0);
}

Here is the caller graph for this function:

void compile ( char *  string)

Definition at line 1314 of file chew.c.

{
  /* Add words to the dictionary.  */
  char *word;
  string = nextword (string, &word);
  while (string && *string && word[0])
    {
      if (strcmp (word, "var") == 0)
       {
         string = nextword (string, &word);

         add_var (word);
         string = nextword (string, &word);
       }
      else if (word[0] == ':')
       {
         dict_type *ptr;
         /* Compile a word and add to dictionary.  */
         string = nextword (string, &word);

         ptr = newentry (word);
         string = nextword (string, &word);
         while (word[0] != ';')
           {
             switch (word[0])
              {
              case '"':
                /* got a string, embed magic push string
                   function */
                add_to_definition (ptr, push_text);
                add_to_definition (ptr, (stinst_type) (word + 1));
                break;
              case '0':
              case '1':
              case '2':
              case '3':
              case '4':
              case '5':
              case '6':
              case '7':
              case '8':
              case '9':
                /* Got a number, embedd the magic push number
                   function */
                add_to_definition (ptr, push_number);
                add_to_definition (ptr, (stinst_type) atol (word));
                break;
              default:
                add_to_definition (ptr, call);
                add_to_definition (ptr, (stinst_type) lookup_word (word));
              }

             string = nextword (string, &word);
           }
         add_to_definition (ptr, 0);
         string = nextword (string, &word);
       }
      else
       {
         fprintf (stderr, "syntax error at %s\n", string - 1);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int copy_past_newline ( string_type ptr,
unsigned int  idx,
string_type dst 
) [static]

Definition at line 846 of file chew.c.

{
  int column = 0;

  while (at (ptr, idx) && at (ptr, idx) != '\n')
    {
      if (at (ptr, idx) == '\t')
       {
         /* Expand tabs.  Neither makeinfo nor TeX can cope well with
            them.  */
         do
           catchar (dst, ' ');
         while (++column & 7);
       }
      else
       {
         catchar (dst, at (ptr, idx));
         column++;
       }
      idx++;

    }
  catchar (dst, at (ptr, idx));
  idx++;
  return idx;

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void courierize ( ) [static]

Definition at line 639 of file chew.c.

{
  string_type out;
  unsigned int idx = 0;
  int command = 0;

  init_string (&out);

  while (at (tos, idx))
    {
      if (at (tos, idx) == '\n'
         && (at (tos, idx +1 ) == '.'
             || at (tos, idx + 1) == '|'))
       {
         cattext (&out, "\n@example\n");
         do
           {
             idx += 2;

             while (at (tos, idx) && at (tos, idx) != '\n')
              {
                if (command > 1)
                  {
                    /* We are inside {} parameters of some command;
                      Just pass through until matching brace.  */
                    if (at (tos, idx) == '{')
                     ++command;
                    else if (at (tos, idx) == '}')
                     --command;
                  }
                else if (command != 0)
                  {
                    if (at (tos, idx) == '{')
                     ++command;
                    else if (!islower ((unsigned char) at (tos, idx)))
                     --command;
                  }
                else if (at (tos, idx) == '@'
                        && islower ((unsigned char) at (tos, idx + 1)))
                  {
                    ++command;
                  }
                else if (at (tos, idx) == '{' && at (tos, idx + 1) == '*')
                  {
                    cattext (&out, "/*");
                    idx += 2;
                    continue;
                  }
                else if (at (tos, idx) == '*' && at (tos, idx + 1) == '}')
                  {
                    cattext (&out, "*/");
                    idx += 2;
                    continue;
                  }
                else if (at (tos, idx) == '{'
                        || at (tos, idx) == '}')
                  {
                    catchar (&out, '@');
                  }

                catchar (&out, at (tos, idx));
                idx++;
              }
             catchar (&out, '\n');
           }
         while (at (tos, idx) == '\n'
               && ((at (tos, idx + 1) == '.')
                   || (at (tos, idx + 1) == '|')))
           ;
         cattext (&out, "@end example");
       }
      else
       {
         catchar (&out, at (tos, idx));
         idx++;
       }
    }

  overwrite_string (tos, &out);
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void delete_string ( string_type buffer) [static]

Definition at line 168 of file chew.c.

{
  free (buffer->ptr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void die ( char *  msg) [static]

Definition at line 295 of file chew.c.

{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void do_fancy_stuff ( ) [static]

Definition at line 781 of file chew.c.

{
  unsigned int idx = 0;
  string_type out;
  init_string (&out);
  while (at (tos, idx))
    {
      if (at (tos, idx) == '<'
         && at (tos, idx + 1) == '<'
         && !isspace ((unsigned char) at (tos, idx + 2)))
       {
         /* This qualifies as a << startup.  */
         idx += 2;
         cattext (&out, "@code{");
         while (at (tos, idx)
               && at (tos, idx) != '>' )
           {
             catchar (&out, at (tos, idx));
             idx++;

           }
         cattext (&out, "}");
         idx += 2;
       }
      else
       {
         catchar (&out, at (tos, idx));
         idx++;
       }
    }
  delete_string (tos);
  *tos = out;
  pc++;

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void drop ( ) [static]

Definition at line 1066 of file chew.c.

{
  tos--;
  check_range ();
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void exec ( dict_type *  word) [static]

Definition at line 357 of file chew.c.

{
  pc = word->code;
  while (*pc)
    (*pc) ();
}

Here is the caller graph for this function:

static int find ( string_type str,
char *  what 
) [static]

Definition at line 142 of file chew.c.

{
  unsigned int i;
  char *p;
  p = what;
  for (i = 0; i < str->write_idx && *p; i++)
    {
      if (*p == str->ptr[i])
       p++;
      else
       p = what;
    }
  return (*p == 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void get_stuff_in_command ( ) [static]

Definition at line 1029 of file chew.c.

{
  tos++;
  check_range ();
  init_string (tos);

  while (at (ptr, idx))
    {
      if (iscommand (ptr, idx))
       break;
      idx = copy_past_newline (ptr, idx, tos);
    }
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hello ( ) [static]

Definition at line 1396 of file chew.c.

{
  printf ("hello\n");
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void icatstr ( ) [static]

Definition at line 1082 of file chew.c.

{
  tos--;
  check_range ();
  catstr (tos, tos + 1);
  delete_string (tos + 1);
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void icheck_range ( ) [static]

Definition at line 312 of file chew.c.

{
  if (isp < istack)
    die ("underflow in integer stack");
  if (isp >= istack + STACK)
    die ("overflow in integer stack");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void icopy_past_newline ( ) [static]

Definition at line 878 of file chew.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void idrop ( ) [static]

Definition at line 1074 of file chew.c.

{
  isp--;
  icheck_range ();
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void indent ( ) [static]

Definition at line 978 of file chew.c.

{
  string_type out;
  int tab = 0;
  int idx = 0;
  int ol = 0;
  init_string (&out);
  while (at (tos, idx))
    {
      switch (at (tos, idx))
       {
       case '\n':
         cattext (&out, "\n");
         idx++;
         if (tab && at (tos, idx))
           {
             cattext (&out, "    ");
           }
         ol = 0;
         break;
       case '(':
         tab++;
         if (ol == 0)
           cattext (&out, "   ");
         idx++;
         cattext (&out, "(");
         ol = 1;
         break;
       case ')':
         tab--;
         cattext (&out, ")");
         idx++;
         ol = 1;

         break;
       default:
         catchar (&out, at (tos, idx));
         ol = 1;

         idx++;
         break;
       }
    }

  pc++;
  delete_string (tos);
  *tos = out;

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_string ( string_type buffer) [static]

Definition at line 135 of file chew.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_string_with_size ( string_type buffer,
unsigned int  size 
) [static]

Definition at line 125 of file chew.c.

{
  buffer->write_idx = 0;
  buffer->size = size;
  buffer->ptr = malloc (size);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void internalmode ( ) [static]

Definition at line 1102 of file chew.c.

{
  internal_mode = *(isp);
  isp--;
  icheck_range ();
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int iscommand ( string_type ptr,
unsigned int  idx 
) [static]

Definition at line 820 of file chew.c.

{
  unsigned int len = 0;
  while (at (ptr, idx))
    {
      if (isupper ((unsigned char) at (ptr, idx))
         || at (ptr, idx) == ' ' || at (ptr, idx) == '_')
       {
         len++;
         idx++;
       }
      else if (at (ptr, idx) == '\n')
       {
         if (len > 3)
           return 1;
         return 0;
       }
      else
       return 0;
    }
  return 0;
}

Here is the caller graph for this function:

static void kill_bogus_lines ( ) [static]

Definition at line 891 of file chew.c.

{
  int sl;

  int idx = 0;
  int c;
  int dot = 0;

  string_type out;
  init_string (&out);
  /* Drop leading nl.  */
  while (at (tos, idx) == '\n')
    {
      idx++;
    }
  c = idx;

  /* If the first char is a '.' prepend a newline so that it is
     recognized properly later.  */
  if (at (tos, idx) == '.')
    catchar (&out, '\n');

  /* Find the last char.  */
  while (at (tos, idx))
    {
      idx++;
    }

  /* Find the last non white before the nl.  */
  idx--;

  while (idx && isspace ((unsigned char) at (tos, idx)))
    idx--;
  idx++;

  /* Copy buffer upto last char, but blank lines before and after
     dots don't count.  */
  sl = 1;

  while (c < idx)
    {
      if (at (tos, c) == '\n'
         && at (tos, c + 1) == '\n'
         && at (tos, c + 2) == '.')
       {
         /* Ignore two newlines before a dot.  */
         c++;
       }
      else if (at (tos, c) == '.' && sl)
       {
         /* remember that this line started with a dot.  */
         dot = 2;
       }
      else if (at (tos, c) == '\n'
              && at (tos, c + 1) == '\n'
              && dot)
       {
         c++;
         /* Ignore two newlines when last line was dot.  */
       }

      catchar (&out, at (tos, c));
      if (at (tos, c) == '\n')
       {
         sl = 1;

         if (dot == 2)
           dot = 1;
         else
           dot = 0;
       }
      else
       sl = 0;

      c++;

    }

  /* Append nl.  */
  catchar (&out, '\n');
  pc++;
  delete_string (tos);
  *tos = out;

}

Here is the call graph for this function:

Here is the caller graph for this function:

dict_type* lookup_word ( char *  word)

Definition at line 1213 of file chew.c.

{
  dict_type *ptr = root;
  while (ptr)
    {
      if (strcmp (ptr->word, word) == 0)
       return ptr;
      ptr = ptr->next;
    }
  if (warning)
    fprintf (stderr, "Can't find %s\n", word);
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  ac,
av   
)

Definition at line 1473 of file chew.c.

{
  unsigned int i;
  string_type buffer;
  string_type pptr;

  init_string (&buffer);
  init_string (&pptr);
  init_string (stack + 0);
  tos = stack + 1;
  ptr = &pptr;

  add_intrinsic ("push_text", push_text);
  add_intrinsic ("!", bang);
  add_intrinsic ("@", atsign);
  add_intrinsic ("hello", hello);
  add_intrinsic ("stdout", stdout_);
  add_intrinsic ("stderr", stderr_);
  add_intrinsic ("print", print);
  add_intrinsic ("skip_past_newline", skip_past_newline);
  add_intrinsic ("catstr", icatstr);
  add_intrinsic ("copy_past_newline", icopy_past_newline);
  add_intrinsic ("dup", other_dup);
  add_intrinsic ("drop", drop);
  add_intrinsic ("idrop", idrop);
  add_intrinsic ("remchar", remchar);
  add_intrinsic ("get_stuff_in_command", get_stuff_in_command);
  add_intrinsic ("do_fancy_stuff", do_fancy_stuff);
  add_intrinsic ("bulletize", bulletize);
  add_intrinsic ("courierize", courierize);
  /* If the following line gives an error, exit() is not declared in the
     ../hosts/foo.h file for this host.  Fix it there, not here!  */
  /* No, don't fix it anywhere; see comment on chew_exit--Ian Taylor.  */
  add_intrinsic ("exit", chew_exit);
  add_intrinsic ("swap", swap);
  add_intrinsic ("outputdots", outputdots);
  add_intrinsic ("paramstuff", paramstuff);
  add_intrinsic ("maybecatstr", maybecatstr);
  add_intrinsic ("translatecomments", translatecomments);
  add_intrinsic ("kill_bogus_lines", kill_bogus_lines);
  add_intrinsic ("indent", indent);
  add_intrinsic ("internalmode", internalmode);
  add_intrinsic ("print_stack_level", print_stack_level);
  add_intrinsic ("strip_trailing_newlines", strip_trailing_newlines);

  /* Put a nl at the start.  */
  catchar (&buffer, '\n');

  read_in (&buffer, stdin);
  remove_noncomments (&buffer, ptr);
  for (i = 1; i < (unsigned int) ac; i++)
    {
      if (av[i][0] == '-')
       {
         if (av[i][1] == 'f')
           {
             string_type b;
             FILE *f;
             init_string (&b);

             f = fopen (av[i + 1], "r");
             if (!f)
              {
                fprintf (stderr, "Can't open the input file %s\n",
                        av[i + 1]);
                return 33;
              }

             read_in (&b, f);
             compile (b.ptr);
             perform ();
           }
         else if (av[i][1] == 'i')
           {
             internal_wanted = 1;
           }
         else if (av[i][1] == 'w')
           {
             warning = 1;
           }
         else
           usage ();
       }
    }
  write_buffer (stack + 0, stdout);
  if (tos != stack)
    {
      fprintf (stderr, "finishing with current stack level %d\n",
              tos - stack);
      return 1;
    }
  return 0;
}

Here is the call graph for this function:

static void maybecatstr ( ) [static]

Definition at line 1111 of file chew.c.

Here is the call graph for this function:

Here is the caller graph for this function:

dict_type* newentry ( char *  word)

Definition at line 1263 of file chew.c.

{
  dict_type *new = (dict_type *) malloc (sizeof (dict_type));
  new->word = word;
  new->next = root;
  root = new;
  new->code = (stinst_type *) malloc (sizeof (stinst_type));
  new->code_length = 1;
  new->code_end = 0;
  return new;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* nextword ( char *  string,
char **  word 
)

Definition at line 1124 of file chew.c.

{
  char *word_start;
  int idx;
  char *dst;
  char *src;

  int length = 0;

  while (isspace ((unsigned char) *string) || *string == '-')
    {
      if (*string == '-')
       {
         while (*string && *string != '\n')
           string++;

       }
      else
       {
         string++;
       }
    }
  if (!*string)
    return 0;

  word_start = string;
  if (*string == '"')
    {
      do
       {
         string++;
         length++;
         if (*string == '\\')
           {
             string += 2;
             length += 2;
           }
       }
      while (*string != '"');
    }
  else
    {
      while (!isspace ((unsigned char) *string))
       {
         string++;
         length++;

       }
    }

  *word = malloc (length + 1);

  dst = *word;
  src = word_start;

  for (idx = 0; idx < length; idx++)
    {
      if (src[idx] == '\\')
       switch (src[idx + 1])
         {
         case 'n':
           *dst++ = '\n';
           idx++;
           break;
         case '"':
         case '\\':
           *dst++ = src[idx + 1];
           idx++;
           break;
         default:
           *dst++ = '\\';
           break;
         }
      else
       *dst++ = src[idx];
    }
  *dst++ = 0;

  if (*string)
    return string + 1;
  else
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void other_dup ( ) [static]

Definition at line 1056 of file chew.c.

{
  tos++;
  check_range ();
  init_string (tos);
  catstr (tos, tos - 1);
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void outputdots ( ) [static]

Definition at line 594 of file chew.c.

{
  unsigned int idx = 0;
  string_type out;
  init_string (&out);

  while (at (tos, idx))
    {
      if (at (tos, idx) == '\n' && at (tos, idx + 1) == '.')
       {
         char c;
         idx += 2;

         while ((c = at (tos, idx)) && c != '\n')
           {
             if (c == '{' && at (tos, idx + 1) == '*')
              {
                cattext (&out, "/*");
                idx += 2;
              }
             else if (c == '*' && at (tos, idx + 1) == '}')
              {
                cattext (&out, "*/");
                idx += 2;
              }
             else
              {
                catchar (&out, c);
                idx++;
              }
           }
         catchar (&out, '\n');
       }
      else
       {
         idx++;
       }
    }

  overwrite_string (tos, &out);
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void overwrite_string ( string_type dst,
string_type src 
) [static]

Definition at line 207 of file chew.c.

{
  free (dst->ptr);
  dst->size = src->size;
  dst->write_idx = src->write_idx;
  dst->ptr = src->ptr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void paramstuff ( ) [static]

Definition at line 489 of file chew.c.

{
  unsigned int openp;
  unsigned int fname;
  unsigned int idx;
  unsigned int len;
  string_type out;
  init_string (&out);

#define NO_PARAMS 1

  /* Make sure that it's not already param'd or proto'd.  */
  if (NO_PARAMS
      || find (tos, "PARAMS") || find (tos, "PROTO") || !find (tos, "("))
    {
      catstr (&out, tos);
    }
  else
    {
      /* Find the open paren.  */
      for (openp = 0; at (tos, openp) != '(' && at (tos, openp); openp++)
       ;

      fname = openp;
      /* Step back to the fname.  */
      fname--;
      while (fname && isspace ((unsigned char) at (tos, fname)))
       fname--;
      while (fname
            && !isspace ((unsigned char) at (tos,fname))
            && at (tos,fname) != '*')
       fname--;

      fname++;

      /* Output type, omitting trailing whitespace character(s), if
         any.  */
      for (len = fname; 0 < len; len--)
       {
         if (!isspace ((unsigned char) at (tos, len - 1)))
           break;
       }
      for (idx = 0; idx < len; idx++)
       catchar (&out, at (tos, idx));

      cattext (&out, "\n"); /* Insert a newline between type and fnname */

      /* Output function name, omitting trailing whitespace
         character(s), if any.  */
      for (len = openp; 0 < len; len--)
       {
         if (!isspace ((unsigned char) at (tos, len - 1)))
           break;
       }
      for (idx = fname; idx < len; idx++)
       catchar (&out, at (tos, idx));

      cattext (&out, " PARAMS (");

      for (idx = openp; at (tos, idx) && at (tos, idx) != ';'; idx++)
       catchar (&out, at (tos, idx));

      cattext (&out, ");\n\n");
    }
  overwrite_string (tos, &out);
  pc++;

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void perform ( ) [static]

Definition at line 1229 of file chew.c.

{
  tos = stack;

  while (at (ptr, idx))
    {
      /* It's worth looking through the command list.  */
      if (iscommand (ptr, idx))
       {
         char *next;
         dict_type *word;

         (void) nextword (addr (ptr, idx), &next);

         word = lookup_word (next);

         if (word)
           {
             exec (word);
           }
         else
           {
             if (warning)
              fprintf (stderr, "warning, %s is not recognised\n", next);
             skip_past_newline ();
           }

       }
      else
       skip_past_newline ();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void print ( ) [static]

Definition at line 1421 of file chew.c.

{
  if (*isp == 1)
    write_buffer (tos, stdout);
  else if (*isp == 2)
    write_buffer (tos, stderr);
  else
    fprintf (stderr, "print: illegal print destination `%ld'\n", *isp);
  isp--;
  tos--;
  icheck_range ();
  check_range ();
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void print_stack_level ( ) [static]

Definition at line 473 of file chew.c.

{
  fprintf (stderr, "current string stack depth = %d, ", tos - stack);
  fprintf (stderr, "current integer stack depth = %d\n", isp - istack);
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void push_number ( ) [static]

Definition at line 394 of file chew.c.

{
  isp++;
  icheck_range ();
  pc++;
  *isp = (long) (*pc);
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void push_text ( ) [static]

Definition at line 404 of file chew.c.

{
  tos++;
  check_range ();
  init_string (tos);
  pc++;
  cattext (tos, *((char **) pc));
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void read_in ( string_type str,
FILE *  file 
) [static]

Definition at line 1437 of file chew.c.

{
  char buff[10000];
  unsigned int r;
  do
    {
      r = fread (buff, 1, sizeof (buff), file);
      catbuf (str, buff, r);
    }
  while (r);
  buff[0] = 0;

  catbuf (str, buff, 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void remchar ( ) [static]

Definition at line 376 of file chew.c.

{
  if (tos->write_idx)
    tos->write_idx--;
  pc++;
}

Here is the caller graph for this function:

static void remove_noncomments ( string_type src,
string_type dst 
) [static]

Definition at line 420 of file chew.c.

{
  unsigned int idx = 0;

  while (at (src, idx))
    {
      /* Now see if we have a comment at the start of the line.  */
      if (at (src, idx) == '\n'
         && at (src, idx + 1) == '/'
         && at (src, idx + 2) == '*')
       {
         idx += 3;

         idx = skip_white_and_stars (src, idx);

         /* Remove leading dot */
         if (at (src, idx) == '.')
           idx++;

         /* Copy to the end of the line, or till the end of the
            comment.  */
         while (at (src, idx))
           {
             if (at (src, idx) == '\n')
              {
                /* end of line, echo and scrape of leading blanks  */
                if (at (src, idx + 1) == '\n')
                  catchar (dst, '\n');
                catchar (dst, '\n');
                idx++;
                idx = skip_white_and_stars (src, idx);
              }
             else if (at (src, idx) == '*' && at (src, idx + 1) == '/')
              {
                idx += 2;
                cattext (dst, "\nENDDD\n");
                break;
              }
             else
              {
                catchar (dst, at (src, idx));
                idx++;
              }
           }
       }
      else
       idx++;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void skip_past_newline ( ) [static]

Definition at line 1092 of file chew.c.

{
  while (at (ptr, idx)
        && at (ptr, idx) != '\n')
    idx++;
  idx++;
  pc++;
}

Here is the caller graph for this function:

static unsigned int skip_white_and_stars ( string_type src,
unsigned int  idx 
) [static]

Definition at line 250 of file chew.c.

{
  char c;
  while ((c = at (src, idx)),
        isspace ((unsigned char) c)
        || (c == '*'
            /* Don't skip past end-of-comment or star as first
              character on its line.  */
            && at (src, idx +1) != '/'
            && at (src, idx -1) != '\n'))
    idx++;
  return idx;
}

Here is the caller graph for this function:

static void stderr_ ( ) [static]

Definition at line 1412 of file chew.c.

{
  isp++;
  icheck_range ();
  *isp = 2;
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void stdout_ ( ) [static]

Definition at line 1403 of file chew.c.

{
  isp++;
  icheck_range ();
  *isp = 1;
  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void strip_trailing_newlines ( ) [static]

Definition at line 384 of file chew.c.

{
  while ((isspace ((unsigned char) at (tos, tos->write_idx - 1))
         || at (tos, tos->write_idx - 1) == '\n')
        && tos->write_idx > 0)
    tos->write_idx--;
  pc++;
}

Here is the caller graph for this function:

static void swap ( ) [static]

Definition at line 1045 of file chew.c.

{
  string_type t;

  t = tos[0];
  tos[0] = tos[-1];
  tos[-1] = t;
  pc++;
}

Here is the caller graph for this function:

static void translatecomments ( ) [static]

Definition at line 562 of file chew.c.

{
  unsigned int idx = 0;
  string_type out;
  init_string (&out);

  while (at (tos, idx))
    {
      if (at (tos, idx) == '{' && at (tos, idx + 1) == '*')
       {
         cattext (&out, "/*");
         idx += 2;
       }
      else if (at (tos, idx) == '*' && at (tos, idx + 1) == '}')
       {
         cattext (&out, "*/");
         idx += 2;
       }
      else
       {
         catchar (&out, at (tos, idx));
         idx++;
       }
    }

  overwrite_string (tos, &out);

  pc++;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void usage ( ) [static]

Definition at line 1455 of file chew.c.

{
  fprintf (stderr, "usage: -[d|i|g] <file >file\n");
  exit (33);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void write_buffer ( string_type buffer,
FILE *  f 
) [static]

Definition at line 160 of file chew.c.

{
  fwrite (buffer->ptr, buffer->write_idx, 1, f);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 271 of file chew.c.

Definition at line 96 of file chew.c.

Definition at line 95 of file chew.c.

long* isp = &istack[0]

Definition at line 278 of file chew.c.

Definition at line 277 of file chew.c.

tmpdir mixed lib D_PAGED start address *Disassembly of section *<\.plt\+0x10 > lr pc

Definition at line 274 of file chew.c.

Definition at line 272 of file chew.c.

dict_type* root

Definition at line 1210 of file chew.c.

Definition at line 276 of file chew.c.

Definition at line 275 of file chew.c.

Definition at line 268 of file chew.c.

Definition at line 269 of file chew.c.

Definition at line 98 of file chew.c.