9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: smiley@zenzebra.mv.com
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] Making read(1) an rc(1) builtin?
Date: Mon,  4 Apr 2011 21:35:26 +0000	[thread overview]
Message-ID: <86vcythf8h.fsf@cmarib.ramside> (raw)
In-Reply-To: <BANLkTik=fh5sAr5cR+PRNGD+LJETeOgyqA@mail.gmail.com> (roger peppe's message of "Mon, 4 Apr 2011 10:26:39 +0100")

roger peppe <rogpeppe@gmail.com> writes:

> when i've needed a "-n safe" version of echo in
> the past, i've used something like this:
>
> fn myecho {echo -n $"* ^ '
> '}

That doesn't work right when (~ $#* 0).  It outputs a rogue space prior
to the newline.  echo, with no arguments, should ouput just a newline.


"Lyndon Nerenberg (VE6BBM/VE7TFX)"  <lyndon@orthanc.ca> writes:

>> (As a side note, if anyone goes into rc(1)'s source to implement any of
>> this, please add a "--" option (or similar) to the "echo" builtin while
>> you're there.
>
> Echo is not a builtin, and for one possible solution see
> /n/sources/contrib/lyndon/echon.c

Ah, you're right; echo isn't a builtin.  I guess echo would be another
big candidate for elevation to "builtin" status, then.

Unfortunately, echon.c doesn't solve the problem either, because it
doesn't output a trailing newline.  The crux of the problem is how to
output "-n" on a line by itself, followed by a newline.  I don't think
it can be done symmetrically without adding another option to echo.  It
can be done by wrapping "echo" in if/switch statement, but that violates
symmetry of invocation.  Ideally, echo would be invokable like:

    $ echo -n $foo # suppress newline
    $ echo -y $foo # force newline
    $ echo $foo    # newline by default


erik quanstrom <quanstro@quanstro.net> writes:

> could you be concrete about your performance problem.
> if you don't have a performance problem, then there's no
> point to optimizing.

I'm trying to write an Acme client in rc(1).  I'd like to avoid spawning
a new read(1) process every time I make a keystroke or click the mouse.
Using multi-line reads wouldn't help much, because interactivity needs
to be maintained.

I'm using rc(1) because the /mnt/acme/%d/events interface is
well-documented (in /sys/doc/acme/acme.ps), but the C code under
/acme/bin/source/ for reading /mnt/acme/%d/events it is definitively
cryptic.  I've managed to peel away the extra layers of code from one of
the simpler Acme clients, in /acme/bin/source/adict/win.c, and am in the
process of creating a general-purpose Acme event parser in C.  The
output of the filter will be in a form easily digestible by scripts, and
would provide a good "skeleton" example of event parsing for other
coders to build upon.  (There doesn't currently appear to be any such
"starter code" under /acme/bin/source or /sys/doc.)

If only Acme put a single extra space immediately prior the first
integer (c0) in it's event messages, this parsing could have been done
almost entirely within rc(1).

I know that using awk(1) is a possibility, but awk(1) still has to
system() every "test -e", just like rc(1) does.  I would use scheme, but
the scheme in fgb's contrib doesn't seem to provide any way of
stat(2)ing path names without resorting to its foreign function
interface.  :(

All combined (forking read/test/echo, forking awk/sed/dd, parsing
/mnt/acme/%d/events, etc.)... this, I think, is why languages like Perl
came into existence and became so popular.  I could definitely write an
Acme event parser in Perl, or even in bash(1).  rc(1) is just a few
small features shy of making it practical to do in rc(1).

--
+---------------------------------------------------------------+
|E-Mail: smiley@zenzebra.mv.com             PGP key ID: BC549F8B|
|Fingerprint: 9329 DB4A 30F5 6EDA D2BA  3489 DAB7 555A BC54 9F8B|
+---------------------------------------------------------------+



  reply	other threads:[~2011-04-04 21:35 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-03 22:30 smiley at zenzebra.mv.com
2011-04-03 23:22 ` pmarin
2011-04-03 23:41 ` Tristan Plumb
2011-04-04  2:02   ` Ethan Grammatikidis
2011-04-04  2:53   ` erik quanstrom
2011-04-04  7:54     ` Tristan Plumb
2011-04-04  9:26     ` roger peppe
2011-04-04 21:35       ` smiley [this message]
2011-04-04 21:46         ` Anthony Sorace
2011-04-04 22:03           ` erik quanstrom
2011-04-05  8:57           ` Balwinder S Dheeman
2011-04-04 22:00         ` Oleg Finkelshteyn
2011-04-04 22:33         ` erik quanstrom
2011-04-04 23:01         ` Lyndon Nerenberg
2011-04-05  8:58         ` yy
2011-04-05 19:54           ` Ethan Grammatikidis
2011-04-05 19:56             ` erik quanstrom
2011-04-05 20:54               ` Ethan Grammatikidis
2011-04-05 21:53                 ` andrey mirtchovski
2011-04-06 16:32                   ` Bakul Shah
2011-04-06 16:43                     ` roger peppe
2011-04-06 18:15                       ` erik quanstrom
2011-04-06 18:37                         ` Yaroslav
2011-04-07  8:45                           ` Greg Comeau
2011-04-06 18:18                     ` erik quanstrom
2011-04-07  8:45                     ` Greg Comeau
2011-04-05  9:10         ` roger peppe
2011-04-05 15:47           ` ron minnich
2011-04-05 15:52             ` Jacob Todd
2011-04-05 15:57               ` erik quanstrom
2011-04-05 16:04               ` Rudolf Sykora
2011-04-05 17:17                 ` ron minnich
2011-04-05 17:49             ` smiley
2011-04-05 18:01               ` erik quanstrom
2011-04-05 19:50               ` Yaroslav
2011-04-06 15:27                 ` smiley
2011-04-06 15:32                   ` Jacob Todd
2011-04-07  1:26                     ` [9fans] Busy mouse WAS: " smiley
2011-04-07 11:49                       ` erik quanstrom
2011-04-07 19:59                         ` smiley
2011-04-07 20:19                           ` erik quanstrom
2011-04-09 12:26                             ` smiley
2011-04-09 12:33                               ` erik quanstrom
2011-04-05 16:28         ` [9fans] " dexen deVries
2011-04-05 17:05         ` Bakul Shah
2011-04-03 23:51 ` Lyndon Nerenberg (VE6BBM/VE7TFX)
2011-04-04  3:01 ` erik quanstrom

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=86vcythf8h.fsf@cmarib.ramside \
    --to=smiley@zenzebra.mv.com \
    --cc=9fans@9fans.net \
    /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).