9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Brdline and the last line
@ 2013-10-09 15:53 Steve Simon
  2013-10-09 16:04 ` erik quanstrom
  2014-05-27  3:49 ` 有澤 健治
  0 siblings, 2 replies; 4+ messages in thread
From: Steve Simon @ 2013-10-09 15:53 UTC (permalink / raw)
  To: 9fans

Hi all

It has long been an irritation that Brdline returns failure (to match the
end of line token) at end of file if the file does not end with a newline.

This is correct but annoying.

does anyone had a neat snippet of code which ensures we parse the
last line correctly?

For files on the filesystem I just fix them, but I am wrapping Brdline
around a tcp connection so I am not in control of how people terminate
their files...

-Steve



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

* Re: [9fans] Brdline and the last line
  2013-10-09 15:53 [9fans] Brdline and the last line Steve Simon
@ 2013-10-09 16:04 ` erik quanstrom
  2013-10-10  3:46   ` 有澤 健治
  2014-05-27  3:49 ` 有澤 健治
  1 sibling, 1 reply; 4+ messages in thread
From: erik quanstrom @ 2013-10-09 16:04 UTC (permalink / raw)
  To: 9fans

On Wed Oct  9 11:54:41 EDT 2013, steve@quintile.net wrote:
> Hi all
>
> It has long been an irritation that Brdline returns failure (to match the
> end of line token) at end of file if the file does not end with a newline.
>
> This is correct but annoying.
>
> does anyone had a neat snippet of code which ensures we parse the
> last line correctly?
>
> For files on the filesystem I just fix them, but I am wrapping Brdline
> around a tcp connection so I am not in control of how people terminate
> their files...

how about

int
brdline(Biobuf *b, char *buf, int nbuf)
{
	int i, rv;
	Rune r;

	for(i = 0; i < nbuf - UTFmax - 1; ){
		rv = Bgetrune(b);
		if(rv == -1 || rv == '\n')
			break;
		r = rv;
		i += chartorune(&r, buf+i);
	}
	buf[i] = 0;
	return i;
}

- erik



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

* Re: [9fans] Brdline and the last line
  2013-10-09 16:04 ` erik quanstrom
@ 2013-10-10  3:46   ` 有澤 健治
  0 siblings, 0 replies; 4+ messages in thread
From: 有澤 健治 @ 2013-10-10  3:46 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

If speed is matter, try rdline() in Kirara.
http://plan9.aichi-u.ac.jp/netlib/kirara/kirara-1.2a.tgz

More improved version will be included in kirara-2.0 (to be released).

On 2013/10/10, at 1:04, erik quanstrom wrote:

> On Wed Oct  9 11:54:41 EDT 2013, steve@quintile.net wrote:
>> Hi all
>>
>> It has long been an irritation that Brdline returns failure (to match the
>> end of line token) at end of file if the file does not end with a newline.
>>
>> This is correct but annoying.
>>
>> does anyone had a neat snippet of code which ensures we parse the
>> last line correctly?
>>
>> For files on the filesystem I just fix them, but I am wrapping Brdline
>> around a tcp connection so I am not in control of how people terminate
>> their files...
>
> how about
>
> int
> brdline(Biobuf *b, char *buf, int nbuf)
> {
> 	int i, rv;
> 	Rune r;
>
> 	for(i = 0; i < nbuf - UTFmax - 1; ){
> 		rv = Bgetrune(b);
> 		if(rv == -1 || rv == '\n')
> 			break;
> 		r = rv;
> 		i += chartorune(&r, buf+i);
> 	}
> 	buf[i] = 0;
> 	return i;
> }
>
> - erik
>




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

* Re: [9fans] Brdline and the last line
  2013-10-09 15:53 [9fans] Brdline and the last line Steve Simon
  2013-10-09 16:04 ` erik quanstrom
@ 2014-05-27  3:49 ` 有澤 健治
  1 sibling, 0 replies; 4+ messages in thread
From: 有澤 健治 @ 2014-05-27  3:49 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Try rdline in Kirara package.
http://plan9.aichi-u.ac.jp/netlib/

On 2013/10/10, at 0:53, Steve Simon wrote:

> Hi all
>
> It has long been an irritation that Brdline returns failure (to match the
> end of line token) at end of file if the file does not end with a newline.
>
> This is correct but annoying.
>
> does anyone had a neat snippet of code which ensures we parse the
> last line correctly?
>
> For files on the filesystem I just fix them, but I am wrapping Brdline
> around a tcp connection so I am not in control of how people terminate
> their files...
>
> -Steve
>




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

end of thread, other threads:[~2014-05-27  3:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-09 15:53 [9fans] Brdline and the last line Steve Simon
2013-10-09 16:04 ` erik quanstrom
2013-10-10  3:46   ` 有澤 健治
2014-05-27  3:49 ` 有澤 健治

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