| 1 | /* | 
| 2 |  * This Source Code Form is subject to the terms of the Mozilla Public | 
| 3 |  * License, v. 2.0.  If a copy of the MPL was not distributed with this | 
| 4 |  * file, You can obtain one at http://mozilla.org/MPL/2.0/. | 
| 5 |  * | 
| 6 |  * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. | 
| 7 |  */ | 
| 8 |  | 
| 9 | /* | 
| 10 |  * @+ Implementation | 
| 11 |  * The implementation needs the stream abstraction, which also provides | 
| 12 |  * primitives to compress/decompress files on the fly. | 
| 13 |  * The file can plain ASCII, gzipped or bzipped, decided by the extention | 
| 14 |  * (none, gz or bz2). The default is plain ASCII, which is formatted to | 
| 15 |  * pre presented on the screen directly. | 
| 16 |  */ | 
| 17 | #ifndef _TABLET_IO2_H_ | 
| 18 | #define _TABLET_IO2_H_ | 
| 19 |  | 
| 20 | /* #define _DEBUG_TABLET_ */ | 
| 21 |  | 
| 22 | #include "gdk.h" | 
| 23 | #include "mal_exception.h" | 
| 24 | #include "mal_client.h" | 
| 25 | #include "mal_interpreter.h" | 
| 26 |  | 
| 27 | typedef struct Column_t { | 
| 28 | 	const char *name;			/* column title */ | 
| 29 | 	const char *sep; | 
| 30 | 	const char *rsep; | 
| 31 | 	int seplen; | 
| 32 | 	char *type; | 
| 33 | 	int adt;					/* type index */ | 
| 34 | 	BAT *c;						/* set to NULL when scalar is meant */ | 
| 35 | 	BATiter ci; | 
| 36 | 	BUN p; | 
| 37 | 	unsigned int tabs;			/* field size in tab positions */ | 
| 38 | 	const char *nullstr;		/* null representation */ | 
| 39 | 	size_t null_length;			/* its length */ | 
| 40 | 	unsigned int width;			/* actual column width */ | 
| 41 | 	unsigned int maxwidth;		/* permissible width */ | 
| 42 | 	int fieldstart;				/* Fixed character field load positions */ | 
| 43 | 	int fieldwidth; | 
| 44 | 	int scale, precision; | 
| 45 | 	ssize_t (*tostr)(void *, char **buf, size_t *len, int type, const void *a); | 
| 46 | 	void *(*frstr)(struct Column_t *fmt, int type, const char *s); | 
| 47 | 	void *extra; | 
| 48 | 	void *data; | 
| 49 | 	int skip;					/* only skip to the next field */ | 
| 50 | 	size_t len; | 
| 51 | 	bit ws;						/* if set we need to skip white space */ | 
| 52 | 	char quote;					/* if set use this character for string quotes */ | 
| 53 | 	const void *nildata; | 
| 54 | 	int size; | 
| 55 | } Column; | 
| 56 |  | 
| 57 | /* | 
| 58 |  * All table printing is based on building a report structure first. | 
| 59 |  * This table structure is private to a client, which made us to | 
| 60 |  * keep it in an ADT. | 
| 61 |  */ | 
| 62 |  | 
| 63 | typedef struct Table_t { | 
| 64 | 	BUN offset; | 
| 65 | 	BUN nr;						/* allocated space for table loads */ | 
| 66 | 	BUN nr_attrs;				/* attributes found sofar */ | 
| 67 | 	Column *format;				/* remove later */ | 
| 68 | 	str error;					/* last error */ | 
| 69 | 	int tryall;					/* skip erroneous lines */ | 
| 70 | 	str filename;				/* source */ | 
| 71 | 	BAT *complaints;			/* lines that did not match the required input */ | 
| 72 | } Tablet; | 
| 73 |  | 
| 74 | mal_export BUN SQLload_file(Client cntxt, Tablet *as, bstream *b, stream *out, const char *csep, const char *rsep, char quote, lng skip, lng maxrow, int best, bool from_stdin, const char *tabnam); | 
| 75 | mal_export str TABLETcreate_bats(Tablet *as, BUN est); | 
| 76 | mal_export str TABLETcollect(BAT **bats, Tablet *as); | 
| 77 | mal_export str TABLETcollect_parts(BAT **bats, Tablet *as, BUN offset); | 
| 78 | mal_export void TABLETdestroy_format(Tablet *as); | 
| 79 | mal_export int TABLEToutput_file(Tablet *as, BAT *order, stream *s); | 
| 80 | mal_export str COPYrejects(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); | 
| 81 | mal_export str COPYrejects_clear(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); | 
| 82 |  | 
| 83 | #endif | 
| 84 |  |