The R Project SVN R

Rev

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

Rev 47481 Rev 47713
Line 38... Line 38...
38
    SEXP ans = R_NilValue, ans2;
38
    SEXP ans = R_NilValue, ans2;
39
    int nn, nnn, nread;
39
    int nn, nnn, nread;
40
    char c;
40
    char c;
41
 
41
 
42
    context[last] = '\0';
42
    context[last] = '\0';
43
    for (i=R_ParseContextLast; last>0 ; i--) {
43
    for (i=R_ParseContextLast; last>0 ; i += PARSE_CONTEXT_SIZE - 1) {
44
	i = i % PARSE_CONTEXT_SIZE;
44
	i = i % PARSE_CONTEXT_SIZE;
45
	context[--last] = R_ParseContext[i];
45
	context[--last] = R_ParseContext[i];
46
	if (!context[last]) {
46
	if (!context[last]) {
47
	    last++;
47
	    last++;
48
	    break;
48
	    break;
Line 94... Line 94...
94
	    strncpy(buffer, CHAR(STRING_ELT(filename, 0)), buflen - 1);
94
	    strncpy(buffer, CHAR(STRING_ELT(filename, 0)), buflen - 1);
95
	UNPROTECT(1);
95
	UNPROTECT(1);
96
    }
96
    }
97
}
97
}
98
 
98
 
-
 
99
static SEXP tabExpand(SEXP strings)
-
 
100
{
-
 
101
    int i;
-
 
102
    char buffer[200], *b;
-
 
103
    const char *input;
-
 
104
    SEXP result;
-
 
105
    PROTECT(result = allocVector(STRSXP, length(strings)));
-
 
106
    for (i = 0; i < length(strings); i++) {
-
 
107
    	input = CHAR(STRING_ELT(strings, i));
-
 
108
    	for (b = buffer; input && b-buffer < 192; input++) {
-
 
109
    	    if (*input == '\t') do {
-
 
110
    	    	*b++ = ' ';
-
 
111
    	    } while (((b-buffer) & 7) != 0);
-
 
112
    	    else *b++ = *input;
-
 
113
    	}
-
 
114
    	*b = '\0';
-
 
115
    	SET_STRING_ELT(result, i, mkCharCE(buffer, Rf_getCharCE(STRING_ELT(strings, i))));
-
 
116
    }
-
 
117
    UNPROTECT(1);
-
 
118
    return result;
-
 
119
}
-
 
120
    	
99
void attribute_hidden parseError(SEXP call, int linenum)
121
void attribute_hidden parseError(SEXP call, int linenum)
100
{
122
{
101
    SEXP context = getParseContext();
123
    SEXP context;
102
    int len = length(context);
124
    int len, width;
103
    char filename[128];
125
    char filename[128], buffer[10];
-
 
126
    PROTECT(context = tabExpand(getParseContext()));
-
 
127
    len = length(context);
104
    if (linenum) {
128
    if (linenum) {
105
	getParseFilename(filename, sizeof(filename)-2);
129
	getParseFilename(filename, sizeof(filename)-2);
106
	if (strlen(filename)) strcpy(filename + strlen(filename), ":");
130
	if (strlen(filename)) strcpy(filename + strlen(filename), ":");
107
 
131
 
108
	switch (len) {
132
	switch (len) {
109
	case 0:
133
	case 0:
110
	    error(_("%s%d:%d: %s"),
134
	    error(_("%s%d:%d: %s"),
111
		  filename, linenum, R_ParseErrorCol, R_ParseErrorMsg);
135
		  filename, linenum, R_ParseErrorCol, R_ParseErrorMsg);
112
	    break;
136
	    break;
113
	case 1:
137
	case 1:
-
 
138
	    sprintf(buffer, "%d: %n", R_ParseContextLine, &width); 
-
 
139
	    Rprintf("Context is '%s'", CHAR(STRING_ELT(context,0)));
114
	    error(_("%s%d:%d: %s\n%d: %s"),
140
	    error(_("%s%d:%d: %s\n%d: %s\n%*s"),
115
		  filename, linenum, R_ParseErrorCol, R_ParseErrorMsg,
141
		  filename, linenum, R_ParseErrorCol, R_ParseErrorMsg,
116
		  R_ParseContextLine, CHAR(STRING_ELT(context, 0)));
142
		  R_ParseContextLine, CHAR(STRING_ELT(context, 0)), 
-
 
143
		  width+R_ParseErrorCol, "^");
117
	    break;
144
	    break;
118
	default:
145
	default:
-
 
146
	    sprintf(buffer, "%d: %n", R_ParseContextLine, &width);
119
	    error(_("%s%d:%d: %s\n%d: %s\n%d: %s"),
147
	    error(_("%s%d:%d: %s\n%d: %s\n%d: %s\n%*s"),
120
		  filename, linenum, R_ParseErrorCol, R_ParseErrorMsg,
148
		  filename, linenum, R_ParseErrorCol, R_ParseErrorMsg,
121
		  R_ParseContextLine-1, CHAR(STRING_ELT(context, len-2)),
149
		  R_ParseContextLine-1, CHAR(STRING_ELT(context, len-2)),
122
		  R_ParseContextLine, CHAR(STRING_ELT(context, len-1)));
150
		  R_ParseContextLine, CHAR(STRING_ELT(context, len-1)), 
-
 
151
		  width+R_ParseErrorCol, "^");
123
	    break;
152
	    break;
124
	}
153
	}
125
    } else {
154
    } else {
126
	switch (len) {
155
	switch (len) {
127
	case 0:
156
	case 0:
Line 136... Line 165...
136
		  R_ParseErrorMsg, CHAR(STRING_ELT(context, len-2)),
165
		  R_ParseErrorMsg, CHAR(STRING_ELT(context, len-2)),
137
		  CHAR(STRING_ELT(context, len-1)));
166
		  CHAR(STRING_ELT(context, len-1)));
138
	    break;
167
	    break;
139
	}
168
	}
140
    }
169
    }
-
 
170
    UNPROTECT(1);
141
}
171
}
142
 
172
 
143
/* "do_parse" - the user interface input/output to files.
173
/* "do_parse" - the user interface input/output to files.
144
 
174
 
145
 The internal R_Parse.. functions are defined in ./gram.y (-> gram.c)
175
 The internal R_Parse.. functions are defined in ./gram.y (-> gram.c)