Update the changelog
[opencv] / apps / Hawk / CVEiCL / EiC / src / error.c
1 /* error.c
2  *
3  *      (C) Copyright Apr 15 1995, Edmond J. Breen.
4  *                 ALL RIGHTS RESERVED.
5  * This code may be copied for personal, non-profit use only.
6  *
7  */
8
9
10
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 #include "global.h"
15 #include "lexer.h"
16 #include "xalloc.h"
17 #include "preproc.h"
18 #include "error.h"
19
20 #include <stdarg.h>
21
22 int EiC_ParseError, EiC_ErrorRecover;
23 int EiC_errs = 0;
24
25
26 static void messageDisplay(char *msg);
27
28 void (*EiC_messageDisplay)(char *) = messageDisplay;
29
30
31
32 void EiC_setMessageDisplay(void (*t)(char *msg))
33 {
34     EiC_messageDisplay = t;
35 }
36
37
38                /*CUT match.cut*/
39 int EiC_match(int t, char *m)
40 {
41     extern token_t *token;
42     int lookahead;
43     char message[80];
44
45     lookahead = EiC_lexan();
46     if (EiC_ErrorRecover) {             /* error recovery method */
47         while ((lookahead != t && lookahead != ';') && lookahead != DONE) {
48             if(lookahead == STR) 
49                 xfree(token->Val.p.p);
50             lookahead = EiC_lexan();
51         }
52         if (lookahead == t || lookahead == ';') {
53             EiC_ErrorRecover = 0;
54             if (lookahead != t)
55                 retractlexan();
56             return 1;
57         } else
58             return 0;
59     }
60     if (lookahead != t) {
61
62         sprintf(message, "Expected %s", m);
63         EiC_error(message);
64         return 0;
65     }
66     return 1;
67 }
68               /*END CUT*/
69
70
71 void EiC_clear_err_msgs(void)
72 {
73     EiC_errs = 0;
74 }
75
76 static void messageDisplay(char *msg)
77 {
78     fprintf(stderr,msg);
79 }
80
81 void EiC_formatMessage(char *msg, ...)
82 {
83     va_list args;
84     char buff2[1024];
85     va_start(args,msg);
86
87
88     vsprintf(buff2,msg,args);
89     EiC_messageDisplay(buff2);
90
91     va_end(args);
92 }
93
94 void EiC_error(char *msg, ...)
95 {
96     char *buff1, *buff2;
97     va_list args;
98     int ln;
99     
100     va_start(args,msg);
101
102     ln = strlen(msg);
103     buff1 = malloc(ln + 256);
104     buff2 = malloc(ln + 512);
105     
106     if (!EiC_ErrorRecover) {
107         EiC_errs++;
108         EiC_ErrorRecover = EiC_ParseError = 1;
109         sprintf(buff1,"Error in %s near line %d: %s\n",
110                 CurrentFileName(),
111                 CurrentLineNo(),
112                 msg);
113         vsprintf(buff2,buff1,args);
114         EiC_messageDisplay(buff2);
115     }
116     free(buff1);
117     free(buff2);
118     va_end(args);
119 }
120
121 void EiC_warningerror(char *msg, ...)
122 {
123     va_list args;
124     char *buff1, *buff2;
125     int ln;
126
127
128     va_start(args,msg);
129
130     ln = strlen(msg);
131     buff1 = malloc(ln + 256);
132     buff2 = malloc(ln + 512);
133
134     EiC_errs++;
135     sprintf(buff1,"Warning: in %s near line %d: %s\n",
136             CurrentFileName(),
137             CurrentLineNo(),
138             msg);
139     vsprintf(buff2,buff1,args);
140     EiC_messageDisplay(buff2);
141
142     free(buff1);
143     free(buff2);
144     va_end(args);
145 }
146
147
148
149
150
151