📄 default.c
字号:
if ((c = read_config_file(config_file))) goto ok; mem_free(config_file); config_file = stracpy(prefix); if (!config_file) return; add_to_strn(&config_file, "."); add_to_strn(&config_file, name); if ((c = read_config_file(config_file))) goto ok; mem_free(config_file); return; ok: parse_config_file(config_file, c, all_options); mem_free(c); mem_free(config_file);}void load_config(void){#ifdef SHARED_CONFIG_DIR load_config_file(SHARED_CONFIG_DIR, "links.cfg");#endif load_config_file(links_home, "links.cfg"); load_config_file(links_home, "html.cfg"); load_config_file(links_home, "user.cfg");}/* prefix: directory * name: name of the configuration file (typ. links.cfg) */int write_config_data(unsigned char *prefix, unsigned char *name, struct option *o, struct terminal *term){ int err; unsigned char *c, *config_file; if (!(c = create_config_string(o))) return -1; config_file = stracpy(prefix); if (!config_file) { mem_free(c); return -1; } add_to_strn(&config_file, name); 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){#ifdef G if (F) update_driver_param();#endif 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 *dbl_rd(struct option *o, unsigned char *c){ unsigned char *tok = get_token(&c); char *end; double d; if (!tok) return "Missing argument"; d = strtod(tok, &end); if (*end) { mem_free(tok); return "Number expected"; } if (100*d < o->min || 100*d > o->max) { mem_free(tok); return "Out of range"; } *(double *)o->ptr = d; mem_free(tok); return NULL;}void dbl_wr(struct option *o, unsigned char **s, int *l){ char number[80]; snprintf(number, sizeof number, "%.4f", *(double*)o->ptr); add_nm(o, s, l); add_to_str(s, l, number);}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, 128)) 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; new.accept_http = !!(n & 32); new.accept_ftp = !!(n & 64); 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;}unsigned char *block_rd(struct option *o, unsigned char *c){ unsigned char *err = "Error reading image block specification"; unsigned char* url; if(!(url = get_token(&c))) return err; block_add_URL_fn(NULL, url); mem_free(url); return NULL;}void block_wr(struct option *o, unsigned char **s, int *l){ struct block *a; foreachback(a, blocks) { add_nm(o, s, l); add_quoted_to_str(s, l, a->url); }}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 + (!!a->accept_http) * 32 + (!!a->accept_ftp) * 64); 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] > '3') goto err_f; ts->m11_hack = (w[0] - '0') & 1; ts->braille = !!((w[0] - '0') & 2); 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] > '3') 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -