-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherror.c
More file actions
116 lines (96 loc) · 2.23 KB
/
error.c
File metadata and controls
116 lines (96 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdio.h>
#include <string.h>
#include "misc.h"
#include "defs.h"
#include "cvt.h"
#include "struct.h"
#include "tokens.h"
#include "tkn_ext.h"
extern BOOLEAN syntax_error;
extern char *text_ptr;
extern int line_count;
extern char *line_ptr;
extern char current_file_name[];
/*
* parse_mesg() - Print given message, message type, and current
* line number. Skip to error_eol.
*/
void parse_mesg(error_string, error_type, error_eol)
char *error_string, *error_type;
char error_eol;
{
char *err_ptr;
int i, offset;
TOKEN token;
syntax_error = TRUE;
offset = text_ptr - line_ptr - 1;
/* Find end of line */
for (err_ptr = line_ptr; (*err_ptr != '\0') &&
(*err_ptr != LF); err_ptr++) ;
if (*error_string) {
(void) fprintf(stderr, "\n%s - Parse %s: %s.\nOccurred at line %d near:\n",
current_file_name, error_type, error_string, line_count);
/* Print offending line */
(void) fwrite(line_ptr, err_ptr - line_ptr + 1, 1, stderr);
for (i = 0; i < offset; i++)
if (line_ptr[i] < ' ')
(void) fputc(line_ptr[i], stderr);
else
(void) fputc(' ', stderr);
(void) fputc('^', stderr);
if (*err_ptr == '\0')
(void) fputc(LF, stderr);
}
if (*err_ptr != '\0')
err_ptr++;
/* Skip to end-of-line */
if (error_eol == '\0')
return;
else
if (error_eol == LF) {
text_ptr = err_ptr;
line_ptr = err_ptr;
line_count++;
} else {
if (*(text_ptr - 1) != ';') {
do {
i = get_token(&token);
} while ((i != END_OF_FILE) && (i != END_OF_LINE));
}
/* Point at end of line */
text_ptr--;
}
}
/*
* parse_error() - Print given error message and current line number.
* Called when an unrecognised or unprocessable token
* appears.
*/
void parse_error(error_string)
char *error_string;
{
if (syntax_error)
/* Already had an error on this line */
return;
parse_mesg(error_string, "error", END_OF_LINE);
}
/*
* Do a parse_error(), but move to END_OF_LINE, not ';'
*/
void control_error(error_string)
char *error_string;
{
#ifdef IGNORE_CONTROL_ERRORS
parse_mesg("", "", LF);
#else
parse_mesg(error_string, "error", LF);
#endif
}
/*
* parse_warning - Generate a warning message
*/
void parse_warning(warning_string)
char *warning_string;
{
parse_mesg(warning_string, "warning", '\0');
}