void prog_func(struct terminal *term, struct list_head *list, unsigned char *param, unsigned char *name) { unsigned char *prog, *cmd; if (!(prog = get_prog(list)) || !*prog) { msg_box(term, NULL, TEXT(T_NO_PROGRAM), AL_CENTER | AL_EXTD_TEXT, TEXT(T_NO_PROGRAM_SPECIFIED_FOR), " ", name, ".", NULL, NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC); return; } if ((cmd = subst_file(prog, param, 0))) { exec_on_terminal(term, cmd, "", 1); mem_free(cmd); } }
void textarea_edit(int op, struct terminal *term_, struct form_state *fs_, struct document_view *doc_view_, struct link *link_) { struct textarea_data *td = NULL; assert ((op == 0 || op == 1) && term_); if_assert_failed return; if (op == 0 && get_cmd_opt_bool("anonymous")) { info_box(term_, 0, N_("Error"), ALIGN_CENTER, N_("You cannot launch an external" " editor in the anonymous mode.")); return; } if (op == 0) { unsigned char *ed; unsigned char *ex; assert(fs_ && doc_view_ && link_ && term_); td = init_textarea_data(term_, fs_, doc_view_, link_); if (!td) return; ed = get_opt_str("document.browse.forms.editor", doc_view_->session); if (!ed || !*ed) { ed = getenv("EDITOR"); if (!ed || !*ed) ed = "vi"; } ex = straconcat(ed, " ", td->fn, (unsigned char *) NULL); if (!ex) { unlink(td->fn); done_textarea_data(td); return; } td->term->textarea_data = td; exec_on_terminal(td->term, ex, "", TERM_EXEC_FG); mem_free(ex); return; } else if (op == 1) { struct string file; td = term_->textarea_data; term_->textarea_data = NULL; assert(td); if (!td->fs || !init_string(&file) || !add_file_to_string(&file, td->fn)) { done_textarea_data(td); return; } if (file.length > td->fc_maxlength) { file.source[td->fc_maxlength] = '\0'; /* Casting size_t fc_maxlength to unsigned int * and formatting it with "%u" is safe, * because fc_maxlength is smaller than * file.length, which is an int. */ info_box(td->term, MSGBOX_FREE_TEXT, N_("Warning"), ALIGN_CENTER, msg_text(td->term, N_("You have exceeded the textarea's" " size limit: your input is %d" " bytes, but the maximum is %u" " bytes.\n\n" "Your input has been truncated," " but you can still recover the" " text that you entered from" " this file: %s"), file.length, (unsigned int) td->fc_maxlength, td->fn)); } else { unlink(td->fn); } mem_free(td->fs->value); td->fs->value = file.source; td->fs->state = file.length; if (td->doc_view && td->link) draw_form_entry(td->term, td->doc_view, td->link); } done_textarea_data(td); }