On Wed Oct 9 11:54:41 EDT 2013, [email protected] 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