9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Brdline() and continuation lines
@ 2012-09-19  8:48 Steve Simon
  2012-09-19 13:35 ` erik quanstrom
  2012-09-19 13:49 ` Charles Forsyth
  0 siblings, 2 replies; 3+ messages in thread
From: Steve Simon @ 2012-09-19  8:48 UTC (permalink / raw)
  To: 9fans

Hi,

Anyone worked out an idiom that would allow me to
use Brdline()/Blinelen() to read a file which
contains continuation lines?

I want to read a text file which consists of lines terminated
by newlines, but lines with leading whitespace are considered
to be continuation lines.

Brdline() is very neat allowing me to parse input lines inside the
Biobuf buffer without copying them to "user space", however if I
do a Brdline(), get a line and then attempt to do another Brdline()
I am in danger of releaseing the buffer space used by the first read.

I am happy if the answer is "Brdline() cannot do this", I just feel like
I am missing a trick, and there is elegant solution.

-Steve



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

* Re: [9fans] Brdline() and continuation lines
  2012-09-19  8:48 [9fans] Brdline() and continuation lines Steve Simon
@ 2012-09-19 13:35 ` erik quanstrom
  2012-09-19 13:49 ` Charles Forsyth
  1 sibling, 0 replies; 3+ messages in thread
From: erik quanstrom @ 2012-09-19 13:35 UTC (permalink / raw)
  To: 9fans

> Anyone worked out an idiom that would allow me to
> use Brdline()/Blinelen() to read a file which
> contains continuation lines?
>
> I want to read a text file which consists of lines terminated
> by newlines, but lines with leading whitespace are considered
> to be continuation lines.
>
> Brdline() is very neat allowing me to parse input lines inside the
> Biobuf buffer without copying them to "user space", however if I
> do a Brdline(), get a line and then attempt to do another Brdline()
> I am in danger of releaseing the buffer space used by the first read.
>
> I am happy if the answer is "Brdline() cannot do this", I just feel like
> I am missing a trick, and there is elegant solution.

/*
 * Bgetrune seems like overkill, but avoids passing up bad runes.
 */
int
Brdlinec(Biobuf *b, char *s, char *e)
{
	char *p;
	int x, slash;
	Rune r;

	for(p = s; e-p > UTFmax+1;){
		x = Bgetrune(b);
		if(x == -1)
			return -1;
		r = x;
		if(r == '\\'){
			x = Bgetrune(b);
			if(x == -1)
				return -1;
			if(x == '\n')
				continue;
			p += runetochar(p, &r);
			r = x;
		}else if(r == '\n')
			break;
		p += runetochar(p, r);
	}
	*p = 0;
	return p-e;
}




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

* Re: [9fans] Brdline() and continuation lines
  2012-09-19  8:48 [9fans] Brdline() and continuation lines Steve Simon
  2012-09-19 13:35 ` erik quanstrom
@ 2012-09-19 13:49 ` Charles Forsyth
  1 sibling, 0 replies; 3+ messages in thread
From: Charles Forsyth @ 2012-09-19 13:49 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 239 bytes --]

I don't see how it can do it.

On 19 September 2012 09:48, Steve Simon <steve@quintile.net> wrote:

> I am happy if the answer is "Brdline() cannot do this", I just feel like
> I am missing a trick, and there is elegant solution.
>

[-- Attachment #2: Type: text/html, Size: 519 bytes --]

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

end of thread, other threads:[~2012-09-19 13:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-19  8:48 [9fans] Brdline() and continuation lines Steve Simon
2012-09-19 13:35 ` erik quanstrom
2012-09-19 13:49 ` Charles Forsyth

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