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

📄 search.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
字号:
#include <u.h>#include <libc.h>#include <bio.h>#include <thread.h>#include "object.h"#include "parse.h"#include "search.h"Object *search(Object *rt, Object *parent, Reprog *preg) {	/* Create a `search object', a subtree of rt containing	 * only objects with s in their value of key fields plus	 * their parentage.	 *	 * Algorithm: depth-first traversal of rt.  On the way down,	 * copy rt to nr (new root), on the way back up, delete	 * subtrees without match.	 *	 * returns null when there are no matches in rt's subtree	 */	Object *o, *nr;	char *s;	int i;	int yes = 0;	nr = newobject(rt->type, parent);	nr->orig = rt->orig?rt->orig:rt;	nr->value = rt->value;	strncpy(nr->key, rt->key, KEYLEN);	if((((s = nr->value)) && regexec(preg, s, nil, 0) == 1)	|| (((s = nr->value)) && regexec(preg, s, nil, 0) == 1))		yes = 1;	for(i = 0; i < rt->nchildren; i++)		if((o = search((Object*)rt->children[i], nr, preg))){			yes = 1;			addchild(nr, o, "search");		}	if(yes == 0){		freeobject(nr, "s");		return nil;	}	return nr;}

⌨️ 快捷键说明

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