-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrb_comp.error.c
More file actions
190 lines (154 loc) · 4 KB
/
rb_comp.error.c
File metadata and controls
190 lines (154 loc) · 4 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* -MODULE----------------------------------------------------------------------
RapidBATCH
Copyright (C) 2008, 2009 by Phorward Software Technologies, Jan Max Meyer
http://www.phorward-software.com ++ mail@phorward-software.com
File: rb_comp.error.c
Author: Jan Max Meyer
Usage: Compiler error reporting
----------------------------------------------------------------------------- */
/*
* Includes
*/
#include "rb_global.h"
/*
* Global variables
*/
static XML_T errors;
/*
* Functions
*/
/* -FUNCTION--------------------------------------------------------------------
Function: rb_comp_error()
Author: Jan Max Meyer
Usage: Compile-time error reporting function.
Parameters: char* file Filename
int line Line number in filename
char* id Error message catalog
identifier
... Parameter pairs of char*:
- Wildcard-Identifier
- Value
Last parameter must be
(char*)NULL;
Returns: void
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
void rb_comp_error( srcpos* pos, char* id, ... )
{
struct
{
char wildcard[ 80 + 1 ];
char* value;
char* _match;
} values[64];
XML_T ident;
va_list args;
int i;
int vcount;
int match;
char* tpl_ptr;
char* result = (char*)NULL;
long copy_size;
long prev_size;
long size = 0L;
PROC( "rb_error" );
PARMS( "pos", "%p", pos );
PARMS( "id", "%s", id );
va_start( args, id );
for( vcount = 0; vcount < 64; vcount++ )
{
if( !( values[vcount].value = va_arg( args, char* ) ) )
break;
sprintf( values[vcount].wildcard, "##%.78s", values[vcount].value );
values[vcount].value = va_arg( args, char* );
if( !values[vcount].value )
values[vcount].value = pstrdup( "" );
}
/* Do I already have a language catalogue? */
if( !errors )
{
if( !( errors = xml_parse_file( "errors.xml" ) ) )
{
MSG( "Can't read error message catalogue" );
VOIDRET;
}
}
/* Find error message */
for( ident = xml_child( errors, "msg" ); ident; ident = xml_next( ident ) )
{
if( !strcmp( (char*)xml_attr( ident, "id" ), id ) )
{
tpl_ptr = xml_txt( ident );
do
{
for( i = 0; i < vcount; i++ )
values[i]._match = strstr( tpl_ptr, values[i].wildcard );
match = vcount;
for( i = 0; i < vcount; i++ )
{
if( values[i]._match != (char*)NULL )
{
if( match == vcount ||
values[match]._match > values[i]._match )
match = i;
}
}
prev_size = size;
if( match < vcount )
{
copy_size = (long)( values[match]._match - tpl_ptr );
size += (long)strlen( values[match].value );
}
else
copy_size = (long)strlen( tpl_ptr );
size += copy_size;
if( result )
result = (char*)prealloc( (char*)result,
( size + 1 ) * sizeof( char ) );
else
result = (char*)pmalloc( ( size + 1 ) * sizeof( char ) );
memcpy( result + prev_size, tpl_ptr,
copy_size * sizeof( char ) );
if( match < vcount )
memcpy( result + prev_size + copy_size,
values[match].value, strlen( values[match].value )
* sizeof( char ) );
result[size] = '\0';
if( match < vcount )
tpl_ptr += copy_size + strlen( values[match].wildcard );
}
while( match < vcount );
va_end( args );
/* Print error message */
if( pos )
{
if( pos->filename )
{
fprintf( stderr, "%s, line %ld, error: %s\n",
pos->filename, pos->line, result );
}
else
fprintf( stderr, "line %ld, error: %s\n",
pos->line, result );
}
else
{
fprintf( stderr, "error: %s\n", result );
}
fflush( stderr );
pfree( result );
break;
}
}
if( !ident )
{
fprintf( stderr, "undefined error message: %s\n", id );
for( i = 0; i < vcount; i++ )
{
fprintf( stderr, " >%s< = >%s<\n",
values[i].wildcard, values[i].value );
}
}
VOIDRET;
}