1 /* 2 * R : A Computer Language for Statistical Data Analysis 3 * Copyright (C) 2000-2017 The R Core Team. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, a copy is available at 17 * https://www.R-project.org/Licenses/ 18 */ 19 20 21 /* This header is not part of the R API (see 'Writing R Extensions') */ 22 23 #ifndef R_EXT_CONNECTIONS_H_ 24 #define R_EXT_CONNECTIONS_H_ 25 26 #include <R_ext/Boolean.h> 27 28 #if defined(__cplusplus) && !defined(DO_NOT_USE_CXX_HEADERS) 29 # include <cstddef> 30 # include <cstdarg> 31 #else 32 # include <stddef.h> /* for size_t */ 33 # include <stdarg.h> /* for va_list */ 34 #endif 35 36 /* IMPORTANT: we do not expect future connection APIs to be 37 backward-compatible so if you use this, you *must* check the 38 version and proceed only if it matches what you expect. 39 40 We explicitly reserve the right to change the connection 41 implementation without a compatibility layer. 42 */ 43 #define R_CONNECTIONS_VERSION 1 44 45 /* this allows the opaque pointer definition to be made available 46 in Rinternals.h */ 47 #ifndef HAVE_RCONNECTION_TYPEDEF 48 typedef struct Rconn *Rconnection; 49 #endif 50 struct Rconn { 51 char* class; 52 char* description; 53 int enc; /* the encoding of 'description' */ 54 char mode[5]; 55 Rboolean text, isopen, incomplete, canread, canwrite, canseek, blocking, 56 isGzcon; 57 Rboolean (*open)(struct Rconn *); 58 void (*close)(struct Rconn *); /* routine closing after auto open */ 59 void (*destroy)(struct Rconn *); /* when closing connection */ 60 int (*vfprintf)(struct Rconn *, const char *, va_list); 61 int (*fgetc)(struct Rconn *); 62 int (*fgetc_internal)(struct Rconn *); 63 double (*seek)(struct Rconn *, double, int, int); 64 void (*truncate)(struct Rconn *); 65 int (*fflush)(struct Rconn *); 66 size_t (*read)(void *, size_t, size_t, struct Rconn *); 67 size_t (*write)(const void *, size_t, size_t, struct Rconn *); 68 int nPushBack, posPushBack; /* number of lines, position on top line */ 69 char **PushBack; 70 int save, save2; 71 char encname[101]; 72 /* will be iconv_t, which is a pointer. NULL if not in use */ 73 void *inconv, *outconv; 74 /* The idea here is that no MBCS char will ever not fit */ 75 char iconvbuff[25], oconvbuff[50], *next, init_out[25]; 76 short navail, inavail; 77 Rboolean EOF_signalled; 78 Rboolean UTF8out; 79 void *id; 80 void *ex_ptr; 81 void *private; 82 int status; /* for pipes etc */ 83 unsigned char *buff; 84 size_t buff_len, buff_stored_len, buff_pos; 85 }; 86 87 #ifdef __cplusplus 88 extern "C" { 89 #endif 90 91 SEXP R_new_custom_connection(const char *description, const char *mode, const char *class_name, Rconnection *ptr); 92 size_t R_ReadConnection(Rconnection con, void *buf, size_t n); 93 size_t R_WriteConnection(Rconnection con, void *buf, size_t n); 94 Rconnection R_GetConnection(SEXP sConn); // added in R 3.3.0 95 96 #ifdef __cplusplus 97 } 98 #endif 99 100 #endif 101