CXXR (C++ R)
IOStuff.h
1 /*CXXR $Id: IOStuff.h 1348 2013-02-25 17:49:03Z arr $
2  *CXXR
3  *CXXR This file is part of CXXR, a project to refactor the R interpreter
4  *CXXR into C++. It may consist in whole or in part of program code and
5  *CXXR documentation taken from the R project itself, incorporated into
6  *CXXR CXXR (and possibly MODIFIED) under the terms of the GNU General Public
7  *CXXR Licence.
8  *CXXR
9  *CXXR CXXR is Copyright (C) 2008-13 Andrew R. Runnalls, subject to such other
10  *CXXR copyrights and copyright restrictions as may be stated below.
11  *CXXR
12  *CXXR CXXR is not part of the R project, and bugs and other issues should
13  *CXXR not be reported via r-bugs or other R project channels; instead refer
14  *CXXR to the CXXR website.
15  *CXXR */
16 
17 /*
18  * R : A Computer Language for Statistical Data Analysis
19  * Copyright (C) 1997 Robert Gentleman and Ross Ihaka
20  * Copyright (C) 2005 R Core Team
21  *
22  * This program is free software; you can redistribute it and/or modify
23  * it under the terms of the GNU General Public License as published by
24  * the Free Software Foundation; either version 2 of the License, or
25  * (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License
33  * along with this program; if not, a copy is available at
34  * http://www.r-project.org/Licenses/
35  */
36 
37 #ifndef R_IOSTUFF_H
38 #define R_IOSTUFF_H
39 
40 /*
41  * I/O Support for Consoles and Character Vectors
42  *
43  * This code provides analogues for the stdio routines "fgetc" and
44  * (formerly) "ungetc" for "consoles" and character vectors. These routines
45  * are used for parsing input from the console window and character
46  * vectors.
47  */
48 
49 #include <Defn.h>
50 #include <stdio.h>
51 
52 #define IOBSIZE 4096
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 typedef struct BufferListItem {
59  unsigned char buf[IOBSIZE];
60  struct BufferListItem *next;
61 } BufferListItem;
62 
63 typedef struct IoBuffer {
64  BufferListItem *start_buf; /* First buffer item */
65  BufferListItem *write_buf; /* Write pointer location */
66  unsigned char *write_ptr; /* Write pointer location */
67  int write_offset; /* Write pointer location */
68  BufferListItem *read_buf; /* Read pointer location */
69  unsigned char *read_ptr; /* Read pointer location */
70  int read_offset; /* Read pointer location */
71 } IoBuffer;
72 
73 
74 typedef struct TextBuffer {
75  void *vmax; /* Memory stack top */
76  unsigned char *buf; /* Line buffer */
77  unsigned char *bufp; /* Line buffer location */
78  SEXP text; /* String Vector */
79  int ntext; /* Vector length */
80  int offset; /* Offset within vector */
81 } TextBuffer;
82 
83 #ifndef __MAIN__
84 extern
85 #else
86 attribute_hidden
87 #endif
88 IoBuffer R_ConsoleIob; /* Console IO Buffer */
89 
90 /*- some of these really could be void */
91 int R_IoBufferInit(IoBuffer*);
92 int R_IoBufferFree(IoBuffer*);
93 int R_IoBufferReadReset(IoBuffer*);
94 int R_IoBufferWriteReset(IoBuffer*);
95 int R_IoBufferGetc(IoBuffer*);
96 int R_IoBufferPutc(int, IoBuffer*);
97 int R_IoBufferPuts(char*, IoBuffer*);
98 int R_IoBufferReadOffset(IoBuffer*);
99 
100 int R_TextBufferInit(TextBuffer*, SEXP);
101 int R_TextBufferFree(TextBuffer*);
102 int R_TextBufferGetc(TextBuffer*);
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif /* not R_IOSTUFF_H */