* editcmd.c (edit_ext_cmd): Revoked my last change.
Этот коммит содержится в:
родитель
7b6f1db773
Коммит
7a505ea99d
@ -1,3 +1,7 @@
|
|||||||
|
2004-09-26 Roland Illig <roland.illig@gmx.de>
|
||||||
|
|
||||||
|
* editcmd.c (edit_ext_cmd): Revoked my last change.
|
||||||
|
|
||||||
2004-09-25 Roland Illig <roland.illig@gmx.de>
|
2004-09-25 Roland Illig <roland.illig@gmx.de>
|
||||||
|
|
||||||
* editcmd.c (edit_ext_cmd): Replaced the old version with a new
|
* editcmd.c (edit_ext_cmd): Replaced the old version with a new
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
|
|
||||||
#include "edit.h"
|
#include "edit.h"
|
||||||
#include "editlock.h"
|
#include "editlock.h"
|
||||||
@ -43,7 +41,6 @@
|
|||||||
#include "../src/dialog.h" /* do_refresh() */
|
#include "../src/dialog.h" /* do_refresh() */
|
||||||
#include "../src/wtools.h" /* message() */
|
#include "../src/wtools.h" /* message() */
|
||||||
#include "../src/charsets.h"
|
#include "../src/charsets.h"
|
||||||
#include "../src/pipethrough.h"
|
|
||||||
|
|
||||||
#define edit_get_load_file(f,h) input_expand_dialog (h, _(" Enter file name: "), f)
|
#define edit_get_load_file(f,h) input_expand_dialog (h, _(" Enter file name: "), f)
|
||||||
#define edit_get_save_file(f,h) input_expand_dialog (h, _(" Enter file name: "), f)
|
#define edit_get_save_file(f,h) input_expand_dialog (h, _(" Enter file name: "), f)
|
||||||
@ -2396,71 +2393,36 @@ int edit_sort_cmd (WEdit * edit)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pipes the selected block through an external command and inserts the
|
/*
|
||||||
* program's output. */
|
* Ask user for a command, execute it and paste its output back to the
|
||||||
|
* editor.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
edit_ext_cmd (WEdit *edit)
|
edit_ext_cmd (WEdit *edit)
|
||||||
{
|
{
|
||||||
const char *title_i18n = _(" External Command ");
|
char *exp;
|
||||||
char *command = NULL;
|
int e;
|
||||||
char *block = NULL;
|
|
||||||
const char *error = NULL;
|
|
||||||
long start_mark, end_mark;
|
|
||||||
struct pipe_inbuffer inbuf = {NULL, 0};
|
|
||||||
struct pipe_outbuffer outbuf = {NULL, 0};
|
|
||||||
struct pipe_outbuffer errbuf = {NULL, 0};
|
|
||||||
int block_len;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
if (eval_marks (edit, &start_mark, &end_mark) == 0 /* OK */) {
|
exp =
|
||||||
block = edit_get_block (edit, start_mark, end_mark, &block_len);
|
input_dialog (_("Paste output of external command"),
|
||||||
if (block == NULL) {
|
_("Enter shell command(s):"), NULL);
|
||||||
error = _(" Could not get the current block. ");
|
|
||||||
goto cleanup;
|
if (!exp)
|
||||||
}
|
return 1;
|
||||||
|
|
||||||
|
e = system (catstrs (exp, " > ", home_dir, TEMP_FILE, (char *) NULL));
|
||||||
|
g_free (exp);
|
||||||
|
|
||||||
|
if (e) {
|
||||||
|
edit_error_dialog (_("External command"),
|
||||||
|
get_sys_error (_("Cannot execute command")));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
command = input_dialog (title_i18n, _(" Enter a shell command: "), "");
|
|
||||||
if (command == NULL)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
inbuf.data = block;
|
|
||||||
inbuf.size = block_len;
|
|
||||||
if (pipethrough(command, &inbuf, &outbuf, &errbuf, &status) == -1) {
|
|
||||||
error = get_sys_error (_(" Error executing the shell command. "));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WIFEXITED(status)) {
|
|
||||||
if (WEXITSTATUS(status) != 0) {
|
|
||||||
if (query_dialog(title_i18n, _(" The command returned unsuccessfully. Continue anyway? "),
|
|
||||||
D_ERROR, 2, _(" &Yes "), _(" &No ")) != 0 /* first button */)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error = _(" The command died unexpectedly. ");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (block != NULL && edit_block_delete_cmd (edit) != 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (outbuf.data != NULL) {
|
|
||||||
size_t i;
|
|
||||||
for (i = 0; i < outbuf.size; i++)
|
|
||||||
edit_insert (edit, ((char *) outbuf.data)[i]);
|
|
||||||
}
|
|
||||||
edit->force |= REDRAW_COMPLETELY;
|
edit->force |= REDRAW_COMPLETELY;
|
||||||
cleanup:
|
|
||||||
if (error != NULL) {
|
|
||||||
edit_error_dialog (title_i18n, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
pipe_outbuffer_finalize (&outbuf);
|
edit_insert_file (edit, catstrs (home_dir, TEMP_FILE, (char *) NULL));
|
||||||
pipe_outbuffer_finalize (&errbuf);
|
return 0;
|
||||||
g_free (block);
|
|
||||||
g_free (command);
|
|
||||||
return (error == NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if block is 1, a block must be highlighted and the shell command
|
/* if block is 1, a block must be highlighted and the shell command
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user