initial commit
[bills-tools.git] / calc / calcgo
blobec0938c88df8f9c4c6f004eaad64ebed25b6f68a
1 #!/usr/bin/env rc
2 compile=8g
3 link=8l
4 base=/tmp/calcscript
5 errs=$1^.errs
6 script=$base^.go
7 oldVals=''
8 newVals=''
9 file=$1
10 *=()
11 while (line=`{read}) {
12         var=`{echo $line|sed -e 's/^([^=]*)=.*$/\1/'}
13         value=`{echo $line|sed -e 's/^[^=]*=(.*)$/\1/'}
14         *=($* $var $value)
15         if (! ~ $oldVals '') {
16                 oldVals=$"oldVals', '
17                 newVals=$"newVals', '
18         }
19         oldVals=$"oldVals'"'$var'" : '$"value
20         newVals=$"newVals'"'$var'" : '$var
22 cat <<here > $script
23 package main
24 import . "fmt"
25 func main() {
26 here
27 while (! ~ $#* 0) {
28         echo (' '$1^' := float64('$2')') >> $script
29         shift 2
31 <$file{
32 read>/dev/null
33 cat >> $script
35 cat<<here >> $script
36         func() {
37                 oldVars := map[string]float64{$oldVals}
38                 for k, v := range map[string]float64{$newVals} {
39                         if v != oldVars[k] {
40                                 Println(k, "=", v)
41                         }
42                 }
43         }()
45 here
46 $compile -o $base^.8 $script > $errs && $link -o $base $base^.8 >> $errs && $base