fixed LICENSE
[bills-tools.git] / calc / calcgo
blob424a36e394dab7c3360e2a7b770ed9df6e06fb60
1 #!/usr/bin/env rc
3 # calc, (c) Oct, 2010, by Bill Burdick
4 # licensed with the ZLIB license (see the LICENSE file)
6 compile=8g
7 link=8l
8 base=/tmp/calcscript
9 errs=$1^.errs
10 script=$base^.go
11 oldVals=''
12 newVals=''
13 file=$1
14 *=()
15 while (line=`{read}) {
16         var=`{echo $line|sed -e 's/^([^=]*)=.*$/\1/'}
17         value=`{echo $line|sed -e 's/^[^=]*=(.*)$/\1/'}
18         *=($* $var $value)
19         if (! ~ $oldVals '') {
20                 oldVals=$"oldVals', '
21                 newVals=$"newVals', '
22         }
23         oldVals=$"oldVals'"'$var'" : '$"value
24         newVals=$"newVals'"'$var'" : '$var
26 cat <<here > $script
27 package main
28 import . "fmt"
29 here
30 if (grep '//BODY' $file > /dev/null) {
31     awk '/\/\/BODY/{exit}skipped{print}!skipped{skipped=1}' < $file >> $script
33 cat <<here >> $script
34 func main() {
35 here
36 while (! ~ $#* 0) {
37         echo (' '$1^' := float64('$2')') >> $script
38         shift 2
40 if (grep '//BODY' $file > /dev/null) {
41     awk 'yes{print}/\/\/BODY/{yes=1}' < $file >> $script
43 if not {
44     <$file{
45         read>/dev/null
46         cat >> $script
47     }
49 cat<<here >> $script
50         func() {
51                 oldVars := map[string]float64{$oldVals}
52                 for k, v := range map[string]float64{$newVals} {
53                         if v != oldVars[k] {
54                                 Println(k, "=", v)
55                         }
56                 }
57         }()
59 here
60 $compile -o $base^.8 $script > $errs && $link -o $base $base^.8 >> $errs && $base