1 #ifdef DTPY 2 #include "py_fread.h" 3 #else 4 #define STRICT_R_HEADERS 5 #include <R.h> 6 #include "po.h" 7 #define STOP error 8 #define DTPRINT Rprintf 9 #endif 10 11 typedef void (*writer_fun_t)(const void *, int64_t, char **); 12 13 // in the order of writer_fun_t in fwriteR.c 14 void writeBool8(); 15 void writeBool32(); 16 void writeBool32AsString(); 17 void writeInt32(); 18 void writeInt64(); 19 void writeFloat64(); 20 void writeComplex(); 21 void writeITime(); 22 void writeDateInt32(); 23 void writeDateFloat64(); 24 void writePOSIXct(); 25 void writeNanotime(); 26 void writeString(); 27 void writeCategString(); 28 void writeList(); 29 30 void write_chars(const char *source, char **dest); 31 32 typedef enum { // same order as fun[] above 33 WF_Bool8, 34 WF_Bool32, 35 WF_Bool32AsString, 36 WF_Int32, 37 WF_Int64, 38 WF_Float64, 39 WF_Complex, 40 WF_ITime, 41 WF_DateInt32, 42 WF_DateFloat64, 43 WF_POSIXct, 44 WF_Nanotime, 45 WF_String, 46 WF_CategString, 47 WF_List 48 } WFs; 49 50 static const int writerMaxLen[] = { // same order as fun[] and WFs above; max field width used for calculating upper bound line length 51 5, //&writeBool8 "false" 52 5, //&writeBool32 "false" 53 5, //&writeBool32AsString "false" 54 11, //&writeInt32 "-2147483647" 55 20, //&writeInt64 "-9223372036854775807" 56 29, //&writeFloat64 "-3.141592653589793115998E-123" [max sf 22 consistent with options()$digits] 57 60, //&writeComplex "-3.141592653589793115998E-123+2.7182818284590450907956i" [3x writeFloat64,+,i] 58 32, //&writeITime 59 16, //&writeDateInt32 60 16, //&writeDateFloat64 61 32, //&writePOSIXct 62 48, //&writeNanotime 63 0, //&writeString 64 0, //&writeCategString 65 0, //&writeList 66 }; 67 68 typedef struct fwriteMainArgs 69 { 70 // Name of the file to open (a \0-terminated C string). If the file name 71 // contains non-ASCII characters, it should be UTF-8 encoded (however fread 72 // will not validate the encoding). 73 const char *filename; 74 int ncol; 75 int64_t nrow; 76 // a vector of pointers to all-same-length column vectors 77 const void **columns; 78 writer_fun_t *funs; // a vector of writer_fun_t function pointers 79 80 // length ncol vector containing which fun[] to use for each column 81 // one byte to use 8 times less cache lines than a vector of function pointers would do 82 // A limit of 256 writers seems more than sufficient 83 uint8_t *whichFun; 84 85 const void *colNames; // NULL means no header, otherwise ncol strings 86 bool doRowNames; // optional, likely false 87 const void *rowNames; // if doRowNames is true and rowNames is not NULL then they're used, otherwise row numbers are output. 88 char sep; 89 char sep2; 90 char dec; 91 const char *eol; 92 const char *na; 93 94 // The quote character is always " (ascii 34) and cannot be changed since nobody on Earth uses a different quoting character, surely 95 // doQuote controls whether to quote fields or not. NA=="auto" (default) means the contents are inspected to see if sep, eol or quote 96 // is present and if so, quotes the filed. Else 1=quote all fields, 0=no quoting even when sep is present 97 int8_t doQuote; 98 99 bool qmethodEscape; // true means escape quotes using backslash, else double-up double quotes. 100 int scipen; // same as options('scipen') in R -- used to penalize scientific notation when 101 // deciding to write scientific or full decimal format (e.g. in comparing 102 // 10000000 to 1e+07, first has width 8, second has width 5; prefer the former 103 // iff scipen >= 3=8-5 104 bool squashDateTime; 105 bool append; 106 int buffMB; // [1-1024] default 8MB 107 int nth; 108 bool showProgress; 109 bool is_gzip; 110 bool bom; 111 const char *yaml; 112 bool verbose; 113 } fwriteMainArgs; 114 115 void fwriteMain(fwriteMainArgs args); 116 117