From mboxrd@z Thu Jan 1 00:00:00 1970 References: <4c6dec5271e325c32ee144badfeae4c8@quintile.net> <25ea711db6f83d26ca16faf38466bdcc@ladd.quanstro.net> In-Reply-To: <25ea711db6f83d26ca16faf38466bdcc@ladd.quanstro.net> Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: text/plain; charset=us-ascii Message-Id: <9BDABDE6-950E-4532-B895-ED2115DD2F4E@ar.aichi-u.ac.jp> Content-Transfer-Encoding: 7bit From: =?iso-2022-jp?B?GyRCTS1fNxsoQiAbJEI3cjwjGyhC?= Date: Thu, 10 Oct 2013 12:46:03 +0900 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Subject: Re: [9fans] Brdline and the last line Topicbox-Message-UUID: 84eb5950-ead8-11e9-9d60-3106f5b1d025 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 >