# Generator - a Inkscape extension to generate end-use files from a model
# Copyright (C) 2008 Aurélio A. Heckert
#
+# Added CSV parser from
+# http://fixunix.com/unix/83523-how-do-i-read-split-derive-csv-using-bash-script.html
+# by Chris F.A. Johnson <cfaj@freeshell.org> http://cfaj.freeshell.org
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
exit 1
fi
-function sep_line {
- sed 's/^\([^"]*\("[^"]*"[^"]*\)*"[^"]*\),/\1#COMMAHACK#/g' |
- sed 's/,/\n/g' | sed "s/\"\"/\"/g; s/^['\"]\|['\"]$//g"
+#function sep_line {
+# sed 's/^\([^"]*\("[^"]*"[^"]*\)*"[^"]*\),/\1#COMMAHACK#/g' |
+# sed 's/,/\n/g' | sed "s/\"\"/\"/g; s/^['\"]\|['\"]$//g"
+#}
+
+function csv_split() { ## USAGE: csv_split CSV_RECORD
+ local record=${1%"${CR}"}
+ local right
+ local vnum=0
+ unset values
+ while [ -n "$record" ]
+ do
+
+ case $record in
+ \"*) right=${record#*\",}
+ value=${record%%\",*}
+ values[$vnum]=${value#\"}
+ ;;
+ *) values[$vnum]=${record%%,*}
+ right=${record#*,}
+ ;;
+ esac
+
+ case $record in
+ *,*) record=${right} ;;
+ *) record=${record#\"}
+ values[$vnum]=${record%\"}
+ break;;
+ esac
+
+ echo ${values[$vnum]}
+
+ vnum=$(( $vnum + 1 ))
+
+ done
}
# Set column names:
eval "$(
col=0
- head --lines=1 "$data_file" | sep_line |
+ csv_split `head --lines=1 "$data_file"` |
while read name; do
let col++
if [ "$var_type" == "name" ]; then
while read line; do
col=0
replace="$(
- echo "$line" | sep_line |
+ csv_split "$line" |
while read val; do
let col++
echo -n "s/%VAR_${col_name[$col]}%/$(