The R Project SVN R

Rev

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

Rev 77730 Rev 87901
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1995, 1996, 1997,  Robert Gentleman and Ross Ihaka
3
 *  Copyright (C) 1995, 1996, 1997,  Robert Gentleman and Ross Ihaka
4
 *                2007-2020 The R Core Team
4
 *                2007-2025 The R Core Team
5
 *
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
9
 *  (at your option) any later version.
Line 69... Line 69...
69
}
69
}
70
 
70
 
71
 
71
 
72
/* Reset the read/write pointers of an IoBuffer */
72
/* Reset the read/write pointers of an IoBuffer */
73
 
73
 
74
int attribute_hidden R_IoBufferWriteReset(IoBuffer *iob)
74
attribute_hidden int R_IoBufferWriteReset(IoBuffer *iob)
75
{
75
{
76
    if (iob == NULL || iob->start_buf == NULL)
76
    if (iob == NULL || iob->start_buf == NULL)
77
	return 0;
77
	return 0;
78
    iob->write_buf = iob->start_buf;
78
    iob->write_buf = iob->start_buf;
79
    iob->write_ptr = iob->write_buf->buf;
79
    iob->write_ptr = iob->write_buf->buf;
Line 84... Line 84...
84
    return 1;
84
    return 1;
85
}
85
}
86
 
86
 
87
/* Reset the read pointer of an IoBuffer */
87
/* Reset the read pointer of an IoBuffer */
88
 
88
 
89
int attribute_hidden R_IoBufferReadReset(IoBuffer *iob)
89
attribute_hidden int R_IoBufferReadReset(IoBuffer *iob)
90
{
90
{
91
    if (iob == NULL || iob->start_buf == NULL)
91
    if (iob == NULL || iob->start_buf == NULL)
92
	return 0;
92
	return 0;
93
    iob->read_buf = iob->start_buf;
93
    iob->read_buf = iob->start_buf;
94
    iob->read_ptr = iob->read_buf->buf;
94
    iob->read_ptr = iob->read_buf->buf;
Line 97... Line 97...
97
}
97
}
98
 
98
 
99
/* Allocate an initial BufferListItem for IoBuffer */
99
/* Allocate an initial BufferListItem for IoBuffer */
100
/* Initialize the counts and pointers. */
100
/* Initialize the counts and pointers. */
101
 
101
 
102
int attribute_hidden R_IoBufferInit(IoBuffer *iob)
102
attribute_hidden int R_IoBufferInit(IoBuffer *iob)
103
{
103
{
104
    if (iob == NULL) return 0;
104
    if (iob == NULL) return 0;
105
    iob->start_buf = (BufferListItem*)malloc(sizeof(BufferListItem));
105
    iob->start_buf = (BufferListItem*)malloc(sizeof(BufferListItem));
106
    if (iob->start_buf == NULL) return 0;
106
    if (iob->start_buf == NULL) return 0;
107
    iob->start_buf->next = NULL;
107
    iob->start_buf->next = NULL;
Line 110... Line 110...
110
 
110
 
111
/* Free any BufferListItem's associated with an IoBuffer */
111
/* Free any BufferListItem's associated with an IoBuffer */
112
/* This resets pointers to NULL, which could be detected */
112
/* This resets pointers to NULL, which could be detected */
113
/* in other calls. */
113
/* in other calls. */
114
 
114
 
115
int attribute_hidden R_IoBufferFree(IoBuffer *iob)
115
attribute_hidden int R_IoBufferFree(IoBuffer *iob)
116
{
116
{
117
    BufferListItem *thisItem, *nextItem;
117
    BufferListItem *thisItem, *nextItem;
118
    if (iob == NULL || iob->start_buf == NULL)
118
    if (iob == NULL || iob->start_buf == NULL)
119
	return 0;
119
	return 0;
120
    thisItem = iob->start_buf;
120
    thisItem = iob->start_buf;
Line 126... Line 126...
126
    return 1;
126
    return 1;
127
}
127
}
128
 
128
 
129
/* Add a character to an IoBuffer */
129
/* Add a character to an IoBuffer */
130
 
130
 
131
int attribute_hidden R_IoBufferPutc(int c, IoBuffer *iob)
131
attribute_hidden int R_IoBufferPutc(int c, IoBuffer *iob)
132
{
132
{
133
    if (iob->write_offset == IOBSIZE)
133
    if (iob->write_offset == IOBSIZE)
134
	NextWriteBufferListItem(iob);
134
	NextWriteBufferListItem(iob);
135
    *(iob->write_ptr)++ = (char) c;
135
    *(iob->write_ptr)++ = (char) c;
136
    iob->write_offset++;
136
    iob->write_offset++;
137
    return 0;/*not used*/
137
    return 0;/*not used*/
138
}
138
}
139
 
139
 
140
/* Add a (null terminated) string to an IoBuffer */
140
/* Add a (null terminated) string to an IoBuffer */
141
 
141
 
142
int attribute_hidden R_IoBufferPuts(char *s, IoBuffer *iob)
142
attribute_hidden int R_IoBufferPuts(char *s, IoBuffer *iob)
143
{
143
{
144
    char *p;
144
    char *p;
145
    int n = 0;
145
    int n = 0;
146
    for (p = s; *p; p++) {
146
    for (p = s; *p; p++) {
147
	R_IoBufferPutc(*p, iob);
147
	R_IoBufferPutc(*p, iob);
Line 150... Line 150...
150
    return n;
150
    return n;
151
}
151
}
152
 
152
 
153
/* Read a character from an IoBuffer */
153
/* Read a character from an IoBuffer */
154
 
154
 
155
int attribute_hidden R_IoBufferGetc(IoBuffer *iob)
155
attribute_hidden int R_IoBufferGetc(IoBuffer *iob)
156
{
156
{
157
    if (iob->read_buf == iob->write_buf &&
157
    if (iob->read_buf == iob->write_buf &&
158
       iob->read_offset >= iob->write_offset)
158
       iob->read_offset >= iob->write_offset)
159
	return EOF;
159
	return EOF;
160
    if (iob->read_offset == IOBSIZE) NextReadBufferListItem(iob);
160
    if (iob->read_offset == IOBSIZE) NextReadBufferListItem(iob);
Line 162... Line 162...
162
    return *(iob->read_ptr)++;
162
    return *(iob->read_ptr)++;
163
}
163
}
164
 
164
 
165
/* What is our current offset, taking all blocks into account? */
165
/* What is our current offset, taking all blocks into account? */
166
 
166
 
167
int attribute_hidden R_IoBufferReadOffset(IoBuffer *iob)
167
attribute_hidden int R_IoBufferReadOffset(IoBuffer *iob)
168
{
168
{
169
    int result = iob->read_offset;
169
    int result = iob->read_offset;
170
    BufferListItem* buf = iob->start_buf;
170
    BufferListItem* buf = iob->start_buf;
171
    while(buf && buf != iob->read_buf) {
171
    while(buf && buf != iob->read_buf) {
172
    	result += IOBSIZE;
172
    	result += IOBSIZE;
Line 194... Line 194...
194
	return CHAR(x);
194
	return CHAR(x);
195
    else
195
    else
196
	return translateChar(x);
196
	return translateChar(x);
197
}
197
}
198
 
198
 
199
int attribute_hidden R_TextBufferInit(TextBuffer *txtb, SEXP text)
199
attribute_hidden int R_TextBufferInit(TextBuffer *txtb, SEXP text)
200
{
200
{
201
    int i, k, l, n;
201
    int i, k, l, n;
202
    if (isString(text)) {
202
    if (isString(text)) {
203
	// translateChar might allocate
203
	// translateChar might allocate
204
	void *vmax = vmaxget();
204
	void *vmax = vmaxget();
Line 234... Line 234...
234
    }
234
    }
235
}
235
}
236
 
236
 
237
/* Finalization code for text buffers */
237
/* Finalization code for text buffers */
238
 
238
 
239
int attribute_hidden R_TextBufferFree(TextBuffer *txtb)
239
attribute_hidden int R_TextBufferFree(TextBuffer *txtb)
240
{
240
{
241
    vmaxset(txtb->vmax);
241
    vmaxset(txtb->vmax);
242
    return 0;/* not used */
242
    return 0;/* not used */
243
}
243
}
244
 
244
 
245
/* Getc for text buffers */
245
/* Getc for text buffers */
246
 
246
 
247
int attribute_hidden R_TextBufferGetc(TextBuffer *txtb)
247
attribute_hidden int R_TextBufferGetc(TextBuffer *txtb)
248
{
248
{
249
    if (txtb->buf == NULL)
249
    if (txtb->buf == NULL)
250
	return EOF;
250
	return EOF;
251
    if (*(txtb->bufp) == '\0') {
251
    if (*(txtb->bufp) == '\0') {
252
	if (txtb->offset == txtb->ntext) {
252
	if (txtb->offset == txtb->ntext) {