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

📄 html_r.c

📁 this is the file used to browse web
💻 C
📖 第 1 页 / 共 3 页
字号:
	if (aa) {		*aa = from == -1;		if (hard && !*aa) *aa = 2;	}	if (hard || from == -1) from = def;	if (frm) *frm = from;	return get_translation_table(from, to);}struct document_options *d_opt;void format_html(struct cache_entry *ce, struct f_data *screen){	unsigned char *url = ce->url;	struct fragment *fr;	struct part *rp;	unsigned char *start, *end;	unsigned char *head, *t;	int hdl;	int i;	memset(table_cache_hash, 0, sizeof(table_cache_hash));	d_opt = &screen->opt;	screen->use_tag = ce->count;	defrag_entry(ce);	fr = ce->frag.next;	if ((void *)fr == &ce->frag || fr->offset || !fr->length) start = NULL, end = NULL;	else start = fr->data, end = fr->data + fr->length;	startf = start;	eofff = end;	head = init_str(), hdl = 0;	if (ce->head) add_to_str(&head, &hdl, ce->head);	scan_http_equiv(start, end, &head, &hdl, &t);	convert_table = get_convert_table(head, screen->opt.cp, screen->opt.assume_cp, &screen->cp, &screen->ass, screen->opt.hard_assume);	screen->opt.real_cp = screen->cp;	i = d_opt->plain; d_opt->plain = 0;	screen->title = convert_string(convert_table, t, strlen(t));	d_opt->plain = i;	mem_free(t);	push_base_format(url, &screen->opt);	table_level = 0;	g_ctrl_num = 0;	last_form_tag = NULL;	last_form_attr = NULL;	last_input_tag = NULL;	if ((rp = format_html_part(start, end, par_format.align, par_format.leftmargin, screen->opt.xw, screen, 0, 0, head, 1))) mem_free(rp);	mem_free(head);	screen->x = 0;	for (i = screen->y - 1; i >= 0; i--) {		if (!screen->data[i].l) mem_free(screen->data[i].d), screen->y--;		else break;	}	for (i = 0; i < screen->y; i++) if (screen->data[i].l > screen->x) screen->x = screen->data[i].l;	if (form.action) mem_free(form.action), form.action = NULL;	if (form.target) mem_free(form.target), form.target = NULL;	kill_html_stack_item(html_stack.next);	if (html_stack.next != &html_stack) {		internal("html stack not empty after operation");		init_list(html_stack);	}	screen->bg = 007 << 8; /* !!! FIXME */	sort_links(screen);	if (screen->frame_desc) screen->frame = 1;	/*{		FILE *f = fopen("forms", "a");		struct form_control *form;		unsigned char *qq;		fprintf(f,"FORM:\n");		foreach(form, screen->forms) fprintf(f, "g=%d f=%d c=%d t:%d\n", form->g_ctrl_num, form->form_num, form->ctrl_num, form->type);		fprintf(f,"fragment: \n");		for (qq = start; qq < end; qq++) fprintf(f, "%c", *qq);		fprintf(f,"----------\n\n");		fclose(f);	}*/}static inline int compare_opt(struct document_options *o1, struct document_options *o2){	if (o1->xw == o2->xw &&	    o1->yw == o2->yw &&	    o1->xp == o2->xp &&	    o1->yp == o2->yp &&	    o1->col == o2->col &&	    o1->cp == o2->cp &&	    o1->assume_cp == o2->assume_cp &&	    o1->hard_assume == o2->hard_assume &&	    o1->tables == o2->tables &&	    o1->frames == o2->frames &&	    o1->images == o2->images &&	    o1->margin == o2->margin &&	    o1->plain == o2->plain &&	    !memcmp(&o1->default_fg, &o2->default_fg, sizeof(struct rgb)) &&	    !memcmp(&o1->default_bg, &o2->default_bg, sizeof(struct rgb)) &&	    !memcmp(&o1->default_link, &o2->default_link, sizeof(struct rgb)) &&	    !memcmp(&o1->default_vlink, &o2->default_vlink, sizeof(struct rgb)) &&	    o1->num_links == o2->num_links &&	    o1->table_order == o2->table_order &&	    !strcasecmp(o1->framename, o2->framename)) return 0;	return 1;}static inline void copy_opt(struct document_options *o1, struct document_options *o2){	memcpy(o1, o2, sizeof(struct document_options));	o1->framename = stracpy(o2->framename);}struct list_head format_cache = {&format_cache, &format_cache};int format_cache_entries = 0;void shrink_format_cache(int u){	struct f_data *ce;	delete_unused_format_cache_entries();	if (format_cache_entries < 0) {		internal("format_cache_entries underflow");		format_cache_entries = 0;	} 	ce = format_cache.prev;	while ((u || format_cache_entries > max_format_cache_entries) && (void *)ce != &format_cache) {		if (ce->refcount) {			ce = ce->prev;			continue;		}		ce = ce->prev;		destroy_formatted(ce->next);		format_cache_entries--;	}}void count_format_cache(){	struct f_data *ce;	format_cache_entries = 0;	foreach(ce, format_cache) if (!ce->refcount) format_cache_entries++;}void delete_unused_format_cache_entries(){	struct f_data *ce;	foreach(ce, format_cache) {		struct cache_entry *cee = NULL;		if (!ce->refcount && (find_in_cache(ce->url, &cee) || !cee || cee->count != ce->use_tag)) {			if (!cee) internal("file %s disappeared from cache", ce->url);			ce = ce->prev;			destroy_formatted(ce->next);			format_cache_entries--;		}	}}void format_cache_reactivate(struct f_data *ce){	del_from_list(ce);	add_to_list(format_cache, ce);}void cached_format_html(struct view_state *vs, struct f_data_c *screen, struct document_options *opt){	unsigned char *n;	struct f_data *ce;	struct cache_entry *cee;	if (!vs) return;	n = screen->name; screen->name = NULL;	detach_formatted(screen);	screen->name = n;	screen->link_bg = NULL;	screen->link_bg_n = 0;	screen->vs = vs;	screen->xl = screen->yl = -1;	screen->f_data = NULL;	foreach(ce, format_cache) if (!strcmp(ce->url, vs->url) && !compare_opt(&ce->opt, opt)) {		cee = NULL;		if (find_in_cache(vs->url, &cee) || !cee || cee->count != ce->use_tag) {			if (!cee) internal("file %s disappeared from cache", ce->url);			if (!ce->refcount) {				ce = ce->prev;				destroy_formatted(ce->next);				format_cache_entries--;			}			continue;		}		format_cache_reactivate(ce);		if (!ce->refcount++) format_cache_entries--;		screen->f_data = ce;		goto sx;	}	if (find_in_cache(vs->url, &cee) || !cee) {		internal("document to format not found");		return;	}	cee->refcount++;	shrink_memory(0);	ce = mem_alloc(SIZEOF_F_DATA);	init_formatted(ce);	ce->refcount = 1;	ce->url = stracpy(vs->url);	copy_opt(&ce->opt, opt);	add_to_list(format_cache, ce);	screen->f_data = ce;	ce->time_to_get = -get_time();	format_html(cee, ce);	ce->time_to_get += get_time();	sx:	screen->xw = ce->opt.xw;	screen->yw = ce->opt.yw;	screen->xp = ce->opt.xp;	screen->yp = ce->opt.yp;}long formatted_info(int type){	int i = 0;	struct f_data *ce;	switch (type) {		case CI_FILES:			foreach(ce, format_cache) i++;			return i;		case CI_LOCKED:			foreach(ce, format_cache) i += !!ce->refcount;			return i;		default:			internal("formatted_info: bad request");	}	return 0;}void add_frame_to_list(struct session *ses, struct f_data_c *fd){	struct f_data_c *f, *fp;	foreach(f, ses->scrn_frames) {		if (f->yp > fd->yp || (f->yp == fd->yp && f->xp > fd->xp)) {			add_at_pos(f->prev, fd);			return;		}	}	fp = (struct f_data_c *)ses->scrn_frames.prev;	add_at_pos(fp, fd);}struct f_data_c *find_fd(struct session *ses, unsigned char *name, int depth, int x, int y){	struct f_data_c *fd;	foreachback(fd, ses->scrn_frames) if (!strcasecmp(fd->name, name) && !fd->used) {		fd->used = 1;		fd->depth = depth;		return fd;	}	fd = mem_alloc(sizeof(struct f_data_c));	memset(fd, 0, sizeof(struct f_data_c));	fd->used = 1;	fd->name = stracpy(name);	fd->depth = depth;	fd->xp = x, fd->yp = y;	fd->search_word = &ses->search_word;	/*add_to_list(ses->scrn_frames, fd);*/	add_frame_to_list(ses, fd);	return fd;}struct f_data_c *format_frame(struct session *ses, unsigned char *name, unsigned char *url, struct document_options *o, int depth){	struct cache_entry *ce;	struct view_state *vs;	struct f_data_c *fd;	struct frame *fr;	repeat:	if (!(fr = ses_find_frame(ses, name))) return NULL;	vs = &fr->vs;	if (find_in_cache(vs->url, &ce) || !ce) return NULL;	if (ce->redirect && fr->redirect_cnt < MAX_REDIRECTS) {		unsigned char *u;		if ((u = join_urls(vs->url, ce->redirect))) {			fr->redirect_cnt++;			ses_change_frame_url(ses, name, u);			mem_free(u);			goto repeat;		}	}	if (!(fd = find_fd(ses, name, depth, o->xp, o->yp))) return NULL;	cached_format_html(vs, fd, o);	return fd;}void format_frames(struct session *ses, struct frameset_desc *fsd, struct document_options *op, int depth){	int i, j, n;	struct document_options o;	if (depth > HTML_MAX_FRAME_DEPTH) return;	memcpy(&o, op, sizeof(struct document_options));	if (o.margin) o.margin = 1;	n = 0;	for (j = 0; j < fsd->y; j++) {		o.xp = op->xp;		for (i = 0; i < fsd->x; i++) {			struct f_data_c *fdc;			o.xw = fsd->f[n].xw;			o.yw = fsd->f[n].yw;			o.framename = fsd->f[n].name;			if (fsd->f[n].subframe) format_frames(ses, fsd->f[n].subframe, &o, depth + 1);			else if (fsd->f[n].name) {				fdc = format_frame(ses, fsd->f[n].name, fsd->f[n].url, &o, depth);				if (fdc && fdc->f_data && fdc->f_data->frame) format_frames(ses, fdc->f_data->frame_desc, &o, depth + 1);			}			o.xp += o.xw + 1;			n++;		}		o.yp += o.yw + 1;	}				/*for (i = 0; i < fsd->n; i++) {		if (!fsd->horiz) o.xw = fsd->f[i].width;		else o.yw = fsd->f[i].width;		o.framename = fsd->f[i].name;		if (fsd->f[i].subframe) format_frames(ses, fsd->f[i].subframe, &o);		else format_frame(ses, fsd->f[i].name, fsd->f[i].url, &o);		if (!fsd->horiz) o.xp += fsd->f[i].width + 1;		else o.yp += fsd->f[i].width + 1;	}*/}void html_interpret(struct session *ses){	struct view_state *l;	struct document_options o;	struct f_data_c *fd, *cf = NULL;	/*debug("I");*/	if (!ses->screen) {		ses->screen = mem_alloc(sizeof(struct f_data_c));		memset(ses->screen, 0, sizeof(struct f_data_c));		ses->screen->search_word = &ses->search_word;	}	if (!list_empty(ses->history)) l = &cur_loc(ses)->vs;	else l = NULL;	o.xp = 0;	o.yp = 1;	o.xw = ses->term->x;	if (ses->term->y < 2) o.yw = 0;	else o.yw = ses->term->y - 2;	o.col = ses->term->spec->col;	o.cp = ses->term->spec->charset;	ds2do(&ses->ds, &o);	if ((o.plain = l ? l->plain : 1) == -1) o.plain = 0;	if (l) l->plain = o.plain;	memcpy(&o.default_fg, &default_fg, sizeof(struct rgb));	memcpy(&o.default_bg, &default_bg, sizeof(struct rgb));	memcpy(&o.default_link, &default_link, sizeof(struct rgb));	memcpy(&o.default_vlink, &default_vlink, sizeof(struct rgb));	o.framename = "";	foreach(fd, ses->scrn_frames) fd->used = 0;	cached_format_html(l, ses->screen, &o);	if (ses->screen->f_data && ses->screen->f_data->frame) {		cf = current_frame(ses);		format_frames(ses, ses->screen->f_data->frame_desc, &o, 0);	}	foreach(fd, ses->scrn_frames) if (!fd->used) {		struct f_data_c *fdp = fd->prev;		detach_formatted(fd);		del_from_list(fd);		mem_free(fd);		fd = fdp;	}	if (cf) {		int n = 0;		foreach(fd, ses->scrn_frames) {			if (fd->f_data && fd->f_data->frame) continue;			if (fd == cf) {				cur_loc(ses)->vs.current_link = n;				break;			}			n++;		}	}}void add_srch_chr(struct f_data *f, unsigned char c, int x, int y, int nn){	int n = f->nsearch;	if (c == ' ' && (!n || f->search[n - 1].c == ' ')) return;	f->search[n].c = c;	f->search[n].x = x;	f->search[n].y = y;	f->search[n].n = nn;	f->nsearch++;}/*void sdbg(struct f_data *f){	struct node *n;	foreachback(n, f->nodes) {		int xm = n->x + n->xw, ym = n->y + n->yw;		printf("%d %d - %d %d\n", n->x, n->y, xm, ym);		fflush(stdout);	}	debug("!");}*/void sort_srch(struct f_data *f){	int i;	int *min, *max;	if ((unsigned)f->y > MAXINT / sizeof(struct search *)) overalloc();	if ((unsigned)f->y > MAXINT / sizeof(int)) overalloc();	f->slines1 = mem_alloc(f->y * sizeof(struct search *));	f->slines2 = mem_alloc(f->y * sizeof(struct search *));	min = mem_alloc(f->y * sizeof(int));	max = mem_alloc(f->y * sizeof(int));	memset(f->slines1, 0, f->y * sizeof(struct search *));	memset(f->slines2, 0, f->y * sizeof(struct search *));	for (i = 0; i < f->y; i++) min[i] = MAXINT, max[i] = 0;	for (i = 0; i < f->nsearch; i++) {		struct search *s = &f->search[i];		if (s->x < min[s->y]) min[s->y] = s->x, f->slines1[s->y] = s;		if (s->x + s->n > max[s->y]) max[s->y] = s->x + s->n, f->slines2[s->y] = s;	}	mem_free(min);	mem_free(max);}static inline int is_spc(chr c){	return (unsigned char)c <= ' ' || c & ATTR_FRAME;}int get_srch(struct f_data *f){	struct node *n;	int cnt = 0;	int cc = !f->search;	foreachback(n, f->nodes) {		int x, y;		int xm = n->x + n->xw, ym = n->y + n->yw;		/*printf("%d %d - %d %d\n", n->x, n->y, xm, ym);		fflush(stdout);*/		for (y = n->y; y < ym && y < f->y; y++) {			int ns = 1;			for (x = n->x; x < xm && x < f->data[y].l; x++) {				unsigned char c = f->data[y].d[x];				if (is_spc(f->data[y].d[x])) c = ' ';				if (c == ' ' && ns) continue;				c = charset_upcase(c, f->opt.cp);				if (ns) {					if (!cc) add_srch_chr(f, c, x, y, 1);					else cnt++;					ns = 0;					continue;				}				if (c != ' ')  if (!cc) add_srch_chr(f, c, x, y, 1);					       else cnt++;				else {					int xx;					for (xx = x + 1; xx < xm && xx < f->data[y].l; xx++) if (!is_spc(f->data[y].d[xx])) goto ja_uz_z_toho_programovani_asi_zcvoknu;					xx = x;					ja_uz_z_toho_programovani_asi_zcvoknu:				/* uz jsem zcvoknul, trpim poruchou osobnosti */					if (!cc) add_srch_chr(f, ' ', x, y, xx - x);					else cnt++;					if (xx == x) break;					x = xx - 1;				}			}			if (!cc) add_srch_chr(f, ' ', x, y, 0);			else cnt++;		}	}	return cnt;	}void get_search_data(struct f_data *f){	int n;	if (f->search) return;	n = get_srch(f);	f->nsearch = 0;	if ((unsigned)n > MAXINT / sizeof(struct search)) overalloc();	f->search = mem_alloc(n * sizeof(struct search));	get_srch(f);	while (f->nsearch && f->search[f->nsearch - 1].c == ' ') f->nsearch--;	/*debug("!");*/	sort_srch(f);}

⌨️ 快捷键说明

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