CXXR (C++ R)
Rconnections.h
1 /*CXXR $Id: Rconnections.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) 2000-2011 The R Core Team.
20  *
21  * This program is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation; either version 2 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with this program; if not, a copy is available at
33  * http://www.r-project.org/Licenses/
34  */
35 
36 #ifndef R_CONNECTIONS_H_
37 #define R_CONNECTIONS_H_
38 #include <R_ext/Boolean.h>
39 
40 /* NB: this is a private header, and not installed. The internals of
41  connections are private and subject to change without notice. */
42 
43 #if defined(HAVE_OFF_T) && defined(HAVE_FSEEKO) && defined(HAVE_SYS_TYPES_H)
44 #include <sys/types.h>
45 #endif
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /* this allows the opaque pointer definition to be made available
52  in Rinternals.h */
53 #ifndef HAVE_RCONNECTION_TYPEDEF
54 typedef struct Rconn *Rconnection;
55 #endif
56 struct Rconn {
57  char* connclass;
58  char* description;
59  int enc; /* the encoding of 'description' */
60  char mode[5];
61  Rboolean text, isopen, incomplete, canread, canwrite, canseek, blocking,
62  isGzcon;
63  Rboolean (*open)(struct Rconn *);
64  void (*close)(struct Rconn *); /* routine closing after auto open */
65  void (*destroy)(struct Rconn *); /* when closing connection */
66  int (*vfprintf)(struct Rconn *, const char *, va_list);
67  int (*fgetc)(struct Rconn *);
68  int (*fgetc_internal)(struct Rconn *);
69  double (*seek)(struct Rconn *, double, int, int);
70  void (*truncate)(struct Rconn *);
71  int (*fflush)(struct Rconn *);
72  size_t (*read)(void *, size_t, size_t, struct Rconn *);
73  size_t (*write)(const void *, size_t, size_t, struct Rconn *);
74  int nPushBack, posPushBack; /* number of lines, position on top line */
75  char **PushBack;
76  int save, save2;
77  char encname[101];
78  /* will be iconv_t, which is a pointer. NULL if not in use */
79  void *inconv, *outconv;
80  /* The idea here is that no MBCS char will ever not fit */
81  char iconvbuff[25], oconvbuff[50], *next, init_out[25];
82  short navail, inavail;
83  Rboolean EOF_signalled;
84  Rboolean UTF8out;
85  void *id;
86  void *ex_ptr;
87  void *connprivate;
88 };
89 
90 
91 typedef enum {HTTPsh, FTPsh, HTTPSsh} UrlScheme;
92 
93 /* used in internet module */
94 typedef struct urlconn {
95  void *ctxt;
96  UrlScheme type;
97 } *Rurlconn;
98 
99 /* used in internet module */
100 typedef struct sockconn {
101  int port;
102  int server;
103  int fd;
104  int timeout;
105  char *host;
106  char inbuf[4096], *pstart, *pend;
107 } *Rsockconn;
108 
109 /* used in X11 module */
110 typedef struct clpconn {
111  char *buff;
112  int pos, len, last, sizeKB;
113  Rboolean warned;
114 } *Rclpconn;
115 
116 #define init_con Rf_init_con
117 #define con_pushback Rf_con_pushback
118 
119 int Rconn_fgetc(Rconnection con);
120 int Rconn_ungetc(int c, Rconnection con);
121 int Rconn_getline(Rconnection con, char *buf, int bufsize);
122 int Rconn_printf(Rconnection con, const char *format, ...);
123 Rconnection getConnection(int n);
124 Rconnection getConnection_no_err(int n);
125 Rboolean switch_stdout(int icon, int closeOnExit);
126 void init_con(Rconnection newconn, const char *description, int enc,
127  const char * const mode);
128 Rconnection R_newurl(const char *description, const char * const mode);
129 Rconnection R_newsock(const char *host, int port, int server, const char * const mode, int timeout);
130 Rconnection in_R_newsock(const char *host, int port, int server, const char *const mode, int timeout);
131 Rconnection R_newunz(const char *description, const char * const mode);
132 int dummy_fgetc(Rconnection con);
133 int dummy_vfprintf(Rconnection con, const char *format, va_list ap);
134 int getActiveSink(int n);
135 void con_pushback(Rconnection con, Rboolean newLine, char *line);
136 size_t R_WriteConnection(Rconnection con, const void *buf, size_t n);
137 
138 int Rsockselect(int nsock, int *insockfd, int *ready, int *write, double timeout);
139 
140 #define set_iconv Rf_set_iconv
141 void set_iconv(Rconnection con);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif /* R_CONNECTIONS_H_ */
148