default.c

来自「this is the file used to browse web」· C语言 代码 · 共 1,139 行 · 第 1/3 页

C
1,139
字号
	if ((err = write_to_config_file(config_file, c))) {		if (term) msg_box(term, NULL, TEXT(T_CONFIG_ERROR), AL_CENTER | AL_EXTD_TEXT, TEXT(T_UNABLE_TO_WRITE_TO_CONFIG_FILE), ": ", get_err_msg(-err), NULL, NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);		mem_free(c);		mem_free(config_file);		return -1;	}	mem_free(c);	mem_free(config_file);	return 0;}void write_config(struct terminal *term){	write_config_data(links_home, "links.cfg", links_options, term);}void write_html_config(struct terminal *term){	write_config_data(links_home, "html.cfg", html_options, term);}void add_nm(struct option *o, unsigned char **s, int *l){	if (*l) add_to_str(s, l, NEWLINE);	add_to_str(s, l, o->cfg_name);	add_to_str(s, l, " ");}void add_quoted_to_str(unsigned char **s, int *l, unsigned char *q){	add_chr_to_str(s, l, '"');	while (*q) {		if (*q == '"' || *q == '\\') add_chr_to_str(s, l, '\\');		add_chr_to_str(s, l, *q);		q++;	}	add_chr_to_str(s, l, '"');}unsigned char *num_rd(struct option *o, unsigned char *c){	unsigned char *tok = get_token(&c);	unsigned char *end;	long l;	if (!tok) return "Missing argument";	l = strtolx(tok, &end);	if (*end) {		mem_free(tok);		return "Number expected";	}	if (l < o->min || l > o->max) {		mem_free(tok);		return "Out of range";	}	*(int *)o->ptr = l;	mem_free(tok);	return NULL;}void num_wr(struct option *o, unsigned char **s, int *l){	add_nm(o, s, l);	add_knum_to_str(s, l, *(int *)o->ptr);}unsigned char *str_rd(struct option *o, unsigned char *c){	unsigned char *tok = get_token(&c);	unsigned char *e = NULL;	if (!tok) return NULL;	if (strlen(tok) + 1 > (size_t)o->max) e = "String too long";	else strcpy(o->ptr, tok);	mem_free(tok);	return e;}void str_wr(struct option *o, unsigned char **s, int *l){	add_nm(o, s, l);	if (strlen(o->ptr) + 1 > (size_t)o->max) {		unsigned char *s1 = init_str();		int l1 = 0;		add_bytes_to_str(&s1, &l1, o->ptr, o->max - 1);		add_quoted_to_str(s, l, s1);		mem_free(s1);	}	else add_quoted_to_str(s, l, o->ptr);}unsigned char *cp_rd(struct option *o, unsigned char *c){	unsigned char *tok = get_token(&c);	unsigned char *e = NULL;	int i;	if (!tok) return "Missing argument";	if ((i = get_cp_index(tok)) == -1) e = "Unknown codepage";	else if (o->min == 1 && is_cp_special(i)) e = "UTF-8 can't be here";	else *(int *)o->ptr = i;	mem_free(tok);	return e;}void cp_wr(struct option *o, unsigned char **s, int *l){	unsigned char *n = get_cp_mime_name(*(int *)o->ptr);	add_nm(o, s, l);	add_to_str(s, l, n);}unsigned char *lang_rd(struct option *o, unsigned char *c){	int i;	unsigned char *tok = get_token(&c);	if (!tok) return "Missing argument";	for (i = 0; i < n_languages(); i++)		if (!(strcasecmp(language_name(i), tok))) {			set_language(i);			mem_free(tok);			return NULL;		}	mem_free(tok);	return "Unknown language";}void lang_wr(struct option *o, unsigned char **s, int *l){	add_nm(o, s, l);	add_quoted_to_str(s, l, language_name(current_language));}int getnum(unsigned char *s, int *n, int r1, int r2){	unsigned char *e;	long l = strtol(s, (char **)(void *)&e, 10);	if (*e || !*s) return -1;	if (l < r1 || l >= r2) return -1;	*n = (int)l;	return 0;}unsigned char *type_rd(struct option *o, unsigned char *c){	unsigned char *err = "Error reading association specification";	struct assoc new;	unsigned char *w;	int n;	memset(&new, 0, sizeof(struct assoc));	if (!(new.label = get_token(&c))) goto err;	if (!(new.ct = get_token(&c))) goto err;	if (!(new.prog = get_token(&c))) goto err;	if (!(w = get_token(&c))) goto err;	if (getnum(w, &n, 0, 32)) goto err_f;	mem_free(w);	new.cons = !!(n & 1);	new.xwin = !!(n & 2);	new.ask = !!(n & 4);	if ((n & 8) || (n & 16)) new.block = !!(n & 16);	else new.block = !new.xwin || new.cons;	if (!(w = get_token(&c))) goto err;	if (strlen(w) != 1 || w[0] < '0' || w[0] > '9') goto err_f;	new.system = w[0] - '0';	mem_free(w);	update_assoc(&new);	err = NULL;	err:	if (new.label) mem_free(new.label);	if (new.ct) mem_free(new.ct);	if (new.prog) mem_free(new.prog);	return err;	err_f:	mem_free(w);	goto err;}void type_wr(struct option *o, unsigned char **s, int *l){	struct assoc *a;	foreachback(a, assoc) {		add_nm(o, s, l);		add_quoted_to_str(s, l, a->label);		add_to_str(s, l, " ");		add_quoted_to_str(s, l, a->ct);		add_to_str(s, l, " ");		add_quoted_to_str(s, l, a->prog);		add_to_str(s, l, " ");		add_num_to_str(s, l, (!!a->cons) + (!!a->xwin) * 2 + (!!a->ask) * 4 + (!a->block) * 8 + (!!a->block) * 16);		add_to_str(s, l, " ");		add_num_to_str(s, l, a->system);	}}unsigned char *ext_rd(struct option *o, unsigned char *c){	unsigned char *err = "Error reading extension specification";	struct extension new;	memset(&new, 0, sizeof(struct extension));	if (!(new.ext = get_token(&c))) goto err;	if (!(new.ct = get_token(&c))) goto err;	update_ext(&new);	err = NULL;	err:	if (new.ext) mem_free(new.ext);	if (new.ct) mem_free(new.ct);	return err;}void ext_wr(struct option *o, unsigned char **s, int *l){	struct extension *a;	foreachback(a, extensions) {		add_nm(o, s, l);		add_quoted_to_str(s, l, a->ext);		add_to_str(s, l, " ");		add_quoted_to_str(s, l, a->ct);	}}unsigned char *prog_rd(struct option *o, unsigned char *c){	unsigned char *err = "Error reading program specification";	unsigned char *prog, *w;	if (!(prog = get_token(&c))) goto err_1;	if (!(w = get_token(&c))) goto err_2;	if (strlen(w) != 1 || w[0] < '0' || w[0] > '9') goto err_3;	update_prog(o->ptr, prog, w[0] - '0');	err = NULL;	err_3:	mem_free(w);	err_2:	mem_free(prog);	err_1:	return err;}void prog_wr(struct option *o, unsigned char **s, int *l){	struct protocol_program *a;	foreachback(a, *(struct list_head *)o->ptr) {		if (!*a->prog) continue;		add_nm(o, s, l);		add_quoted_to_str(s, l, a->prog);		add_to_str(s, l, " ");		add_num_to_str(s, l, a->system);	}}unsigned char *term_rd(struct option *o, unsigned char *c){	struct term_spec *ts;	unsigned char *w;	int i;	if (!(w = get_token(&c))) goto err;	if (!(ts = new_term_spec(w))) {		mem_free(w);		goto end;	}	mem_free(w);	if (!(w = get_token(&c))) goto err;	if (strlen(w) != 1 || w[0] < '0' || w[0] > '4') goto err_f;	ts->mode = w[0] - '0';	mem_free(w);	if (!(w = get_token(&c))) goto err;	if (strlen(w) != 1 || w[0] < '0' || w[0] > '1') goto err_f;	ts->m11_hack = w[0] - '0';	mem_free(w);	if (!(w = get_token(&c))) goto err;	if (strlen(w) != 1 || w[0] < '0' || w[0] > '7') goto err_f;	ts->col = (w[0] - '0') & 1;	ts->restrict_852 = !!((w[0] - '0') & 2);	ts->block_cursor = !!((w[0] - '0') & 4);	mem_free(w);	if (!(w = get_token(&c))) goto err;	if ((i = get_cp_index(w)) == -1 || is_cp_special(i)) goto err_f;	ts->charset = i;	mem_free(w);	end:	return NULL;	err_f:	mem_free(w);	err:	return "Error reading terminal specification";}unsigned char *term2_rd(struct option *o, unsigned char *c){	struct term_spec *ts;	unsigned char *w;	int i;	if (!(w = get_token(&c))) goto err;	if (!(ts = new_term_spec(w))) {		mem_free(w);		goto end;	}	mem_free(w);	if (!(w = get_token(&c))) goto err;	if (strlen(w) != 1 || w[0] < '0' || w[0] > '4') goto err_f;	ts->mode = w[0] - '0';	mem_free(w);	if (!(w = get_token(&c))) goto err;	if (strlen(w) != 1 || w[0] < '0' || w[0] > '1') goto err_f;	ts->m11_hack = w[0] - '0';	mem_free(w);	if (!(w = get_token(&c))) goto err;	if (strlen(w) != 1 || w[0] < '0' || w[0] > '1') goto err_f;	ts->restrict_852 = w[0] - '0';	mem_free(w);	if (!(w = get_token(&c))) goto err;	if (strlen(w) != 1 || w[0] < '0' || w[0] > '1') goto err_f;	ts->col = w[0] - '0';	mem_free(w);	if (!(w = get_token(&c))) goto err;	if ((i = get_cp_index(w)) == -1 || is_cp_special(i)) goto err_f;	ts->charset = i;	mem_free(w);	end:	return NULL;	err_f:	mem_free(w);	err:	return "Error reading terminal specification";}void term_wr(struct option *o, unsigned char **s, int *l){	struct term_spec *ts;	foreachback(ts, term_specs) {		add_nm(o, s, l);		add_quoted_to_str(s, l, ts->term);		add_to_str(s, l, " ");		add_num_to_str(s, l, ts->mode);		add_to_str(s, l, " ");		add_num_to_str(s, l, ts->m11_hack);		add_to_str(s, l, " ");		add_num_to_str(s, l, !!ts->col + !!ts->restrict_852 * 2 + !!ts->block_cursor * 4);		add_to_str(s, l, " ");		add_to_str(s, l, get_cp_mime_name(ts->charset));	}}unsigned char *gen_cmd(struct option *o, unsigned char ***argv, int *argc){	unsigned char *e;	int l;	unsigned char *r;	if (!*argc) return "Parameter expected";	e = init_str();	l = 0;	add_quoted_to_str(&e, &l, **argv);	r = o->rd_cfg(o, e);	mem_free(e);	if (r) return r;	(*argv)++; (*argc)--;	return NULL;}unsigned char *lookup_cmd(struct option *o, unsigned char ***argv, int *argc){	ip addr;	unsigned char *p = (unsigned char *)&addr;	if (!*argc) return "Parameter expected";	if (*argc >= 2) return "Too many parameters";	(*argv)++; (*argc)--;	if (do_real_lookup(*(*argv - 1), &addr)) {#ifdef HAVE_HERROR		herror("error");#else		fprintf(stderr, "error: host not found\n");#endif		return "";	}	printf("%d.%d.%d.%d\n", (int)p[0], (int)p[1], (int)p[2], (int)p[3]);	fflush(stdout);	return "";}unsigned char *version_cmd(struct option *o, unsigned char ***argv, int *argc){	printf("Links " VERSION_STRING "\n");	fflush(stdout);	return "";

⌨️ 快捷键说明

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