From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Tue, 1 Feb 2005 20:06:36 -0500 From: Russ Cox To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Subject: Re: [9fans] Brdline In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: Topicbox-Message-UUID: 3c03d7e4-eace-11e9-9e20-41e7f4b1d025 try using Brdstr instead. On Wed, 2 Feb 2005 09:37:14 +0900, arisawa@ar.aichi-u.ac.jp wrote: > Hello, > > The following program falls into endless loop if we execute > echo -n alice | 8.out > Try. > > #include > #include > #include > > 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 >