|
@@ -2182,11 +2182,10 @@ int edit_sort_cmd (WEdit * edit)
|
|
|
/* if block is 1, a block must be highlighted and the shell command
|
|
|
processes it. If block is 0 the shell command is a straight system
|
|
|
command, that just produces some output which is to be inserted */
|
|
|
-void
|
|
|
+void
|
|
|
edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
|
|
|
{
|
|
|
long start_mark, end_mark;
|
|
|
- struct stat s;
|
|
|
char buf[BUFSIZ];
|
|
|
FILE *script_home = NULL;
|
|
|
FILE *script_src = NULL;
|
|
@@ -2194,49 +2193,50 @@ edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
|
|
|
char *o = NULL;
|
|
|
char *h = NULL;
|
|
|
char *b = NULL;
|
|
|
- char *e = NULL;
|
|
|
|
|
|
- o = g_strconcat (mc_home, shell_cmd, 0); /* original source script */
|
|
|
- h = g_strconcat (home_dir, EDIT_DIR, shell_cmd, 0); /* home script */
|
|
|
- b = g_strconcat (home_dir, BLOCK_FILE, 0); /* block file */
|
|
|
- e = g_strconcat (home_dir, ERROR_FILE, 0); /* error file */
|
|
|
+ o = catstrs (mc_home, shell_cmd, 0); /* original source script */
|
|
|
+ h = catstrs (home_dir, EDIT_DIR, shell_cmd, 0); /* home script */
|
|
|
+ b = catstrs (home_dir, BLOCK_FILE, 0); /* block file */
|
|
|
|
|
|
if (!(script_home = fopen (h, "r"))) {
|
|
|
if (!(script_home = fopen (h, "w"))) {
|
|
|
- edit_error_dialog ("", get_sys_error (g_strconcat
|
|
|
+ edit_error_dialog ("", get_sys_error (catstrs
|
|
|
(_
|
|
|
("Error create script:"),
|
|
|
h, 0)));
|
|
|
- goto err;
|
|
|
+ return;
|
|
|
}
|
|
|
if (!(script_src = fopen (o, "r"))) {
|
|
|
fclose (script_home);
|
|
|
unlink (h);
|
|
|
- edit_error_dialog ("", get_sys_error (g_strconcat
|
|
|
+ edit_error_dialog ("", get_sys_error (catstrs
|
|
|
(_("Error read script:"),
|
|
|
o, 0)));
|
|
|
- goto err;
|
|
|
+ return;
|
|
|
}
|
|
|
while (fgets (buf, sizeof (buf), script_src))
|
|
|
fputs (buf, script_home);
|
|
|
if (fclose (script_home)) {
|
|
|
- edit_error_dialog ("", get_sys_error (g_strconcat
|
|
|
+ edit_error_dialog ("", get_sys_error (catstrs
|
|
|
(_
|
|
|
("Error close script:"),
|
|
|
h, 0)));
|
|
|
- goto err;
|
|
|
+ return;
|
|
|
}
|
|
|
chmod (h, 0700);
|
|
|
- edit_error_dialog ("", get_sys_error (g_strconcat
|
|
|
+ edit_error_dialog ("", get_sys_error (catstrs
|
|
|
(_("Script created:"), h,
|
|
|
0)));
|
|
|
}
|
|
|
+
|
|
|
+ open_error_pipe ();
|
|
|
+
|
|
|
if (block) { /* for marked block run indent formatter */
|
|
|
if (eval_marks (edit, &start_mark, &end_mark)) {
|
|
|
edit_error_dialog (_("Process block"),
|
|
|
_
|
|
|
(" You must first highlight a block of text. "));
|
|
|
- goto err;
|
|
|
+ return;
|
|
|
}
|
|
|
edit_save_block (edit, b, start_mark, end_mark);
|
|
|
|
|
@@ -2248,9 +2248,8 @@ edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
|
|
|
* $2 - file containing the current block.
|
|
|
* $3 - file where error messages should be put.
|
|
|
*/
|
|
|
- execute (g_strconcat (" ", home_dir, EDIT_DIR, shell_cmd, " ",
|
|
|
- edit->filename, " ", home_dir, BLOCK_FILE,
|
|
|
- " ", home_dir, ERROR_FILE, NULL));
|
|
|
+ system (catstrs (" ", home_dir, EDIT_DIR, shell_cmd, " ",
|
|
|
+ edit->filename, " ", home_dir, BLOCK_FILE, NULL));
|
|
|
|
|
|
} else {
|
|
|
/*
|
|
@@ -2258,42 +2257,25 @@ edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
|
|
|
* Arguments:
|
|
|
* $1 - name of the edited file.
|
|
|
*/
|
|
|
- execute (g_strconcat (" ", home_dir, EDIT_DIR, shell_cmd, " ",
|
|
|
- edit->filename, NULL));
|
|
|
+ system (catstrs (" ", home_dir, EDIT_DIR, shell_cmd, " ",
|
|
|
+ edit->filename, NULL));
|
|
|
}
|
|
|
|
|
|
+ close_error_pipe (0, 0);
|
|
|
+
|
|
|
edit_refresh_cmd (edit);
|
|
|
edit->force |= REDRAW_COMPLETELY;
|
|
|
|
|
|
/* insert result block */
|
|
|
if (block) {
|
|
|
- if (mc_stat (e, &s) == 0) {
|
|
|
- if (!s.st_size) { /* no error messages */
|
|
|
- if (edit_block_delete_cmd (edit))
|
|
|
- goto err;
|
|
|
- edit_insert_file (edit, b);
|
|
|
- } else {
|
|
|
- edit_insert_file (edit, e);
|
|
|
- }
|
|
|
- } else {
|
|
|
- edit_error_dialog ("",
|
|
|
- get_sys_error (g_strconcat
|
|
|
- (_
|
|
|
- ("Error trying to stat file:"),
|
|
|
- e, 0)));
|
|
|
- edit->force |= REDRAW_COMPLETELY;
|
|
|
- }
|
|
|
+ if (edit_block_delete_cmd (edit))
|
|
|
+ return;
|
|
|
+ edit_insert_file (edit, b);
|
|
|
if ((block_file = fopen (b, "w")))
|
|
|
fclose (block_file);
|
|
|
- goto err;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- err:
|
|
|
- g_free (o);
|
|
|
- g_free (h);
|
|
|
- g_free (b);
|
|
|
- g_free (e);
|
|
|
-
|
|
|
return;
|
|
|
}
|
|
|
|