OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [doc/] [makedoc.c] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/* chew
/* chew
   Copyright (C) 1990-1992 Free Software Foundation, Inc.
   Copyright (C) 1990-1992 Free Software Foundation, Inc.
   Contributed by steve chamberlain @cygnus
   Contributed by steve chamberlain @cygnus
 
 
 
 
This program is free software; you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
(at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 
/*
/*
 Yet another way of extracting documentation from source.
 Yet another way of extracting documentation from source.
 No, I haven't finished it yet, but I hope you people like it better
 No, I haven't finished it yet, but I hope you people like it better
 that the old way
 that the old way
 
 
 sac
 sac
 
 
Basically, this is a sort of string forth, maybe we should call it
Basically, this is a sort of string forth, maybe we should call it
struth?
struth?
 
 
You define new words thus:
You define new words thus:
: <newword> <oldwords> ;
: <newword> <oldwords> ;
There is  no
There is  no
 
 
*/
*/
 
 
 
 
 
 
#include "ansidecl.h"
#include "ansidecl.h"
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
 
 
#define DEF_SIZE 5000
#define DEF_SIZE 5000
#define STACK 50
#define STACK 50
#define MIN_CMDLEN      4       /* Minimum length of a command */
#define MIN_CMDLEN      4       /* Minimum length of a command */
 
 
int internal_wanted;
int internal_wanted;
int internal_mode;
int internal_mode;
int Verbose=0;
int Verbose=0;
 
 
 
 
 
 
/* Here is a string type ... */
/* Here is a string type ... */
 
 
typedef struct buffer
typedef struct buffer
{
{
    char *ptr;
    char *ptr;
    unsigned int write_idx;
    unsigned int write_idx;
    unsigned int size;
    unsigned int size;
} string_type;
} string_type;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
static void DEFUN(init_string_with_size,(buffer, size),
static void DEFUN(init_string_with_size,(buffer, size),
           string_type *buffer AND
           string_type *buffer AND
           unsigned int size )
           unsigned int size )
{
{
  buffer->write_idx = 0;
  buffer->write_idx = 0;
  buffer->size = size;
  buffer->size = size;
  buffer->ptr = malloc(size);
  buffer->ptr = malloc(size);
}
}
 
 
static void DEFUN(init_string,(buffer),
static void DEFUN(init_string,(buffer),
           string_type *buffer)
           string_type *buffer)
{
{
    init_string_with_size(buffer, DEF_SIZE);
    init_string_with_size(buffer, DEF_SIZE);
 
 
}
}
 
 
static int DEFUN(find, (str, what),
static int DEFUN(find, (str, what),
          string_type *str AND
          string_type *str AND
          char *what)
          char *what)
{
{
    unsigned int i;
    unsigned int i;
    char *p;
    char *p;
    p = what;
    p = what;
    for (i = 0; i < str->write_idx && *p; i++)
    for (i = 0; i < str->write_idx && *p; i++)
    {
    {
        if (*p == str->ptr[i])
        if (*p == str->ptr[i])
         p++;
         p++;
        else
        else
         p = what;
         p = what;
    }
    }
    return (*p == 0);
    return (*p == 0);
 
 
}
}
 
 
static void DEFUN(write_buffer,(buffer),
static void DEFUN(write_buffer,(buffer),
           string_type *buffer)
           string_type *buffer)
{
{
    fwrite(buffer->ptr, buffer->write_idx, 1, stdout);
    fwrite(buffer->ptr, buffer->write_idx, 1, stdout);
}
}
 
 
 
 
static void DEFUN(delete_string,(buffer),
static void DEFUN(delete_string,(buffer),
           string_type *buffer)
           string_type *buffer)
{
{
    free(buffer->ptr);
    free(buffer->ptr);
}
}
 
 
 
 
static char *DEFUN(addr, (buffer, idx),
static char *DEFUN(addr, (buffer, idx),
            string_type *buffer AND
            string_type *buffer AND
            unsigned int idx)
            unsigned int idx)
{
{
    return buffer->ptr + idx;
    return buffer->ptr + idx;
}
}
 
 
static char DEFUN(at,(buffer, pos),
static char DEFUN(at,(buffer, pos),
           string_type *buffer AND
           string_type *buffer AND
           unsigned int pos)
           unsigned int pos)
{
{
    if ( pos >= buffer->write_idx)
    if ( pos >= buffer->write_idx)
    {
    {
        return 0;
        return 0;
    }
    }
    return buffer->ptr[pos];
    return buffer->ptr[pos];
}
}
 
 
static void DEFUN(catchar,(buffer, ch),
static void DEFUN(catchar,(buffer, ch),
           string_type *buffer AND
           string_type *buffer AND
           char ch)
           char ch)
{
{
  if (buffer->write_idx == buffer->size)
  if (buffer->write_idx == buffer->size)
  {
  {
    buffer->size *=2;
    buffer->size *=2;
    buffer->ptr = realloc(buffer->ptr, buffer->size);
    buffer->ptr = realloc(buffer->ptr, buffer->size);
  }
  }
 
 
  buffer->ptr[buffer->write_idx ++ ] = ch;
  buffer->ptr[buffer->write_idx ++ ] = ch;
}
}
 
 
 
 
static void DEFUN(overwrite_string,(dst,   src),
static void DEFUN(overwrite_string,(dst,   src),
           string_type *dst AND
           string_type *dst AND
           string_type *src)
           string_type *src)
{
{
    free(dst->ptr);
    free(dst->ptr);
    dst->size = src->size;
    dst->size = src->size;
    dst->write_idx = src->write_idx;
    dst->write_idx = src->write_idx;
    dst->ptr = src->ptr;
    dst->ptr = src->ptr;
}
}
 
 
static void DEFUN(catstr,(dst, src),
static void DEFUN(catstr,(dst, src),
           string_type *dst AND
           string_type *dst AND
           string_type *src)
           string_type *src)
{
{
    unsigned int i;
    unsigned int i;
    for (i = 0; i < src->write_idx; i++)
    for (i = 0; i < src->write_idx; i++)
    {
    {
        catchar(dst, src->ptr[i]);
        catchar(dst, src->ptr[i]);
    }
    }
}
}
 
 
 
 
static void DEFUN(cattext,(buffer, string),
static void DEFUN(cattext,(buffer, string),
           string_type *buffer AND
           string_type *buffer AND
           char *string)
           char *string)
{
{
 
 
    while (*string)
    while (*string)
    {
    {
        catchar(buffer, *string);
        catchar(buffer, *string);
        string++;
        string++;
    }
    }
}
}
 
 
static void DEFUN(catbuf,(buffer, buf, len),
static void DEFUN(catbuf,(buffer, buf, len),
           string_type *buffer AND
           string_type *buffer AND
           char *buf AND
           char *buf AND
           unsigned int len)
           unsigned int len)
{
{
 
 
    while (len--)
    while (len--)
    {
    {
        catchar(buffer, *buf);
        catchar(buffer, *buf);
        buf++;
        buf++;
    }
    }
}
}
 
 
 
 
 
 
static unsigned int
static unsigned int
DEFUN(skip_white_and_stars,(src, idx),
DEFUN(skip_white_and_stars,(src, idx),
      string_type *src AND
      string_type *src AND
      unsigned int idx)
      unsigned int idx)
{
{
    while (isspace(at(src,idx))
    while (isspace(at(src,idx))
           || (at(src,idx) == '*' && at(src,idx +1) !='/'))
           || (at(src,idx) == '*' && at(src,idx +1) !='/'))
     idx++;
     idx++;
    return idx;
    return idx;
 
 
 
 
}
}
/***********************************************************************/
/***********************************************************************/
 
 
 
 
string_type stack[STACK];
string_type stack[STACK];
string_type *tos;
string_type *tos;
 
 
unsigned int idx = 0; /* Pos in input buffer */
unsigned int idx = 0; /* Pos in input buffer */
string_type *ptr; /* and the buffer */
string_type *ptr; /* and the buffer */
typedef void (*stinst_type)(NOARGS);
typedef void (*stinst_type)(NOARGS);
stinst_type *pc;
stinst_type *pc;
stinst_type sstack[STACK];
stinst_type sstack[STACK];
stinst_type *ssp = &sstack[0];
stinst_type *ssp = &sstack[0];
int istack[STACK];
int istack[STACK];
int *isp = &istack[0];
int *isp = &istack[0];
 
 
typedef int *word_type;
typedef int *word_type;
 
 
 
 
 
 
struct dict_struct
struct dict_struct
{
{
    char *word;
    char *word;
    struct dict_struct *next;
    struct dict_struct *next;
   stinst_type *code;
   stinst_type *code;
    int code_length;
    int code_length;
    int code_end;
    int code_end;
    int var;
    int var;
 
 
};
};
typedef struct dict_struct dict_type;
typedef struct dict_struct dict_type;
#define WORD(x) static void x(NOARGS)
#define WORD(x) static void x(NOARGS)
 
 
static void DEFUN(exec,(word),
static void DEFUN(exec,(word),
                  dict_type *word)
                  dict_type *word)
{
{
    pc = word->code;
    pc = word->code;
    while (*pc)
    while (*pc)
    {
    {
        (*pc)();
        (*pc)();
    }
    }
 
 
}
}
WORD(call)
WORD(call)
{
{
stinst_type *oldpc = pc;
stinst_type *oldpc = pc;
    dict_type *e;
    dict_type *e;
    e =  (dict_type *)(pc [1]);
    e =  (dict_type *)(pc [1]);
    exec(e);
    exec(e);
    pc = oldpc + 2;
    pc = oldpc + 2;
 
 
}
}
 
 
WORD(remchar)
WORD(remchar)
{
{
    tos->write_idx--;
    tos->write_idx--;
    pc++;
    pc++;
 
 
}
}
 
 
WORD(push_number)
WORD(push_number)
{
{
    isp++;
    isp++;
    pc++;
    pc++;
    *isp = (int)(*pc);
    *isp = (int)(*pc);
    pc++;
    pc++;
 
 
}
}
 
 
 
 
 
 
 
 
WORD(push_text)
WORD(push_text)
{
{
 
 
    tos++;
    tos++;
    init_string(tos);
    init_string(tos);
    pc++;
    pc++;
    cattext(tos,*((char **)pc));
    cattext(tos,*((char **)pc));
    pc++;
    pc++;
 
 
}
}
 
 
 
 
 
 
/* This function removes everything not inside comments starting on
/* This function removes everything not inside comments starting on
   the first char of the line from the  string, also when copying
   the first char of the line from the  string, also when copying
   comments, removes blank space and leading *'s
   comments, removes blank space and leading *'s
   Blank lines are turned into one blank line
   Blank lines are turned into one blank line
 */
 */
 
 
static void
static void
DEFUN(remove_noncomments,(src,dst),
DEFUN(remove_noncomments,(src,dst),
           string_type *src AND
           string_type *src AND
           string_type *dst)
           string_type *dst)
{
{
    unsigned int idx = 0;
    unsigned int idx = 0;
 
 
    while (at(src,idx))
    while (at(src,idx))
    {
    {
        /* Now see if we have a comment at the start of the line */
        /* Now see if we have a comment at the start of the line */
        if (at(src,idx) == '\n'
        if (at(src,idx) == '\n'
            && at(src,idx+1) ==  '/'
            && at(src,idx+1) ==  '/'
            && at(src,idx+2) == '*')
            && at(src,idx+2) == '*')
        {
        {
            idx+=3;
            idx+=3;
 
 
            idx = skip_white_and_stars(src,idx);
            idx = skip_white_and_stars(src,idx);
 
 
            /* Remove leading dot */
            /* Remove leading dot */
            if (at(src, idx) == '.')
            if (at(src, idx) == '.')
             idx++;
             idx++;
 
 
            /* Copy to the end of the line, or till the end of the
            /* Copy to the end of the line, or till the end of the
               comment */
               comment */
            while (at(src, idx))
            while (at(src, idx))
            {
            {
                if (at(src, idx) == '\n')
                if (at(src, idx) == '\n')
                {
                {
                    /* end of line, echo and scrape of leading blanks  */
                    /* end of line, echo and scrape of leading blanks  */
                    if (at(src,idx +1) == '\n')
                    if (at(src,idx +1) == '\n')
                     catchar(dst,'\n');
                     catchar(dst,'\n');
                    catchar(dst,'\n');
                    catchar(dst,'\n');
                    idx++;
                    idx++;
                    idx =   skip_white_and_stars(src, idx);
                    idx =   skip_white_and_stars(src, idx);
                }
                }
                else if (at(src, idx) == '*' && at(src,idx+1) == '/')
                else if (at(src, idx) == '*' && at(src,idx+1) == '/')
                {
                {
                    idx +=2 ;
                    idx +=2 ;
                    cattext(dst,"\nENDDD\n");
                    cattext(dst,"\nENDDD\n");
                    break;
                    break;
                }
                }
                else
                else
                {
                {
                    catchar(dst, at(src, idx));
                    catchar(dst, at(src, idx));
                    idx++;
                    idx++;
                }
                }
            }
            }
        }
        }
        else idx++;
        else idx++;
    }
    }
}
}
/* turn foobar name(stuff); into foobar EXFUN(name,(stuff));
/* turn foobar name(stuff); into foobar EXFUN(name,(stuff));
 
 
 */
 */
 
 
static void
static void
DEFUN_VOID(exfunstuff)
DEFUN_VOID(exfunstuff)
{
{
    unsigned int openp;
    unsigned int openp;
    unsigned int fname;
    unsigned int fname;
    unsigned int idx;
    unsigned int idx;
    string_type out;
    string_type out;
    init_string(&out);
    init_string(&out);
 
 
 
 
    /* make sure that it's not already exfuned */
    /* make sure that it's not already exfuned */
    if(find(tos,"EXFUN") || find(tos,"PROTO") || !find(tos,"(")) {
    if(find(tos,"EXFUN") || find(tos,"PROTO") || !find(tos,"(")) {
            catstr(&out,tos);
            catstr(&out,tos);
        }
        }
    else
    else
    {
    {
 
 
        /*Find the open paren*/
        /*Find the open paren*/
        for (openp = 0; at(tos, openp) != '('  && at(tos,openp); openp++)
        for (openp = 0; at(tos, openp) != '('  && at(tos,openp); openp++)
         ;
         ;
 
 
        fname = openp;
        fname = openp;
        /* Step back to the fname */
        /* Step back to the fname */
        fname--;
        fname--;
        while (fname && isspace(at(tos, fname)))
        while (fname && isspace(at(tos, fname)))
         fname --;
         fname --;
        while (fname && !isspace(at(tos,fname)) && at(tos,fname) != '*')
        while (fname && !isspace(at(tos,fname)) && at(tos,fname) != '*')
         fname--;
         fname--;
 
 
        fname++;
        fname++;
 
 
        for (idx = 0; idx < fname; idx++)
        for (idx = 0; idx < fname; idx++)
        {
        {
            catchar(&out, at(tos,idx));
            catchar(&out, at(tos,idx));
        }
        }
 
 
        cattext(&out,"EXFUN(");
        cattext(&out,"EXFUN(");
        for (idx = fname; idx < openp; idx++)
        for (idx = fname; idx < openp; idx++)
        {
        {
            catchar(&out, at(tos,idx));
            catchar(&out, at(tos,idx));
        }
        }
        cattext(&out,", ");
        cattext(&out,", ");
        while (at(tos,idx) && at(tos,idx) !=';')
        while (at(tos,idx) && at(tos,idx) !=';')
        {
        {
            catchar(&out, at(tos, idx));
            catchar(&out, at(tos, idx));
            idx++;
            idx++;
        }
        }
        cattext(&out,");\n");
        cattext(&out,");\n");
    }
    }
    overwrite_string(tos, &out);
    overwrite_string(tos, &out);
    pc++;
    pc++;
 
 
}
}
 
 
 
 
 
 
/* turn {*
/* turn {*
   and *} into comments */
   and *} into comments */
 
 
WORD(translatecomments)
WORD(translatecomments)
{
{
    unsigned int idx = 0;
    unsigned int idx = 0;
    string_type out;
    string_type out;
    init_string(&out);
    init_string(&out);
 
 
    while (at(tos, idx))
    while (at(tos, idx))
    {
    {
        if (at(tos,idx) == '{' && at(tos,idx+1) =='*')
        if (at(tos,idx) == '{' && at(tos,idx+1) =='*')
        {
        {
            cattext(&out,"      /*");
            cattext(&out,"      /*");
            idx+=2;
            idx+=2;
        }
        }
        else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
        else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
        {
        {
            cattext(&out,"*/");
            cattext(&out,"*/");
            idx+=2;
            idx+=2;
        }
        }
        else
        else
        {
        {
            catchar(&out, at(tos, idx));
            catchar(&out, at(tos, idx));
            idx++;
            idx++;
        }
        }
    }
    }
 
 
 
 
    overwrite_string(tos, &out);
    overwrite_string(tos, &out);
 
 
    pc++;
    pc++;
 
 
}
}
 
 
/* find something like
/* find something like
   QUICKREF
   QUICKREF
     memchar ansi  pure
     memchar ansi  pure
 
 
     into
     into
     merge with words on tos and output them to stderror
     merge with words on tos and output them to stderror
 
 
*/
*/
WORD(quickref)
WORD(quickref)
{
{
  string_type *nos = tos-1;
  string_type *nos = tos-1;
  unsigned int nosscan = 0;
  unsigned int nosscan = 0;
  unsigned int idx = 0;
  unsigned int idx = 0;
 
 
  while (at(tos, idx))
  while (at(tos, idx))
  {
  {
    if (at(tos,idx) == '~')
    if (at(tos,idx) == '~')
    {
    {
      /* Skip the whitespace */
      /* Skip the whitespace */
      while (at(nos, nosscan) == ' ')
      while (at(nos, nosscan) == ' ')
       nosscan++;
       nosscan++;
 
 
      /* Sub the next word from the nos*/
      /* Sub the next word from the nos*/
      while (at(nos, nosscan) != ' ' &&
      while (at(nos, nosscan) != ' ' &&
             at(nos, nosscan) != 0)
             at(nos, nosscan) != 0)
      {
      {
        fprintf(stderr, "%c", at(nos, nosscan));
        fprintf(stderr, "%c", at(nos, nosscan));
        nosscan++;
        nosscan++;
      }
      }
    }
    }
 
 
    else
    else
    {
    {
      fprintf(stderr,"%c", at(tos, idx));
      fprintf(stderr,"%c", at(tos, idx));
 
 
    }
    }
    idx++;
    idx++;
  }
  }
 
 
  delete_string(tos);
  delete_string(tos);
  delete_string(nos);
  delete_string(nos);
  tos-=2;
  tos-=2;
  pc++;
  pc++;
 
 
}
}
 
 
#if 0
#if 0
/* turn everything not starting with a . into a comment */
/* turn everything not starting with a . into a comment */
 
 
WORD(manglecomments)
WORD(manglecomments)
{
{
    unsigned int idx = 0;
    unsigned int idx = 0;
    string_type out;
    string_type out;
    init_string(&out);
    init_string(&out);
 
 
    while (at(tos, idx))
    while (at(tos, idx))
    {
    {
        if (at(tos,idx) == '\n' && at(tos,idx+1) =='*')
        if (at(tos,idx) == '\n' && at(tos,idx+1) =='*')
        {
        {
            cattext(&out,"      /*");
            cattext(&out,"      /*");
            idx+=2;
            idx+=2;
        }
        }
        else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
        else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
        {
        {
            cattext(&out,"*/");
            cattext(&out,"*/");
            idx+=2;
            idx+=2;
        }
        }
        else
        else
        {
        {
            catchar(&out, at(tos, idx));
            catchar(&out, at(tos, idx));
            idx++;
            idx++;
        }
        }
    }
    }
 
 
 
 
    overwrite_string(tos, &out);
    overwrite_string(tos, &out);
 
 
    pc++;
    pc++;
 
 
}
}
#endif
#endif
 
 
/* Mod tos so that only lines with leading dots remain */
/* Mod tos so that only lines with leading dots remain */
static void
static void
DEFUN_VOID(outputdots)
DEFUN_VOID(outputdots)
{
{
    unsigned int idx = 0;
    unsigned int idx = 0;
    string_type out;
    string_type out;
    init_string(&out);
    init_string(&out);
 
 
    while (at(tos, idx))
    while (at(tos, idx))
    {
    {
        if (at(tos, idx) == '\n' && at(tos, idx+1) == '.')
        if (at(tos, idx) == '\n' && at(tos, idx+1) == '.')
        {
        {
            idx += 2;
            idx += 2;
 
 
            while (at(tos, idx) && at(tos, idx)!='\n')
            while (at(tos, idx) && at(tos, idx)!='\n')
            {
            {
                if (at(tos,idx) == '{' && at(tos,idx+1) =='*')
                if (at(tos,idx) == '{' && at(tos,idx+1) =='*')
                {
                {
                    cattext(&out," /*");
                    cattext(&out," /*");
                    idx+=2;
                    idx+=2;
                }
                }
                else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
                else if (at(tos,idx) == '*' && at(tos,idx+1) =='}')
                {
                {
                    cattext(&out,"*/");
                    cattext(&out,"*/");
                    idx+=2;
                    idx+=2;
                }
                }
                else
                else
                {
                {
                    catchar(&out, at(tos, idx));
                    catchar(&out, at(tos, idx));
                    idx++;
                    idx++;
                }
                }
            }
            }
            catchar(&out,'\n');
            catchar(&out,'\n');
        }
        }
        else
        else
        {
        {
            idx++;
            idx++;
        }
        }
    }
    }
 
 
    overwrite_string(tos, &out);
    overwrite_string(tos, &out);
    pc++;
    pc++;
 
 
}
}
 
 
/* Find lines starting with . and | and put example around them on tos
/* Find lines starting with . and | and put example around them on tos
   turn
   turn
   {*  into open comment and *} into close comment
   {*  into open comment and *} into close comment
   escape curlies
   escape curlies
 
 
*/
*/
WORD(courierize)
WORD(courierize)
{
{
    string_type out;
    string_type out;
    unsigned int idx = 0;
    unsigned int idx = 0;
 
 
    init_string(&out);
    init_string(&out);
 
 
    while (at(tos, idx))
    while (at(tos, idx))
    {
    {
        if (at(tos, idx) == '\n'
        if (at(tos, idx) == '\n'
            && (at(tos, idx +1 ) == '.'
            && (at(tos, idx +1 ) == '.'
                || at(tos,idx+1) == '|'))
                || at(tos,idx+1) == '|'))
        {
        {
            cattext(&out,"\n@smallexample\n");
            cattext(&out,"\n@smallexample\n");
            do
            do
            {
            {
                idx += 2;
                idx += 2;
 
 
                while (at(tos, idx) && at(tos, idx)!='\n')
                while (at(tos, idx) && at(tos, idx)!='\n')
                {
                {
                    if (at(tos,idx)=='{' && at(tos,idx+1) =='*')
                    if (at(tos,idx)=='{' && at(tos,idx+1) =='*')
                    {
                    {
                        cattext(&out," /*");
                        cattext(&out," /*");
                        idx+=2;
                        idx+=2;
                    }
                    }
                    else if (at(tos,idx)=='*' && at(tos,idx+1) =='}')
                    else if (at(tos,idx)=='*' && at(tos,idx+1) =='}')
                    {
                    {
                        cattext(&out,"*/");
                        cattext(&out,"*/");
                        idx+=2;
                        idx+=2;
                    }
                    }
                    else if (at(tos,idx) == '{')
                    else if (at(tos,idx) == '{')
                    {
                    {
                        cattext(&out,"@{");
                        cattext(&out,"@{");
                        idx++;
                        idx++;
                    }
                    }
                    else if (at(tos,idx) == '}')
                    else if (at(tos,idx) == '}')
                    {
                    {
                        cattext(&out,"@}");
                        cattext(&out,"@}");
                        idx++;
                        idx++;
                    }
                    }
                    else
                    else
                    {
                    {
                        catchar(&out, at(tos, idx));
                        catchar(&out, at(tos, idx));
                        idx++;
                        idx++;
                    }
                    }
 
 
                }
                }
                catchar(&out,'\n');
                catchar(&out,'\n');
            }
            }
            while (at(tos, idx) == '\n'
            while (at(tos, idx) == '\n'
                   && (at(tos, idx+1) == '.')
                   && (at(tos, idx+1) == '.')
                   || (at(tos,idx+1) == '|'));
                   || (at(tos,idx+1) == '|'));
            cattext(&out,"@end smallexample");
            cattext(&out,"@end smallexample");
        }
        }
        else
        else
        {
        {
            catchar(&out, at(tos, idx));
            catchar(&out, at(tos, idx));
            idx++;
            idx++;
        }
        }
    }
    }
 
 
    overwrite_string(tos, &out);
    overwrite_string(tos, &out);
    pc++;
    pc++;
 
 
 
 
}
}
 
 
/*
/*
bulletize:  look for bullet item commands at start of line
bulletize:  look for bullet item commands at start of line
 Bullet list:
 Bullet list:
   O+  emit @itemize @bullet
   O+  emit @itemize @bullet
   o   emit @item       [note lowercase]
   o   emit @item       [note lowercase]
   O-  emit @end itemize
   O-  emit @end itemize
 
 
 Variable label list:
 Variable label list:
   o+  emit @table @code
   o+  emit @table @code
   o   emit @item
   o   emit @item
   o-  emit @end table
   o-  emit @end table
*/
*/
 
 
 
 
WORD(bulletize)
WORD(bulletize)
{
{
  unsigned int idx = 0;
  unsigned int idx = 0;
  string_type out;
  string_type out;
  init_string(&out);
  init_string(&out);
 
 
  while (at(tos, idx)) {
  while (at(tos, idx)) {
       if (at(tos, idx) == '\n' &&  at(tos, idx+1) == 'o')
       if (at(tos, idx) == '\n' &&  at(tos, idx+1) == 'o')
       {
       {
         if (at(tos,idx+2) == '+') {
         if (at(tos,idx+2) == '+') {
             cattext(&out,"\n@table @code\n");
             cattext(&out,"\n@table @code\n");
             idx+=3;
             idx+=3;
           }
           }
         else if (at(tos,idx+2) == '-') {
         else if (at(tos,idx+2) == '-') {
             cattext(&out,"\n@end table\n");
             cattext(&out,"\n@end table\n");
             idx+=3;
             idx+=3;
           }
           }
         else if (isspace(at(tos,idx+2))) {
         else if (isspace(at(tos,idx+2))) {
             cattext(&out,"\n@item ");
             cattext(&out,"\n@item ");
             idx+=3;
             idx+=3;
           }
           }
         else {
         else {
             catchar(&out, at(tos, idx));
             catchar(&out, at(tos, idx));
             idx++;
             idx++;
           }
           }
       }
       }
 
 
       else
       else
        if (at(tos, idx) == '\n' &&  at(tos, idx+1) == 'O')
        if (at(tos, idx) == '\n' &&  at(tos, idx+1) == 'O')
        {
        {
          if (at(tos,idx+2) == '+') {
          if (at(tos,idx+2) == '+') {
              cattext(&out,"\n@itemize @bullet\n");
              cattext(&out,"\n@itemize @bullet\n");
              idx+=3;
              idx+=3;
            }
            }
 
 
          else if (at(tos,idx+2) == '-') {
          else if (at(tos,idx+2) == '-') {
              cattext(&out,"\n@end itemize\n");
              cattext(&out,"\n@end itemize\n");
              idx+=3;
              idx+=3;
            }
            }
          else {
          else {
              catchar(&out, at(tos, idx));
              catchar(&out, at(tos, idx));
              idx++;
              idx++;
            }
            }
        }
        }
        else
        else
        {
        {
          catchar(&out, at(tos, idx));
          catchar(&out, at(tos, idx));
          idx++;
          idx++;
        }
        }
    }
    }
 
 
  delete_string(tos);
  delete_string(tos);
  *tos = out;
  *tos = out;
  pc++;
  pc++;
 
 
}
}
 
 
/* Turn <<foo>> into @code{foo} in place at TOS
/* Turn <<foo>> into @code{foo} in place at TOS
   Turn <[foo]> into @var{foo} in place at TOS
   Turn <[foo]> into @var{foo} in place at TOS
   nest them too !
   nest them too !
 
 
*/
*/
 
 
 
 
WORD(do_fancy_stuff)
WORD(do_fancy_stuff)
 {
 {
    unsigned int idx = 0;
    unsigned int idx = 0;
    string_type out;
    string_type out;
    init_string(&out);
    init_string(&out);
    while (at(tos, idx))
    while (at(tos, idx))
    {
    {
        if (at(tos, idx) == '<'
        if (at(tos, idx) == '<'
            && at(tos, idx+1) == '<'
            && at(tos, idx+1) == '<'
            && (!isspace(at(tos,idx + 2)) || at(tos,idx+3) == '>'))
            && (!isspace(at(tos,idx + 2)) || at(tos,idx+3) == '>'))
        {
        {
            /* This qualifies as a << startup */
            /* This qualifies as a << startup */
            idx +=2;
            idx +=2;
            cattext(&out,"@code{");
            cattext(&out,"@code{");
          }
          }
 
 
        else    if (at(tos, idx) == '<'
        else    if (at(tos, idx) == '<'
            && at(tos, idx+1) == '['
            && at(tos, idx+1) == '['
            && !isspace(at(tos,idx + 2)))
            && !isspace(at(tos,idx + 2)))
        {
        {
            /* This qualifies as a <[ startup */
            /* This qualifies as a <[ startup */
            idx +=2;
            idx +=2;
            cattext(&out,"@var{");
            cattext(&out,"@var{");
          }
          }
        else if (at(tos, idx) == '>'
        else if (at(tos, idx) == '>'
                 && at(tos,idx+1) =='>')
                 && at(tos,idx+1) =='>')
        {
        {
 
 
            cattext(&out,"}");
            cattext(&out,"}");
            idx+=2;
            idx+=2;
        }
        }
        else if (at(tos, idx) == ']'
        else if (at(tos, idx) == ']'
                 && at(tos,idx+1) =='>')
                 && at(tos,idx+1) =='>')
        {
        {
            cattext(&out,"}");
            cattext(&out,"}");
            idx+=2;
            idx+=2;
        }
        }
        else
        else
        {
        {
            catchar(&out, at(tos, idx));
            catchar(&out, at(tos, idx));
            idx++;
            idx++;
        }
        }
    }
    }
    delete_string(tos);
    delete_string(tos);
    *tos = out;
    *tos = out;
    pc++;
    pc++;
 
 
}
}
/* A command is all upper case,and alone on a line */
/* A command is all upper case,and alone on a line */
static int
static int
DEFUN( iscommand,(ptr, idx),
DEFUN( iscommand,(ptr, idx),
      string_type *ptr AND
      string_type *ptr AND
      unsigned int idx)
      unsigned int idx)
{
{
    unsigned int len = 0;
    unsigned int len = 0;
    while (at(ptr,idx)) {
    while (at(ptr,idx)) {
            if (isupper(at(ptr,idx)) || at(ptr,idx) == ' ' ||
            if (isupper(at(ptr,idx)) || at(ptr,idx) == ' ' ||
                at(ptr,idx) == '_')
                at(ptr,idx) == '_')
            {
            {
             len++;
             len++;
             idx++;
             idx++;
         }
         }
            else if(at(ptr,idx) == '\n')
            else if(at(ptr,idx) == '\n')
            {
            {
                /* The length check will never fail on a real command
                /* The length check will never fail on a real command
                 * because the commands are screened as the definitions file
                 * because the commands are screened as the definitions file
                 * is read.  */
                 * is read.  */
                if (len >= MIN_CMDLEN) return 1;
                if (len >= MIN_CMDLEN) return 1;
                return 0;
                return 0;
            }
            }
            else return 0;
            else return 0;
        }
        }
    return 0;
    return 0;
 
 
}
}
 
 
 
 
unsigned int
unsigned int
DEFUN(copy_past_newline,(ptr, idx, dst),
DEFUN(copy_past_newline,(ptr, idx, dst),
      string_type *ptr AND
      string_type *ptr AND
      unsigned int idx AND
      unsigned int idx AND
      string_type *dst)
      string_type *dst)
{
{
    while (at(ptr, idx) && at(ptr, idx) != '\n')
    while (at(ptr, idx) && at(ptr, idx) != '\n')
    {
    {
        catchar(dst, at(ptr, idx));
        catchar(dst, at(ptr, idx));
        idx++;
        idx++;
 
 
    }
    }
    catchar(dst, at(ptr, idx));
    catchar(dst, at(ptr, idx));
    idx++;
    idx++;
    return idx;
    return idx;
 
 
}
}
 
 
WORD(icopy_past_newline)
WORD(icopy_past_newline)
{
{
    tos++;
    tos++;
    init_string(tos);
    init_string(tos);
    idx = copy_past_newline(ptr, idx, tos);
    idx = copy_past_newline(ptr, idx, tos);
    pc++;
    pc++;
}
}
 
 
 
 
/* indent
/* indent
   Take the string at the top of the stack, do some prettying */
   Take the string at the top of the stack, do some prettying */
 
 
 
 
 
 
 
 
WORD(kill_bogus_lines)
WORD(kill_bogus_lines)
{
{
    int sl ;
    int sl ;
 
 
    int idx = 0;
    int idx = 0;
    int c;
    int c;
    int dot = 0    ;
    int dot = 0    ;
 
 
    string_type out;
    string_type out;
    init_string(&out);
    init_string(&out);
    /* Drop leading nl */
    /* Drop leading nl */
    while (at(tos,idx) == '\n')
    while (at(tos,idx) == '\n')
    {
    {
        idx++;
        idx++;
    }
    }
    c = idx;
    c = idx;
 
 
    /* Find the last char */
    /* Find the last char */
    while (at(tos,idx))
    while (at(tos,idx))
    {
    {
        idx++;
        idx++;
    }
    }
 
 
    /* find the last non white before the nl */
    /* find the last non white before the nl */
    idx--;
    idx--;
 
 
    while (idx && isspace(at(tos,idx)))
    while (idx && isspace(at(tos,idx)))
     idx--;
     idx--;
    idx++;
    idx++;
 
 
    /* Copy buffer upto last char, but blank lines before and after
    /* Copy buffer upto last char, but blank lines before and after
       dots don't count */
       dots don't count */
    sl = 1;
    sl = 1;
 
 
    while (c < idx)
    while (c < idx)
    {
    {
        if (at(tos,c) == '\n'
        if (at(tos,c) == '\n'
            && at(tos,c+1) == '\n'
            && at(tos,c+1) == '\n'
            && at(tos,c+2) == '.')
            && at(tos,c+2) == '.')
        {
        {
            /* Ignore two linelines before  a dot*/
            /* Ignore two linelines before  a dot*/
            c++;
            c++;
        }
        }
        else if (at(tos,c) == '.' && sl)
        else if (at(tos,c) == '.' && sl)
        {
        {
            /* remember that this line started with a dot */
            /* remember that this line started with a dot */
            dot=2;
            dot=2;
        }
        }
        else if (at(tos,c) == '\n'
        else if (at(tos,c) == '\n'
                 && at(tos,c+1) == '\n'
                 && at(tos,c+1) == '\n'
                 && dot)
                 && dot)
        {
        {
            c++;
            c++;
            /* Ignore two newlines when last line was dot */
            /* Ignore two newlines when last line was dot */
        }
        }
 
 
        catchar(&out, at(tos,c));
        catchar(&out, at(tos,c));
        if (at(tos,c) == '\n')
        if (at(tos,c) == '\n')
        {
        {
            sl = 1;
            sl = 1;
 
 
            if (dot == 2)dot=1;else dot = 0;
            if (dot == 2)dot=1;else dot = 0;
        }
        }
 
 
        c++;
        c++;
 
 
    }
    }
 
 
    /* Append nl*/
    /* Append nl*/
    catchar(&out, '\n');
    catchar(&out, '\n');
    pc++;
    pc++;
    delete_string(tos);
    delete_string(tos);
    *tos = out;
    *tos = out;
 
 
 
 
}
}
 
 
WORD(indent)
WORD(indent)
{
{
    string_type out;
    string_type out;
    int tab = 0;
    int tab = 0;
    int idx = 0;
    int idx = 0;
    int ol =0;
    int ol =0;
    init_string(&out);
    init_string(&out);
    while (at(tos,idx)) {
    while (at(tos,idx)) {
            switch (at(tos,idx))
            switch (at(tos,idx))
            {
            {
              case '\n':
              case '\n':
                cattext(&out,"\n");
                cattext(&out,"\n");
                idx++;
                idx++;
                if (tab)
                if (tab)
                {
                {
                    cattext(&out,"    ");
                    cattext(&out,"    ");
                }
                }
                ol = 0;
                ol = 0;
                break;
                break;
              case '(':
              case '(':
                tab++;
                tab++;
                if (ol == 0)
                if (ol == 0)
                    cattext(&out,"   ");
                    cattext(&out,"   ");
                idx++;
                idx++;
                cattext(&out,"(");
                cattext(&out,"(");
                ol = 1;
                ol = 1;
                break;
                break;
              case ')':
              case ')':
                tab--;
                tab--;
                cattext(&out,")");
                cattext(&out,")");
                idx++;
                idx++;
                ol=1;
                ol=1;
 
 
                break;
                break;
              default:
              default:
                catchar(&out,at(tos,idx));
                catchar(&out,at(tos,idx));
                ol=1;
                ol=1;
 
 
                idx++;
                idx++;
                break;
                break;
            }
            }
        }
        }
 
 
    pc++;
    pc++;
    delete_string(tos);
    delete_string(tos);
    *tos = out;
    *tos = out;
 
 
}
}
 
 
/* Change the TOS so that all that is left is the stuff inside the
/* Change the TOS so that all that is left is the stuff inside the
 first <<foo>> .
 first <<foo>> .
*/
*/
 
 
WORD(get_stuff_in_angle)
WORD(get_stuff_in_angle)
{
{
  unsigned int idx = 0;
  unsigned int idx = 0;
  string_type out;
  string_type out;
  init_string(&out);
  init_string(&out);
 
 
  while (at(tos, idx))
  while (at(tos, idx))
    {
    {
      if (at(tos,idx) == '<' && at(tos,idx+1) =='<')
      if (at(tos,idx) == '<' && at(tos,idx+1) =='<')
        {
        {
          idx+=2;
          idx+=2;
 
 
          while (!(at(tos,idx) == '>' && at(tos,idx+1) == '>'))
          while (!(at(tos,idx) == '>' && at(tos,idx+1) == '>'))
            {
            {
              catchar(&out, at(tos, idx));
              catchar(&out, at(tos, idx));
              idx++;
              idx++;
            }
            }
          break;
          break;
        }
        }
      idx++;
      idx++;
    }
    }
  catchar(&out,'\n');
  catchar(&out,'\n');
 
 
  overwrite_string(tos, &out);
  overwrite_string(tos, &out);
  pc++;
  pc++;
}
}
 
 
 
 
WORD(get_stuff_in_command)
WORD(get_stuff_in_command)
{
{
  tos++;
  tos++;
  init_string(tos);
  init_string(tos);
 
 
  while (at(ptr, idx)) {
  while (at(ptr, idx)) {
    if (iscommand(ptr, idx))  break;
    if (iscommand(ptr, idx))  break;
    idx =   copy_past_newline(ptr, idx, tos);
    idx =   copy_past_newline(ptr, idx, tos);
  }
  }
  pc++;
  pc++;
}
}
 
 
WORD(swap)
WORD(swap)
{
{
    string_type t;
    string_type t;
 
 
    t = tos[0];
    t = tos[0];
    tos[0] = tos[-1];
    tos[0] = tos[-1];
    tos[-1] =t;
    tos[-1] =t;
    pc++;
    pc++;
 
 
}
}
 
 
WORD(dup)
WORD(dup)
{
{
    tos++;
    tos++;
    init_string(tos);
    init_string(tos);
    catstr(tos, tos-1);
    catstr(tos, tos-1);
    pc++;
    pc++;
 
 
}
}
 
 
 
 
 
 
WORD(icatstr)
WORD(icatstr)
{
{
    catstr(tos-1, tos);
    catstr(tos-1, tos);
    delete_string(tos);
    delete_string(tos);
    tos--;
    tos--;
    pc++;
    pc++;
 
 
}
}
 
 
WORD(skip_past_newline)
WORD(skip_past_newline)
{
{
    while (at(ptr,idx)
    while (at(ptr,idx)
           && at(ptr,idx) != '\n')
           && at(ptr,idx) != '\n')
     idx++;
     idx++;
    idx++;
    idx++;
    pc++;
    pc++;
}
}
 
 
 
 
WORD(internalmode)
WORD(internalmode)
{
{
    internal_mode = *(isp);
    internal_mode = *(isp);
    isp--;
    isp--;
    pc++;
    pc++;
}
}
 
 
WORD(maybecatstr)
WORD(maybecatstr)
{
{
    if (internal_wanted == internal_mode)
    if (internal_wanted == internal_mode)
    {
    {
        catstr(tos-1, tos);
        catstr(tos-1, tos);
    }
    }
    delete_string(tos);
    delete_string(tos);
    tos--;
    tos--;
    pc++;
    pc++;
 
 
}
}
 
 
char *
char *
DEFUN(nextword,(string, word),
DEFUN(nextword,(string, word),
      char *string AND
      char *string AND
      char **word)
      char **word)
{
{
  char *word_start;
  char *word_start;
  int idx;
  int idx;
  char *dst;
  char *dst;
  char *src;
  char *src;
 
 
  int length = 0;
  int length = 0;
 
 
  while (isspace(*string) || *string == '-') {
  while (isspace(*string) || *string == '-') {
      if (*string == '-')
      if (*string == '-')
      {
      {
        while (*string && *string != '\n')
        while (*string && *string != '\n')
         string++;
         string++;
 
 
      }
      }
      else {
      else {
          string++;
          string++;
        }
        }
    }
    }
  if (!*string) return 0;
  if (!*string) return 0;
 
 
  word_start = string;
  word_start = string;
  if (*string == '"')
  if (*string == '"')
  {
  {
    string++;
    string++;
    length++;
    length++;
 
 
    while (*string != '"')
    while (*string != '"')
    {
    {
      string++;
      string++;
      length++;
      length++;
    }
    }
  }
  }
  else
  else
  {
  {
 
 
 
 
    while (!isspace(*string))
    while (!isspace(*string))
    {
    {
      string++;
      string++;
      length++;
      length++;
    }
    }
  }
  }
 
 
  *word = malloc(length + 1);
  *word = malloc(length + 1);
 
 
  dst = *word;
  dst = *word;
  src = word_start;
  src = word_start;
 
 
 
 
  for (idx= 0; idx < length; idx++)
  for (idx= 0; idx < length; idx++)
  {
  {
 
 
    if (src[idx] == '\\' && src[idx+1] == 'n')
    if (src[idx] == '\\' && src[idx+1] == 'n')
    {
    {
      *dst++ = '\n';
      *dst++ = '\n';
      idx++;
      idx++;
 
 
    }
    }
    else *dst++ = src[idx];
    else *dst++ = src[idx];
  }
  }
  *dst++ = 0;
  *dst++ = 0;
 
 
 
 
 
 
 
 
 
 
  if(*string)
  if(*string)
   return string + 1;
   return string + 1;
  else
  else
   return 0;
   return 0;
 
 
}
}
dict_type *root;
dict_type *root;
dict_type *
dict_type *
DEFUN(lookup_word,(word),
DEFUN(lookup_word,(word),
      char *word)
      char *word)
{
{
    dict_type *ptr = root;
    dict_type *ptr = root;
    while (ptr) {
    while (ptr) {
            if (strcmp(ptr->word, word) == 0) return ptr;
            if (strcmp(ptr->word, word) == 0) return ptr;
            ptr = ptr->next;
            ptr = ptr->next;
 
 
         }
         }
    fprintf(stderr,"Can't find %s\n",word);
    fprintf(stderr,"Can't find %s\n",word);
    return 0;
    return 0;
 
 
 
 
}
}
 
 
static void DEFUN_VOID(perform)
static void DEFUN_VOID(perform)
{
{
    tos = stack;
    tos = stack;
 
 
    while (at(ptr, idx)) {
    while (at(ptr, idx)) {
            /* It's worth looking through the command list */
            /* It's worth looking through the command list */
            if (iscommand(ptr, idx))
            if (iscommand(ptr, idx))
            {
            {
                char *next;
                char *next;
                dict_type *word ;
                dict_type *word ;
 
 
                (void)          nextword(addr(ptr, idx), &next);
                (void)          nextword(addr(ptr, idx), &next);
 
 
 
 
                word = lookup_word(next);
                word = lookup_word(next);
 
 
 
 
 
 
 
 
                if (word)
                if (word)
                {
                {
                    if(Verbose)  fprintf(stderr, "CMD '%s'\n", word->word);
                    if(Verbose)  fprintf(stderr, "CMD '%s'\n", word->word);
                    exec(word);
                    exec(word);
                }
                }
                else
                else
                {
                {
                    fprintf(stderr,"warning, %s is not recognised\n",  next);
                    fprintf(stderr,"warning, %s is not recognised\n",  next);
                    skip_past_newline();
                    skip_past_newline();
                }
                }
 
 
            }
            }
            else skip_past_newline();
            else skip_past_newline();
 
 
        }
        }
}
}
 
 
dict_type *
dict_type *
DEFUN(newentry,(word),
DEFUN(newentry,(word),
      char *word)
      char *word)
{
{
    dict_type *new = (dict_type *)malloc(sizeof(dict_type));
    dict_type *new = (dict_type *)malloc(sizeof(dict_type));
    new->word = word;
    new->word = word;
    new->next = root;
    new->next = root;
    root = new;
    root = new;
    new->code = (stinst_type *)malloc(sizeof(stinst_type ));
    new->code = (stinst_type *)malloc(sizeof(stinst_type ));
    new->code_length = 1;
    new->code_length = 1;
    new->code_end = 0;
    new->code_end = 0;
    return new;
    return new;
 
 
}
}
 
 
 
 
unsigned int
unsigned int
DEFUN(add_to_definition,(entry, word),
DEFUN(add_to_definition,(entry, word),
      dict_type *entry AND
      dict_type *entry AND
      stinst_type word)
      stinst_type word)
{
{
    if (entry->code_end == entry->code_length)
    if (entry->code_end == entry->code_length)
    {
    {
        entry->code_length += 2;
        entry->code_length += 2;
        entry->code =
        entry->code =
         (stinst_type *) realloc((char *)(entry->code),
         (stinst_type *) realloc((char *)(entry->code),
                               entry->code_length *sizeof(word_type));
                               entry->code_length *sizeof(word_type));
    }
    }
    entry->code[entry->code_end] = word;
    entry->code[entry->code_end] = word;
 
 
return     entry->code_end++;
return     entry->code_end++;
}
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void
void
DEFUN(add_intrinsic,(name, func),
DEFUN(add_intrinsic,(name, func),
      char *name AND
      char *name AND
      void (*func)(NOARGS))
      void (*func)(NOARGS))
{
{
    dict_type *new = newentry(name);
    dict_type *new = newentry(name);
    add_to_definition(new, func);
    add_to_definition(new, func);
    add_to_definition(new, 0);
    add_to_definition(new, 0);
}
}
 
 
void
void
DEFUN(add_var,(name),
DEFUN(add_var,(name),
      char *name)
      char *name)
{
{
    dict_type *new = newentry(name);
    dict_type *new = newentry(name);
    add_to_definition(new, push_number);
    add_to_definition(new, push_number);
    add_to_definition(new, (stinst_type)(&(new->var)));
    add_to_definition(new, (stinst_type)(&(new->var)));
    add_to_definition(new,0);
    add_to_definition(new,0);
 
 
}
}
 
 
 
 
 
 
 
 
int
int
DEFUN(compile, (string),
DEFUN(compile, (string),
      char *string)
      char *string)
 
 
{
{
    int  ret=0;
    int  ret=0;
    /* add words to the dictionary */
    /* add words to the dictionary */
    char *word;
    char *word;
    string = nextword(string, &word);
    string = nextword(string, &word);
    while (string && *string && word[0])
    while (string && *string && word[0])
    {
    {
        if (strcmp(word,"var")==0)
        if (strcmp(word,"var")==0)
        {
        {
          string=nextword(string, &word);
          string=nextword(string, &word);
 
 
          add_var(word);
          add_var(word);
          string=nextword(string, &word);
          string=nextword(string, &word);
        }
        }
        else
        else
 
 
        if (word[0] == ':')
        if (word[0] == ':')
        {
        {
            dict_type *ptr;
            dict_type *ptr;
            /* Compile a word and add to dictionary */
            /* Compile a word and add to dictionary */
            string = nextword(string, &word);
            string = nextword(string, &word);
            if(Verbose)  fprintf(stderr, "Found command '%s'\n", word);
            if(Verbose)  fprintf(stderr, "Found command '%s'\n", word);
            if(strlen(word) < MIN_CMDLEN)  {
            if(strlen(word) < MIN_CMDLEN)  {
                fprintf(stderr, "ERROR:  Command '%s' is too short ", word);
                fprintf(stderr, "ERROR:  Command '%s' is too short ", word);
                fprintf(stderr, "(MIN_CMDLEN is %d)\n", MIN_CMDLEN);
                fprintf(stderr, "(MIN_CMDLEN is %d)\n", MIN_CMDLEN);
                ret++;
                ret++;
            }
            }
 
 
            ptr = newentry(word);
            ptr = newentry(word);
            string = nextword(string, &word);
            string = nextword(string, &word);
            while (word[0] != ';' )
            while (word[0] != ';' )
            {
            {
                 switch (word[0])
                 switch (word[0])
                 {
                 {
 
 
 
 
                   case '"':
                   case '"':
                     /* got a string, embed magic push string
                     /* got a string, embed magic push string
                        function */
                        function */
                     add_to_definition(ptr, push_text);
                     add_to_definition(ptr, push_text);
                     add_to_definition(ptr, (stinst_type)(word+1));
                     add_to_definition(ptr, (stinst_type)(word+1));
                     break;
                     break;
                   case '0':
                   case '0':
                   case '1':
                   case '1':
                   case '2':
                   case '2':
                   case '3':
                   case '3':
                   case '4':
                   case '4':
                   case '5':
                   case '5':
                   case '6':
                   case '6':
                   case '7':
                   case '7':
                   case '8':
                   case '8':
                   case '9':
                   case '9':
                     /* Got a number, embedd the magic push number
                     /* Got a number, embedd the magic push number
                        function */
                        function */
                     add_to_definition(ptr, push_number);
                     add_to_definition(ptr, push_number);
                     add_to_definition(ptr, atol(word));
                     add_to_definition(ptr, atol(word));
                     break;
                     break;
                   default:
                   default:
                     add_to_definition(ptr, call);
                     add_to_definition(ptr, call);
                     add_to_definition(ptr, lookup_word(word));
                     add_to_definition(ptr, lookup_word(word));
                 }
                 }
 
 
                string = nextword(string, &word);
                string = nextword(string, &word);
            }
            }
            add_to_definition(ptr,0);
            add_to_definition(ptr,0);
            string = nextword(string, &word);
            string = nextword(string, &word);
        }
        }
        else
        else
        {
        {
            fprintf(stderr,"syntax error at %s\n",string-1);
            fprintf(stderr,"syntax error at %s\n",string-1);
            ret++;
            ret++;
        }
        }
    }
    }
 
 
return(ret);
return(ret);
}
}
 
 
 
 
static void DEFUN_VOID(bang)
static void DEFUN_VOID(bang)
{
{
*(int *)((isp[0])) = isp[-1];
*(int *)((isp[0])) = isp[-1];
isp-=2;
isp-=2;
pc++;
pc++;
 
 
}
}
 
 
WORD(atsign)
WORD(atsign)
{
{
    isp[0] = *(int *)(isp[0]);
    isp[0] = *(int *)(isp[0]);
    pc++;
    pc++;
}
}
 
 
WORD(hello)
WORD(hello)
{
{
 
 
    printf("hello\n");
    printf("hello\n");
    pc++;
    pc++;
}
}
 
 
 
 
 
 
static void DEFUN(read_in, (str, file),
static void DEFUN(read_in, (str, file),
           string_type *str AND
           string_type *str AND
                  FILE *file)
                  FILE *file)
{
{
    char buff[10000];
    char buff[10000];
    unsigned int r;
    unsigned int r;
    do
    do
    {
    {
        r = fread(buff, 1, sizeof(buff), file);
        r = fread(buff, 1, sizeof(buff), file);
        catbuf(str, buff, r);
        catbuf(str, buff, r);
    }
    }
    while (r);
    while (r);
    buff[0] = 0;
    buff[0] = 0;
 
 
    catbuf(str, buff,1);
    catbuf(str, buff,1);
 
 
}
}
 
 
 
 
#if 0
#if 0
static void DEFUN_VOID(usage)
static void DEFUN_VOID(usage)
{
{
    fprintf(stderr,"usage: -[i|v] -f macrofile <file >file\n");
    fprintf(stderr,"usage: -[i|v] -f macrofile <file >file\n");
    exit(33);
    exit(33);
}
}
#endif
#endif
 
 
int DEFUN(main,(ac,av),
int DEFUN(main,(ac,av),
int ac AND
int ac AND
char *av[])
char *av[])
{
{
    unsigned int i;
    unsigned int i;
 
 
 
 
    string_type buffer;
    string_type buffer;
    string_type pptr;
    string_type pptr;
 
 
 
 
    init_string(&buffer);
    init_string(&buffer);
    init_string(&pptr);
    init_string(&pptr);
    init_string(stack+0);
    init_string(stack+0);
    tos=stack+1;
    tos=stack+1;
    ptr = &pptr;
    ptr = &pptr;
 
 
    add_intrinsic("push_text", push_text);
    add_intrinsic("push_text", push_text);
    add_intrinsic("!", bang);
    add_intrinsic("!", bang);
    add_intrinsic("@", atsign);
    add_intrinsic("@", atsign);
    add_intrinsic("hello",hello);
    add_intrinsic("hello",hello);
    add_intrinsic("skip_past_newline", skip_past_newline );
    add_intrinsic("skip_past_newline", skip_past_newline );
    add_intrinsic("catstr", icatstr );
    add_intrinsic("catstr", icatstr );
    add_intrinsic("copy_past_newline", icopy_past_newline );
    add_intrinsic("copy_past_newline", icopy_past_newline );
    add_intrinsic("dup", dup );
    add_intrinsic("dup", dup );
    add_intrinsic("remchar", remchar );
    add_intrinsic("remchar", remchar );
    add_intrinsic("get_stuff_in_command", get_stuff_in_command );
    add_intrinsic("get_stuff_in_command", get_stuff_in_command );
    add_intrinsic("get_stuff_in_angle", get_stuff_in_angle );
    add_intrinsic("get_stuff_in_angle", get_stuff_in_angle );
    add_intrinsic("do_fancy_stuff", do_fancy_stuff );
    add_intrinsic("do_fancy_stuff", do_fancy_stuff );
    add_intrinsic("bulletize", bulletize );
    add_intrinsic("bulletize", bulletize );
    add_intrinsic("courierize", courierize );
    add_intrinsic("courierize", courierize );
    add_intrinsic("swap", swap );
    add_intrinsic("swap", swap );
    add_intrinsic("outputdots", outputdots );
    add_intrinsic("outputdots", outputdots );
    add_intrinsic("exfunstuff", exfunstuff );
    add_intrinsic("exfunstuff", exfunstuff );
    add_intrinsic("maybecatstr", maybecatstr );
    add_intrinsic("maybecatstr", maybecatstr );
    add_intrinsic("translatecomments", translatecomments );
    add_intrinsic("translatecomments", translatecomments );
    add_intrinsic("kill_bogus_lines", kill_bogus_lines);
    add_intrinsic("kill_bogus_lines", kill_bogus_lines);
    add_intrinsic("indent", indent);
    add_intrinsic("indent", indent);
    add_intrinsic("quickref", quickref);
    add_intrinsic("quickref", quickref);
    add_intrinsic("internalmode", internalmode);
    add_intrinsic("internalmode", internalmode);
 
 
    /* Put a nl at the start */
    /* Put a nl at the start */
    catchar(&buffer,'\n');
    catchar(&buffer,'\n');
 
 
    read_in(&buffer, stdin);
    read_in(&buffer, stdin);
    remove_noncomments(&buffer, ptr);
    remove_noncomments(&buffer, ptr);
    for (i= 1; i < ac; i++)
    for (i= 1; i < ac; i++)
    {
    {
        if (av[i][0] == '-')
        if (av[i][0] == '-')
        {
        {
            if (av[i][1] == 'f')
            if (av[i][1] == 'f')
            {
            {
                string_type b;
                string_type b;
                FILE *f;
                FILE *f;
                init_string(&b);
                init_string(&b);
 
 
                f  = fopen(av[i+1],"r");
                f  = fopen(av[i+1],"r");
                if (!f)
                if (!f)
                {
                {
                  fprintf(stderr,"Can't open the input file %s\n",av[i+1]);
                  fprintf(stderr,"Can't open the input file %s\n",av[i+1]);
                  return 33;
                  return 33;
                }
                }
                if(Verbose)  fprintf(stderr, "Reading -f '%s'\n", av[i+1]);
                if(Verbose)  fprintf(stderr, "Reading -f '%s'\n", av[i+1]);
 
 
 
 
                read_in(&b, f);
                read_in(&b, f);
                if( compile(b.ptr) )  { fclose(f); exit(1); }
                if( compile(b.ptr) )  { fclose(f); exit(1); }
                perform();
                perform();
                fclose(f);
                fclose(f);
            }
            }
            else    if (av[i][1] == 'i')
            else    if (av[i][1] == 'i')
            {
            {
                internal_wanted = 1;
                internal_wanted = 1;
            }
            }
            else    if (av[i][1] == 'v')
            else    if (av[i][1] == 'v')
            {
            {
                Verbose++;
                Verbose++;
            }
            }
        }
        }
 
 
    }
    }
    write_buffer(stack+0);
    write_buffer(stack+0);
    return 0;
    return 0;
}
}
 
 
 
 
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.