📄 types.c
字号:
} } else { for (a=s->prev; a!=s; a=a->prev) if (a->depth>-1) { if (a->label && casestrstr(a->label,str)) return a; if (a->ct && casestrstr(a->ct,str)) return a; } } if (a==s&&a->depth>-1&&a->label && casestrstr(a->label,str)) return a; if (a==s&&a->depth>-1&&a->ct && casestrstr(a->ct,str)) return a; return NULL;}void update_assoc(struct assoc *new){ struct assoc *repl; if (!new->label[0] || !new->ct[0] || !new->prog[0]) return; foreach(repl, assoc) if (!strcmp(repl->label, new->label) && !strcmp(repl->ct, new->ct) && !strcmp(repl->prog, new->prog) && repl->block == new->block && repl->cons == new->cons && repl->xwin == new->xwin && repl->ask == new->ask && repl->accept_http == new->accept_http && repl->accept_ftp == new->accept_ftp && repl->system == new->system) { del_from_list(repl); add_to_list(assoc, repl); return; } repl = mem_calloc(sizeof(struct assoc)); add_to_list(assoc, repl); repl->label = stracpy(new->label); repl->ct = stracpy(new->ct); repl->prog = stracpy(new->prog); repl->block = new->block; repl->cons = new->cons; repl->xwin = new->xwin; repl->ask = new->ask; repl->accept_http = new->accept_http; repl->accept_ftp = new->accept_ftp; repl->system = new->system; repl->type = 0; /*new->system = new->system; co to je? */}/*------------------------ EXTENSIONS -----------------------*//* DECLARATIONS */void ext_edit_item(struct dialog_data *,void *,void (*)(struct dialog_data *,void *,void *,struct list_description *),void *, unsigned char);void ext_copy_item(void *, void *);void *ext_default_value(struct session*, unsigned char);void *ext_new_item(void *);void ext_delete_item(void *);void *ext_find_item(void *start, unsigned char *str, int direction);unsigned char *ext_type_item(struct terminal *, void *, int);struct list extensions = { &extensions, &extensions, 0, -1, NULL };struct history ext_search_history = { 0, { &ext_search_history.items, &ext_search_history.items } };struct list_description ext_ld={ 0, /* 0= flat; 1=tree */ &extensions, /* list */ ext_new_item, ext_edit_item, assoc_default_value, ext_delete_item, ext_copy_item, ext_type_item, ext_find_item, &ext_search_history, 0, /* this is set in init_assoc function */ 40, /* width of main window */ 8, /* # of items in main window */ T_eXTENSION, T_EXTENSIONS_ALREADY_IN_USE, T_EXTENSIONS_MANAGER, T_DELETE_EXTENSION, 0, /* no button */ NULL, /* no button */ 0,0,0,0, /* internal vars */ 0, /* modified */ NULL, NULL, 0,};void *ext_new_item(void *ignore){ struct extension *new; ignore=ignore; new = mem_calloc(sizeof(struct extension)); new->ext = stracpy(""); new->ct = stracpy(""); new->type=0; return new;}void ext_delete_item(void *data){ struct extension *del=(struct extension *)data; struct extension *next=del->next; struct extension *prev=del->prev; if (del->ext)mem_free(del->ext); if (del->ct)mem_free(del->ct); if (next)next->prev=del->prev; if (prev)prev->next=del->next; mem_free(del);}void ext_copy_item(void *in, void *out){ struct extension *item_in=(struct extension *)in; struct extension *item_out=(struct extension *)out; if (item_out->ext)mem_free(item_out->ext); if (item_out->ct)mem_free(item_out->ct); item_out->ext=stracpy(item_in->ext); item_out->ct=stracpy(item_in->ct);}/* allocate string and print extension into it *//* x: 0=type all, 1=type title only */unsigned char *ext_type_item(struct terminal *term, void *data, int x){ unsigned char *txt, *txt1; struct conv_table *table; struct extension* item=(struct extension*)data; if ((struct list*)item==(&extensions)) return stracpy(_(TEXT(T_FILE_EXTENSIONS),term)); txt=stracpy(item->ext); if (item->ct){add_to_strn(&txt,": ");add_to_strn(&txt,item->ct);} table=get_translation_table(assoc_ld.codepage,term->spec->charset); txt1=convert_string(table,txt,strlen(txt),NULL); mem_free(txt); return txt1;}void menu_ext_manager(struct terminal *term,void *fcp,struct session *ses){ create_list_window(&ext_ld,&extensions,term,ses);}unsigned char *ext_msg[] = { TEXT(T_EXTENSION_S), TEXT(T_CONTENT_TYPE),};void ext_edit_item_fn(struct dialog_data *dlg){ struct terminal *term = dlg->win->term; int max = 0, min = 0; int w, rw; int y = gf_val(-1, -G_BFU_FONT_SIZE); if (dlg->win->term->spec->braille) y += gf_val(1, G_BFU_FONT_SIZE); max_text_width(term, ext_msg[0], &max, AL_LEFT); min_text_width(term, ext_msg[0], &min, AL_LEFT); max_text_width(term, ext_msg[1], &max, AL_LEFT); min_text_width(term, ext_msg[1], &min, AL_LEFT); max_buttons_width(term, dlg->items + 2, 2, &max); min_buttons_width(term, dlg->items + 2, 2, &min); w = term->x * 9 / 10 - 2 * DIALOG_LB; if (w > max) w = max; if (w < min) w = min; if (w > term->x - 2 * DIALOG_LB) w = term->x - 2 * DIALOG_LB; if (w < 1) w = 1; rw = 0; dlg_format_text_and_field(dlg, NULL, ext_msg[0], &dlg->items[0], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT); y += gf_val(1, G_BFU_FONT_SIZE * 1); dlg_format_text_and_field(dlg, NULL, ext_msg[1], &dlg->items[1], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT); y += gf_val(1, G_BFU_FONT_SIZE * 1); dlg_format_buttons(dlg, NULL, dlg->items + 2, 2, 0, &y, w, &rw, AL_CENTER); w = rw; dlg->xw = w + 2 * DIALOG_LB; dlg->yw = y + 2 * DIALOG_TB; center_dlg(dlg); draw_dlg(dlg); y = dlg->y + DIALOG_TB; if (dlg->win->term->spec->braille) y += gf_val(1, G_BFU_FONT_SIZE); dlg_format_text_and_field(dlg, term, ext_msg[0], &dlg->items[0], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT); y += gf_val(1, G_BFU_FONT_SIZE); dlg_format_text_and_field(dlg, term, ext_msg[1], &dlg->items[1], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT); y += gf_val(1, G_BFU_FONT_SIZE); dlg_format_buttons(dlg, term, &dlg->items[2], 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);}/* Puts url and title into the bookmark item */void ext_edit_done(void *data){ struct dialog *d=(struct dialog*)data; struct extension *item=(struct extension *)d->udata; struct assoc_ok_struct* s=(struct assoc_ok_struct*)d->udata2; unsigned char *txt; struct conv_table *table; unsigned char *ext, *ct; ext=(unsigned char *)&d->items[5]; ct=ext+MAX_STR_LEN; table=get_translation_table(s->dlg->win->term->spec->charset,ext_ld.codepage); txt=convert_string(table,ext,strlen(ext),NULL); mem_free(item->ext); item->ext=txt; txt=convert_string(table,ct,strlen(ct),NULL); mem_free(item->ct); item->ct=txt; s->fn(s->dlg,s->data,item,&ext_ld); d->udata=0; /* for abort function */}/* destroys an item, this function is called when edit window is aborted */void ext_edit_abort(struct dialog_data *data){ struct extension *item=(struct extension*)data->dlg->udata; struct dialog *dlg=data->dlg; mem_free(dlg->udata2); if (item)ext_delete_item(item);}void ext_edit_item(struct dialog_data *dlg, void *data, void (*ok_fn)(struct dialog_data *, void *, void *, struct list_description *), void *ok_arg, unsigned char dlg_title){ struct extension *new=(struct extension*)data; struct terminal *term=dlg->win->term; struct dialog *d; struct assoc_ok_struct *s; unsigned char *ext; unsigned char *ct; d = mem_calloc(sizeof(struct dialog) + 5 * sizeof(struct dialog_item) + 2 * MAX_STR_LEN); ext=(unsigned char *)&d->items[5]; ct = ext + MAX_STR_LEN; if (new->ext)strncpy(ext, new->ext, MAX_STR_LEN); if (new->ct)strncpy(ct, new->ct, MAX_STR_LEN); /* Create the dialog */ s=mem_alloc(sizeof(struct assoc_ok_struct)); s->fn=ok_fn; s->data=ok_arg; s->dlg=dlg; switch (dlg_title) { case TITLE_EDIT: d->title=TEXT(T_EDIT_EXTENSION); break; case TITLE_ADD: d->title=TEXT(T_ADD_EXTENSION); break; default: internal("Unsupported dialog title.\n"); } d->udata=data; d->udata2=s; d->abort=ext_edit_abort; d->refresh=ext_edit_done; d->refresh_data = d; d->title = TEXT(T_EXTENSION); d->fn = ext_edit_item_fn; d->items[0].type = D_FIELD; d->items[0].dlen = MAX_STR_LEN; d->items[0].data = ext; d->items[0].fn = check_nonempty; d->items[1].type = D_FIELD; d->items[1].dlen = MAX_STR_LEN; d->items[1].data = ct; d->items[1].fn = check_nonempty; d->items[2].type = D_BUTTON; d->items[2].gid = B_ENTER; d->items[2].fn = ok_dialog; d->items[2].text = TEXT(T_OK); d->items[3].type = D_BUTTON; d->items[3].gid = B_ESC; d->items[3].text = TEXT(T_CANCEL); d->items[3].fn = cancel_dialog; d->items[4].type = D_END; do_dialog(term, d, getml(d, NULL));}void *ext_find_item(void *start, unsigned char *str, int direction){ struct extension *e,*s=(struct extension *)start; if (direction==1) { for (e=s->next; e!=s; e=e->next) if (e->depth>-1) { if (e->ext && casestrstr(e->ext,str)) return e; if (e->ct && casestrstr(e->ct,str)) return e; } } else { for (e=s->prev; e!=s; e=e->prev) if (e->depth>-1) { if (e->ext && casestrstr(e->ext,str)) return e; if (e->ct && casestrstr(e->ct,str)) return e; } } if (e==s&&e->depth>-1&&e->ext && casestrstr(e->ext,str)) return e; if (e==s&&e->depth>-1&&e->ct && casestrstr(e->ct,str)) return e; return NULL;}void update_ext(struct extension *new){ struct extension *repl; if (!new->ext[0] || !new->ct[0]) return; foreach(repl, extensions) if (!strcmp(repl->ext, new->ext) && !strcmp(repl->ct, new->ct)) { del_from_list(repl); add_to_list(extensions, repl); return; } repl = mem_calloc(sizeof(struct extension)); add_to_list(extensions, repl); repl->ext = stracpy(new->ext); repl->ct = stracpy(new->ct); repl->type=0;}/* creates default extensions if extension list is empty */void create_initial_extensions(void){ struct extension ext; if (!list_empty(extensions))return; /* here you can add any default extension you want */ ext.ext="aif,aiff,aifc",ext.ct="audio/x-aiff",update_ext(&ext); ext.ext="au,snd",ext.ct="audio/basic",update_ext(&ext); ext.ext="avi",ext.ct="video/x-msvideo",update_ext(&ext); ext.ext="deb",ext.ct="application/x-debian-package",update_ext(&ext); ext.ext="dl",ext.ct="video/dl",update_ext(&ext); ext.ext="dxf",ext.ct="application/dxf",update_ext(&ext); ext.ext="dvi",ext.ct="application/x-dvi",update_ext(&ext); ext.ext="fli",ext.ct="video/fli",update_ext(&ext); ext.ext="g",ext.ct="application/brlcad",update_ext(&ext); ext.ext="gbr",ext.ct="application/gerber",update_ext(&ext); ext.ext="gif",ext.ct="image/gif",update_ext(&ext); ext.ext="gl",ext.ct="video/gl",update_ext(&ext);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -