ruby_rnv 0.3.0 → 0.5.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 +88 -381
- data/ext/rnv/ruby_rnv.h +62 -0
- data/ext/rnv/ruby_rnv_err.c +548 -0
- data/ext/rnv/src/ary.c +1 -2
- data/ext/rnv/src/drv.c +78 -62
- data/ext/rnv/src/drv.h +3 -2
- 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 +61 -28
- 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/data_type_library.rb +5 -7
- data/lib/rnv/error.rb +103 -3
- data/lib/rnv/validator.rb +75 -7
- metadata +4 -2
data/ext/rnv/src/ary.c
CHANGED
data/ext/rnv/src/drv.c
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
#include "type.h"
|
2
|
-
|
3
1
|
/* $Id: drv.c,v 1.41 2004/03/13 13:28:02 dvd Exp $ */
|
2
|
+
#include "type.h"
|
4
3
|
|
5
4
|
#include "xmlc.h" /*xmlc_white_space*/
|
6
5
|
#include "m.h"
|
@@ -28,10 +27,10 @@
|
|
28
27
|
#define M_SET(p) drv_st->memo[drv_st->i_m][M_SIZE-1]=p
|
29
28
|
#define M_RET(m) drv_st->memo[m][M_SIZE-1]
|
30
29
|
|
31
|
-
#define err(msg) (*
|
32
|
-
void drv_default_verror_handler(
|
30
|
+
#define err(msg) (*handler)(data,erno|ERBIT_DRV,msg"\n",ap);
|
31
|
+
void drv_default_verror_handler(void *data, int erno, int (*handler)(void *data, int erno,char *format, va_list ap), va_list ap) {
|
33
32
|
if(erno&ERBIT_XSD) {
|
34
|
-
xsd_default_verror_handler(
|
33
|
+
xsd_default_verror_handler(data, erno&~ERBIT_XSD,handler, ap);
|
35
34
|
} else {
|
36
35
|
switch(erno) {
|
37
36
|
case DRV_ER_NODTL: err("no datatype library for URI '%s'"); break;
|
@@ -40,14 +39,12 @@ void drv_default_verror_handler(rnv_t *rnv, int erno,va_list ap) {
|
|
40
39
|
}
|
41
40
|
}
|
42
41
|
|
43
|
-
static void error_handler(
|
44
|
-
va_list ap; va_start(ap,erno); (
|
42
|
+
static void error_handler(drv_st_t *drv_st,int erno,...) {
|
43
|
+
va_list ap; va_start(ap,erno); drv_default_verror_handler(drv_st->user_data, erno, drv_st->verror_handler, ap); va_end(ap);
|
45
44
|
}
|
46
45
|
|
47
|
-
static void
|
48
|
-
|
49
|
-
static void new_memo(rnv_t *rnv, drv_st_t *drv_st, int typ) {
|
50
|
-
if(rnv->drv_compact) ht_deli(&drv_st->ht_m,drv_st->i_m);
|
46
|
+
static void new_memo(drv_st_t *drv_st, int typ) {
|
47
|
+
if(drv_st->drv_compact) ht_deli(&drv_st->ht_m,drv_st->i_m);
|
51
48
|
drv_st->memo[drv_st->i_m][0]=typ;
|
52
49
|
}
|
53
50
|
|
@@ -62,47 +59,47 @@ static int hash_m(void *user, int m) {
|
|
62
59
|
return ((me[0]&0x7)|((me[1]^me[2]^me[3])<<3))*PRIME_M;
|
63
60
|
}
|
64
61
|
|
65
|
-
static int newStartTagOpen(
|
62
|
+
static int newStartTagOpen(drv_st_t *drv_st, int p,int uri,int name) {
|
66
63
|
int *me=drv_st->memo[drv_st->i_m];
|
67
|
-
new_memo(
|
64
|
+
new_memo(drv_st, M_STO);
|
68
65
|
me[1]=p; me[2]=uri; me[3]=name;
|
69
66
|
return ht_get(&drv_st->ht_m,drv_st->i_m);
|
70
67
|
}
|
71
68
|
|
72
|
-
static int newAttributeOpen(
|
69
|
+
static int newAttributeOpen(drv_st_t *drv_st, int p,int uri,int name) {
|
73
70
|
int *me=drv_st->memo[drv_st->i_m];
|
74
|
-
new_memo(
|
71
|
+
new_memo(drv_st, M_ATT);
|
75
72
|
me[1]=p; me[2]=uri; me[3]=name;
|
76
73
|
return ht_get(&drv_st->ht_m,drv_st->i_m);
|
77
74
|
}
|
78
75
|
|
79
|
-
static int newStartTagClose(
|
76
|
+
static int newStartTagClose(drv_st_t *drv_st, int p) {
|
80
77
|
int *me=drv_st->memo[drv_st->i_m];
|
81
|
-
new_memo(
|
78
|
+
new_memo(drv_st, M_STC);
|
82
79
|
me[1]=p; me[2]=me[3]=0;
|
83
80
|
return ht_get(&drv_st->ht_m,drv_st->i_m);
|
84
81
|
}
|
85
82
|
|
86
|
-
static int newMixedText(
|
83
|
+
static int newMixedText(drv_st_t *drv_st, int p) {
|
87
84
|
int *me=drv_st->memo[drv_st->i_m];
|
88
|
-
new_memo(
|
85
|
+
new_memo(drv_st, M_TXT);
|
89
86
|
me[1]=p; me[2]=me[3]=0;
|
90
87
|
return ht_get(&drv_st->ht_m,drv_st->i_m);
|
91
88
|
}
|
92
89
|
|
93
|
-
static int newEndTag(
|
90
|
+
static int newEndTag(drv_st_t *drv_st, int p) {
|
94
91
|
int *me=drv_st->memo[drv_st->i_m];
|
95
|
-
new_memo(
|
92
|
+
new_memo(drv_st, M_END);
|
96
93
|
me[1]=p; me[2]=me[3]=0;
|
97
94
|
return ht_get(&drv_st->ht_m,drv_st->i_m);
|
98
95
|
}
|
99
96
|
|
100
|
-
static void accept_m(
|
97
|
+
static void accept_m(drv_st_t *drv_st) {
|
101
98
|
if(ht_get(&drv_st->ht_m,drv_st->i_m)!=-1) {
|
102
|
-
if(
|
99
|
+
if(drv_st->drv_compact) ht_del(&drv_st->ht_m,drv_st->i_m); else return;
|
103
100
|
}
|
104
101
|
ht_put(&drv_st->ht_m,drv_st->i_m++);
|
105
|
-
if(
|
102
|
+
if(drv_st->drv_compact&&drv_st->i_m==LIM_M) drv_st->i_m=0;
|
106
103
|
if(drv_st->i_m==drv_st->len_m) drv_st->memo=(int(*)[M_SIZE])m_stretch(drv_st->memo,drv_st->len_m=2*drv_st->i_m,drv_st->i_m,sizeof(int[M_SIZE]));
|
107
104
|
}
|
108
105
|
|
@@ -119,39 +116,46 @@ static int builtin_equal(rnv_t *rnv, rn_st_t *rn_st, rx_st_t *rx_st, int uri, ch
|
|
119
116
|
|
120
117
|
static int builtin_allows(rnv_t *rnv, rn_st_t *rn_st, rx_st_t *rx_st, int uri, char *typ,char *ps,char *s,int n) {return 1;}
|
121
118
|
|
122
|
-
static
|
119
|
+
static int emb_xsd_allows(rnv_t *rnv, rn_st_t *rn_st, rx_st_t *rx_st, int uri, char *typ,char *ps,char *s,int n) {
|
120
|
+
return xsd_allows(rx_st, typ,ps,s,n);
|
121
|
+
}
|
122
|
+
|
123
|
+
static int emb_xsd_equal(rnv_t *rnv, rn_st_t *rn_st, rx_st_t *rx_st, int uri, char *typ,char *val,char *s,int n) {
|
124
|
+
return xsd_equal(rx_st, typ,val,s,n);
|
125
|
+
}
|
123
126
|
|
124
127
|
void drv_init(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, rx_st_t *rx_st) {
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
+
rx_st->verror_handler = &verror_default_handler;
|
129
|
+
drv_st->verror_handler = &verror_default_handler;
|
130
|
+
|
128
131
|
xsd_init(rx_st);
|
129
|
-
|
132
|
+
|
133
|
+
if(rnv->verror_handler)
|
134
|
+
rx_st->verror_handler = rnv->verror_handler;
|
135
|
+
rx_st->user_data = rnv->user_data;
|
136
|
+
|
130
137
|
drv_st->memo=(int (*)[M_SIZE])m_alloc(drv_st->len_m=LEN_M,sizeof(int[M_SIZE]));
|
131
138
|
drv_st->dtl=(struct dtl*)m_alloc(drv_st->len_dtl=LEN_DTL,sizeof(struct dtl));
|
132
139
|
drv_st->ht_m.user = drv_st;
|
133
140
|
ht_init(&drv_st->ht_m,LEN_M,&hash_m,&equal_m);
|
134
|
-
windup(rnv, drv_st, rn_st);
|
135
|
-
}
|
136
141
|
|
137
|
-
|
138
|
-
|
139
|
-
|
142
|
+
drv_st->i_m=0; drv_st->n_dtl=0;
|
143
|
+
drv_add_dtl(rnv, drv_st, rn_st, rnv->rn_string+0,&fallback_equal,&fallback_allows); /* guard at 0 */
|
144
|
+
drv_add_dtl(rnv, drv_st, rn_st, rnv->rn_string+0,&builtin_equal,&builtin_allows);
|
145
|
+
drv_add_dtl(rnv, drv_st, rn_st, rnv->rn_string+rnv->rn_xsd_uri,&emb_xsd_equal,&emb_xsd_allows);
|
140
146
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
static void windup(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st) {
|
146
|
-
drv_st->i_m=0; drv_st->n_dtl=0;
|
147
|
-
drv_add_dtl(rnv, drv_st, rn_st, rnv->rn_string+0,&fallback_equal,&fallback_allows); /* guard at 0 */
|
148
|
-
drv_add_dtl(rnv, drv_st, rn_st, rnv->rn_string+0,&builtin_equal,&builtin_allows);
|
149
|
-
drv_add_dtl(rnv, drv_st, rn_st, rnv->rn_string+rnv->rn_xsd_uri,&emb_xsd_equal,&emb_xsd_allows);
|
147
|
+
if(rnv->verror_handler)
|
148
|
+
drv_st->verror_handler = rnv->verror_handler;
|
149
|
+
drv_st->user_data = rnv->user_data;
|
150
150
|
}
|
151
151
|
|
152
|
-
void
|
153
|
-
|
154
|
-
|
152
|
+
void drv_dispose(drv_st_t *drv_st) {
|
153
|
+
if (drv_st->memo)
|
154
|
+
m_free(drv_st->memo);
|
155
|
+
if (drv_st->dtl)
|
156
|
+
m_free(drv_st->dtl);
|
157
|
+
ht_dispose(&drv_st->ht_m);
|
158
|
+
m_free(drv_st);
|
155
159
|
}
|
156
160
|
|
157
161
|
void drv_add_dtl(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, char *suri,
|
@@ -168,7 +172,7 @@ static struct dtl *getdtl(rnv_t *rnv, drv_st_t *drv_st, int uri) {
|
|
168
172
|
int i;
|
169
173
|
drv_st->dtl[0].uri=uri; i=drv_st->n_dtl;
|
170
174
|
while(drv_st->dtl[--i].uri!=uri);
|
171
|
-
if(i==0) error_handler(
|
175
|
+
if(i==0) error_handler(drv_st, DRV_ER_NODTL,rnv->rn_string+uri);
|
172
176
|
return drv_st->dtl+i;
|
173
177
|
}
|
174
178
|
|
@@ -203,7 +207,7 @@ static int apply_after(rnv_t *rnv, rn_st_t *rn_st, int (*f)(rnv_t *rnv, rn_st_t
|
|
203
207
|
static int start_tag_open(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p,int uri,int name,int recover) {
|
204
208
|
int nc,p1,p2,m,ret=0;
|
205
209
|
if(!recover) {
|
206
|
-
m=newStartTagOpen(
|
210
|
+
m=newStartTagOpen(drv_st, p,uri,name);
|
207
211
|
if(m!=-1) return M_RET(m);
|
208
212
|
}
|
209
213
|
switch(RN_P_TYP(p)) {
|
@@ -236,8 +240,8 @@ static int start_tag_open(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p,in
|
|
236
240
|
default: assert(0);
|
237
241
|
}
|
238
242
|
if(!recover) {
|
239
|
-
newStartTagOpen(
|
240
|
-
accept_m(
|
243
|
+
newStartTagOpen(drv_st, p,uri,name); M_SET(ret);
|
244
|
+
accept_m(drv_st);
|
241
245
|
}
|
242
246
|
return ret;
|
243
247
|
}
|
@@ -249,7 +253,7 @@ static int puorg_rn(rnv_t *rnv, rn_st_t *rn_st, int p2,int p1) {return rn_group(
|
|
249
253
|
|
250
254
|
static int attribute_open(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p,int uri,int name) {
|
251
255
|
int nc,p1,p2,m,ret=0;
|
252
|
-
m=newAttributeOpen(
|
256
|
+
m=newAttributeOpen(drv_st, p,uri,name);
|
253
257
|
if(m!=-1) return M_RET(m);
|
254
258
|
switch(RN_P_TYP(p)) {
|
255
259
|
case RN_P_NOT_ALLOWED: case RN_P_EMPTY: case RN_P_TEXT:
|
@@ -281,8 +285,8 @@ static int attribute_open(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p,in
|
|
281
285
|
break;
|
282
286
|
default: assert(0);
|
283
287
|
}
|
284
|
-
newAttributeOpen(
|
285
|
-
accept_m(
|
288
|
+
newAttributeOpen(drv_st, p,uri,name); M_SET(ret);
|
289
|
+
accept_m(drv_st);
|
286
290
|
return ret;
|
287
291
|
}
|
288
292
|
|
@@ -295,7 +299,7 @@ extern int drv_attribute_close_recover(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn
|
|
295
299
|
static int start_tag_close(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p,int recover) {
|
296
300
|
int p1,p2,ret=0,m;
|
297
301
|
if(!recover) {
|
298
|
-
m=newStartTagClose(
|
302
|
+
m=newStartTagClose(drv_st, p);
|
299
303
|
if(m!=-1) return M_RET(m);
|
300
304
|
}
|
301
305
|
switch(RN_P_TYP(p)) {
|
@@ -325,8 +329,8 @@ static int start_tag_close(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p,i
|
|
325
329
|
default: assert(0);
|
326
330
|
}
|
327
331
|
if(!recover) {
|
328
|
-
newStartTagClose(
|
329
|
-
accept_m(
|
332
|
+
newStartTagClose(drv_st, p); M_SET(ret);
|
333
|
+
accept_m(drv_st);
|
330
334
|
}
|
331
335
|
return ret;
|
332
336
|
}
|
@@ -377,7 +381,18 @@ static int text(rnv_t *rnv, rn_st_t *rn_st, rx_st_t *rx_st, drv_st_t *drv_st, in
|
|
377
381
|
ret=rn_nullable(list(rnv, rn_st, rx_st, drv_st, p1,s,n))?rnv->rn_empty:rnv->rn_notAllowed;
|
378
382
|
break;
|
379
383
|
case RN_P_DATA: rn_Data(p,dt,ps); rn_Datatype(dt,lib,typ);
|
384
|
+
int i;
|
385
|
+
// avoid dtl called multiple times for same data
|
386
|
+
for(i = 0;i<drv_st->n_dtl_cb;i++) {
|
387
|
+
if(drv_st->dtl_cb[i].p == p)
|
388
|
+
ret = drv_st->dtl_cb[i].ret;
|
389
|
+
}
|
390
|
+
if(!ret) {
|
380
391
|
ret=getdtl(rnv, drv_st, lib)->allows(rnv,rn_st,rx_st, lib, rnv->rn_string+typ,rnv->rn_string+ps,s,n)?rnv->rn_empty:rnv->rn_notAllowed;
|
392
|
+
drv_st->dtl_cb[drv_st->n_dtl_cb].p = p;
|
393
|
+
drv_st->dtl_cb[drv_st->n_dtl_cb].ret = ret;
|
394
|
+
drv_st->n_dtl_cb++;
|
395
|
+
}
|
381
396
|
break;
|
382
397
|
case RN_P_DATA_EXCEPT: rn_DataExcept(p,p1,p2);
|
383
398
|
ret=text(rnv, rn_st, rx_st, drv_st, p1,s,n)==rnv->rn_empty&&!rn_nullable(text(rnv, rn_st, rx_st, drv_st, p2,s,n))?rnv->rn_empty:rnv->rn_notAllowed;
|
@@ -391,6 +406,7 @@ static int text(rnv_t *rnv, rn_st_t *rn_st, rx_st_t *rx_st, drv_st_t *drv_st, in
|
|
391
406
|
}
|
392
407
|
|
393
408
|
static int textws(rnv_t *rnv, rn_st_t *rn_st, rx_st_t *rx_st, drv_st_t *drv_st, int p,char *s,int n) {
|
409
|
+
drv_st->n_dtl_cb = 0;
|
394
410
|
int p1=text(rnv, rn_st, rx_st, drv_st, p,s,n),ws=1;
|
395
411
|
char *end=s+n;
|
396
412
|
while(s!=end) {if(!xmlc_white_space(*s)) {ws=0; break;} ++s;}
|
@@ -401,7 +417,7 @@ int drv_text_recover(int p,char *s,int n) {return p;}
|
|
401
417
|
|
402
418
|
static int mixed_text(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p) { /* matches text in mixed context */
|
403
419
|
int p1,p2,ret=0,m;
|
404
|
-
m=newMixedText(
|
420
|
+
m=newMixedText(drv_st, p);
|
405
421
|
if(m!=-1) return M_RET(m);
|
406
422
|
switch(RN_P_TYP(p)) {
|
407
423
|
case RN_P_NOT_ALLOWED: case RN_P_EMPTY:
|
@@ -430,8 +446,8 @@ static int mixed_text(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p) { /*
|
|
430
446
|
break;
|
431
447
|
default: assert(0);
|
432
448
|
}
|
433
|
-
newMixedText(
|
434
|
-
accept_m(
|
449
|
+
newMixedText(drv_st, p); M_SET(ret);
|
450
|
+
accept_m(drv_st);
|
435
451
|
return ret;
|
436
452
|
}
|
437
453
|
int drv_mixed_text(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p) {return mixed_text(rnv, drv_st, rn_st, p);}
|
@@ -440,7 +456,7 @@ int drv_mixed_text_recover(int p) {return p;}
|
|
440
456
|
static int end_tag(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p,int recover) {
|
441
457
|
int p1,p2,ret=0,m;
|
442
458
|
if(!recover) {
|
443
|
-
m=newEndTag(
|
459
|
+
m=newEndTag(drv_st, p);
|
444
460
|
if(m!=-1) return M_RET(m);
|
445
461
|
}
|
446
462
|
switch(RN_P_TYP(p)) {
|
@@ -459,8 +475,8 @@ static int end_tag(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, int p,int recov
|
|
459
475
|
default: assert(0);
|
460
476
|
}
|
461
477
|
if(!recover) {
|
462
|
-
newEndTag(
|
463
|
-
accept_m(
|
478
|
+
newEndTag(drv_st, p); M_SET(ret);
|
479
|
+
accept_m(drv_st);
|
464
480
|
}
|
465
481
|
return ret;
|
466
482
|
}
|
data/ext/rnv/src/drv.h
CHANGED
@@ -15,10 +15,11 @@ struct dtl {
|
|
15
15
|
int (*allows)(rnv_t *rnv, rn_st_t *rn_st, rx_st_t *rx_st, int uri, char *typ,char *ps,char *s,int n);
|
16
16
|
};
|
17
17
|
|
18
|
-
extern void drv_default_verror_handler(
|
18
|
+
extern void drv_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 drv_init(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, rx_st_t *rx_st);
|
21
|
-
|
21
|
+
|
22
|
+
extern void drv_dispose(drv_st_t *drv_st);
|
22
23
|
|
23
24
|
/* Expat passes character data unterminated. Hence functions that can deal with cdata expect the length of the data */
|
24
25
|
extern void drv_add_dtl(rnv_t *rnv, drv_st_t *drv_st, rn_st_t *rn_st, char *suri,
|
data/ext/rnv/src/er.c
CHANGED
@@ -12,4 +12,4 @@ int er_default_printf(char *format,...) {
|
|
12
12
|
return ret;
|
13
13
|
}
|
14
14
|
int er_default_vprintf(char *format,va_list ap) {return vfprintf(stderr,format,ap);}
|
15
|
-
int verror_default_handler(
|
15
|
+
int verror_default_handler(void *data, int erno, char *format,va_list ap) {return vfprintf(stderr,format,ap);}
|
data/ext/rnv/src/er.h
CHANGED
@@ -11,6 +11,6 @@ extern int (*er_vprintf)(char *format,va_list ap);
|
|
11
11
|
|
12
12
|
extern int er_default_printf(char *format,...);
|
13
13
|
extern int er_default_vprintf(char *format,va_list ap);
|
14
|
-
extern int verror_default_handler(
|
14
|
+
extern int verror_default_handler(void *data, int erno, char *format,va_list ap);
|
15
15
|
|
16
16
|
#endif
|
data/ext/rnv/src/erbit.h
CHANGED
data/ext/rnv/src/rn.c
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
#include "type.h"
|
2
|
-
|
3
1
|
/* $Id: rn.c,v 1.62 2004/03/13 14:12:11 dvd Exp $ */
|
4
2
|
|
5
3
|
#include <string.h> /* strcmp,strlen,strcpy*/
|
4
|
+
|
5
|
+
#include "type.h"
|
6
|
+
|
6
7
|
#include "m.h"
|
7
8
|
#include "s.h" /* s_hval */
|
8
9
|
#include "ht.h"
|
@@ -276,10 +277,7 @@ static int equal_p(void *user, int p1,int p2);
|
|
276
277
|
static int equal_nc(void *user, int nc1,int nc2);
|
277
278
|
static int equal_s(void *user, int s1,int s2);
|
278
279
|
|
279
|
-
static void windup(rnv_t *rnv, rn_st_t *rn_st);
|
280
|
-
|
281
280
|
void rn_init(rnv_t *rnv, rn_st_t *rn_st) {
|
282
|
-
memset(rn_st, 0, sizeof(rn_st_t));
|
283
281
|
rnv->rn_pattern=(int *)m_alloc(rn_st->len_p=P_AVG_SIZE*LEN_P,sizeof(int));
|
284
282
|
rnv->rn_nameclass=(int *)m_alloc(rn_st->len_nc=NC_AVG_SIZE*LEN_NC,sizeof(int));
|
285
283
|
rnv->rn_string=(char*)m_alloc(rn_st->len_s=S_AVG_SIZE*LEN_S,sizeof(char));
|
@@ -289,27 +287,27 @@ void rn_init(rnv_t *rnv, rn_st_t *rn_st) {
|
|
289
287
|
ht_init(&rn_st->ht_p,LEN_P,&hash_p,&equal_p);
|
290
288
|
ht_init(&rn_st->ht_nc,LEN_NC,&hash_nc,&equal_nc);
|
291
289
|
ht_init(&rn_st->ht_s,LEN_S,&hash_s,&equal_s);
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
rn_st->
|
310
|
-
|
311
|
-
|
312
|
-
|
290
|
+
|
291
|
+
rn_st->i_p=rn_st->i_nc=rn_st->i_s=0;
|
292
|
+
rn_st->adding_ps=0;
|
293
|
+
rnv->rn_pattern[0]=RN_P_ERROR; accept_p(rnv, rn_st);
|
294
|
+
rnv->rn_nameclass[0]=RN_NC_ERROR; accept_nc(rnv, rn_st);
|
295
|
+
rn_newString(rnv, rn_st, "");
|
296
|
+
rnv->rn_notAllowed=rn_newNotAllowed(rnv, rn_st);
|
297
|
+
rnv->rn_empty=rn_newEmpty(rnv, rn_st);
|
298
|
+
rnv->rn_text=rn_newText(rnv, rn_st);
|
299
|
+
rn_st->BASE_P=rn_st->i_p;
|
300
|
+
rnv->rn_dt_string=rn_newDatatype(rnv, rn_st, 0,rn_newString(rnv, rn_st, "string"));
|
301
|
+
rnv->rn_dt_token=rn_newDatatype(rnv, rn_st, 0,rn_newString(rnv, rn_st, "token"));
|
302
|
+
rnv->rn_xsd_uri=rn_newString(rnv, rn_st, "http://www.w3.org/2001/XMLSchema-datatypes");
|
303
|
+
}
|
304
|
+
|
305
|
+
void rn_dispose(rn_st_t *rn_st) {
|
306
|
+
ht_dispose(&rn_st->ht_p);
|
307
|
+
ht_dispose(&rn_st->ht_nc);
|
308
|
+
ht_dispose(&rn_st->ht_s);
|
309
|
+
|
310
|
+
m_free(rn_st);
|
313
311
|
}
|
314
312
|
|
315
313
|
static int hash_p(void *user, int p) {
|
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));
|