-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCsv.c
51 lines (42 loc) · 834 Bytes
/
Csv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Comma separated value database format scanner
*/
#include "sunclock.h"
static char *csptr; // CSV scan pointer
/* CSVSCANINIT -- Initialise scanning of a CSV record. */
void CSVscanInit(char *s)
{
csptr = s;
}
/* CSVSCANFIELD -- Scan next field from a CSV record. */
int CSVscanField(char *f)
{
int foundfield = FALSE;
if (*csptr != EOS) {
foundfield = TRUE;
if (*csptr == '"') {
csptr++;
while (*csptr != EOS) {
if (*csptr == '"') {
if (csptr[1] == '"') {
*f++ = '"';
csptr += 2;
} else {
csptr++;
break;
}
} else {
*f++ = *csptr++;
}
}
}
while (*csptr != ',' && *csptr != EOS) {
*f++ = *csptr++;
}
if (*csptr == ',') {
csptr++;
}
}
*f++ = EOS;
return foundfield;
}