added LICENSE files
[bills-tools.git] / calc / calcgo
Commit [+]AuthorDateLineData
a99794b5 Bill Burdick2010-10-22 13:30:30 +02001#!/usr/bin/env rc
2732974c
BB
Bill Burdick2010-10-22 13:35:42 +02002
3# calc, (c) Oct, 2010, by Bill Burdick
4# licensed with the ZLIB license (see the LICENSE file)
5
a99794b5
BB
Bill Burdick2010-10-22 13:30:30 +02006compile=8g
7link=8l
8base=/tmp/calcscript
9errs=$1^.errs
10script=$base^.go
11oldVals=''
12newVals=''
13file=$1
14*=()
15while (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
25}
26cat <<here > $script
27package main
28import . "fmt"
6bbf4186
BB
Bill Burdick2010-11-09 17:02:18 +020029here
30if (grep '//BODY' $file > /dev/null) {
31 awk '/\/\/BODY/{exit}skipped{print}!skipped{skipped=1}' < $file >> $script
32}
33cat <<here >> $script
a99794b5
BB
Bill Burdick2010-10-22 13:30:30 +020034func main() {
35here
36while (! ~ $#* 0) {
37 echo (' '$1^' := float64('$2')') >> $script
38 shift 2
39}
6bbf4186
BB
Bill Burdick2010-11-09 17:02:18 +020040if (grep '//BODY' $file > /dev/null) {
41 awk 'yes{print}/\/\/BODY/{yes=1}' < $file >> $script
42}
43if not {
44 <$file{
45 read>/dev/null
46 cat >> $script
47 }
a99794b5
BB
Bill Burdick2010-10-22 13:30:30 +020048}
49cat<<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 }()
58}
59here
60$compile -o $base^.8 $script > $errs && $link -o $base $base^.8 >> $errs && $base