rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
From: culliton@srg.af.mil (Tom Culliton x2278)
To: alan@oldp.astro.wisc.edu, rc@hawkwind.utcs.toronto.edu
Subject: Re: wishlist
Date: Wed, 26 May 1993 12:59:40 -0400	[thread overview]
Message-ID: <9305261259.aa03721@ceres.srg.af.mil> (raw)

Alan finds a reason why he doesn't need read:

> So, there I was, walking home after work, muttering under my breath,
> and mulling over the analogy between rc having to exec to read a line
> and C having to perform a system call to read a char.  I though I had
> the clincher in this argument.  Then it dawned on me -- we can use
> buffered IO in rc (read many lines with one exec) exactly as we do in C
> (read many chars with one system call).

Strangely enough it was thoughts along this line that that convinced me
that read might be a good idea!  My first thought was that if execing
for each line was too slow why not just do something like this:

	buf = ``($nl) { cat }

And then just step through the list in any of the usual ways.  Of course
the problem is that even rc may not be able to stuff the whole file into
the environment, other programs could choke big time, and it would slow
down forking.  The next step is to get clever and use sed to grab
chunks:

	eof=()
	buf = ``($nl) { sed 20q }
	if (~ $#buf 0) eof = 1;

Of course this is also going to bloat the environment, albeit to a
lesser extent, with the buffer, code to fetch from the buffer and
transparently refill it when it empties, not to mention code to reset
the buffer, etc.  (I may write this up and post it later.)

In shell scripts read is used for two different purposes, getting one
line from a user, or chewing through a theoretically infinite input
stream one line at a time.  In the first case efficiency is usually not
a concern, but in the second case it obviously is.  The fact that the
same generalized facility would serve both cases well, and that these
are fairly common things to do, seem like a good argument for adding
read. (or something like it)

Tom


             reply	other threads:[~1993-05-26 18:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-05-26 16:59 Tom Culliton x2278 [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 17:26 wishlist Alan Watson
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=9305261259.aa03721@ceres.srg.af.mil \
    --to=culliton@srg.af.mil \
    --cc=alan@oldp.astro.wisc.edu \
    --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).