mirror of https://github.com/MidnightCommander/mc
* edit-widget.h: Eliminate ERROR_FILE.
* edit.c: Remove all references to ERROR_FILE. * editcmd.c (edit_block_process_cmd): Revert to using catstrs(), those strings are freed now. Use system(), not execute() to execute commands. Use open_error_pipe() and close_error_pipe() to keep track of errors.
This commit is contained in:
parent
6f0a3ef49f
commit
221c35266c
|
@ -1,3 +1,12 @@
|
||||||
|
2002-08-24 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
|
* edit-widget.h: Eliminate ERROR_FILE.
|
||||||
|
* edit.c: Remove all references to ERROR_FILE.
|
||||||
|
* editcmd.c (edit_block_process_cmd): Revert to using catstrs(),
|
||||||
|
those strings are freed now. Use system(), not execute() to
|
||||||
|
execute commands. Use open_error_pipe() and close_error_pipe()
|
||||||
|
to keep track of errors.
|
||||||
|
|
||||||
2002-08-22 Pavel Roskin <proski@gnu.org>
|
2002-08-22 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
* editcmd.c: Clean up global variables in the completion code.
|
* editcmd.c: Clean up global variables in the completion code.
|
||||||
|
|
|
@ -126,7 +126,6 @@ typedef struct editor_widget WEdit;
|
||||||
#define CLIP_FILE EDIT_DIR PATH_SEP_STR "cooledit.clip"
|
#define CLIP_FILE EDIT_DIR PATH_SEP_STR "cooledit.clip"
|
||||||
#define MACRO_FILE EDIT_DIR PATH_SEP_STR "cooledit.macros"
|
#define MACRO_FILE EDIT_DIR PATH_SEP_STR "cooledit.macros"
|
||||||
#define BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block"
|
#define BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block"
|
||||||
#define ERROR_FILE EDIT_DIR PATH_SEP_STR "cooledit.error"
|
|
||||||
#define TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp"
|
#define TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp"
|
||||||
|
|
||||||
#endif /* !__EDIT_WIDGET_H */
|
#endif /* !__EDIT_WIDGET_H */
|
||||||
|
|
43
edit/edit.c
43
edit/edit.c
|
@ -2682,51 +2682,40 @@ void edit_execute_macro (WEdit * edit, struct macro macro[], int n)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* User edit menu, like user menu (F2) but only in editor. */
|
/* User edit menu, like user menu (F2) but only in editor. */
|
||||||
void user_menu (WEdit *edit)
|
void
|
||||||
|
user_menu (WEdit * edit)
|
||||||
{
|
{
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
int nomark;
|
int nomark;
|
||||||
struct stat status;
|
struct stat status;
|
||||||
long start_mark, end_mark;
|
long start_mark, end_mark;
|
||||||
char *block_file = catstrs (home_dir, BLOCK_FILE, 0);
|
char *block_file = catstrs (home_dir, BLOCK_FILE, 0);
|
||||||
char *error_file = catstrs (home_dir, ERROR_FILE, 0);
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
nomark = eval_marks (edit, &start_mark, &end_mark);
|
nomark = eval_marks (edit, &start_mark, &end_mark);
|
||||||
if (! nomark) /* remember marked or not */
|
if (!nomark) /* remember marked or not */
|
||||||
edit_save_block (edit, block_file, start_mark, end_mark);
|
edit_save_block (edit, block_file, start_mark, end_mark);
|
||||||
|
|
||||||
/* run shell scripts from menu */
|
/* run shell scripts from menu */
|
||||||
user_menu_cmd (edit);
|
user_menu_cmd (edit);
|
||||||
|
|
||||||
if (mc_stat (error_file, &status) != 0 || !status.st_size) {
|
|
||||||
/* no error messages */
|
|
||||||
if (mc_stat (block_file, &status) != 0 || !status.st_size) {
|
|
||||||
/* no block messages */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! nomark) {
|
if (mc_stat (block_file, &status) != 0 || !status.st_size) {
|
||||||
/* i.e. we have marked block */
|
/* no block messages */
|
||||||
rc = edit_block_delete_cmd(edit);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rc) {
|
if (!nomark) {
|
||||||
edit_insert_file (edit, block_file);
|
/* i.e. we have marked block */
|
||||||
}
|
rc = edit_block_delete_cmd (edit);
|
||||||
} else {
|
}
|
||||||
/* error file exists and is not empty */
|
|
||||||
edit_cursor_to_bol (edit);
|
|
||||||
edit_insert_file (edit, error_file);
|
|
||||||
|
|
||||||
/* truncate error file */
|
if (!rc) {
|
||||||
if ((fd = fopen (error_file, "w")))
|
edit_insert_file (edit, block_file);
|
||||||
fclose(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* truncate block file */
|
/* truncate block file */
|
||||||
if ((fd = fopen (block_file, "w"))) {
|
if ((fd = fopen (block_file, "w"))) {
|
||||||
fclose(fd);
|
fclose (fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
edit_refresh_cmd (edit);
|
edit_refresh_cmd (edit);
|
||||||
|
|
|
@ -2182,11 +2182,10 @@ int edit_sort_cmd (WEdit * edit)
|
||||||
/* 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
|
||||||
processes it. If block is 0 the shell command is a straight system
|
processes it. If block is 0 the shell command is a straight system
|
||||||
command, that just produces some output which is to be inserted */
|
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)
|
edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
|
||||||
{
|
{
|
||||||
long start_mark, end_mark;
|
long start_mark, end_mark;
|
||||||
struct stat s;
|
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
FILE *script_home = NULL;
|
FILE *script_home = NULL;
|
||||||
FILE *script_src = 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 *o = NULL;
|
||||||
char *h = NULL;
|
char *h = NULL;
|
||||||
char *b = NULL;
|
char *b = NULL;
|
||||||
char *e = NULL;
|
|
||||||
|
|
||||||
o = g_strconcat (mc_home, shell_cmd, 0); /* original source script */
|
o = catstrs (mc_home, shell_cmd, 0); /* original source script */
|
||||||
h = g_strconcat (home_dir, EDIT_DIR, shell_cmd, 0); /* home script */
|
h = catstrs (home_dir, EDIT_DIR, shell_cmd, 0); /* home script */
|
||||||
b = g_strconcat (home_dir, BLOCK_FILE, 0); /* block file */
|
b = catstrs (home_dir, BLOCK_FILE, 0); /* block file */
|
||||||
e = g_strconcat (home_dir, ERROR_FILE, 0); /* error file */
|
|
||||||
|
|
||||||
if (!(script_home = fopen (h, "r"))) {
|
if (!(script_home = fopen (h, "r"))) {
|
||||||
if (!(script_home = fopen (h, "w"))) {
|
if (!(script_home = fopen (h, "w"))) {
|
||||||
edit_error_dialog ("", get_sys_error (g_strconcat
|
edit_error_dialog ("", get_sys_error (catstrs
|
||||||
(_
|
(_
|
||||||
("Error create script:"),
|
("Error create script:"),
|
||||||
h, 0)));
|
h, 0)));
|
||||||
goto err;
|
return;
|
||||||
}
|
}
|
||||||
if (!(script_src = fopen (o, "r"))) {
|
if (!(script_src = fopen (o, "r"))) {
|
||||||
fclose (script_home);
|
fclose (script_home);
|
||||||
unlink (h);
|
unlink (h);
|
||||||
edit_error_dialog ("", get_sys_error (g_strconcat
|
edit_error_dialog ("", get_sys_error (catstrs
|
||||||
(_("Error read script:"),
|
(_("Error read script:"),
|
||||||
o, 0)));
|
o, 0)));
|
||||||
goto err;
|
return;
|
||||||
}
|
}
|
||||||
while (fgets (buf, sizeof (buf), script_src))
|
while (fgets (buf, sizeof (buf), script_src))
|
||||||
fputs (buf, script_home);
|
fputs (buf, script_home);
|
||||||
if (fclose (script_home)) {
|
if (fclose (script_home)) {
|
||||||
edit_error_dialog ("", get_sys_error (g_strconcat
|
edit_error_dialog ("", get_sys_error (catstrs
|
||||||
(_
|
(_
|
||||||
("Error close script:"),
|
("Error close script:"),
|
||||||
h, 0)));
|
h, 0)));
|
||||||
goto err;
|
return;
|
||||||
}
|
}
|
||||||
chmod (h, 0700);
|
chmod (h, 0700);
|
||||||
edit_error_dialog ("", get_sys_error (g_strconcat
|
edit_error_dialog ("", get_sys_error (catstrs
|
||||||
(_("Script created:"), h,
|
(_("Script created:"), h,
|
||||||
0)));
|
0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open_error_pipe ();
|
||||||
|
|
||||||
if (block) { /* for marked block run indent formatter */
|
if (block) { /* for marked block run indent formatter */
|
||||||
if (eval_marks (edit, &start_mark, &end_mark)) {
|
if (eval_marks (edit, &start_mark, &end_mark)) {
|
||||||
edit_error_dialog (_("Process block"),
|
edit_error_dialog (_("Process block"),
|
||||||
_
|
_
|
||||||
(" You must first highlight a block of text. "));
|
(" You must first highlight a block of text. "));
|
||||||
goto err;
|
return;
|
||||||
}
|
}
|
||||||
edit_save_block (edit, b, start_mark, end_mark);
|
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.
|
* $2 - file containing the current block.
|
||||||
* $3 - file where error messages should be put.
|
* $3 - file where error messages should be put.
|
||||||
*/
|
*/
|
||||||
execute (g_strconcat (" ", home_dir, EDIT_DIR, shell_cmd, " ",
|
system (catstrs (" ", home_dir, EDIT_DIR, shell_cmd, " ",
|
||||||
edit->filename, " ", home_dir, BLOCK_FILE,
|
edit->filename, " ", home_dir, BLOCK_FILE, NULL));
|
||||||
" ", home_dir, ERROR_FILE, NULL));
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
|
@ -2258,42 +2257,25 @@ edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
|
||||||
* Arguments:
|
* Arguments:
|
||||||
* $1 - name of the edited file.
|
* $1 - name of the edited file.
|
||||||
*/
|
*/
|
||||||
execute (g_strconcat (" ", home_dir, EDIT_DIR, shell_cmd, " ",
|
system (catstrs (" ", home_dir, EDIT_DIR, shell_cmd, " ",
|
||||||
edit->filename, NULL));
|
edit->filename, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close_error_pipe (0, 0);
|
||||||
|
|
||||||
edit_refresh_cmd (edit);
|
edit_refresh_cmd (edit);
|
||||||
edit->force |= REDRAW_COMPLETELY;
|
edit->force |= REDRAW_COMPLETELY;
|
||||||
|
|
||||||
/* insert result block */
|
/* insert result block */
|
||||||
if (block) {
|
if (block) {
|
||||||
if (mc_stat (e, &s) == 0) {
|
if (edit_block_delete_cmd (edit))
|
||||||
if (!s.st_size) { /* no error messages */
|
return;
|
||||||
if (edit_block_delete_cmd (edit))
|
edit_insert_file (edit, b);
|
||||||
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 ((block_file = fopen (b, "w")))
|
if ((block_file = fopen (b, "w")))
|
||||||
fclose (block_file);
|
fclose (block_file);
|
||||||
goto err;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
err:
|
|
||||||
g_free (o);
|
|
||||||
g_free (h);
|
|
||||||
g_free (b);
|
|
||||||
g_free (e);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue