From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from oldp.astro.wisc.edu ([128.104.39.15]) by hawkwind.utcs.toronto.edu with SMTP id <2706>; Wed, 26 May 1993 14:32:49 -0400 Received: by oldp.astro.wisc.edu (5.65/DEC-Ultrix/4.3) id AA07844; Wed, 26 May 1993 12:26:57 -0500 Message-Id: <9305261726.AA07844@oldp.astro.wisc.edu> To: culliton@srg.srg.af.mil (Tom Culliton x2278) Subject: Re: wishlist Cc: rc@hawkwind.utcs.toronto.edu Date: Wed, 26 May 1993 13:26:56 -0400 From: Alan Watson X-Mts: smtp You can't use sed, as you don't know how much it buffers stuff up internally. Same with awk. You cannot use ifs = $nl { foo = `{ cat } }, as you lose blank lines and cannot tell if the final line ends in a $nl or not. I had enough of that kind of stuff I coded this up in about 10 minutes last night -- it works as a technology demonstrator, but (a) the C code needs re-writing to read N chars first and then one char at a time until the end of the line, and (b) it all needs some better error checking. bufread reads a line at a time into the variable, including any trailing newline, and sets the variable to () at EOF. Hope this helps you get a start, Alan. fn copy { @ { exec <$1 >$2 while ( bufread line ibuf && ! ~ $#line 0 ) bufwrite line obuf bufflush obuf } } fn bufread { _var = $1 _buf = $2 { if ( ~ $#$_buf 0 ) { ifs = () { eval '*' '=' `{ ./buffill } } } else { * = $$_buf } $_var = $1 if ( ! ~ $#* 0 ) shift $_buf = $* } } fn bufwrite { _var = $1 _buf = $2 { if ( ~ $#$_buf 4 ) { bufflush $_buf $_buf = () } $_buf = ( $$_buf $$_var ) } } fn bufflush { _buf = $1 _text = () { * = $$_buf while ( ! ~ $#* 0 ) { _text = $text^$1 shift } echo -n $text } } buffill.c: #include #define N 256 #define writestr(fd,s) (write ((fd),(s), sizeof (s) - 1)) int main () { char c; char lastc; int n; writestr (1, "( "); n = 0; while (n < N || c != '\n') { if (read (0, &c, 1) != 1) break; if (n == 0 || lastc == '\n') writestr (1, "'"); if (c == '\'') writestr (1, "''"); else if (c == '\n') writestr (1, "\n' "); else write (1, &c, 1); lastc = c; n++; } if (n != 0 && c != '\n') writestr (1, "' "); writestr (1, ")"); return 0; }