56 #define ST_TAILSPACE 3
57 #define ST_END_QUOTE 4
58 #define istspace iswspace
74 snextch(
struct sinput* in) {
78 if ((ch = fgetc(in->in)) == EOF) {
80 GERB_MESSAGE(
"errno:%d", errno);
89 ch = (
unsigned char)*(in->src)++;
98 wnextch(
struct winput* in) {
112 csv_parse_str(
struct sinput* in,
char* buf,
size_t bn,
char* row[],
int rn,
int sep,
int flags) {
113 int trim, quotes, ch, state, r, j, t, inquotes;
115 trim = flags & CSV_TRIM;
116 quotes = flags & CSV_QUOTES;
121 memset(row, 0,
sizeof(
char*) * rn);
123 while (rn && bn && (ch = snextch(in)) > 0) {
126 if (ch !=
'\n' && ch != sep && isspace(ch)) {
133 }
else if (quotes && ch ==
'"') {
143 state = ST_END_QUOTE;
146 }
else if (ch == sep || ch ==
'\n') {
160 }
else if (quotes && ch ==
'"') {
162 GERB_MESSAGE(_(
"%d: unexpected quote in element"), errno);
167 if (!trim || isspace(ch) == 0) {
173 if (ch == sep || ch ==
'\n') {
186 }
else if (quotes && ch ==
'"' && state != ST_TAILSPACE) {
192 }
else if (isspace(ch)) {
193 state = ST_TAILSPACE;
197 GERB_MESSAGE(_(
"%d: bad end quote in element"), errno);
204 if (state == ST_TAILSPACE || state == ST_END_QUOTE || (state == ST_COLLECT && !inquotes)) {
219 GERB_MESSAGE(
"E2BIG %d ", errno);
225 GERB_MESSAGE(
"EILSEQ %d ", errno);
239 csv_parse_wcs(
struct winput* in,
wchar_t* buf,
size_t bn,
wchar_t* row[],
int rn, wint_t sep,
int flags) {
240 int trim, quotes, state, r, j, t, inquotes;
243 trim = flags & CSV_TRIM;
244 quotes = flags & CSV_QUOTES;
249 memset(row, 0,
sizeof(
wchar_t*) * rn);
251 while (rn && bn && (ch = wnextch(in)) > 0) {
254 if (ch != L
'\n' && ch != sep && iswspace(ch)) {
261 }
else if (quotes && ch == L
'"') {
271 state = ST_END_QUOTE;
274 }
else if (ch == sep || ch == L
'\n') {
287 }
else if (quotes && ch == L
'"') {
289 GERB_MESSAGE(_(
"%d: unexpected quote in element"), errno);
294 if (!trim || iswspace(ch) == 0) {
300 if (ch == sep || ch == L
'\n') {
313 }
else if (quotes && ch == L
'"' && state != ST_TAILSPACE) {
319 }
else if (iswspace(ch)) {
320 state = ST_TAILSPACE;
324 GERB_MESSAGE(_(
"%d: bad end quote in element "), errno);
331 if (state == ST_TAILSPACE || state == ST_END_QUOTE || (state == ST_COLLECT && !inquotes)) {
346 GERB_MESSAGE(
"%d", errno);
352 GERB_MESSAGE(
"%d", errno);
363 csv_row_parse_wcs(
const wchar_t* src,
size_t sn,
wchar_t* buf,
size_t bn,
wchar_t* row[],
int rn,
int sep,
int trim) {
368 return csv_parse_wcs(&input, buf, bn, row, rn, (wint_t)sep, trim);
372 csv_row_parse_str(
const char* src,
size_t sn,
char* buf,
size_t bn,
char* row[],
int rn,
int sep,
int trim) {
378 return csv_parse_str(&input, buf, bn, row, rn, sep, trim);
382 csv_row_fread(FILE* in,
char* buf,
size_t bn,
char* row[],
int numcols,
int sep,
int trim) {
386 return csv_parse_str(&input, buf, bn, row, numcols, sep, trim);
Header info for the parsing support functions for the pick and place parser.
Sets up internal definitions for handling csv-style files.
The main header file for the libgerbv library.