From: Alan Watson <alan@oldp.astro.wisc.edu>
To: culliton@srg.srg.af.mil (Tom Culliton x2278)
Cc: rc@hawkwind.utcs.toronto.edu
Subject: Re: wishlist
Date: Wed, 26 May 1993 13:26:56 -0400 [thread overview]
Message-ID: <9305261726.AA07844@oldp.astro.wisc.edu> (raw)
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 <unistd.h>
#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;
}
next reply other threads:[~1993-05-26 18:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
1993-05-26 17:26 Alan Watson [this message]
-- strict thread matches above, loose matches on Subject: below --
1993-05-26 17:49 wishlist Tom Culliton x2278
1993-05-26 17:29 wishlist Alan Watson
1993-05-26 16:59 wishlist Tom Culliton x2278
1993-05-26 6:57 wishlist Bengt KLEBERG
1993-05-26 17:51 ` wishlist Chris Siebenmann
1993-05-26 19:04 ` wishlist mycroft
1993-05-26 3:08 wishlist Alan Watson
1993-05-26 3:02 wishlist Byron Rakitzis
1993-05-26 3:06 ` wishlist Scott Schwartz
1993-05-25 23:58 wishlist Tom Culliton x2278
1993-05-25 21:29 wishlist Alan Watson
[not found] <alan@oldp.astro.wisc.edu>
1993-05-25 6:55 ` wishlist malte
1993-05-25 9:16 ` wishlist John Mackin
1993-05-25 1:43 wishlist Alan Watson
1993-05-24 16:13 wishlist Erik Quanstrom
1993-05-24 15:17 wishlist Tom Culliton x2278
1993-05-22 0:43 wishlist Scott Schwartz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9305261726.AA07844@oldp.astro.wisc.edu \
--to=alan@oldp.astro.wisc.edu \
--cc=culliton@srg.srg.af.mil \
--cc=rc@hawkwind.utcs.toronto.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).