home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_300
/
355_02
/
slk2.exe
/
SPP
/
PR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-09
|
4KB
|
207 lines
/*
New Sherlock Preprocessor -- printing routines for debugging.
source: pr.c
started: May 19, 1986
version:
July 20, 1988
February 16, 1989
change the output of pr_tok() so that it is more
suitable for user error messages.
PUBLIC DOMAIN SOFTWARE
Sherlock, including the SPP, SDEL and SDIF programs, was placed in
the public domain on June 15, 1991, by its author,
Edward K. Ream
166 North Prospect Ave.
Madison, WI 53705.
(608) 257-0802
Sherlock may be used for any commercial or non-commercial purpose.
DISCLAIMER OF WARRANTIES
Edward K. Ream (Ream) specifically disclaims all warranties,
expressed or implied, with respect to this computer software,
including but not limited to implied warranties of merchantability
and fitness for a particular purpose. In no event shall Ream be
liable for any loss of profit or any commercial damage, including
but not limited to special, incidental consequential or other damages.
*/
#include "spp.h"
/*
WARNING!! These two tables must change if enum.h changes.
*/
static char * scope_tab [] = {
"NULL_SCOPE", "OUTER_SCOPE", "OLD_FORMAL_SCOPE",
"NEW_FORMAL_SCOPE", "STRUCT_SCOPE", "BLOCK_SCOPE"
};
static char * FAR tok_tab [] = {
"<NULL>", "<ERROR>",
"auto", "char", "const", "double", "enum", "extern",
"float", "int", "long", "noalias", "register", "short",
"static", "typedef", "signed", "struct", "union",
"unsigned", "void", "volatile",
"break", "case",
"continue", "default", "do", "else", "for",
"goto", "if", "return", "switch", "while",
"entry", "sizeof",
",", "<newline>", ";", "[", "{", "(", "]", "}", ")",
":", "?",
"ARRAY", "->", ".", "&&", "||", ",",
"=",
"&=", "/=", "<<=", "-=", "%=",
"|=", "+=", ">>=", "*=", "^=",
"&", "|", "+", "*", "^",
"/", "<<", "-", "%", ">>",
"==", ">=", ">", "<=", "<", "!=",
"--", "++", "!", "~",
"(cast)", "post--", "post++", "pre--", "pre++",
"&", "-", "+", "*", "call",
"character", "end-of-file",
"identifier", "integer", "float", "long integer",
"string",
"unsigned long", "long double",
"...", "label", "bool"
};
/*
Return the print string of a bool.
*/
char *
pr_bool(flag)
bool flag;
{
return flag ? "TRUE" : "FALSE";
}
/*
Return the print string of a character.
*/
static char pdefault[] = "@";
char *
pr_ch(c)
int c;
{
switch (c) {
case ARG_FLAG: return "ARG:";
case POUND_FLAG: return "POUND:";
case CONCAT_FLAG: return "<CONCAT_FLAG>";
case EORT: return "<EORT>";
case EXPAND_OFF: return "<EXPAND_OFF>";
case '\0': return "<\\0>";
case '\t': return "<TAB>";
case '\n': return "<NL>";
case '\r': return "<CR>";
case '\a': return "<ALERT>";
case ' ': return "< >";
case END_FILE: return "<END_FILE>";
default:
pdefault[0] = c;
pdefault[1] = '\0';
return &pdefault[0];
}
}
/*
Return the print string of tok.
Do not assume that t_symbol[] refers to tok.
*/
char *
pr_op(tok)
en_tokens tok;
{
if ((int)tok >= 0 && (int)tok <= LAST_ENUM_TOK) {
return tok_tab [(int)tok];
}
else {
return "BAD TOKEN";
}
}
char *
pr_scope(en_scope scope)
{
return scope_tab [scope];
}
/*
Return the print string of a string.
*/
static char pr_buf [1000];
char *
pr_str(s)
char *s;
{
strcpy(pr_buf, "");
while (*s) {
strcat(pr_buf, pr_ch(*s));
s++;
}
return &pr_buf[0];
}
/*
Return the print string of the current token.
Assume the t_symbol refers to the global token.
*/
static char buffer [200];
static char buffer2 [100];
char *
pr_tok()
{
if (is(ID_TOK)) {
if (t_length >= 200-5) {
printf("truncated identifier: %s\n", t_symbol);
exit(1);
return "";
}
else {
strcpy(buffer, t_symbol);
return buffer;
}
}
else if (is(STRING_TOK)) {
if (t_length >= 200-5) {
printf("truncated string: %s\n", t_symbol);
exit(1);
return "";
}
else {
strcpy(buffer, t_symbol);
return buffer;
}
}
else if (is(INT_TOK)) {
ltoa(t_value, buffer2, 10);
return buffer2;
}
else if (token < LABEL_TOK) {
return tok_tab [(int)token];
}
else {
return "BAD TOKEN";
}
}