The R Project SVN R

Rev

Rev 5731 | Rev 6201 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5731 Rev 6189
Line 27... Line 27...
27
#include "Parse.h"
27
#include "Parse.h"
28
 
28
 
29
extern IoBuffer R_ConsoleIob;
29
extern IoBuffer R_ConsoleIob;
30
extern int errno;
30
extern int errno;
31
 
31
 
32
static int ValidFileSpec(SEXP f)
-
 
33
{
-
 
34
    if (isString(f) && length(f) > 0 && CHAR(STRING(f)[0])[0])
32
/* "do_parse" - the user interface input/output to files.
35
	return 1;
-
 
36
    return 0;
-
 
37
}
-
 
38
 
33
 
39
/* "do_parse" - the user interface input/output to files. */
34
 The internal R_Parse.. functions are defined in ./gram.y (-> gram.c)
40
/* See parse, below, for the internal function.  The */
-
 
41
/* arguments are "file", "number", "text", "prompt". */
-
 
42
/* If there is text then that is read and the other */
-
 
43
/* arguments are ignored. */
-
 
44
 
35
 
-
 
36
 .Internal( parse(file, n, text, prompt) )
-
 
37
 If there is text then that is read and the other arguments are ignored.
-
 
38
*/
45
SEXP do_parse(SEXP call, SEXP op, SEXP args, SEXP env)
39
SEXP do_parse(SEXP call, SEXP op, SEXP args, SEXP env)
46
{
40
{
47
    SEXP file, text, prompt, s;
41
    SEXP file, text, prompt, s;
48
    FILE *fp;
42
    FILE *fp;
49
    int num, pstacktop, status;
43
    int num, pstacktop, status;
Line 56... Line 50...
56
    args = CDR(args);
50
    args = CDR(args);
57
 
51
 
58
    num = asInteger(CAR(args));
52
    num = asInteger(CAR(args));
59
    args = CDR(args);
53
    args = CDR(args);
60
 
54
 
61
    PROTECT(text = coerceVector(CAR(args), STRSXP)); 
55
    PROTECT(text = coerceVector(CAR(args), STRSXP));
62
    args = CDR(args);
56
    args = CDR(args);
63
 
57
 
64
    prompt = CAR(args);
58
    prompt = CAR(args);
65
    if (prompt == R_NilValue)
59
    if (prompt == R_NilValue)
66
	PROTECT(prompt);
60
	PROTECT(prompt);
Line 75... Line 69...
75
	if (status != PARSE_OK)
69
	if (status != PARSE_OK)
76
	    errorcall(call, "parse error");
70
	    errorcall(call, "parse error");
77
	UNPROTECT(3);
71
	UNPROTECT(3);
78
	return s;
72
	return s;
79
    }
73
    }
80
    else if (ValidFileSpec(file)) {
74
    else if (isValidString(file)) {
81
	if (num == NA_INTEGER)
75
	if (num == NA_INTEGER)
82
	    num = -1;
76
	    num = -1;
83
	fp = R_fopen(R_ExpandFileName(CHAR(STRING(file)[0])), "r");
77
	fp = R_fopen(R_ExpandFileName(CHAR(STRING(file)[0])), "r");
84
	if (!fp)
78
	if (!fp)
85
	    errorcall(call, "unable to open file for parsing");
79
	    errorcall(call, "unable to open file for parsing");
Line 98... Line 92...
98
	    errorcall(call, "parse error");
92
	    errorcall(call, "parse error");
99
	UNPROTECT(3);
93
	UNPROTECT(3);
100
	return s;
94
	return s;
101
    }
95
    }
102
}
96
}
-
 
97
 
-
 
98