aboutsummaryrefslogtreecommitdiff
path: root/sc2csv
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-09-18 16:38:09 -0300
committerSilvio Rhatto <user@example.org>2014-09-18 16:38:09 -0300
commitc8240eaeba261304a000103c9524e15f4a29c492 (patch)
tree0613665bcc3c5db54836231f55e64213f2a17ca1 /sc2csv
downloadutils-spreadsheet-c8240eaeba261304a000103c9524e15f4a29c492.tar.gz
utils-spreadsheet-c8240eaeba261304a000103c9524e15f4a29c492.tar.bz2
Initial import
Diffstat (limited to 'sc2csv')
-rwxr-xr-xsc2csv73
1 files changed, 73 insertions, 0 deletions
diff --git a/sc2csv b/sc2csv
new file mode 100755
index 0000000..2f2fae5
--- /dev/null
+++ b/sc2csv
@@ -0,0 +1,73 @@
+#!/usr/bin/gawk -f
+#
+# sc2csv ver. 0.1 (2001/12/4)
+# Copyright (C) 2001 SIGEHUZI Tomoo (tomoo@s.email.ne.jp)
+
+function pos(s, n, a) {
+ sub(/[0-9]*$/, " &", s);
+ n = split(s, a);
+ if (n != 2) return 1;
+ J = a[2];
+ s = a[1];
+ n = split(s, a, "");
+ if (n < 1) return 1;
+ I = 0;
+ for (i = 1; i <= n; i++) {
+ if (a[i] !~ /^[A-Z]$/) return 1;
+ I = I * 26 + v[a[i]];
+ }
+ if (I > N[J]) N[J] = I;
+ return 0;
+}
+
+
+function invalid_line() {
+ print "Invalid line:", $0 > "/dev/stderr";
+ exit(1);
+}
+
+
+BEGIN {
+ nap = split("ABCDEFGHIJKLMNOPQRSTUVWXYZ", ap, "");
+ for (i = 1; i <= nap; i++) v[ap[i]] = i - 1;
+}
+
+
+/^\#/ {next;}
+
+
+/^goto / {next;}
+
+
+{
+ if (NF == 0) next;
+ if ($1 ~ /^fmt$/) next;
+ if (pos($2) || $3 != "=") invalid_line();
+ val = $0;
+ sub(/^[^=]*= /, "", val);
+ if ($1 == "let") {
+ if (val ~ /^@dts\([0-9]*,[0-9]*,[0-9]*\)$/) {
+ split(substr(val, 6, length(val) - 6), date, ",");
+ a[I,J] = sprintf("%d/%d/%d", date[1], date[2], date[3]);
+ }
+ else a[I,J] = val;
+ }
+ else if ($1 ~ /^(left|right)string$/) {
+ if (val ~ /^".*"$/) {
+ s = substr(val, 2, length(val) - 2);
+ gsub(/\\t/, "\t", s);
+ gsub(/\\n/, "\n", s);
+ gsub(/\\"/, "\"\"", s);
+ a[I,J] = (s ~ /[,"\n\t]/) ? sprintf("\"%s\"", s) : s;
+ }
+ else a[I,J] = val; # Much left to be done.
+ }
+ else invalid_line();
+}
+
+END {
+ for (j = 0; j <= J; j++) {
+ for (i = 0; i < N[j]; i++) printf("%s,", a[i,j]);
+ print a[i,j];
+ }
+}