9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Brdline
@ 2006-01-16 11:35 Gorka guardiola
  2006-01-16 12:30 ` Charles Forsyth
  0 siblings, 1 reply; 41+ messages in thread
From: Gorka guardiola @ 2006-01-16 11:35 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Is there any reason why Brdline, bio(2) returns void * instead of char *
which I think it should return?. Just curious.
--
- curiosity sKilled the cat


^ permalink raw reply	[flat|nested] 41+ messages in thread
* [9fans] Brdline
@ 2005-02-02  0:37 arisawa
  2005-02-02  1:06 ` Russ Cox
  0 siblings, 1 reply; 41+ messages in thread
From: arisawa @ 2005-02-02  0:37 UTC (permalink / raw)
  To: 9fans

Hello,

The following program falls into endless loop if we execute
	echo -n alice | 8.out
Try.

#include <u.h>
#include <libc.h>
#include <bio.h>

void
main()
{	Biobuf in;
	char *p;
	int lines;
	Binit(&in, 0, OREAD);
	lines = 0;
	for(;;){
		p = Brdline(&in, '\n');
		if(p == nil){
			if(Blinelen(&in) == 0)
				break;
		}else
			lines++;
	}
	print("lines=%d\n",lines);
}



I have been desired to have such a Brdline
that can work even if we execute:
	echo -n alice | 8.out

Current Brdline requires delim as second argument,
and the worse the delim is left untouched *mostly*
at Blinelen -1
We must replace it using Blinelen by '\0' if we want the
returned value to be used as string.
This makes program difficult if input data doesn't have delim.

My imagination of new Brdline (or some other name) is:

void
main()
{	Biobuf in;
	char *p;
	Binit(&in,0,OREAD);
	while((p = Brdline(&in)))
		print("%s", p);
}

'\n' is automatically replaced by '\0',
and '\0' is automatically appended at EOF.
p is nil only at EOF.
some function will be required to detect buffer full.
if buffer full the next Brdline should return the
pointer of the character that is replaced by '\0'
after fixing the value.

Kenji Arisawa


^ permalink raw reply	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2006-01-19  1:20 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-16 11:35 [9fans] Brdline Gorka guardiola
2006-01-16 12:30 ` Charles Forsyth
2006-01-16 13:27   ` Bruce Ellis
2006-01-16 13:37     ` Gorka guardiola
2006-01-16 13:57       ` Charles Forsyth
2006-01-16 14:24         ` Bruce Ellis
2006-01-17  0:56         ` erik quanstrom
2006-01-17  1:35           ` Russ Cox
2006-01-17  1:42             ` erik quanstrom
2006-01-17  1:47               ` Russ Cox
2006-01-17 10:01               ` Charles Forsyth
2006-01-17 16:45                 ` Bruce Ellis
2006-01-18  5:38                   ` Simon Williams
2006-01-18  5:49                     ` Bruce Ellis
2006-01-18  5:54                     ` Paul Lalonde
2006-01-18  6:11                       ` Bruce Ellis
2006-01-18 14:25                         ` Bruce Ellis
2006-01-18 15:26                           ` Ronald G Minnich
2006-01-18 23:06                             ` Adrian Tritschler
2006-01-19  1:20                               ` Bruce Ellis
2006-01-18 15:45                         ` Paul Lalonde
2006-01-18 16:41                           ` Bruce Ellis
2006-01-18 16:47                           ` Wes Kussmaul
2006-01-18 16:57                             ` Bruce Ellis
2006-01-18 17:37                               ` David Leimbach
2006-01-18 17:50                                 ` Bruce Ellis
2006-01-18 18:00                               ` Sape Mullender
2006-01-18 17:01                             ` Paul Lalonde
2006-01-18 17:30                               ` Charles Forsyth
2006-01-18 18:04                               ` Wes Kussmaul
2006-01-18 20:22                                 ` Skip Tavakkolian
2006-01-18 20:31                                   ` andrey mirtchovski
2006-01-18 23:01                                     ` Bruce Ellis
2006-01-18 22:56                                   ` Joel Salomon
2006-01-18 15:25                       ` Brantley Coile
2006-01-18 16:35                         ` Paul Lalonde
2006-01-17  9:59             ` [9fans] ulong Charles Forsyth
2006-01-17 12:30               ` Russ Cox
2006-01-17 16:55                 ` Bruce Ellis
  -- strict thread matches above, loose matches on Subject: below --
2005-02-02  0:37 [9fans] Brdline arisawa
2005-02-02  1:06 ` Russ Cox

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).