Introduction
Introduction Statistics Contact Development Disclaimer Help
Initial commit - csvtofsv - Convert CSV to FSV (`fs' (0x1c) as FS and `rs' (0x1…
hg clone https://bitbucket.org/iamleot/csvtofsv
Log
Files
Refs
README
---
changeset fe779850f664a14c83dd752e6f64cb81a4a19ef6
Author: Leonardo Taccari <[email protected]>
Date: Tue, 25 Jun 2019 10:48:52
Initial commit
Diffstat:
csvtofsv.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
t/01.csv | 2 +
t/01.fsv | 1 +
t/02.csv | 8 +++++++
t/02.fsv | 2 +
5 files changed, 76 insertions(+), 0 deletions(-)
---
diff -r 000000000000 -r fe779850f664 csvtofsv.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/csvtofsv.c Tue Jun 25 10:48:52 2019 +0200
@@ -0,0 +1,63 @@
+#include <stdbool.h>
+#include <stdio.h>
+
+#define FS 034
+#define RS 036
+
+int
+main(int argc, char *argv[])
+{
+ int c, nc;
+ bool first, quoted;
+
+ first = true;
+ quoted = false;
+ while ((c = getchar()) != EOF) {
+ switch (c) {
+ case '"':
+ if (first) {
+ quoted = true;
+ first = false;
+ } else if ((nc = getchar()) != EOF) {
+ if (quoted && nc == '"') {
+ putchar('"');
+ } else if (quoted && nc == ',') {
+ putchar(FS);
+ first = true;
+ quoted = false;
+ } else if (quoted && nc == '\n') {
+ putchar(RS);
+ first = true;
+ quoted = false;
+ } else {
+ ungetc(nc, stdin);
+ }
+ }
+ break;
+ case ',':
+ if (quoted) {
+ putchar(',');
+ } else {
+ putchar(FS);
+ first = true;
+ }
+ break;
+ case '\n':
+ if (quoted) {
+ putchar('\n');
+ } else {
+ putchar(RS);
+ first = true;
+ }
+ break;
+ case '\r':
+ /* ignore */
+ break;
+ default:
+ putchar(c);
+ break;
+ }
+ }
+
+ return 0;
+}
diff -r 000000000000 -r fe779850f664 t/01.csv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/t/01.csv Tue Jun 25 10:48:52 2019 +0200
@@ -0,0 +1,2 @@
+1,2,3,4
+one,two,three,four
diff -r 000000000000 -r fe779850f664 t/01.fsv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/t/01.fsv Tue Jun 25 10:48:52 2019 +0200
@@ -0,0 +1,1 @@
+1
2
3
4
one
two
three
four
\ No newline at end of file
diff -r 000000000000 -r fe779850f664 t/02.csv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/t/02.csv Tue Jun 25 10:48:52 2019 +0200
@@ -0,0 +1,8 @@
+"",,
+empty,empty,empty
+" "," ","
+"
+space,tab,newline
+"quoted text","""really "" quoted""",not quoted
+"""",",",",,"
+quote,comma,two commas
diff -r 000000000000 -r fe779850f664 t/02.fsv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/t/02.fsv Tue Jun 25 10:48:52 2019 +0200
@@ -0,0 +1,2 @@
+
empty
empty
empty
+
space
tab
newline
quoted text
"really " quoted"
not quoted
"
,
,,
quote
comma
two commas
\ No newline at end of file
You are viewing proxied material from tccr.it. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.