3 # assign var value -- find var in window and replace its old value with the new one
4 # variables are words made of letters, numbers, and/or _, followed by '=' and, optionally, a number
6 if (echo -n '/(^|[^a-zA-Z0-9_])'$1' *= */+#0;/[0-9.e+\-]*/'|9p write acme/7/addr >[2] /dev/null) {
7 echo -n 'dot=addr'|9p write acme/7/ctl
8 echo -n $2 | 9p write acme/7/data
10 if not echo 'Could not find variable:' $1
13 # copy calc commands from window into /tmp/cmd
14 9p read acme/$winid/body|sed -e '/^#!/,$p;d'>/tmp/cmd
18 # extract variables and values from window
19 sed -n -e '/^#!/q;s/([a-zA-Z0-9_]+) *= *([0-9.e+\-]*)/\n\1=\2\n/g;h;:v;s/\n(.|\n)*//;s/^[a-zA-Z0-9_]+=$/&0/;/^[a-zA-Z0-9_]+=[0-9.e+\-]*/p;g;/\n/!d;s/[^\n]*\n//;h;bv' |
20 # pipe vars (VAR=VALUE) to command
22 # parse vars from commmand and convert to "assign" calls (above function)
23 awk '{loc=index($0, "=");print "assign (" substr($0, 1, loc - 1) ") (" substr($0, loc + 1) ")"}' |
24 # pipe assign commands to rc to plug the values back into the window
26 if (test -s /tmp/cmd.errs) 9p write acme/$winid/errors < /tmp/cmd.errs