1999-05-03 07:29:11 +00:00
|
|
|
/* chew
|
2002-02-01 09:22:53 +00:00
|
|
|
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001,
|
2009-09-02 07:25:43 +00:00
|
|
|
2002, 2003, 2005, 2007, 2009
|
1999-05-03 07:29:11 +00:00
|
|
|
Free Software Foundation, Inc.
|
|
|
|
Contributed by steve chamberlain @cygnus
|
|
|
|
|
2007-07-03 14:26:43 +00:00
|
|
|
This file is part of BFD, the Binary File Descriptor library.
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2007-07-03 14:26:43 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2007-07-03 14:26:43 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2007-07-03 14:26:43 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
/* Yet another way of extracting documentation from source.
|
|
|
|
No, I haven't finished it yet, but I hope you people like it better
|
|
|
|
than the old way
|
2000-09-08 23:46:41 +00:00
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
sac
|
|
|
|
|
|
|
|
Basically, this is a sort of string forth, maybe we should call it
|
|
|
|
struth?
|
|
|
|
|
|
|
|
You define new words thus:
|
|
|
|
: <newword> <oldwords> ;
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Primitives provided by the program:
|
|
|
|
|
|
|
|
Two stacks are provided, a string stack and an integer stack.
|
|
|
|
|
|
|
|
Internal state variables:
|
|
|
|
internal_wanted - indicates whether `-i' was passed
|
|
|
|
internal_mode - user-settable
|
|
|
|
|
|
|
|
Commands:
|
|
|
|
push_text
|
|
|
|
! - pop top of integer stack for address, pop next for value; store
|
|
|
|
@ - treat value on integer stack as the address of an integer; push
|
|
|
|
that integer on the integer stack after popping the "address"
|
|
|
|
hello - print "hello\n" to stdout
|
|
|
|
stdout - put stdout marker on TOS
|
|
|
|
stderr - put stderr marker on TOS
|
|
|
|
print - print TOS-1 on TOS (eg: "hello\n" stdout print)
|
|
|
|
skip_past_newline
|
|
|
|
catstr - fn icatstr
|
|
|
|
copy_past_newline - append input, up to and including newline into TOS
|
|
|
|
dup - fn other_dup
|
|
|
|
drop - discard TOS
|
|
|
|
idrop - ditto
|
|
|
|
remchar - delete last character from TOS
|
|
|
|
get_stuff_in_command
|
|
|
|
do_fancy_stuff - translate <<foo>> to @code{foo} in TOS
|
|
|
|
bulletize - if "o" lines found, prepend @itemize @bullet to TOS
|
|
|
|
and @item to each "o" line; append @end itemize
|
|
|
|
courierize - put @example around . and | lines, translate {* *} { }
|
|
|
|
exit - fn chew_exit
|
|
|
|
swap
|
|
|
|
outputdots - strip out lines without leading dots
|
|
|
|
paramstuff - convert full declaration into "PARAMS" form if not already
|
|
|
|
maybecatstr - do catstr if internal_mode == internal_wanted, discard
|
|
|
|
value in any case
|
|
|
|
translatecomments - turn {* and *} into comment delimiters
|
|
|
|
kill_bogus_lines - get rid of extra newlines
|
|
|
|
indent
|
|
|
|
internalmode - pop from integer stack, set `internalmode' to that value
|
|
|
|
print_stack_level - print current stack depth to stderr
|
|
|
|
strip_trailing_newlines - go ahead, guess...
|
|
|
|
[quoted string] - push string onto string stack
|
|
|
|
[word starting with digit] - push atol(str) onto integer stack
|
|
|
|
|
|
|
|
A command must be all upper-case, and alone on a line.
|
|
|
|
|
|
|
|
Foo. */
|
|
|
|
|
2002-05-25 12:50:18 +00:00
|
|
|
#include "ansidecl.h"
|
1999-05-03 07:29:11 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
2005-07-22 23:54:56 +00:00
|
|
|
#include <stdlib.h>
|
2005-07-24 16:57:42 +00:00
|
|
|
#include <string.h>
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
#define DEF_SIZE 5000
|
|
|
|
#define STACK 50
|
|
|
|
|
|
|
|
int internal_wanted;
|
|
|
|
int internal_mode;
|
|
|
|
|
|
|
|
int warning;
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
/* Here is a string type ... */
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
typedef struct buffer
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
unsigned long write_idx;
|
|
|
|
unsigned long size;
|
|
|
|
} string_type;
|
|
|
|
|
|
|
|
#ifdef __STDC__
|
|
|
|
static void init_string_with_size (string_type *, unsigned int);
|
|
|
|
static void init_string (string_type *);
|
|
|
|
static int find (string_type *, char *);
|
|
|
|
static void write_buffer (string_type *, FILE *);
|
|
|
|
static void delete_string (string_type *);
|
|
|
|
static char *addr (string_type *, unsigned int);
|
|
|
|
static char at (string_type *, unsigned int);
|
|
|
|
static void catchar (string_type *, int);
|
|
|
|
static void overwrite_string (string_type *, string_type *);
|
|
|
|
static void catbuf (string_type *, char *, unsigned int);
|
|
|
|
static void cattext (string_type *, char *);
|
|
|
|
static void catstr (string_type *, string_type *);
|
2007-10-15 02:00:28 +00:00
|
|
|
static void die (char *);
|
1999-05-03 07:29:11 +00:00
|
|
|
#endif
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
init_string_with_size (buffer, size)
|
|
|
|
string_type *buffer;
|
|
|
|
unsigned int size;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
buffer->write_idx = 0;
|
|
|
|
buffer->size = size;
|
2009-09-28 12:15:51 +00:00
|
|
|
buffer->ptr = (char *) malloc (size);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
init_string (buffer)
|
|
|
|
string_type *buffer;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
init_string_with_size (buffer, DEF_SIZE);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static int
|
|
|
|
find (str, what)
|
|
|
|
string_type *str;
|
|
|
|
char *what;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
unsigned int i;
|
|
|
|
char *p;
|
|
|
|
p = what;
|
|
|
|
for (i = 0; i < str->write_idx && *p; i++)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (*p == str->ptr[i])
|
|
|
|
p++;
|
|
|
|
else
|
|
|
|
p = what;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
return (*p == 0);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
write_buffer (buffer, f)
|
|
|
|
string_type *buffer;
|
|
|
|
FILE *f;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2007-10-15 02:00:28 +00:00
|
|
|
if (buffer->write_idx != 0
|
|
|
|
&& fwrite (buffer->ptr, buffer->write_idx, 1, f) != 1)
|
|
|
|
die ("cannot write output");
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
delete_string (buffer)
|
|
|
|
string_type *buffer;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
free (buffer->ptr);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static char *
|
|
|
|
addr (buffer, idx)
|
|
|
|
string_type *buffer;
|
|
|
|
unsigned int idx;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
return buffer->ptr + idx;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static char
|
|
|
|
at (buffer, pos)
|
|
|
|
string_type *buffer;
|
|
|
|
unsigned int pos;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (pos >= buffer->write_idx)
|
1999-05-03 07:29:11 +00:00
|
|
|
return 0;
|
|
|
|
return buffer->ptr[pos];
|
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
catchar (buffer, ch)
|
|
|
|
string_type *buffer;
|
|
|
|
int ch;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (buffer->write_idx == buffer->size)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
buffer->size *= 2;
|
2009-09-28 12:15:51 +00:00
|
|
|
buffer->ptr = (char *) realloc (buffer->ptr, buffer->size);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
buffer->ptr[buffer->write_idx++] = ch;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
overwrite_string (dst, src)
|
|
|
|
string_type *dst;
|
|
|
|
string_type *src;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
free (dst->ptr);
|
|
|
|
dst->size = src->size;
|
|
|
|
dst->write_idx = src->write_idx;
|
|
|
|
dst->ptr = src->ptr;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
catbuf (buffer, buf, len)
|
|
|
|
string_type *buffer;
|
|
|
|
char *buf;
|
|
|
|
unsigned int len;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
if (buffer->write_idx + len >= buffer->size)
|
|
|
|
{
|
|
|
|
while (buffer->write_idx + len >= buffer->size)
|
|
|
|
buffer->size *= 2;
|
2009-09-28 12:15:51 +00:00
|
|
|
buffer->ptr = (char *) realloc (buffer->ptr, buffer->size);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
memcpy (buffer->ptr + buffer->write_idx, buf, len);
|
|
|
|
buffer->write_idx += len;
|
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
cattext (buffer, string)
|
|
|
|
string_type *buffer;
|
|
|
|
char *string;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
catbuf (buffer, string, (unsigned int) strlen (string));
|
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
catstr (dst, src)
|
|
|
|
string_type *dst;
|
|
|
|
string_type *src;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
catbuf (dst, src->ptr, src->write_idx);
|
|
|
|
}
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
static unsigned int
|
2000-09-07 20:22:50 +00:00
|
|
|
skip_white_and_stars (src, idx)
|
|
|
|
string_type *src;
|
|
|
|
unsigned int idx;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
char c;
|
2000-09-08 23:46:41 +00:00
|
|
|
while ((c = at (src, idx)),
|
1999-05-03 07:29:11 +00:00
|
|
|
isspace ((unsigned char) c)
|
|
|
|
|| (c == '*'
|
|
|
|
/* Don't skip past end-of-comment or star as first
|
|
|
|
character on its line. */
|
2000-09-08 23:46:41 +00:00
|
|
|
&& at (src, idx +1) != '/'
|
|
|
|
&& at (src, idx -1) != '\n'))
|
1999-05-03 07:29:11 +00:00
|
|
|
idx++;
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
string_type stack[STACK];
|
|
|
|
string_type *tos;
|
|
|
|
|
|
|
|
unsigned int idx = 0; /* Pos in input buffer */
|
|
|
|
string_type *ptr; /* and the buffer */
|
|
|
|
typedef void (*stinst_type)();
|
|
|
|
stinst_type *pc;
|
|
|
|
stinst_type sstack[STACK];
|
|
|
|
stinst_type *ssp = &sstack[0];
|
|
|
|
long istack[STACK];
|
|
|
|
long *isp = &istack[0];
|
|
|
|
|
|
|
|
typedef int *word_type;
|
|
|
|
|
|
|
|
struct dict_struct
|
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
char *word;
|
|
|
|
struct dict_struct *next;
|
|
|
|
stinst_type *code;
|
|
|
|
int code_length;
|
|
|
|
int code_end;
|
|
|
|
int var;
|
1999-05-03 07:29:11 +00:00
|
|
|
};
|
2000-09-08 23:46:41 +00:00
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
typedef struct dict_struct dict_type;
|
2000-09-08 23:46:41 +00:00
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
static void
|
|
|
|
die (msg)
|
|
|
|
char *msg;
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s\n", msg);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_range ()
|
|
|
|
{
|
|
|
|
if (tos < stack)
|
|
|
|
die ("underflow in string stack");
|
|
|
|
if (tos >= stack + STACK)
|
|
|
|
die ("overflow in string stack");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
icheck_range ()
|
|
|
|
{
|
|
|
|
if (isp < istack)
|
|
|
|
die ("underflow in integer stack");
|
|
|
|
if (isp >= istack + STACK)
|
|
|
|
die ("overflow in integer stack");
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __STDC__
|
|
|
|
static void exec (dict_type *);
|
|
|
|
static void call (void);
|
|
|
|
static void remchar (void), strip_trailing_newlines (void), push_number (void);
|
|
|
|
static void push_text (void);
|
|
|
|
static void remove_noncomments (string_type *, string_type *);
|
|
|
|
static void print_stack_level (void);
|
|
|
|
static void paramstuff (void), translatecomments (void);
|
|
|
|
static void outputdots (void), courierize (void), bulletize (void);
|
|
|
|
static void do_fancy_stuff (void);
|
|
|
|
static int iscommand (string_type *, unsigned int);
|
|
|
|
static int copy_past_newline (string_type *, unsigned int, string_type *);
|
|
|
|
static void icopy_past_newline (void), kill_bogus_lines (void), indent (void);
|
|
|
|
static void get_stuff_in_command (void), swap (void), other_dup (void);
|
|
|
|
static void drop (void), idrop (void);
|
|
|
|
static void icatstr (void), skip_past_newline (void), internalmode (void);
|
|
|
|
static void maybecatstr (void);
|
|
|
|
static char *nextword (char *, char **);
|
|
|
|
dict_type *lookup_word (char *);
|
|
|
|
static void perform (void);
|
|
|
|
dict_type *newentry (char *);
|
|
|
|
unsigned int add_to_definition (dict_type *, stinst_type);
|
|
|
|
void add_intrinsic (char *, void (*)());
|
|
|
|
void add_var (char *);
|
|
|
|
void compile (char *);
|
|
|
|
static void bang (void);
|
|
|
|
static void atsign (void);
|
|
|
|
static void hello (void);
|
|
|
|
static void stdout_ (void);
|
|
|
|
static void stderr_ (void);
|
|
|
|
static void print (void);
|
|
|
|
static void read_in (string_type *, FILE *);
|
|
|
|
static void usage (void);
|
|
|
|
static void chew_exit (void);
|
|
|
|
#endif
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
exec (word)
|
|
|
|
dict_type *word;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
pc = word->code;
|
2000-09-08 23:46:41 +00:00
|
|
|
while (*pc)
|
|
|
|
(*pc) ();
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
call ()
|
2000-09-08 23:46:41 +00:00
|
|
|
{
|
|
|
|
stinst_type *oldpc = pc;
|
|
|
|
dict_type *e;
|
|
|
|
e = (dict_type *) (pc[1]);
|
|
|
|
exec (e);
|
|
|
|
pc = oldpc + 2;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
remchar ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
if (tos->write_idx)
|
2000-09-08 23:46:41 +00:00
|
|
|
tos->write_idx--;
|
1999-05-03 07:29:11 +00:00
|
|
|
pc++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
strip_trailing_newlines ()
|
|
|
|
{
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
push_number ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
isp++;
|
|
|
|
icheck_range ();
|
|
|
|
pc++;
|
|
|
|
*isp = (long) (*pc);
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
push_text ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
tos++;
|
|
|
|
check_range ();
|
|
|
|
init_string (tos);
|
|
|
|
pc++;
|
|
|
|
cattext (tos, *((char **) pc));
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function removes everything not inside comments starting on
|
|
|
|
the first char of the line from the string, also when copying
|
|
|
|
comments, removes blank space and leading *'s.
|
|
|
|
Blank lines are turned into one blank line. */
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
static void
|
|
|
|
remove_noncomments (src, dst)
|
2000-09-07 20:22:50 +00:00
|
|
|
string_type *src;
|
|
|
|
string_type *dst;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
unsigned int idx = 0;
|
|
|
|
|
|
|
|
while (at (src, idx))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
/* 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) == '*')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
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))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (at (src, idx) == '\n')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
/* 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);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else if (at (src, idx) == '*' && at (src, idx + 1) == '/')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
idx += 2;
|
|
|
|
cattext (dst, "\nENDDD\n");
|
|
|
|
break;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
catchar (dst, at (src, idx));
|
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else
|
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_stack_level ()
|
|
|
|
{
|
|
|
|
fprintf (stderr, "current string stack depth = %d, ", tos - stack);
|
|
|
|
fprintf (stderr, "current integer stack depth = %d\n", isp - istack);
|
|
|
|
pc++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* turn:
|
|
|
|
foobar name(stuff);
|
|
|
|
into:
|
|
|
|
foobar
|
|
|
|
name PARAMS ((stuff));
|
|
|
|
and a blank line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2002-08-29 14:37:19 +00:00
|
|
|
paramstuff ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
unsigned int openp;
|
|
|
|
unsigned int fname;
|
|
|
|
unsigned int idx;
|
2001-01-25 20:12:49 +00:00
|
|
|
unsigned int len;
|
2000-09-08 23:46:41 +00:00
|
|
|
string_type out;
|
|
|
|
init_string (&out);
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2003-06-29 10:06:40 +00:00
|
|
|
#define NO_PARAMS 1
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
/* Make sure that it's not already param'd or proto'd. */
|
2003-06-29 10:06:40 +00:00
|
|
|
if (NO_PARAMS
|
|
|
|
|| find (tos, "PARAMS") || find (tos, "PROTO") || !find (tos, "("))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
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) != '*')
|
1999-05-03 07:29:11 +00:00
|
|
|
fname--;
|
2000-09-08 23:46:41 +00:00
|
|
|
|
|
|
|
fname++;
|
|
|
|
|
2001-01-25 20:12:49 +00:00
|
|
|
/* Output type, omitting trailing whitespace character(s), if
|
|
|
|
any. */
|
|
|
|
for (len = fname; 0 < len; len--)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2001-01-25 20:12:49 +00:00
|
|
|
if (!isspace ((unsigned char) at (tos, len - 1)))
|
2001-01-24 22:38:31 +00:00
|
|
|
break;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2001-01-25 20:12:49 +00:00
|
|
|
for (idx = 0; idx < len; idx++)
|
|
|
|
catchar (&out, at (tos, idx));
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "\n"); /* Insert a newline between type and fnname */
|
|
|
|
|
2001-01-25 20:12:49 +00:00
|
|
|
/* Output function name, omitting trailing whitespace
|
|
|
|
character(s), if any. */
|
|
|
|
for (len = openp; 0 < len; len--)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2001-01-25 20:12:49 +00:00
|
|
|
if (!isspace ((unsigned char) at (tos, len - 1)))
|
|
|
|
break;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2001-01-25 20:12:49 +00:00
|
|
|
for (idx = fname; idx < len; idx++)
|
|
|
|
catchar (&out, at (tos, idx));
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, " PARAMS (");
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2001-01-25 20:12:49 +00:00
|
|
|
for (idx = openp; at (tos, idx) && at (tos, idx) != ';'; idx++)
|
|
|
|
catchar (&out, at (tos, idx));
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, ");\n\n");
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
overwrite_string (tos, &out);
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
/* turn {*
|
|
|
|
and *} into comments */
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
translatecomments ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
unsigned int idx = 0;
|
|
|
|
string_type out;
|
|
|
|
init_string (&out);
|
|
|
|
|
|
|
|
while (at (tos, idx))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (at (tos, idx) == '{' && at (tos, idx + 1) == '*')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "/*");
|
|
|
|
idx += 2;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else if (at (tos, idx) == '*' && at (tos, idx + 1) == '}')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "*/");
|
|
|
|
idx += 2;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
catchar (&out, at (tos, idx));
|
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
overwrite_string (tos, &out);
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mod tos so that only lines with leading dots remain */
|
|
|
|
static void
|
2002-08-29 14:37:19 +00:00
|
|
|
outputdots ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
unsigned int idx = 0;
|
|
|
|
string_type out;
|
|
|
|
init_string (&out);
|
|
|
|
|
|
|
|
while (at (tos, idx))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (at (tos, idx) == '\n' && at (tos, idx + 1) == '.')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
idx += 2;
|
2000-09-08 23:46:41 +00:00
|
|
|
|
|
|
|
while ((c = at (tos, idx)) && c != '\n')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (c == '{' && at (tos, idx + 1) == '*')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "/*");
|
|
|
|
idx += 2;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else if (c == '*' && at (tos, idx + 1) == '}')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "*/");
|
|
|
|
idx += 2;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
catchar (&out, c);
|
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
catchar (&out, '\n');
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
overwrite_string (tos, &out);
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find lines starting with . and | and put example around them on tos */
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
courierize ()
|
2000-09-08 23:46:41 +00:00
|
|
|
{
|
|
|
|
string_type out;
|
|
|
|
unsigned int idx = 0;
|
|
|
|
int command = 0;
|
|
|
|
|
|
|
|
init_string (&out);
|
|
|
|
|
|
|
|
while (at (tos, idx))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (at (tos, idx) == '\n'
|
|
|
|
&& (at (tos, idx +1 ) == '.'
|
|
|
|
|| at (tos, idx + 1) == '|'))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "\n@example\n");
|
|
|
|
do
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
idx += 2;
|
|
|
|
|
|
|
|
while (at (tos, idx) && at (tos, idx) != '\n')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2002-01-31 06:23:17 +00:00
|
|
|
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) == '*')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "/*");
|
|
|
|
idx += 2;
|
2002-01-31 06:23:17 +00:00
|
|
|
continue;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else if (at (tos, idx) == '*' && at (tos, idx + 1) == '}')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "*/");
|
|
|
|
idx += 2;
|
2002-01-31 06:23:17 +00:00
|
|
|
continue;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2002-01-31 06:23:17 +00:00
|
|
|
else if (at (tos, idx) == '{'
|
|
|
|
|| at (tos, idx) == '}')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2002-01-31 06:23:17 +00:00
|
|
|
catchar (&out, '@');
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
|
2002-01-31 06:23:17 +00:00
|
|
|
catchar (&out, at (tos, idx));
|
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
catchar (&out, '\n');
|
|
|
|
}
|
|
|
|
while (at (tos, idx) == '\n'
|
|
|
|
&& ((at (tos, idx + 1) == '.')
|
|
|
|
|| (at (tos, idx + 1) == '|')))
|
|
|
|
;
|
|
|
|
cattext (&out, "@end example");
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
catchar (&out, at (tos, idx));
|
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
overwrite_string (tos, &out);
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Finds any lines starting with "o ", if there are any, then turns
|
|
|
|
on @itemize @bullet, and @items each of them. Then ends with @end
|
|
|
|
itemize, inplace at TOS*/
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
bulletize ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
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) == '*')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "*");
|
|
|
|
idx += 2;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else if (at (tos, idx) == '\n'
|
|
|
|
&& at (tos, idx + 1) == 'o'
|
|
|
|
&& isspace ((unsigned char) at (tos, idx + 2)))
|
|
|
|
{
|
|
|
|
if (!on)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "\n@itemize @bullet\n");
|
|
|
|
on = 1;
|
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
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')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "@end itemize");
|
|
|
|
on = 0;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
idx++;
|
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
}
|
|
|
|
if (on)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "@end itemize\n");
|
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
delete_string (tos);
|
|
|
|
*tos = out;
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn <<foo>> into @code{foo} in place at TOS*/
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
do_fancy_stuff ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
unsigned int idx = 0;
|
|
|
|
string_type out;
|
|
|
|
init_string (&out);
|
|
|
|
while (at (tos, idx))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (at (tos, idx) == '<'
|
|
|
|
&& at (tos, idx + 1) == '<'
|
|
|
|
&& !isspace ((unsigned char) at (tos, idx + 2)))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
/* This qualifies as a << startup. */
|
|
|
|
idx += 2;
|
|
|
|
cattext (&out, "@code{");
|
|
|
|
while (at (tos, idx)
|
|
|
|
&& at (tos, idx) != '>' )
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
catchar (&out, at (tos, idx));
|
|
|
|
idx++;
|
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, "}");
|
|
|
|
idx += 2;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
catchar (&out, at (tos, idx));
|
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
delete_string (tos);
|
|
|
|
*tos = out;
|
|
|
|
pc++;
|
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
|
|
|
|
/* A command is all upper case,and alone on a line. */
|
|
|
|
|
|
|
|
static int
|
2000-09-07 20:22:50 +00:00
|
|
|
iscommand (ptr, idx)
|
|
|
|
string_type *ptr;
|
|
|
|
unsigned int idx;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
unsigned int len = 0;
|
|
|
|
while (at (ptr, idx))
|
|
|
|
{
|
|
|
|
if (isupper ((unsigned char) at (ptr, idx))
|
|
|
|
|| at (ptr, idx) == ' ' || at (ptr, idx) == '_')
|
|
|
|
{
|
|
|
|
len++;
|
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else if (at (ptr, idx) == '\n')
|
|
|
|
{
|
|
|
|
if (len > 3)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-09-07 20:22:50 +00:00
|
|
|
copy_past_newline (ptr, idx, dst)
|
|
|
|
string_type *ptr;
|
|
|
|
unsigned int idx;
|
|
|
|
string_type *dst;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
int column = 0;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
while (at (ptr, idx) && at (ptr, idx) != '\n')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
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;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
icopy_past_newline ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
tos++;
|
|
|
|
check_range ();
|
|
|
|
init_string (tos);
|
|
|
|
idx = copy_past_newline (ptr, idx, tos);
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* indent
|
2000-09-08 23:46:41 +00:00
|
|
|
Take the string at the top of the stack, do some prettying. */
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
kill_bogus_lines ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
int sl;
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
int c;
|
|
|
|
int dot = 0;
|
|
|
|
|
|
|
|
string_type out;
|
|
|
|
init_string (&out);
|
|
|
|
/* Drop leading nl. */
|
|
|
|
while (at (tos, idx) == '\n')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
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))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
|
|
|
|
/* Find the last non white before the nl. */
|
|
|
|
idx--;
|
|
|
|
|
|
|
|
while (idx && isspace ((unsigned char) at (tos, idx)))
|
1999-05-03 07:29:11 +00:00
|
|
|
idx--;
|
2000-09-08 23:46:41 +00:00
|
|
|
idx++;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
/* Copy buffer upto last char, but blank lines before and after
|
|
|
|
dots don't count. */
|
|
|
|
sl = 1;
|
|
|
|
|
|
|
|
while (c < idx)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (at (tos, c) == '\n'
|
|
|
|
&& at (tos, c + 1) == '\n'
|
|
|
|
&& at (tos, c + 2) == '.')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
/* Ignore two newlines before a dot. */
|
|
|
|
c++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else if (at (tos, c) == '.' && sl)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
/* remember that this line started with a dot. */
|
|
|
|
dot = 2;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else if (at (tos, c) == '\n'
|
|
|
|
&& at (tos, c + 1) == '\n'
|
|
|
|
&& dot)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
c++;
|
|
|
|
/* Ignore two newlines when last line was dot. */
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
catchar (&out, at (tos, c));
|
|
|
|
if (at (tos, c) == '\n')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
sl = 1;
|
|
|
|
|
|
|
|
if (dot == 2)
|
|
|
|
dot = 1;
|
|
|
|
else
|
|
|
|
dot = 0;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else
|
|
|
|
sl = 0;
|
|
|
|
|
|
|
|
c++;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
|
|
|
|
/* Append nl. */
|
|
|
|
catchar (&out, '\n');
|
|
|
|
pc++;
|
|
|
|
delete_string (tos);
|
|
|
|
*tos = out;
|
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
indent ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
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))
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
cattext (&out, " ");
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
pc++;
|
|
|
|
delete_string (tos);
|
|
|
|
*tos = out;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
get_stuff_in_command ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
tos++;
|
|
|
|
check_range ();
|
|
|
|
init_string (tos);
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
while (at (ptr, idx))
|
|
|
|
{
|
|
|
|
if (iscommand (ptr, idx))
|
|
|
|
break;
|
|
|
|
idx = copy_past_newline (ptr, idx, tos);
|
|
|
|
}
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
swap ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
string_type t;
|
|
|
|
|
|
|
|
t = tos[0];
|
|
|
|
tos[0] = tos[-1];
|
|
|
|
tos[-1] = t;
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
other_dup ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
tos++;
|
|
|
|
check_range ();
|
|
|
|
init_string (tos);
|
|
|
|
catstr (tos, tos - 1);
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
drop ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
tos--;
|
|
|
|
check_range ();
|
|
|
|
pc++;
|
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
idrop ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
isp--;
|
|
|
|
icheck_range ();
|
|
|
|
pc++;
|
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
icatstr ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
tos--;
|
|
|
|
check_range ();
|
|
|
|
catstr (tos, tos + 1);
|
|
|
|
delete_string (tos + 1);
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
skip_past_newline ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
while (at (ptr, idx)
|
|
|
|
&& at (ptr, idx) != '\n')
|
1999-05-03 07:29:11 +00:00
|
|
|
idx++;
|
2000-09-08 23:46:41 +00:00
|
|
|
idx++;
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
internalmode ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
internal_mode = *(isp);
|
|
|
|
isp--;
|
|
|
|
icheck_range ();
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
maybecatstr ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (internal_wanted == internal_mode)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
catstr (tos - 1, tos);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
delete_string (tos);
|
|
|
|
tos--;
|
|
|
|
check_range ();
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2000-09-07 20:22:50 +00:00
|
|
|
nextword (string, word)
|
|
|
|
char *string;
|
|
|
|
char **word;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
char *word_start;
|
|
|
|
int idx;
|
|
|
|
char *dst;
|
|
|
|
char *src;
|
|
|
|
|
|
|
|
int length = 0;
|
|
|
|
|
|
|
|
while (isspace ((unsigned char) *string) || *string == '-')
|
|
|
|
{
|
|
|
|
if (*string == '-')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
while (*string && *string != '\n')
|
1999-05-03 07:29:11 +00:00
|
|
|
string++;
|
2000-09-08 23:46:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
if (!*string)
|
|
|
|
return 0;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
word_start = string;
|
|
|
|
if (*string == '"')
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
string++;
|
|
|
|
length++;
|
|
|
|
if (*string == '\\')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
string += 2;
|
|
|
|
length += 2;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
}
|
|
|
|
while (*string != '"');
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
while (!isspace ((unsigned char) *string))
|
|
|
|
{
|
|
|
|
string++;
|
|
|
|
length++;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2009-09-28 12:15:51 +00:00
|
|
|
*word = (char *) malloc (length + 1);
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
dst = *word;
|
|
|
|
src = word_start;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
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;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
if (*string)
|
|
|
|
return string + 1;
|
|
|
|
else
|
|
|
|
return 0;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
dict_type *root;
|
2000-09-08 23:46:41 +00:00
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
dict_type *
|
2000-09-07 20:22:50 +00:00
|
|
|
lookup_word (word)
|
|
|
|
char *word;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
dict_type *ptr = root;
|
2000-09-08 23:46:41 +00:00
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
if (strcmp (ptr->word, word) == 0)
|
|
|
|
return ptr;
|
1999-05-03 07:29:11 +00:00
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
if (warning)
|
2000-09-08 23:46:41 +00:00
|
|
|
fprintf (stderr, "Can't find %s\n", word);
|
1999-05-03 07:29:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
2002-08-29 14:37:19 +00:00
|
|
|
perform ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
tos = stack;
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
while (at (ptr, idx))
|
|
|
|
{
|
|
|
|
/* It's worth looking through the command list. */
|
|
|
|
if (iscommand (ptr, idx))
|
|
|
|
{
|
|
|
|
char *next;
|
|
|
|
dict_type *word;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
(void) nextword (addr (ptr, idx), &next);
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
word = lookup_word (next);
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
if (word)
|
|
|
|
{
|
|
|
|
exec (word);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (warning)
|
|
|
|
fprintf (stderr, "warning, %s is not recognised\n", next);
|
|
|
|
skip_past_newline ();
|
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else
|
|
|
|
skip_past_newline ();
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dict_type *
|
2000-09-07 20:22:50 +00:00
|
|
|
newentry (word)
|
|
|
|
char *word;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
Updated sources to avoid using the identifier name "new", which is a
keyword in c++.
* bfd/aoutx.h (NAME (aout, make_empty_symbol)): Rename variable
new to new_symbol.
* bfd/coffgen.c (coff_make_empty_symbol)
(coff_bfd_make_debug_symbol): Rename variable new to new_symbol.
* bfd/cpu-ia64-opc.c (ext_reg, ins_imms_scaled): Rename variable
new to new_insn.
* bfd/doc/chew.c (newentry, add_intrinsic): Rename variable new to
new_d.
* bfd/ecoff.c (_bfd_ecoff_make_empty_symbol): Rename variable new
to new_symbol.
* bfd/elf32-m68k.c (elf_m68k_get_got_entry_type): Rename argument
new to new_reloc.
* bfd/hash.c (bfd_hash_lookup): Rename variable new to new_string.
* bfd/ieee.c (ieee_make_empty_symbol): Rename variable new to
new_symbol.
* bfd/linker.c (bfd_new_link_order): Rename variable new to
new_lo.
* bfd/mach-o.c (bfd_mach_o_sizeof_headers): Rename variable new to
symbol.
* bfd/oasys.c (oasys_make_empty_symbol): Rename variable new to
new_symbol_type.
* bfd/pdp11.c (NAME (aout, make_empty_symbol)): Rename variable
new to new_symbol_type.
* bfd/plugin.c (bfd_plugin_make_empty_symbol): Rename variable new
to new_symbol.
* bfd/rs6000-core.c (CoreHdr, VmInfo): Rename union member new to
new_dump.
(read_hdr, rs6000coff_core_p)
(rs6000coff_core_file_matches_executable_p)
(rs6000coff_core_file_failing_command)
(rs6000coff_core_file_failing_signal): Updated function to use new
union member name.
* bfd/som.c (som_make_empty_symbol): Rename variable new to
new_symbol_type.
* bfd/syms.c (_bfd_generic_make_empty_symbol): Rename variable new
to new_symbol.
* bfd/tekhex.c (first_phase, tekhex_make_empty_symbol): Rename
variable new to new_symbol.
* binutils/nlmconv.c (main): Rename variable new to new_name.
* gas/config/tc-arm.c (insert_reg_alias): Rename variable new to
new_reg.
* gas/config/tc-dlx.c (parse_operand): Rename variable new to
new_pos.
* gas/config/tc-ia64.c (ia64_gen_real_reloc_type): Rename variable
new to newr.
* gas/config/tc-mcore.c (parse_exp, parse_imm): Rename variable
new to new_pointer.
* gas/config/tc-microblaze.c (parse_exp, parse_imm, check_got):
Change name from new to new_pointer.
* gas/config/tc-or32.c (parse_operand): Rename variable new to
new_pointer.
* gas/config/tc-pdp11.c (md_assemble): Rename variable new to
new_pointer.
* gas/config/tc-pj.c (alias): Change argument new to new_name.
* gas/config/tc-score.c (s3_build_score_ops_hsh): Rename variable
new to new_opcode. (s3_build_dependency_insn_hsh) Rename variable
new to new_i2n. (s3_convert): Rename variables old and new to
r_old and r_new.
* gas/config/tc-score7.c (s7_build_score_ops_hsh): Rename variable
new to new_opcode. (s7_build_dependency_insn_hsh): Rename variable
new to new_i2d. (s7_b32_relax_to_b16, s7_convert_frag): Rename
variables old and new to r_old and r_new.
* gas/config/tc-sh.c (parse_exp): Rename variable new to
new_pointer.
* gas/config/tc-sh64.c (shmedia_parse_exp): Rename variable new to
new_pointer.
* gas/config/tc-tic4x.c (tic4x_operand_parse): Rename variable new
to new_pointer.
* gas/config/tc-z8k.c (parse_exp): Rename variable new to
new_pointer.
* gas/listing.c (listing_newline): Rename variable new to new_i.
* ld/ldexp.c (exp_intop, exp_bigintop, exp_relop, exp_binop)
(exp_trinop, exp_unop, exp_nameop, exp_assop): Rename variable new
to new_e.
* ld/ldfile.c (ldfile_add_library_path): Rename variable new to
new_dirs. (ldfile_add_arch): Rename variable new to new_arch.
* ld/ldlang.c (new_statement, lang_final, lang_add_wild)
(lang_target, lang_add_fill, lang_add_data, lang_add_assignment)
(lang_add_insert): Rename variable new to new_stmt. (new_afile):
Added missing cast. (lang_memory_region_lookup): Rename variable
new to new_region. (init_os): Rename variable new to
new_userdata. (lang_add_section): Rename variable new to
new_section. (ldlang_add_undef): Rename variable new to
new_undef. (realsymbol): Rename variable new to new_name.
* opcodes/z8kgen.c (internal, gas): Rename variable new to new_op.
Updated sources to avoid using the identifier name "template",
which is a keyword in c++.
* bfd/elf32-arm.c (struct stub_def): Rename member template to
template_sequence. (arm_build_one_stub,
find_stub_size_and_template, arm_size_one_stub, arm_map_one_stub):
Rename variable template to template_sequence.
* bfd/elfxx-ia64.c (elfNN_ia64_relax_br, elfNN_ia64_relax_brl):
Rename variable template to template_val.
* gas/config/tc-arm.c (struct asm_cond, struct asm_psr, struct
asm_barrier_opt): Change member template to
template_name. (md_begin): Update code to reflect new member
names.
* gas/config/tc-i386.c (struct templates, struct _i386_insn)
(match_template, cpu_flags_match, match_reg_size, match_mem_size)
(operand_size_match, md_begin, i386_print_statistics, pi)
(build_vex_prefix, md_assemble, parse_insn, optimize_imm)
(optimize_disp): Updated code to use new names. (parse_insn):
Added casts.
* gas/config/tc-ia64.c (dot_template, emit_one_bundle): Updated
code to use new names.
* gas/config/tc-score.c (struct s3_asm_opcode): Renamed member
template to template_name. (s3_parse_16_32_inst, s3_parse_48_inst,
s3_do_macro_ldst_label, s3_build_score_ops_hsh): Update code to
use new names.
* gas/config/tc-score7.c (struct s7_asm_opcode): Renamed member
template to template_name. (s7_parse_16_32_inst,
s7_do_macro_ldst_label, s7_build_score_ops_hsh): Update code to
use new names.
* gas/config/tc-tic30.c (md_begin, struct tic30_insn)
(md_assemble): Update code to use new names.
* gas/config/tc-tic54x.c (struct _tic54x_insn, md_begin)
(optimize_insn, tic54x_parse_insn, next_line_shows_parallel):
Update code to use new names.
* include/opcode/tic30.h (template): Rename type template to
insn_template. Updated code to use new name.
* include/opcode/tic54x.h (template): Rename type template to
insn_template.
* opcodes/cris-dis.c (bytes_to_skip): Update code to use new name.
* opcodes/i386-dis.c (putop): Update code to use new name.
* opcodes/i386-gen.c (process_i386_opcodes): Update code to use
new name.
* opcodes/i386-opc.h (struct template): Rename struct template to
insn_template. Update code accordingly.
* opcodes/i386-tbl.h (i386_optab): Update type to use new name.
* opcodes/ia64-dis.c (print_insn_ia64): Rename variable template
to template_val.
* opcodes/tic30-dis.c (struct instruction, get_tic30_instruction):
Update code to use new name.
* opcodes/tic54x-dis.c (has_lkaddr, get_insn_size)
(print_parallel_instruction, print_insn_tic54x, tic54x_get_insn):
Update code to use new name.
* opcodes/tic54x-opc.c (tic54x_unknown_opcode, tic54x_optab):
Update type to new name.
2009-08-29 22:11:02 +00:00
|
|
|
dict_type *new_d = (dict_type *) malloc (sizeof (dict_type));
|
|
|
|
new_d->word = word;
|
|
|
|
new_d->next = root;
|
|
|
|
root = new_d;
|
|
|
|
new_d->code = (stinst_type *) malloc (sizeof (stinst_type));
|
|
|
|
new_d->code_length = 1;
|
|
|
|
new_d->code_end = 0;
|
|
|
|
return new_d;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
2000-09-07 20:22:50 +00:00
|
|
|
add_to_definition (entry, word)
|
|
|
|
dict_type *entry;
|
|
|
|
stinst_type word;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (entry->code_end == entry->code_length)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
entry->code_length += 2;
|
|
|
|
entry->code =
|
|
|
|
(stinst_type *) realloc ((char *) (entry->code),
|
|
|
|
entry->code_length * sizeof (word_type));
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
entry->code[entry->code_end] = word;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
return entry->code_end++;
|
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
void
|
2000-09-07 20:22:50 +00:00
|
|
|
add_intrinsic (name, func)
|
|
|
|
char *name;
|
2000-09-08 23:46:41 +00:00
|
|
|
void (*func) ();
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
Updated sources to avoid using the identifier name "new", which is a
keyword in c++.
* bfd/aoutx.h (NAME (aout, make_empty_symbol)): Rename variable
new to new_symbol.
* bfd/coffgen.c (coff_make_empty_symbol)
(coff_bfd_make_debug_symbol): Rename variable new to new_symbol.
* bfd/cpu-ia64-opc.c (ext_reg, ins_imms_scaled): Rename variable
new to new_insn.
* bfd/doc/chew.c (newentry, add_intrinsic): Rename variable new to
new_d.
* bfd/ecoff.c (_bfd_ecoff_make_empty_symbol): Rename variable new
to new_symbol.
* bfd/elf32-m68k.c (elf_m68k_get_got_entry_type): Rename argument
new to new_reloc.
* bfd/hash.c (bfd_hash_lookup): Rename variable new to new_string.
* bfd/ieee.c (ieee_make_empty_symbol): Rename variable new to
new_symbol.
* bfd/linker.c (bfd_new_link_order): Rename variable new to
new_lo.
* bfd/mach-o.c (bfd_mach_o_sizeof_headers): Rename variable new to
symbol.
* bfd/oasys.c (oasys_make_empty_symbol): Rename variable new to
new_symbol_type.
* bfd/pdp11.c (NAME (aout, make_empty_symbol)): Rename variable
new to new_symbol_type.
* bfd/plugin.c (bfd_plugin_make_empty_symbol): Rename variable new
to new_symbol.
* bfd/rs6000-core.c (CoreHdr, VmInfo): Rename union member new to
new_dump.
(read_hdr, rs6000coff_core_p)
(rs6000coff_core_file_matches_executable_p)
(rs6000coff_core_file_failing_command)
(rs6000coff_core_file_failing_signal): Updated function to use new
union member name.
* bfd/som.c (som_make_empty_symbol): Rename variable new to
new_symbol_type.
* bfd/syms.c (_bfd_generic_make_empty_symbol): Rename variable new
to new_symbol.
* bfd/tekhex.c (first_phase, tekhex_make_empty_symbol): Rename
variable new to new_symbol.
* binutils/nlmconv.c (main): Rename variable new to new_name.
* gas/config/tc-arm.c (insert_reg_alias): Rename variable new to
new_reg.
* gas/config/tc-dlx.c (parse_operand): Rename variable new to
new_pos.
* gas/config/tc-ia64.c (ia64_gen_real_reloc_type): Rename variable
new to newr.
* gas/config/tc-mcore.c (parse_exp, parse_imm): Rename variable
new to new_pointer.
* gas/config/tc-microblaze.c (parse_exp, parse_imm, check_got):
Change name from new to new_pointer.
* gas/config/tc-or32.c (parse_operand): Rename variable new to
new_pointer.
* gas/config/tc-pdp11.c (md_assemble): Rename variable new to
new_pointer.
* gas/config/tc-pj.c (alias): Change argument new to new_name.
* gas/config/tc-score.c (s3_build_score_ops_hsh): Rename variable
new to new_opcode. (s3_build_dependency_insn_hsh) Rename variable
new to new_i2n. (s3_convert): Rename variables old and new to
r_old and r_new.
* gas/config/tc-score7.c (s7_build_score_ops_hsh): Rename variable
new to new_opcode. (s7_build_dependency_insn_hsh): Rename variable
new to new_i2d. (s7_b32_relax_to_b16, s7_convert_frag): Rename
variables old and new to r_old and r_new.
* gas/config/tc-sh.c (parse_exp): Rename variable new to
new_pointer.
* gas/config/tc-sh64.c (shmedia_parse_exp): Rename variable new to
new_pointer.
* gas/config/tc-tic4x.c (tic4x_operand_parse): Rename variable new
to new_pointer.
* gas/config/tc-z8k.c (parse_exp): Rename variable new to
new_pointer.
* gas/listing.c (listing_newline): Rename variable new to new_i.
* ld/ldexp.c (exp_intop, exp_bigintop, exp_relop, exp_binop)
(exp_trinop, exp_unop, exp_nameop, exp_assop): Rename variable new
to new_e.
* ld/ldfile.c (ldfile_add_library_path): Rename variable new to
new_dirs. (ldfile_add_arch): Rename variable new to new_arch.
* ld/ldlang.c (new_statement, lang_final, lang_add_wild)
(lang_target, lang_add_fill, lang_add_data, lang_add_assignment)
(lang_add_insert): Rename variable new to new_stmt. (new_afile):
Added missing cast. (lang_memory_region_lookup): Rename variable
new to new_region. (init_os): Rename variable new to
new_userdata. (lang_add_section): Rename variable new to
new_section. (ldlang_add_undef): Rename variable new to
new_undef. (realsymbol): Rename variable new to new_name.
* opcodes/z8kgen.c (internal, gas): Rename variable new to new_op.
Updated sources to avoid using the identifier name "template",
which is a keyword in c++.
* bfd/elf32-arm.c (struct stub_def): Rename member template to
template_sequence. (arm_build_one_stub,
find_stub_size_and_template, arm_size_one_stub, arm_map_one_stub):
Rename variable template to template_sequence.
* bfd/elfxx-ia64.c (elfNN_ia64_relax_br, elfNN_ia64_relax_brl):
Rename variable template to template_val.
* gas/config/tc-arm.c (struct asm_cond, struct asm_psr, struct
asm_barrier_opt): Change member template to
template_name. (md_begin): Update code to reflect new member
names.
* gas/config/tc-i386.c (struct templates, struct _i386_insn)
(match_template, cpu_flags_match, match_reg_size, match_mem_size)
(operand_size_match, md_begin, i386_print_statistics, pi)
(build_vex_prefix, md_assemble, parse_insn, optimize_imm)
(optimize_disp): Updated code to use new names. (parse_insn):
Added casts.
* gas/config/tc-ia64.c (dot_template, emit_one_bundle): Updated
code to use new names.
* gas/config/tc-score.c (struct s3_asm_opcode): Renamed member
template to template_name. (s3_parse_16_32_inst, s3_parse_48_inst,
s3_do_macro_ldst_label, s3_build_score_ops_hsh): Update code to
use new names.
* gas/config/tc-score7.c (struct s7_asm_opcode): Renamed member
template to template_name. (s7_parse_16_32_inst,
s7_do_macro_ldst_label, s7_build_score_ops_hsh): Update code to
use new names.
* gas/config/tc-tic30.c (md_begin, struct tic30_insn)
(md_assemble): Update code to use new names.
* gas/config/tc-tic54x.c (struct _tic54x_insn, md_begin)
(optimize_insn, tic54x_parse_insn, next_line_shows_parallel):
Update code to use new names.
* include/opcode/tic30.h (template): Rename type template to
insn_template. Updated code to use new name.
* include/opcode/tic54x.h (template): Rename type template to
insn_template.
* opcodes/cris-dis.c (bytes_to_skip): Update code to use new name.
* opcodes/i386-dis.c (putop): Update code to use new name.
* opcodes/i386-gen.c (process_i386_opcodes): Update code to use
new name.
* opcodes/i386-opc.h (struct template): Rename struct template to
insn_template. Update code accordingly.
* opcodes/i386-tbl.h (i386_optab): Update type to use new name.
* opcodes/ia64-dis.c (print_insn_ia64): Rename variable template
to template_val.
* opcodes/tic30-dis.c (struct instruction, get_tic30_instruction):
Update code to use new name.
* opcodes/tic54x-dis.c (has_lkaddr, get_insn_size)
(print_parallel_instruction, print_insn_tic54x, tic54x_get_insn):
Update code to use new name.
* opcodes/tic54x-opc.c (tic54x_unknown_opcode, tic54x_optab):
Update type to new name.
2009-08-29 22:11:02 +00:00
|
|
|
dict_type *new_d = newentry (name);
|
|
|
|
add_to_definition (new_d, func);
|
|
|
|
add_to_definition (new_d, 0);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-09-07 20:22:50 +00:00
|
|
|
add_var (name)
|
|
|
|
char *name;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
Updated sources to avoid using the identifier name "new", which is a
keyword in c++.
* bfd/aoutx.h (NAME (aout, make_empty_symbol)): Rename variable
new to new_symbol.
* bfd/coffgen.c (coff_make_empty_symbol)
(coff_bfd_make_debug_symbol): Rename variable new to new_symbol.
* bfd/cpu-ia64-opc.c (ext_reg, ins_imms_scaled): Rename variable
new to new_insn.
* bfd/doc/chew.c (newentry, add_intrinsic): Rename variable new to
new_d.
* bfd/ecoff.c (_bfd_ecoff_make_empty_symbol): Rename variable new
to new_symbol.
* bfd/elf32-m68k.c (elf_m68k_get_got_entry_type): Rename argument
new to new_reloc.
* bfd/hash.c (bfd_hash_lookup): Rename variable new to new_string.
* bfd/ieee.c (ieee_make_empty_symbol): Rename variable new to
new_symbol.
* bfd/linker.c (bfd_new_link_order): Rename variable new to
new_lo.
* bfd/mach-o.c (bfd_mach_o_sizeof_headers): Rename variable new to
symbol.
* bfd/oasys.c (oasys_make_empty_symbol): Rename variable new to
new_symbol_type.
* bfd/pdp11.c (NAME (aout, make_empty_symbol)): Rename variable
new to new_symbol_type.
* bfd/plugin.c (bfd_plugin_make_empty_symbol): Rename variable new
to new_symbol.
* bfd/rs6000-core.c (CoreHdr, VmInfo): Rename union member new to
new_dump.
(read_hdr, rs6000coff_core_p)
(rs6000coff_core_file_matches_executable_p)
(rs6000coff_core_file_failing_command)
(rs6000coff_core_file_failing_signal): Updated function to use new
union member name.
* bfd/som.c (som_make_empty_symbol): Rename variable new to
new_symbol_type.
* bfd/syms.c (_bfd_generic_make_empty_symbol): Rename variable new
to new_symbol.
* bfd/tekhex.c (first_phase, tekhex_make_empty_symbol): Rename
variable new to new_symbol.
* binutils/nlmconv.c (main): Rename variable new to new_name.
* gas/config/tc-arm.c (insert_reg_alias): Rename variable new to
new_reg.
* gas/config/tc-dlx.c (parse_operand): Rename variable new to
new_pos.
* gas/config/tc-ia64.c (ia64_gen_real_reloc_type): Rename variable
new to newr.
* gas/config/tc-mcore.c (parse_exp, parse_imm): Rename variable
new to new_pointer.
* gas/config/tc-microblaze.c (parse_exp, parse_imm, check_got):
Change name from new to new_pointer.
* gas/config/tc-or32.c (parse_operand): Rename variable new to
new_pointer.
* gas/config/tc-pdp11.c (md_assemble): Rename variable new to
new_pointer.
* gas/config/tc-pj.c (alias): Change argument new to new_name.
* gas/config/tc-score.c (s3_build_score_ops_hsh): Rename variable
new to new_opcode. (s3_build_dependency_insn_hsh) Rename variable
new to new_i2n. (s3_convert): Rename variables old and new to
r_old and r_new.
* gas/config/tc-score7.c (s7_build_score_ops_hsh): Rename variable
new to new_opcode. (s7_build_dependency_insn_hsh): Rename variable
new to new_i2d. (s7_b32_relax_to_b16, s7_convert_frag): Rename
variables old and new to r_old and r_new.
* gas/config/tc-sh.c (parse_exp): Rename variable new to
new_pointer.
* gas/config/tc-sh64.c (shmedia_parse_exp): Rename variable new to
new_pointer.
* gas/config/tc-tic4x.c (tic4x_operand_parse): Rename variable new
to new_pointer.
* gas/config/tc-z8k.c (parse_exp): Rename variable new to
new_pointer.
* gas/listing.c (listing_newline): Rename variable new to new_i.
* ld/ldexp.c (exp_intop, exp_bigintop, exp_relop, exp_binop)
(exp_trinop, exp_unop, exp_nameop, exp_assop): Rename variable new
to new_e.
* ld/ldfile.c (ldfile_add_library_path): Rename variable new to
new_dirs. (ldfile_add_arch): Rename variable new to new_arch.
* ld/ldlang.c (new_statement, lang_final, lang_add_wild)
(lang_target, lang_add_fill, lang_add_data, lang_add_assignment)
(lang_add_insert): Rename variable new to new_stmt. (new_afile):
Added missing cast. (lang_memory_region_lookup): Rename variable
new to new_region. (init_os): Rename variable new to
new_userdata. (lang_add_section): Rename variable new to
new_section. (ldlang_add_undef): Rename variable new to
new_undef. (realsymbol): Rename variable new to new_name.
* opcodes/z8kgen.c (internal, gas): Rename variable new to new_op.
Updated sources to avoid using the identifier name "template",
which is a keyword in c++.
* bfd/elf32-arm.c (struct stub_def): Rename member template to
template_sequence. (arm_build_one_stub,
find_stub_size_and_template, arm_size_one_stub, arm_map_one_stub):
Rename variable template to template_sequence.
* bfd/elfxx-ia64.c (elfNN_ia64_relax_br, elfNN_ia64_relax_brl):
Rename variable template to template_val.
* gas/config/tc-arm.c (struct asm_cond, struct asm_psr, struct
asm_barrier_opt): Change member template to
template_name. (md_begin): Update code to reflect new member
names.
* gas/config/tc-i386.c (struct templates, struct _i386_insn)
(match_template, cpu_flags_match, match_reg_size, match_mem_size)
(operand_size_match, md_begin, i386_print_statistics, pi)
(build_vex_prefix, md_assemble, parse_insn, optimize_imm)
(optimize_disp): Updated code to use new names. (parse_insn):
Added casts.
* gas/config/tc-ia64.c (dot_template, emit_one_bundle): Updated
code to use new names.
* gas/config/tc-score.c (struct s3_asm_opcode): Renamed member
template to template_name. (s3_parse_16_32_inst, s3_parse_48_inst,
s3_do_macro_ldst_label, s3_build_score_ops_hsh): Update code to
use new names.
* gas/config/tc-score7.c (struct s7_asm_opcode): Renamed member
template to template_name. (s7_parse_16_32_inst,
s7_do_macro_ldst_label, s7_build_score_ops_hsh): Update code to
use new names.
* gas/config/tc-tic30.c (md_begin, struct tic30_insn)
(md_assemble): Update code to use new names.
* gas/config/tc-tic54x.c (struct _tic54x_insn, md_begin)
(optimize_insn, tic54x_parse_insn, next_line_shows_parallel):
Update code to use new names.
* include/opcode/tic30.h (template): Rename type template to
insn_template. Updated code to use new name.
* include/opcode/tic54x.h (template): Rename type template to
insn_template.
* opcodes/cris-dis.c (bytes_to_skip): Update code to use new name.
* opcodes/i386-dis.c (putop): Update code to use new name.
* opcodes/i386-gen.c (process_i386_opcodes): Update code to use
new name.
* opcodes/i386-opc.h (struct template): Rename struct template to
insn_template. Update code accordingly.
* opcodes/i386-tbl.h (i386_optab): Update type to use new name.
* opcodes/ia64-dis.c (print_insn_ia64): Rename variable template
to template_val.
* opcodes/tic30-dis.c (struct instruction, get_tic30_instruction):
Update code to use new name.
* opcodes/tic54x-dis.c (has_lkaddr, get_insn_size)
(print_parallel_instruction, print_insn_tic54x, tic54x_get_insn):
Update code to use new name.
* opcodes/tic54x-opc.c (tic54x_unknown_opcode, tic54x_optab):
Update type to new name.
2009-08-29 22:11:02 +00:00
|
|
|
dict_type *new_d = newentry (name);
|
|
|
|
add_to_definition (new_d, push_number);
|
|
|
|
add_to_definition (new_d, (stinst_type) (&(new_d->var)));
|
|
|
|
add_to_definition (new_d, 0);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
void
|
2000-09-07 20:22:50 +00:00
|
|
|
compile (string)
|
|
|
|
char *string;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
/* Add words to the dictionary. */
|
|
|
|
char *word;
|
|
|
|
string = nextword (string, &word);
|
|
|
|
while (string && *string && word[0])
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (strcmp (word, "var") == 0)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
string = nextword (string, &word);
|
|
|
|
|
|
|
|
add_var (word);
|
|
|
|
string = nextword (string, &word);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else if (word[0] == ':')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
dict_type *ptr;
|
|
|
|
/* Compile a word and add to dictionary. */
|
|
|
|
string = nextword (string, &word);
|
|
|
|
|
|
|
|
ptr = newentry (word);
|
|
|
|
string = nextword (string, &word);
|
|
|
|
while (word[0] != ';')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
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);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
add_to_definition (ptr, 0);
|
|
|
|
string = nextword (string, &word);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
else
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
fprintf (stderr, "syntax error at %s\n", string - 1);
|
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
2002-08-29 14:37:19 +00:00
|
|
|
bang ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
*(long *) ((isp[0])) = isp[-1];
|
|
|
|
isp -= 2;
|
1999-05-03 07:29:11 +00:00
|
|
|
icheck_range ();
|
|
|
|
pc++;
|
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
atsign ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
isp[0] = *(long *) (isp[0]);
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
hello ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
printf ("hello\n");
|
|
|
|
pc++;
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
stdout_ ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
isp++;
|
|
|
|
icheck_range ();
|
|
|
|
*isp = 1;
|
|
|
|
pc++;
|
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
stderr_ ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
isp++;
|
|
|
|
icheck_range ();
|
|
|
|
*isp = 2;
|
|
|
|
pc++;
|
|
|
|
}
|
|
|
|
|
2002-02-01 09:22:53 +00:00
|
|
|
static void
|
|
|
|
print ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
|
|
|
read_in (str, file)
|
2000-09-08 23:46:41 +00:00
|
|
|
string_type *str;
|
|
|
|
FILE *file;
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
char buff[10000];
|
|
|
|
unsigned int r;
|
|
|
|
do
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
r = fread (buff, 1, sizeof (buff), file);
|
|
|
|
catbuf (str, buff, r);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
while (r);
|
|
|
|
buff[0] = 0;
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
catbuf (str, buff, 1);
|
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
static void
|
2002-08-29 14:37:19 +00:00
|
|
|
usage ()
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
fprintf (stderr, "usage: -[d|i|g] <file >file\n");
|
|
|
|
exit (33);
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* There is no reliable way to declare exit. Sometimes it returns
|
|
|
|
int, and sometimes it returns void. Sometimes it changes between
|
|
|
|
OS releases. Trying to get it declared correctly in the hosts file
|
|
|
|
is a pointless waste of time. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
chew_exit ()
|
|
|
|
{
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2000-09-07 20:22:50 +00:00
|
|
|
int
|
2000-09-08 23:46:41 +00:00
|
|
|
main (ac, av)
|
2000-09-07 20:22:50 +00:00
|
|
|
int ac;
|
|
|
|
char *av[];
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
string_type buffer;
|
|
|
|
string_type pptr;
|
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
init_string (&buffer);
|
|
|
|
init_string (&pptr);
|
|
|
|
init_string (stack + 0);
|
|
|
|
tos = stack + 1;
|
1999-05-03 07:29:11 +00:00
|
|
|
ptr = &pptr;
|
2000-09-08 23:46:41 +00:00
|
|
|
|
|
|
|
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);
|
1999-05-03 07:29:11 +00:00
|
|
|
/* 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. */
|
2000-09-08 23:46:41 +00:00
|
|
|
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++)
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (av[i][0] == '-')
|
1999-05-03 07:29:11 +00:00
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
if (av[i][1] == 'f')
|
|
|
|
{
|
|
|
|
string_type b;
|
|
|
|
FILE *f;
|
|
|
|
init_string (&b);
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-09-08 23:46:41 +00:00
|
|
|
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 ();
|
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2000-09-08 23:46:41 +00:00
|
|
|
write_buffer (stack + 0, stdout);
|
1999-05-03 07:29:11 +00:00
|
|
|
if (tos != stack)
|
|
|
|
{
|
2000-09-08 23:46:41 +00:00
|
|
|
fprintf (stderr, "finishing with current stack level %d\n",
|
|
|
|
tos - stack);
|
1999-05-03 07:29:11 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|