* Re: [9fans] rc of Unix
@ 2003-07-05 17:45 David Presotto
2003-07-05 23:20 ` Kenji Arisawa
0 siblings, 1 reply; 8+ messages in thread
From: David Presotto @ 2003-07-05 17:45 UTC (permalink / raw)
To: 9fans
Guys, read is not a hard program to write. Copy the
plan 9 one or write your own. Should have taken a lot less time
than these messages about sed 1q.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] rc of Unix
2003-07-05 17:45 [9fans] rc of Unix David Presotto
@ 2003-07-05 23:20 ` Kenji Arisawa
2003-07-05 23:48 ` rob pike, esq.
2003-07-06 3:19 ` boyd, rounin
0 siblings, 2 replies; 8+ messages in thread
From: Kenji Arisawa @ 2003-07-05 23:20 UTC (permalink / raw)
To: 9fans
Hello,
I introduced builtin function "read" into Unix rc.
bash$ diff builtins.c builtins.c.orig
30,34d29
< #define RC_READ 1
< #if RC_READ
< static void b_read(char **);
< #endif
<
46,48d40
< #if RC_READ
< { b_read, "read" },
< #endif
111,136d102
<
< #if RC_READ
< /* read that simulate Plan 9 read -- introduced by Kenar */
< static void b_read(char **av) {
< char buf[1024];
< int i = 0;
< if (*++av != NULL) {
< set(FALSE);
< return;
< }
< for(;;){
< if(i == sizeof(buf)){
< write(1, buf, i);
< i = 0;
< }
< if(read(0, &buf[i++], 1) <= 0){
< i--;
< break;
< }
< if(buf[i-1] == '\n')
< break;
< }
< write(1, buf, i);
< set(TRUE);
< }
< #endif
where "builtins.c.orig" is of rc-1.7
I hope that does not introduce a bug ( not tested enough).
Kenji Arisawa
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] rc of Unix
2003-07-05 23:20 ` Kenji Arisawa
@ 2003-07-05 23:48 ` rob pike, esq.
2003-07-06 3:19 ` boyd, rounin
1 sibling, 0 replies; 8+ messages in thread
From: rob pike, esq. @ 2003-07-05 23:48 UTC (permalink / raw)
To: 9fans
can't resist. here is slightly better code.
/* read that simulate Plan 9 read -- introduced by Kenar */
static void b_read(char **av) {
char buf[1024];
if (*++av != NULL) {
set(FALSE);
return;
}
int i = 0;
for(;;){
if(i == sizeof(buf)){
write(1, buf, i);
i = 0;
}
if(read(0, &buf[i], 1) <= 0)
break;
if(buf[i++] == '\n')
break;
}
if(i > 0)
write(1, buf, i);
set(TRUE);
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] rc of Unix
2003-07-05 23:20 ` Kenji Arisawa
2003-07-05 23:48 ` rob pike, esq.
@ 2003-07-06 3:19 ` boyd, rounin
1 sibling, 0 replies; 8+ messages in thread
From: boyd, rounin @ 2003-07-06 3:19 UTC (permalink / raw)
To: 9fans
> I introduced builtin function "read" into Unix rc.
bad move, human ...
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] rc of Unix
2003-07-05 12:15 ` Kenji Arisawa
@ 2003-07-05 14:00 ` boyd, rounin
0 siblings, 0 replies; 8+ messages in thread
From: boyd, rounin @ 2003-07-05 14:00 UTC (permalink / raw)
To: 9fans
i used rc on ultrix for 2+ years and i never really ran into a problem.
yes, sed 1q is different to to plan 9's read 'cos sed 1q discards
the whole input stream whereas read just takes the first line
(preserving the the rest of the input stream).
i don't remember how i avoided this problem, but it probably
involved pipe trickery and awk. it depends on the problem.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] rc of Unix
2003-07-05 2:33 ` Bruce Ellis
@ 2003-07-05 12:15 ` Kenji Arisawa
2003-07-05 14:00 ` boyd, rounin
0 siblings, 1 reply; 8+ messages in thread
From: Kenji Arisawa @ 2003-07-05 12:15 UTC (permalink / raw)
To: 9fans
Hello,
I said:
> bash$ rc
> ; bash$ rc
> ; read
> read not found
> ;
>
> What should I do for "read" in Unix rc ?
>
Ellis:
> sed 1q
Thinks, Ellis.
However "sed 1q" behaves somewhat differently.
In the bellow my input sequence are:
aaa
bbb
ccc
ddd
Plan 9 read:
cpu% read; read
aaa
aaa
bbb
bbb
cpu%
Unix "sed 1q":
bash$ rc
; sed 1q; sed 1q
aaa
bbb
aaa
ccc
ddd
ccc
;
Kenji Arisawa
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9fans] rc of Unix
2003-07-05 2:17 Kenji Arisawa
@ 2003-07-05 2:33 ` Bruce Ellis
2003-07-05 12:15 ` Kenji Arisawa
0 siblings, 1 reply; 8+ messages in thread
From: Bruce Ellis @ 2003-07-05 2:33 UTC (permalink / raw)
To: 9fans
sed 1q
----- Original Message -----
From: "Kenji Arisawa" <arisawa@ar.aichi-u.ac.jp>
To: <9fans@cse.psu.edu>
Sent: Saturday, July 05, 2003 12:17 PM
Subject: [9fans] rc of Unix
> Hello,
>
> bash$ rc
> ; bash$ rc
> ; read
> read not found
> ;
>
> What should I do for "read" in Unix rc ?
>
> Kenji Arisawa
^ permalink raw reply [flat|nested] 8+ messages in thread
* [9fans] rc of Unix
@ 2003-07-05 2:17 Kenji Arisawa
2003-07-05 2:33 ` Bruce Ellis
0 siblings, 1 reply; 8+ messages in thread
From: Kenji Arisawa @ 2003-07-05 2:17 UTC (permalink / raw)
To: 9fans
Hello,
bash$ rc
; bash$ rc
; read
read not found
;
What should I do for "read" in Unix rc ?
Kenji Arisawa
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2003-07-06 3:19 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-05 17:45 [9fans] rc of Unix David Presotto
2003-07-05 23:20 ` Kenji Arisawa
2003-07-05 23:48 ` rob pike, esq.
2003-07-06 3:19 ` boyd, rounin
-- strict thread matches above, loose matches on Subject: below --
2003-07-05 2:17 Kenji Arisawa
2003-07-05 2:33 ` Bruce Ellis
2003-07-05 12:15 ` Kenji Arisawa
2003-07-05 14:00 ` boyd, rounin
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).