Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
263 dpurdie 1
/*
2
	CPP V5 -- printing routines for debugging.
3
 
4
	source:  pr.c
5
	started: May 19, 1986
6
	version: May 31, 1988
7
 
8
	Written by Edward K. Ream.
9
	This software is in the public domain.
10
 
11
	See the read.me file for disclaimer and other information.
12
*/
13
 
14
#include "cpp.h"
15
 
16
 
17
#ifdef SHERLOCK
18
 
19
/*
20
	WARNING!!  This table must change if enum.h changes.
21
*/
22
static char * tok_tab [] = {
23
	"<NULL>", "<ERROR>",
24
 
25
	"auto", "char", "const", "double", "extern",
26
	"float", "int", "long", "register", "short",
27
	"static", "typedef", "signed", "struct", "union",
28
	"unsigned", "void", "volatile",
29
 
30
	"break", "case",
31
	"continue", "default", "do", "else", "enum", "for",
32
	"goto",	"if", "return", "switch", "while",
33
 
34
	"entry", "sizeof",
35
 
36
	",", "<newline>", ";", "[", "{", "(", "]", "}", ")",
37
 
38
	":", "?",
39
 
40
	"ARRAY", "->", ".", "&&", "||", ",",
41
 
42
	"=",
43
	"&=", "/=", "<<=", "-=", "%=",
44
	"|=", "+=", ">>=", "*=", "^=",
45
 
46
	"&", "|", "+", "*", "^",
47
	"/", "<<", "-", "%", ">>",
48
 
49
	"==", ">=", ">", "<=", "<", "!=",
50
 
51
	"--", "++", "!", "~",
52
 
53
	"(cast)", "post--", "post++", "pre--", "pre++",
54
	"&", "-", "+", "*", "call",
55
 
56
	"character", "EOP",
57
	"identifier", "integer", "float", "long integer",
58
	"string",
59
	"...", "label"
60
};
61
 
62
/*
63
	Return the print string of a bool.
64
*/
65
char *
66
pr_bool(flag)
67
bool flag;
68
{
69
	return flag ? "TRUE" : "FALSE";
70
}
71
 
72
/*
73
	Return the print string of a character.
74
*/
75
static char pdefault[] = "@";
76
 
77
char *
78
pr_ch(c)
79
int c;
80
{
81
	switch (c) {
82
	case ARG_FLAG:		return "ARG:";
83
	case POUND_FLAG:	return "POUND:";
84
	case CONCAT_FLAG:	return "<CONCAT_FLAG>";
85
	case EORT:		return "<EORT>";
86
	case EXPAND_OFF:	return "<EXPAND_OFF>";
87
	case '\0':		return "<\\0>";
88
	case '\t':		return "<TAB>";
89
	case '\n':		return "<NL>";
90
	case '\r':		return "<CR>";
91
	case '\a':		return "<ALERT>";
92
	case ' ':		return "< >";
93
	case END_FILE:		return "<END_FILE>";
94
	default:
95
		pdefault[0] = c;
96
		pdefault[1] = '\0';
97
		return &pdefault[0];
98
	}
99
}
100
 
101
/*
102
	Return the print string of tok.
103
	Do not assume that t_symbol[] refers to tok.
104
*/
105
char *
106
pr_op(tok)
107
en_tokens tok;
108
{
109
	if ((int)tok >= 0 && (int)tok <= LABEL_TOK) {
110
		return tok_tab [(int)tok];
111
	}
112
	else {
113
		return "BAD TOKEN";
114
	}
115
}
116
 
117
/*
118
	Return the print string of a string.
119
*/
120
static char pr_buf [1000];
121
 
122
char *
123
pr_str(s)
124
char *s;
125
{
126
	strcpy(pr_buf, "");
127
	while (*s) {
128
		strcat(pr_buf, pr_ch(*s));
129
		s++;
130
	}
131
	return &pr_buf[0];
132
}
133
 
134
/*
135
	Return the print string of the current token.
136
	Assume the t_symbol refers to the global token.
137
*/
138
static char buffer [200];
139
static char buffer2 [100];
140
 
141
char *
142
pr_tok()
143
{
144
	if (is(ID_TOK)) {
145
		if (t_length >= 200-5) {
146
			printf("pr_tok:  bad id: %s\n", t_symbol);
147
			exit(1);
148
			return "";
149
		}
150
		else {
151
			strcpy(buffer, "id: ");
152
			strcat(buffer, t_symbol);
153
			return buffer;
154
		}
155
	}
156
	else if (is(STRING_TOK)) {
157
		if (t_length >= 200-5) {
158
			printf("pr_tok:  bad string: %s\n", t_symbol);
159
			exit(1);
160
			return "";
161
		}
162
		else {
163
			strcpy(buffer, "string: ");
164
			strcat(buffer, t_symbol);
165
			return buffer;
166
		}
167
	}
168
	else if (is(INT_TOK)) {		
169
			strcpy(buffer, "integer: ");
170
			ltoa(t_value, buffer2, 10);
171
			strcat(buffer, buffer2);
172
			return buffer;
173
	}
174
	else if (token < LABEL_TOK) {
175
		return  tok_tab [(int)token];
176
	}
177
	else {
178
		return "BAD TOKEN";
179
	}
180
}
181
 
182
#endif /* SHERLOCK */