ruby_rnv 0.2.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/rnv/extconf.rb +1 -1
- data/ext/rnv/ruby_rnv.c +187 -460
- data/ext/rnv/ruby_rnv.h +62 -0
- data/ext/rnv/ruby_rnv_err.c +545 -0
- data/ext/rnv/src/ary.c +1 -2
- data/ext/rnv/src/drv.c +75 -75
- data/ext/rnv/src/drv.h +12 -3
- data/ext/rnv/src/er.c +1 -1
- data/ext/rnv/src/er.h +1 -1
- data/ext/rnv/src/erbit.h +3 -0
- data/ext/rnv/src/rn.c +24 -26
- data/ext/rnv/src/rn.h +1 -1
- data/ext/rnv/src/rnc.c +28 -16
- data/ext/rnv/src/rnc.h +3 -23
- data/ext/rnv/src/rnd.c +24 -20
- data/ext/rnv/src/rnd.h +3 -2
- data/ext/rnv/src/rnl.c +24 -20
- data/ext/rnv/src/rnl.h +2 -3
- data/ext/rnv/src/rnv.c +20 -18
- data/ext/rnv/src/rnv.h +2 -2
- data/ext/rnv/src/rnx.c +15 -17
- data/ext/rnv/src/rnx.h +2 -3
- data/ext/rnv/src/rx.c +44 -32
- data/ext/rnv/src/rx.h +7 -8
- data/ext/rnv/src/sc.c +5 -0
- data/ext/rnv/src/sc.h +1 -0
- data/ext/rnv/src/type.h +53 -29
- data/ext/rnv/src/xcl.c +24 -27
- data/ext/rnv/src/xsd.c +10 -23
- data/ext/rnv/src/xsd.h +1 -2
- data/lib/rnv.rb +3 -0
- data/lib/rnv/data_type_library.rb +21 -0
- data/lib/rnv/error.rb +39 -0
- data/lib/rnv/pre_processor.rb +25 -0
- data/lib/rnv/validator.rb +18 -11
- metadata +9 -4
data/ext/rnv/src/rn.h
CHANGED
@@ -142,7 +142,7 @@ extern void rn_add_psval(rnv_t *rnv, rn_st_t *rn_st, char *s);
|
|
142
142
|
extern void rn_end_ps(rnv_t *rnv, rn_st_t *rn_st);
|
143
143
|
|
144
144
|
extern void rn_init(rnv_t *rnv, rn_st_t *rn_st);
|
145
|
-
extern void
|
145
|
+
extern void rn_dispose(rn_st_t *rn_st);
|
146
146
|
|
147
147
|
extern void rn_compress(rnv_t *rnv, rn_st_t *rn_st, int *starts,int n);
|
148
148
|
extern int rn_compress_last(rnv_t *rnv, rn_st_t *rn_st, int start);
|
data/ext/rnv/src/rnc.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
#include "type.h"
|
2
|
-
|
3
1
|
/* $Id: rnc.c,v 1.74 2004/08/18 19:10:51 dvd Exp $ */
|
4
|
-
|
5
2
|
#include <fcntl.h> /* open, close */
|
6
3
|
#include <sys/types.h>
|
7
4
|
#include <unistd.h> /* open,read,close */
|
@@ -9,6 +6,8 @@
|
|
9
6
|
#include <errno.h> /*errno*/
|
10
7
|
#include <assert.h> /*assert*/
|
11
8
|
|
9
|
+
#include "type.h"
|
10
|
+
|
12
11
|
#include "u.h"
|
13
12
|
#include "xmlc.h"
|
14
13
|
#include "m.h"
|
@@ -75,9 +74,9 @@ static char *kwdtab[NKWD]={
|
|
75
74
|
#define SYM_DOCUMENTATION 41 /* ## */
|
76
75
|
#define SYM_LITERAL 42
|
77
76
|
|
78
|
-
#define err(msg) (*
|
79
|
-
#define warn(msg) (*
|
80
|
-
void rnc_default_verror_handler(
|
77
|
+
#define err(msg) (*handler)(data,erno|ERBIT_RNC,"%s:%i:%i: error: "msg"\n",ap)
|
78
|
+
#define warn(msg) (*handler)(data,erno|ERBIT_RNC,"%s:%i:%i: warning: "msg"\n",ap)
|
79
|
+
void rnc_default_verror_handler(void *data, int erno, int (*handler)(void *data, int erno,char *format, va_list ap), va_list ap) {
|
81
80
|
switch(erno) {
|
82
81
|
case RNC_ER_IO: err("I/O error: %s\n"); break;
|
83
82
|
case RNC_ER_UTF: err("invalid UTF-8 sequence"); break;
|
@@ -171,6 +170,9 @@ static void rnc_source_init(struct rnc_source *sp,char *fn) {
|
|
171
170
|
sp->cur=0;
|
172
171
|
for(i=0;i!=2;++i) sp->sym[i].s=(char*)m_alloc(
|
173
172
|
sp->sym[i].slen=BUFSIZE,sizeof(char));
|
173
|
+
|
174
|
+
if(!sp->verror_handler)
|
175
|
+
sp->verror_handler= &verror_default_handler;
|
174
176
|
}
|
175
177
|
|
176
178
|
static int rnc_read(struct rnc_source *sp) {
|
@@ -201,20 +203,29 @@ int rnc_errors(struct rnc_source *sp) {
|
|
201
203
|
#define DE_CHOICE 8
|
202
204
|
#define DE_ILEAVE 16
|
203
205
|
|
204
|
-
void rnc_init(
|
205
|
-
|
206
|
-
rnv->rnc_verror_handler=&rnc_default_verror_handler;
|
207
|
-
rn_init(rnv, rn_st);
|
206
|
+
void rnc_init(rnc_st_t *rnc_st) {
|
207
|
+
rnc_st->verror_handler = &verror_default_handler;
|
208
208
|
rnc_st->len_p=LEN_P; rnc_st->path=(char*)m_alloc(rnc_st->len_p,sizeof(char));
|
209
209
|
/* initialize scopes */
|
210
210
|
sc_init(&rnc_st->nss); sc_init(&rnc_st->dts); sc_init(&rnc_st->defs); sc_init(&rnc_st->refs); sc_init(&rnc_st->prefs);
|
211
211
|
}
|
212
212
|
|
213
|
-
void
|
213
|
+
void rnc_dispose(rnc_st_t *rnc_st) {
|
214
|
+
if (rnc_st->path)
|
215
|
+
m_free(rnc_st->path);
|
216
|
+
|
217
|
+
sc_dispose(&rnc_st->nss);
|
218
|
+
sc_dispose(&rnc_st->dts);
|
219
|
+
sc_dispose(&rnc_st->defs);
|
220
|
+
sc_dispose(&rnc_st->refs);
|
221
|
+
sc_dispose(&rnc_st->prefs);
|
222
|
+
|
223
|
+
m_free(rnc_st);
|
224
|
+
}
|
214
225
|
|
215
226
|
static void error(int force,struct rnc_source *sp,int erno,...) {
|
216
227
|
if(force || sp->line != sp->prevline) {
|
217
|
-
va_list ap; va_start(ap,erno);
|
228
|
+
va_list ap; va_start(ap,erno); rnc_default_verror_handler(sp->user_data, erno, sp->verror_handler, ap); va_end(ap);
|
218
229
|
sp->prevline=sp->line;
|
219
230
|
}
|
220
231
|
sp->flags|=SRC_ERRORS;
|
@@ -222,7 +233,7 @@ static void error(int force,struct rnc_source *sp,int erno,...) {
|
|
222
233
|
|
223
234
|
static void warning(int force,struct rnc_source *sp,int erno,...) {
|
224
235
|
if(force || sp->line != sp->prevline) {
|
225
|
-
va_list ap; va_start(ap,erno);
|
236
|
+
va_list ap; va_start(ap,erno); rnc_default_verror_handler(sp->user_data, erno,sp->verror_handler, ap); va_end(ap);
|
226
237
|
}
|
227
238
|
}
|
228
239
|
|
@@ -902,7 +913,8 @@ static void add_well_known_nss(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, int
|
|
902
913
|
static int file(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, struct rnc_source *sp,int nsuri) {
|
903
914
|
int ret=0;
|
904
915
|
struct rnc_source src;
|
905
|
-
src.
|
916
|
+
src.verror_handler = rnv->verror_handler;
|
917
|
+
src.user_data = rnv->user_data;
|
906
918
|
add_well_known_nss(rnv, rnc_st, rn_st, nsuri);
|
907
919
|
if(rnc_open(&src,rnc_st->path)!=-1) {
|
908
920
|
ret=topLevel(rnv, rnc_st, rn_st, &src);
|
@@ -1107,6 +1119,7 @@ static void include(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, struct rnc_sou
|
|
1107
1119
|
nsuri=inherit(rnv, rnc_st, rn_st, sp);
|
1108
1120
|
sc_open(&rnc_st->nss); open_scope(rnc_st, sp);
|
1109
1121
|
if(file(rnv, rnc_st, rn_st, sp,nsuri)!=-1) error(1,sp,RNC_ER_NOTGR,sp->fn,CUR(sp).line,CUR(sp).col);
|
1122
|
+
sc_close(&rnc_st->nss);
|
1110
1123
|
sc_lock(&rnc_st->defs);
|
1111
1124
|
if(CUR(sp).sym==SYM_LCUR) {
|
1112
1125
|
getsym(sp);
|
@@ -1114,7 +1127,6 @@ static void include(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, struct rnc_sou
|
|
1114
1127
|
chk_skip_get(sp,SYM_RCUR);
|
1115
1128
|
}
|
1116
1129
|
fold_scope(rnv, rnc_st, rn_st, sp);
|
1117
|
-
sc_close(&rnc_st->nss);
|
1118
1130
|
}
|
1119
1131
|
}
|
1120
1132
|
|
@@ -1154,7 +1166,7 @@ static int topLevel(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, struct rnc_sou
|
|
1154
1166
|
getsym(sp); getsym(sp);
|
1155
1167
|
while(decl(rnv, rn_st, rnc_st, sp));
|
1156
1168
|
if((is_grammar=(CUR(sp).sym==SYM_GRAMMAR))) {
|
1157
|
-
chk_get(sp,SYM_LCUR);
|
1169
|
+
getsym(sp);chk_get(sp,SYM_LCUR);
|
1158
1170
|
}
|
1159
1171
|
if(grammarContent(rnv, rn_st, rnc_st, sp)) {
|
1160
1172
|
while(grammarContent(rnv, rn_st, rnc_st, sp));
|
data/ext/rnv/src/rnc.h
CHANGED
@@ -31,30 +31,10 @@
|
|
31
31
|
#define RNC_ER_NOSTART 70
|
32
32
|
#define RNC_ER_UNDEF 71
|
33
33
|
|
34
|
-
|
35
|
-
char *s; int slen;
|
36
|
-
int line,col;
|
37
|
-
int sym;
|
38
|
-
};
|
34
|
+
extern void rnc_default_verror_handler(void *data, int erno, int (*handler)(void *data, int erno,char *format, va_list ap), va_list ap);
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
char *fn; int fd;
|
43
|
-
char *buf; int i,n;
|
44
|
-
int complete;
|
45
|
-
int line,col,prevline/*when error reported*/;
|
46
|
-
int u,v,w; int nx;
|
47
|
-
int cur;
|
48
|
-
struct rnc_cym sym[2];
|
49
|
-
|
50
|
-
// FIXME: for error handlers
|
51
|
-
rnv_t *rnv;
|
52
|
-
};
|
53
|
-
|
54
|
-
extern void rnc_default_verror_handler(rnv_t *rnv, int erno,va_list ap);
|
55
|
-
|
56
|
-
extern void rnc_init(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st);
|
57
|
-
extern void rnc_clear(void);
|
36
|
+
extern void rnc_init(rnc_st_t *rnc_st);
|
37
|
+
extern void rnc_dispose(rnc_st_t *rnc_st);
|
58
38
|
|
59
39
|
extern int rnc_open(struct rnc_source *sp,char *fn);
|
60
40
|
extern int rnc_stropen(struct rnc_source *sp,char *fn,char *s,int len);
|
data/ext/rnv/src/rnd.c
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
#include "type.h"
|
2
|
-
|
3
1
|
/* $Id: rnd.c,v 1.33 2004/02/25 00:00:32 dvd Exp $ */
|
4
|
-
|
5
2
|
#include <stdlib.h>
|
6
3
|
#include <assert.h>
|
7
4
|
#include <string.h>
|
5
|
+
|
6
|
+
#include "type.h"
|
7
|
+
|
8
8
|
#include "m.h"
|
9
9
|
#include "rn.h"
|
10
10
|
#include "rnx.h"
|
@@ -15,8 +15,8 @@
|
|
15
15
|
|
16
16
|
#define LEN_F RND_LEN_F
|
17
17
|
|
18
|
-
#define err(msg) (*
|
19
|
-
void rnd_default_verror_handler(
|
18
|
+
#define err(msg) (*handler)(data,erno|ERBIT_RND,"error: "msg"\n",ap)
|
19
|
+
void rnd_default_verror_handler(void *data, int erno, int (*handler)(void *data, int erno,char *format, va_list ap), va_list ap) {
|
20
20
|
switch(erno) {
|
21
21
|
case RND_ER_LOOPST: err("loop in start pattern"); break;
|
22
22
|
case RND_ER_LOOPEL: err("loop in pattern for element '%s'"); break;
|
@@ -30,17 +30,21 @@ void rnd_default_verror_handler(rnv_t *rnv, int erno,va_list ap) {
|
|
30
30
|
}
|
31
31
|
}
|
32
32
|
|
33
|
-
void rnd_init(
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
void rnd_init(rnd_st_t *rnd_st) {
|
34
|
+
rnd_st->verror_handler = &verror_default_handler;
|
35
|
+
}
|
36
|
+
|
37
|
+
void rnd_dispose(rnd_st_t *rnd_st) {
|
38
|
+
if (rnd_st->flat)
|
39
|
+
m_free(rnd_st->flat);
|
40
|
+
m_free(rnd_st);
|
37
41
|
}
|
38
42
|
|
39
43
|
void rnd_clear(void) {}
|
40
44
|
|
41
|
-
static void error_handler(
|
42
|
-
va_list ap; va_start(ap,
|
43
|
-
|
45
|
+
static void error_handler(rnd_st_t *rnd_st, int erno,...) {
|
46
|
+
va_list ap; va_start(ap,erno);
|
47
|
+
rnd_default_verror_handler(rnd_st->user_data, erno, rnd_st->verror_handler, ap);
|
44
48
|
va_end(ap);
|
45
49
|
++rnd_st->errors;
|
46
50
|
}
|
@@ -141,9 +145,9 @@ static void loops(rnv_t *rnv, rnd_st_t *rnd_st) {
|
|
141
145
|
int i=0,p=rnd_st->flat[i],nc=-1,p1;
|
142
146
|
for(;;) {
|
143
147
|
if(loop(rnv, p)) {
|
144
|
-
if(i==0) error_handler(
|
148
|
+
if(i==0) error_handler(rnd_st, RND_ER_LOOPST); else {
|
145
149
|
char *s=rnx_nc2str(rnv, nc);
|
146
|
-
error_handler(
|
150
|
+
error_handler(rnd_st,RND_ER_LOOPEL, s);
|
147
151
|
m_free(s);
|
148
152
|
}
|
149
153
|
}
|
@@ -195,7 +199,7 @@ static void ctypes(rnv_t *rnv, rnd_st_t *rnd_st) {
|
|
195
199
|
ctype(rnv, p1);
|
196
200
|
if(!rn_contentType(rnv, p1)) {
|
197
201
|
char *s=rnx_nc2str(rnv, nc);
|
198
|
-
error_handler(
|
202
|
+
error_handler(rnd_st,RND_ER_CTYPE, s);
|
199
203
|
m_free(s);
|
200
204
|
}
|
201
205
|
}
|
@@ -328,18 +332,18 @@ static void path(rnv_t *rnv, rnd_st_t *rnd_st, int p,int nc) {
|
|
328
332
|
case RN_P_INTERLEAVE: rn_Interleave(p,p1,p2); goto BINARY;
|
329
333
|
case RN_P_GROUP: rn_Group(p,p1,p2); goto BINARY;
|
330
334
|
case RN_P_DATA_EXCEPT: rn_DataExcept(p,p1,p2);
|
331
|
-
if(bad_data_except(rnv, p2)) {char *s=rnx_nc2str(rnv, nc); error_handler(
|
335
|
+
if(bad_data_except(rnv, p2)) {char *s=rnx_nc2str(rnv, nc); error_handler(rnd_st,RND_ER_BADEXPT, s); m_free(s);}
|
332
336
|
goto BINARY;
|
333
337
|
BINARY: path(rnv, rnd_st, p1,nc); path(rnv, rnd_st, p2,nc); break;
|
334
338
|
|
335
339
|
case RN_P_ONE_OR_MORE: rn_OneOrMore(p,p1);
|
336
|
-
if(bad_one_or_more(rnv, p1,0)) {char *s=rnx_nc2str(rnv, nc); error_handler(
|
340
|
+
if(bad_one_or_more(rnv, p1,0)) {char *s=rnx_nc2str(rnv, nc); error_handler(rnd_st,RND_ER_BADMORE, s); m_free(s);}
|
337
341
|
goto UNARY;
|
338
342
|
case RN_P_LIST: rn_List(p,p1);
|
339
|
-
if(bad_list(rnv, p1)) {char *s=rnx_nc2str(rnv, nc); error_handler(
|
343
|
+
if(bad_list(rnv, p1)) {char *s=rnx_nc2str(rnv, nc); error_handler(rnd_st,RND_ER_BADLIST, s); m_free(s);}
|
340
344
|
goto UNARY;
|
341
345
|
case RN_P_ATTRIBUTE: rn_Attribute(p,nc1,p1);
|
342
|
-
if(bad_attribute(rnv, p1)) {char *s=rnx_nc2str(rnv, nc),*s1=rnx_nc2str(rnv, nc1); error_handler(
|
346
|
+
if(bad_attribute(rnv, p1)) {char *s=rnx_nc2str(rnv, nc),*s1=rnx_nc2str(rnv, nc1); error_handler(rnd_st,RND_ER_BADATTR, s1,s); m_free(s1); m_free(s);}
|
343
347
|
goto UNARY;
|
344
348
|
UNARY: path(rnv, rnd_st, p1,nc); break;
|
345
349
|
|
@@ -349,7 +353,7 @@ static void path(rnv_t *rnv, rnd_st_t *rnd_st, int p,int nc) {
|
|
349
353
|
|
350
354
|
static void paths(rnv_t *rnv, rnd_st_t *rnd_st) {
|
351
355
|
int i,p,p1,nc;
|
352
|
-
if(bad_start(rnv, rnd_st->flat[0])) error_handler(
|
356
|
+
if(bad_start(rnv, rnd_st->flat[0])) error_handler(rnd_st, RND_ER_BADSTART);
|
353
357
|
for(i=0;i!=rnd_st->n_f;++i) {
|
354
358
|
p=rnd_st->flat[i];
|
355
359
|
if(RN_P_IS(p,RN_P_ELEMENT)) {
|
data/ext/rnv/src/rnd.h
CHANGED
@@ -15,10 +15,11 @@
|
|
15
15
|
#define RND_ER_BADLIST 6
|
16
16
|
#define RND_ER_BADATTR 7
|
17
17
|
|
18
|
-
extern void rnd_default_verror_handler(
|
18
|
+
extern void rnd_default_verror_handler(void *data, int erno, int (*handler)(void *data, int erno,char *format, va_list ap), va_list ap);
|
19
19
|
|
20
|
-
extern void rnd_init(
|
20
|
+
extern void rnd_init(rnd_st_t *rnd_st);
|
21
21
|
extern void rnd_clear(void);
|
22
|
+
extern void rnd_dispose(rnd_st_t *rnd_st);
|
22
23
|
|
23
24
|
extern int rnd_fixup(rnv_t *rnv, rnd_st_t *rnd_st, rn_st_t *rn_st, int start);
|
24
25
|
|
data/ext/rnv/src/rnl.c
CHANGED
@@ -1,35 +1,36 @@
|
|
1
|
-
#include "type.h"
|
2
|
-
|
3
1
|
/* $Id: rnl.c,v 1.2 2004/01/15 23:47:45 dvd Exp $ */
|
4
|
-
|
5
2
|
#include <stdarg.h>
|
3
|
+
|
4
|
+
#include "type.h"
|
5
|
+
|
6
6
|
#include "erbit.h"
|
7
7
|
#include "rn.h"
|
8
8
|
#include "rnc.h"
|
9
9
|
#include "rnd.h"
|
10
10
|
#include "rnl.h"
|
11
11
|
|
12
|
-
void rnl_default_verror_handler(
|
12
|
+
void rnl_default_verror_handler(void *data, int erno, int (*handler)(void *data, int erno,char *format, va_list ap), va_list ap) {
|
13
13
|
if(erno&ERBIT_RNC) {
|
14
|
-
rnc_default_verror_handler(
|
14
|
+
rnc_default_verror_handler(data, erno&~ERBIT_RNC,handler, ap);
|
15
15
|
} else if(erno&ERBIT_RND) {
|
16
|
-
rnd_default_verror_handler(
|
16
|
+
rnd_default_verror_handler(data, erno&~ERBIT_RND,handler, ap);
|
17
17
|
}
|
18
18
|
}
|
19
19
|
|
20
|
-
|
21
|
-
static void verror_handler_rnd(rnv_t *rnv, int erno,va_list ap) {rnl_default_verror_handler(rnv, erno|ERBIT_RND,ap);}
|
22
|
-
|
23
|
-
void rnl_init(rnv_t *rnv, rn_st_t *rn_st, rnc_st_t *rnc_st, rnd_st_t *rnd_st) {
|
24
|
-
rnv->rnl_verror_handler=&rnl_default_verror_handler;
|
20
|
+
void rnl_init(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, rnd_st_t *rnd_st) {
|
25
21
|
rn_init(rnv, rn_st);
|
26
|
-
rnc_init(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
rnc_init(rnc_st);
|
23
|
+
|
24
|
+
if(rnv->verror_handler)
|
25
|
+
rnc_st->verror_handler = rnv->verror_handler;
|
26
|
+
rnc_st->user_data = rnv->user_data;
|
31
27
|
|
32
|
-
|
28
|
+
rnd_init(rnd_st);
|
29
|
+
|
30
|
+
if(rnv->verror_handler)
|
31
|
+
rnd_st->verror_handler = rnv->verror_handler;
|
32
|
+
rnd_st->user_data = rnv->user_data;
|
33
|
+
}
|
33
34
|
|
34
35
|
static int load(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, rnd_st_t *rnd_st, struct rnc_source *sp) {
|
35
36
|
int start=-1;
|
@@ -42,21 +43,24 @@ static int load(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, rnd_st_t *rnd_st,
|
|
42
43
|
|
43
44
|
int rnl_fn(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, rnd_st_t *rnd_st, char *fn) {
|
44
45
|
struct rnc_source src;
|
45
|
-
src.
|
46
|
+
src.verror_handler = rnv->verror_handler;
|
47
|
+
src.user_data = rnv->user_data;
|
46
48
|
rnc_open(&src,fn);
|
47
49
|
return load(rnv, rnc_st, rn_st, rnd_st, &src);
|
48
50
|
}
|
49
51
|
|
50
52
|
int rnl_fd(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, rnd_st_t *rnd_st, char *fn,int fd) {
|
51
53
|
struct rnc_source src;
|
52
|
-
src.
|
54
|
+
src.verror_handler = rnv->verror_handler;
|
55
|
+
src.user_data = rnv->user_data;
|
53
56
|
rnc_bind(&src,fn,fd);
|
54
57
|
return load(rnv, rnc_st, rn_st, rnd_st, &src);
|
55
58
|
}
|
56
59
|
|
57
60
|
int rnl_s(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, rnd_st_t *rnd_st, char *fn,char *s,int len) {
|
58
61
|
struct rnc_source src;
|
59
|
-
src.
|
62
|
+
src.verror_handler = rnv->verror_handler;
|
63
|
+
src.user_data = rnv->user_data;
|
60
64
|
rnc_stropen(&src,fn,s,len);
|
61
65
|
return load(rnv, rnc_st, rn_st, rnd_st, &src);
|
62
66
|
}
|
data/ext/rnv/src/rnl.h
CHANGED
@@ -6,10 +6,9 @@
|
|
6
6
|
#include <stdarg.h>
|
7
7
|
#include "type.h"
|
8
8
|
|
9
|
-
extern void rnl_default_verror_handler(
|
9
|
+
extern void rnl_default_verror_handler(void *data, int erno, int (*handler)(void *data, int erno,char *format, va_list ap), va_list ap);
|
10
10
|
|
11
|
-
extern void rnl_init(rnv_t *rnv,
|
12
|
-
extern void rnl_clear(void);
|
11
|
+
extern void rnl_init(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, rnd_st_t *rnd_st);
|
13
12
|
|
14
13
|
extern int rnl_fn(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, rnd_st_t *rnd_st, char *fn);
|
15
14
|
extern int rnl_fd(rnv_t *rnv, rnc_st_t *rnc_st, rn_st_t *rn_st, rnd_st_t *rnd_st, char *fn,int fd);
|
data/ext/rnv/src/rnv.c
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
#include "type.h"
|
2
|
-
|
3
1
|
/* $Id: rnv.c,v 1.69 2004/01/28 23:21:24 dvd Exp $ */
|
4
|
-
|
5
2
|
#include <string.h> /*strncpy,strrchr*/
|
6
3
|
#include <assert.h>
|
4
|
+
|
5
|
+
#include "type.h"
|
6
|
+
|
7
7
|
#include "m.h"
|
8
8
|
#include "xmlc.h" /*xmlc_white_space*/
|
9
9
|
#include "erbit.h"
|
@@ -11,10 +11,10 @@
|
|
11
11
|
#include "er.h"
|
12
12
|
#include "rnv.h"
|
13
13
|
|
14
|
-
#define err(msg) (*
|
15
|
-
void rnv_default_verror_handler(
|
14
|
+
#define err(msg) (*handler)(data,erno|ERBIT_RNV,msg"\n",ap);
|
15
|
+
void rnv_default_verror_handler(void *data, int erno, int (*handler)(void *data, int erno,char *format, va_list ap), va_list ap) {
|
16
16
|
if(erno&ERBIT_DRV) {
|
17
|
-
drv_default_verror_handler(
|
17
|
+
drv_default_verror_handler(data, erno&~ERBIT_DRV, handler, ap);
|
18
18
|
} else {
|
19
19
|
switch(erno) {
|
20
20
|
case RNV_ER_ELEM: err("element %s^%s not allowed"); break;
|
@@ -31,24 +31,26 @@ void rnv_default_verror_handler(rnv_t *rnv, int erno,va_list ap) {
|
|
31
31
|
}
|
32
32
|
|
33
33
|
static void error_handler(rnv_t *rnv, int erno,...) {
|
34
|
-
va_list ap; va_start(ap,erno); (
|
34
|
+
va_list ap; va_start(ap,erno); rnv_default_verror_handler(rnv->user_data,erno,rnv->verror_handler,ap); va_end(ap);
|
35
35
|
}
|
36
36
|
|
37
|
-
static void verror_handler_drv(rnv_t *rnv, int erno,va_list ap) {rnv_default_verror_handler(rnv,erno|ERBIT_DRV,ap);}
|
38
|
-
|
39
|
-
static void windup(void);
|
40
37
|
void rnv_init(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, rx_st_t *rx_st) {
|
41
|
-
rnv->
|
38
|
+
if(!rnv->verror_handler)
|
39
|
+
rnv->verror_handler = &verror_default_handler;
|
42
40
|
drv_init(rnv, drv_st, rn_st, rx_st);
|
43
|
-
rnv->drv_verror_handler=&verror_handler_drv;
|
44
|
-
windup();
|
45
|
-
}
|
46
|
-
|
47
|
-
void rnv_clear(void) {
|
48
|
-
windup();
|
49
41
|
}
|
50
42
|
|
51
|
-
|
43
|
+
void rnv_dispose(rnv_t *rnv) {
|
44
|
+
if (rnv->rn_pattern)
|
45
|
+
m_free(rnv->rn_pattern);
|
46
|
+
if (rnv->rn_nameclass)
|
47
|
+
m_free(rnv->rn_nameclass);
|
48
|
+
if (rnv->rn_string)
|
49
|
+
m_free(rnv->rn_string);
|
50
|
+
if (rnv->rnx_exp)
|
51
|
+
m_free(rnv->rnx_exp);
|
52
|
+
|
53
|
+
m_free(rnv);
|
52
54
|
}
|
53
55
|
|
54
56
|
static char *qname_open(char **surip,char **snamep,char *name) {
|
data/ext/rnv/src/rnv.h
CHANGED
@@ -15,10 +15,10 @@
|
|
15
15
|
#define RNV_ER_TEXT 6
|
16
16
|
#define RNV_ER_NOTX 7
|
17
17
|
|
18
|
-
extern void rnv_default_verror_handler(
|
18
|
+
extern void rnv_default_verror_handler(void *data, int erno, int (*handler)(void *data, int erno,char *format, va_list ap), va_list ap);
|
19
19
|
|
20
20
|
extern void rnv_init(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, rx_st_t *rx_st);
|
21
|
-
extern void
|
21
|
+
extern void rnv_dispose(rnv_t *rnv);
|
22
22
|
|
23
23
|
extern int rnv_text(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, rx_st_t *rx_st, int *curp,int *prevp,char *text,int n_t,int mixed);
|
24
24
|
extern int rnv_start_tag(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, rx_st_t *rx_st, int *curp,int *prevp,char *name,char **attrs);
|