aboutsummaryrefslogtreecommitdiff
path: root/csv2sc
diff options
context:
space:
mode:
Diffstat (limited to 'csv2sc')
-rwxr-xr-xcsv2sc76
1 files changed, 76 insertions, 0 deletions
diff --git a/csv2sc b/csv2sc
new file mode 100755
index 0000000..8efb54b
--- /dev/null
+++ b/csv2sc
@@ -0,0 +1,76 @@
+#!/usr/bin/gawk -f
+#
+# csv2sc ver. 0.1 (2001/12/4)
+# Copyright (C) 2001 SIGEHUZI Tomoo (tomoo@s.email.ne.jp)
+
+function is_date(s) {
+ if (split(s, date, "/") != 3) return 0;
+ if (date[1] !~ /(19|20)?[0-9][0-9]/) return 0;
+ if (date[2] !~ /(0?[1-9]|1[012])/) return 0;
+ if (date[2] !~ /(0?[1-9]|[12][0-9]|3[01])/) return 0;
+ return 1;
+}
+
+function i_index(n, i, s) {
+ s = "";
+ for (s = ""; ; n = (n - i) / nix - 1) {
+ i = n % nix;
+ s = sprintf("%s%s", ix[i], s);
+ if (n < 1) break;
+ }
+ return s;
+}
+
+BEGIN {
+ nix = split("BCDEFGHIJKLMNOPQRSTUVWXYZ", ix, "") + 1;
+ ix[0] = "A";
+}
+
+{
+ s = sprintf("%s%s", s, $0);
+ np += gsub(/"/, "\a");
+ if (np % 2) {
+ s = sprintf("%s\n", s);
+ next;
+ }
+ m = n = split(s, a, ",");
+
+ np = 0;
+ s = "";
+ for (i = j = 1; i <= n; i++) {
+ s = sprintf("%s%s", s, a[i]);
+ np += gsub(/"/, "\a", a[i]);
+ if (np % 2) {
+ s = sprintf("%s,", s);
+ continue;
+ }
+ np = 0;
+ a[j++] = s;
+ s = "";
+ }
+ n = j - 1;
+ for (i = 1; i <= n; i++) {
+ s = a[i];
+ sub(/^"/, "", s);
+ sub(/"$/, "", s);
+ gsub(/\\/, "\\\\", s);
+ gsub(/""/, "\\\"", s);
+ gsub(/\n/, "\\n", s);
+ gsub(/\t/, "\\t", s);
+ a[i] = s;
+ }
+
+ for (i = 1; i <= n; i++) {
+ s = a[i];
+ I = i_index(i - 1);
+ if (s ~ /^[0-9.]+$/) printf("let %s%d = %s\n", I, J, s);
+ else if (is_date(s))
+ printf("let %s%d = @dts(%d,%d,%d)\nfmt %s%d \"\004%%Y/%%m/%%d\"\n",
+ I, J, date[1], date[2], date[3], I, J);
+ else printf("leftstring %s%d = \"%s\"\n", I, J, s);
+ }
+
+ J++;
+ np = 0;
+ s = "";
+}