From mboxrd@z Thu Jan 1 00:00:00 1970 From: erik quanstrom Date: Thu, 13 May 2010 09:24:47 -0400 To: 9fans@9fans.net Message-ID: <158d5dc0571fa04cab44a99b3fdf5921@kw.quanstro.net> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: Re: [9fans] hoc output format Topicbox-Message-UUID: 202ba602-ead6-11e9-9d60-3106f5b1d025 On Thu May 13 03:51:56 EDT 2010, santucco@gmail.com wrote: > Yes, I'm agree, but with one exception - awk(1) separates a data from a > code, hoc(1) doesn't do it. So hoc(1) can be used for plain calculation > tasks, not for processing input files with a data. both awk and hoc accept standard input echo 1 + 2 | hoc # (sic, see below) echo 1 2 | hoc -e '{while(read(x) != 0)y += x' ^ $nl ^ ' print y, "\n"}' - echo 1 2 | awk '{for(i = 1; i <= NF; i++) x+= $i}END{print x}' or execute directly from the command line hoc -e '1 + 2' awk 'BEGIN{print 1 + 2; exit}' note that the wierd extra {} are required for hoc. hoc read requests are satisfied from the same file descriptor as the data. so the input needs to be exhausted before read runs. also, the trailing newline on the input is required, since Bgetd() won't accept '1'. this seems like a bug induced by the fact that charstod has one argument too few. if it also returned the number of characters consumed, Bgetd could read int Bgetd(Biobufhdr *bp, double *dp) { double d; struct bgetd b; b.b = bp; b.eof = 0; > b.nchr = 0; > d = charstod(Bgetdf, &b, &n); > if(b.eof || b.nchr != n) return -1; Bungetc(bp); *dp = d; return 1; } - erik