The R Project SVN R-packages

Rev

Rev 7747 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7747 Rev 7986
Line 36... Line 36...
36
    if(out) {
36
    if(out) {
37
	fclose(out); out = NULL;
37
	fclose(out); out = NULL;
38
    }
38
    }
39
#endif
39
#endif
40
 
40
 
41
    PROBLEM "failed to parse json at %d",  num
41
    Rf_error("failed to parse json at %d",  num);
42
	ERROR;
-
 
43
}
42
}
44
 
43
 
45
 
44
 
46
SEXP
45
SEXP
47
R_makeJSONRef(JSONNODE *node)
46
R_makeJSONRef(JSONNODE *node)
Line 154... Line 153...
154
    else 			/* otherwise use our own callback to process the JSONNODE */
153
    else 			/* otherwise use our own callback to process the JSONNODE */
155
	callback = R_json_parser_callback;
154
	callback = R_json_parser_callback;
156
 
155
 
157
    stream = json_new_stream(callback, errorCB, &cb);
156
    stream = json_new_stream(callback, errorCB, &cb);
158
    if(!stream) {
157
    if(!stream) {
159
	PROBLEM "Couldn't create json stream"
158
	Rf_error("Couldn't create json stream");
160
	    ERROR;
-
 
161
    }
159
    }
162
 
160
 
163
    cb.stream = stream;
161
    cb.stream = stream;
164
    cb.cumBytes = 0;
162
    cb.cumBytes = 0;
165
    cb.result = NULL;
163
    cb.result = NULL;
Line 178... Line 176...
178
    if(TYPEOF(conCall) == STRSXP) {
176
    if(TYPEOF(conCall) == STRSXP) {
179
	FILE *f;
177
	FILE *f;
180
	f = fopen(CHAR(STRING_ELT(conCall, 0)), "r");
178
	f = fopen(CHAR(STRING_ELT(conCall, 0)), "r");
181
	if(!f) {
179
	if(!f) {
182
	    json_delete_stream(stream);
180
	    json_delete_stream(stream);
183
	    PROBLEM "cannot open JSON file %s", CHAR(STRING_ELT(conCall, 0))
181
	    Rf_error("cannot open JSON file %s", CHAR(STRING_ELT(conCall, 0)));
184
		ERROR;
-
 
185
	}
182
	}
186
	cb.file = f;
183
	cb.file = f;
187
	    
184
	    
188
	while(readFileData(f, stream, &(cb.cumBytes))) {  }
185
	while(readFileData(f, stream, &(cb.cumBytes))) {  }
189
	fclose(f);
186
	fclose(f);
Line 244... Line 241...
244
    JSONSTREAM *stream;
241
    JSONSTREAM *stream;
245
    FILE *fileptr;
242
    FILE *fileptr;
246
 
243
 
247
    fileptr = fopen(CHAR(STRING_ELT(r_filename, 0)), "r");
244
    fileptr = fopen(CHAR(STRING_ELT(r_filename, 0)), "r");
248
    if(!fileptr) {
245
    if(!fileptr) {
249
	PROBLEM "cannot open file"
246
	Rf_error("cannot open file");
250
	    ERROR;
-
 
251
    }
247
    }
252
 
248
 
253
    stream = json_new_stream(R_json_cb_test_stream, errorCB, NULL);
249
    stream = json_new_stream(R_json_cb_test_stream, errorCB, NULL);
254
    if(!stream) {
250
    if(!stream) {
255
	PROBLEM "Couldn't create json stream"
251
	Rf_error("Couldn't create json stream");
256
	    ERROR;
-
 
257
    }
252
    }
258
 
253
 
259
    json_stream_push(stream, "{ \"a\": [1, 2, 3]}[true, false]");
254
    json_stream_push(stream, "{ \"a\": [1, 2, 3]}[true, false]");
260
 
255
 
261
    while(test_get_data(fileptr, stream)) {   }
256
    while(test_get_data(fileptr, stream)) {   }
Line 274... Line 269...
274
    JSONSTREAM *stream;
269
    JSONSTREAM *stream;
275
    const char *str = CHAR(STRING_ELT(r_filename, 0));
270
    const char *str = CHAR(STRING_ELT(r_filename, 0));
276
 
271
 
277
    stream = json_new_stream(R_json_cb_test_stream, errorCB, NULL);
272
    stream = json_new_stream(R_json_cb_test_stream, errorCB, NULL);
278
    if(!stream) {
273
    if(!stream) {
279
	PROBLEM "Couldn't create json stream"
274
	Rf_error("Couldn't create json stream");
280
	    ERROR;
-
 
281
    }
275
    }
282
 
276
 
283
    json_stream_push(stream, str);
277
    json_stream_push(stream, str);
284
 
278
 
285
    R_ReleaseObject(top);
279
    R_ReleaseObject(top);
Line 294... Line 288...
294
    JSONSTREAM *stream;
288
    JSONSTREAM *stream;
295
    const char *str = CHAR(STRING_ELT(r_filename, 0));
289
    const char *str = CHAR(STRING_ELT(r_filename, 0));
296
 
290
 
297
    stream = json_new_stream(R_json_cb_test_stream, errorCB, NULL);
291
    stream = json_new_stream(R_json_cb_test_stream, errorCB, NULL);
298
    if(!stream) {
292
    if(!stream) {
299
	PROBLEM "Couldn't create json stream"
293
	Rf_error("Couldn't create json stream");
300
	    ERROR;
-
 
301
    }
294
    }
302
    
295
    
303
    int len = (int)strlen(str), cur = 0, blocksize = 100;
296
    int len = (int)strlen(str), cur = 0, blocksize = 100;
304
    char tmp[blocksize + 1];
297
    char tmp[blocksize + 1];
305
    tmp[blocksize] = '\0';
298
    tmp[blocksize] = '\0';
Line 325... Line 318...
325
{
318
{
326
    JSONSTREAM *stream;
319
    JSONSTREAM *stream;
327
 
320
 
328
    stream = json_new_stream(R_json_cb_test_stream, errorCB, NULL);
321
    stream = json_new_stream(R_json_cb_test_stream, errorCB, NULL);
329
    if(!stream) {
322
    if(!stream) {
330
	PROBLEM "Couldn't create json stream"
323
	Rf_error("Couldn't create json stream");
331
	    ERROR;
-
 
332
    }
324
    }
333
    
325
    
334
    int n = 0;
326
    int n = 0;
335
    while(getData(r_getData, stream, &n)) {}
327
    while(getData(r_getData, stream, &n)) {}
336
 
328