コード例 #1
0
ファイル: html.c プロジェクト: 99years/plan9
void
emitword(Bytes *b, Rune *r, int nr)
{
	char *s;
	int space;

	if(nr == 0)
		return;
	s = smprint("%.*S", nr, r);
	space = b->n > 0 && !isspace(b->b[b->n-1]) && (!newitextitem || !closingpunct(*s));
	if(col > 0 && col+space+nr > width){
		growbytes(b, "\n", 1);
		space = 0;
		col = 0;
	}
	if(space && col > 0){
		growbytes(b, " ", 1);
		col++;
	}
	growbytes(b, s, strlen(s));
	col += nr;
	free(s);
	inword = 0;
	newitextitem = 0;
}
コード例 #2
0
ファイル: html.c プロジェクト: grobe0ba/plan9front
void
renderrunes(Bytes *b, Rune *r)
{
	int i, n;

	n = runestrlen(r);
	for(i=0; i<n; i++){
		switch(r[i]){
		case '\n':
			if(inword)
				emitword(b, r+wordi, i-wordi);
			col = 0;
			if(b->n == 0)
				break;	/* don't start with blank lines */
			if(b->n<2 || b->b[b->n-1]!='\n' || b->b[b->n-2]!='\n')
				growbytes(b, "\n", 1);
			break;
		case ' ':
			if(inword)
				emitword(b, r+wordi, i-wordi);
			break;
		default:
			if(!inword)
				wordi = i;
			inword = 1;
			break;
		}
	}
	if(inword)
		emitword(b, r+wordi, i-wordi);
}
コード例 #3
0
ファイル: html.c プロジェクト: grobe0ba/plan9front
char*
loadhtml(int fd)
{
	URLwin *u;
	Bytes *b;
	int n;
	char buf[4096];

	u = emalloc(sizeof(URLwin));
	u->infd = fd;
	u->outfd = 1;
	u->url = estrdup(url);
	u->type = TextHtml;

	b = emalloc(sizeof(Bytes));
	while((n = read(fd, buf, sizeof buf)) > 0)
		growbytes(b, buf, n);
	if(b->b == nil)
		return nil;	/* empty file */
	rendertext(u, b);
	freeurlwin(u);
	return nil;
}