⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parsehist.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
字号:
/* * Read a Wiki history file. * It's a title line then a sequence of Wiki files separated by headers. * * Ddate/time * #body * #... * #... * #... * etc. */#include <u.h>#include <libc.h>#include <bio.h>#include <String.h>#include <thread.h>#include "wiki.h"static char*Brdwline(void *vb, int sep){	Biobufhdr *b;	char *p;	b = vb;	if(Bgetc(b) == '#'){		if(p = Brdline(b, sep))			p[Blinelen(b)-1] = '\0';		return p;	}else{		Bungetc(b);		return nil;		}}Whist*Brdwhist(Biobuf *b){	int i, current, conflict, c, n;	char *author, *comment, *p, *title;	ulong t;	Wdoc *w;	Whist *h;	if((p = Brdline(b, '\n')) == nil){		werrstr("short read: %r");		return nil;	}	p[Blinelen(b)-1] = '\0';	p = strcondense(p, 1);	title = estrdup(p);	w = nil;	n = 0;	t = -1;	author = nil;	comment = nil;	conflict = 0;	current = 0;	while((c = Bgetc(b)) != Beof){		if(c != '#'){			p = Brdline(b, '\n');			if(p == nil)				break;			p[Blinelen(b)-1] = '\0';			switch(c){			case 'D':				t = strtoul(p, 0, 10);				break;			case 'A':				free(author);				author = estrdup(p);				break;			case 'C':				free(comment);				comment = estrdup(p);				break;			case 'X':				conflict = 1;			}		} else {	/* c=='#' */			Bungetc(b);			if(n%8 == 0)				w = erealloc(w, (n+8)*sizeof(w[0]));			w[n].time = t;			w[n].author = author;			w[n].comment = comment;			comment = nil;			author = nil;			w[n].wtxt = Brdpage(Brdwline, b);			w[n].conflict = conflict;			if(w[n].wtxt == nil)				goto Error;			if(!conflict)				current = n;			n++;			conflict = 0;			t = -1;		}	}	if(w==nil)		goto Error;	free(comment);	free(author);	h = emalloc(sizeof *h);	h->title = title;	h->doc = w;	h->ndoc = n;	h->current = current;	incref(h);	setmalloctag(h, getcallerpc(&b));	return h;Error:	free(title);	free(author);	free(comment);	for(i=0; i<n; i++){		free(w[i].author);		free(w[i].comment);		freepage(w[i].wtxt);	}	free(w);	return nil;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -