mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
2000-07-20 Andrew V. Samoilov <sav@bcs.zp.ua>
* gtkedit/editcmd.c (edit_save_file): check fclose()s return value to prevent loss of data (edit_block_process_cmd): don't translate empty string * gtkedit/edit.h (edit_get_write_filter, edit_write_stream, edit_init_file): added declarations * edit.c (edit_filters): constified (edit_get_write_filter): filename constified (user_menu): don't translate empty string * syntax.c (syntax_text): constified (upgrade_syntax_file): syntax_line constified, f closed after use
This commit is contained in:
parent
bace6b783b
commit
090957605c
15
gtkedit/ChangeLog
Normal file
15
gtkedit/ChangeLog
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
2000-07-20 Andrew V. Samoilov <sav@bcs.zp.ua>
|
||||||
|
|
||||||
|
* gtkedit/editcmd.c (edit_save_file): check fclose()s return value
|
||||||
|
to prevent loss of data
|
||||||
|
(edit_block_process_cmd): don't translate empty string
|
||||||
|
|
||||||
|
* gtkedit/edit.h (edit_get_write_filter, edit_write_stream,
|
||||||
|
edit_init_file): added declarations
|
||||||
|
|
||||||
|
* edit.c (edit_filters): constified
|
||||||
|
(edit_get_write_filter): filename constified
|
||||||
|
(user_menu): don't translate empty string
|
||||||
|
|
||||||
|
* syntax.c (syntax_text): constified
|
||||||
|
(upgrade_syntax_file): syntax_line constified, f closed after use
|
@ -182,7 +182,7 @@ int init_dynamic_edit_buffers (WEdit * edit, const char *filename, const char *t
|
|||||||
/* detecting an error on read, is not so easy 'cos there is not way to tell
|
/* detecting an error on read, is not so easy 'cos there is not way to tell
|
||||||
whether you read everything or not. */
|
whether you read everything or not. */
|
||||||
/* FIXME: add proper `triple_pipe_open' to read, write and check errors. */
|
/* FIXME: add proper `triple_pipe_open' to read, write and check errors. */
|
||||||
static struct edit_filters {
|
static const struct edit_filters {
|
||||||
char *read, *write, *extension;
|
char *read, *write, *extension;
|
||||||
} all_filters[] = {
|
} all_filters[] = {
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ char *edit_get_filter (const char *filename)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *edit_get_write_filter (char *writename, char *filename)
|
char *edit_get_write_filter (char *writename, const char *filename)
|
||||||
{
|
{
|
||||||
int i, l;
|
int i, l;
|
||||||
char *p;
|
char *p;
|
||||||
@ -1811,9 +1811,7 @@ void edit_do_undo (WEdit * edit)
|
|||||||
|
|
||||||
static void edit_delete_to_line_end (WEdit * edit)
|
static void edit_delete_to_line_end (WEdit * edit)
|
||||||
{
|
{
|
||||||
for (;;) {
|
while (edit_get_byte (edit, edit->curs1) != '\n') {
|
||||||
if (edit_get_byte (edit, edit->curs1) == '\n')
|
|
||||||
break;
|
|
||||||
if (!edit->curs2)
|
if (!edit->curs2)
|
||||||
break;
|
break;
|
||||||
edit_delete (edit);
|
edit_delete (edit);
|
||||||
@ -1822,9 +1820,7 @@ static void edit_delete_to_line_end (WEdit * edit)
|
|||||||
|
|
||||||
static void edit_delete_to_line_begin (WEdit * edit)
|
static void edit_delete_to_line_begin (WEdit * edit)
|
||||||
{
|
{
|
||||||
for (;;) {
|
while (edit_get_byte (edit, edit->curs1 - 1) != '\n') {
|
||||||
if (edit_get_byte (edit, edit->curs1 - 1) == '\n')
|
|
||||||
break;
|
|
||||||
if (!edit->curs1)
|
if (!edit->curs1)
|
||||||
break;
|
break;
|
||||||
edit_backspace (edit);
|
edit_backspace (edit);
|
||||||
@ -2765,7 +2761,7 @@ void user_menu (WEdit *edit)
|
|||||||
if (fd = fopen (block_file, "w")) fclose(fd);
|
if (fd = fopen (block_file, "w")) fclose(fd);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
edit_error_dialog (_(""),
|
edit_error_dialog ("",
|
||||||
get_sys_error (catstrs (_ ("Error trying to stat file:"),
|
get_sys_error (catstrs (_ ("Error trying to stat file:"),
|
||||||
error_file, 0)));
|
error_file, 0)));
|
||||||
return;
|
return;
|
||||||
|
@ -379,6 +379,8 @@ void edit_push_action (WEdit * edit, long c,...);
|
|||||||
void edit_push_key_press (WEdit * edit);
|
void edit_push_key_press (WEdit * edit);
|
||||||
void edit_insert_ahead (WEdit * edit, int c);
|
void edit_insert_ahead (WEdit * edit, int c);
|
||||||
int edit_save_file (WEdit * edit, const char *filename);
|
int edit_save_file (WEdit * edit, const char *filename);
|
||||||
|
long edit_write_stream (WEdit * edit, FILE * f);
|
||||||
|
char *edit_get_write_filter (char *writename, const char *filename);
|
||||||
int edit_save_cmd (WEdit * edit);
|
int edit_save_cmd (WEdit * edit);
|
||||||
int edit_save_confirm_cmd (WEdit * edit);
|
int edit_save_confirm_cmd (WEdit * edit);
|
||||||
int edit_save_as_cmd (WEdit * edit);
|
int edit_save_as_cmd (WEdit * edit);
|
||||||
@ -453,7 +455,7 @@ void book_mark_inc (WEdit * edit, int line);
|
|||||||
void book_mark_dec (WEdit * edit, int line);
|
void book_mark_dec (WEdit * edit, int line);
|
||||||
|
|
||||||
void user_menu (WEdit *edit);
|
void user_menu (WEdit *edit);
|
||||||
|
void edit_init_file();
|
||||||
|
|
||||||
#ifdef MIDNIGHT
|
#ifdef MIDNIGHT
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ int edit_save_file (WEdit * edit, const char *filename)
|
|||||||
savename = (char *) tempnam (savedir, "cooledit");
|
savename = (char *) tempnam (savedir, "cooledit");
|
||||||
free (savedir);
|
free (savedir);
|
||||||
if (!savename)
|
if (!savename)
|
||||||
goto error_save;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((file = fopen (savename, "w+")) == 0)
|
if ((file = fopen (savename, "w+")) == 0)
|
||||||
goto error_save;
|
goto error_save;
|
||||||
@ -309,7 +309,8 @@ int edit_save_file (WEdit * edit, const char *filename)
|
|||||||
#ifdef CR_LF_TRANSLATION
|
#ifdef CR_LF_TRANSLATION
|
||||||
} else { /* optimised save */
|
} else { /* optimised save */
|
||||||
filelen = edit_write_stream (edit, f);
|
filelen = edit_write_stream (edit, f);
|
||||||
fclose (file);
|
if (fclose (file))
|
||||||
|
filelen = -1;
|
||||||
#else
|
#else
|
||||||
} else {
|
} else {
|
||||||
long buf;
|
long buf;
|
||||||
@ -317,8 +318,7 @@ int edit_save_file (WEdit * edit, const char *filename)
|
|||||||
filelen = edit->last_byte;
|
filelen = edit->last_byte;
|
||||||
while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) {
|
while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) {
|
||||||
if (fwrite ((char *) edit->buffers1[buf], EDIT_BUF_SIZE, 1, file) != 1) {
|
if (fwrite ((char *) edit->buffers1[buf], EDIT_BUF_SIZE, 1, file) != 1) {
|
||||||
filelen = -1;
|
goto error_save;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
buf++;
|
buf++;
|
||||||
}
|
}
|
||||||
@ -341,8 +341,9 @@ int edit_save_file (WEdit * edit, const char *filename)
|
|||||||
}
|
}
|
||||||
edit->curs2++;
|
edit->curs2++;
|
||||||
}
|
}
|
||||||
fclose (file);
|
if (fclose (file))
|
||||||
#endif
|
goto error_save;
|
||||||
|
#endif /* CR_LF_TRANSLATION */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filelen != edit->last_byte)
|
if (filelen != edit->last_byte)
|
||||||
@ -2822,8 +2823,6 @@ int edit_sort_cmd (WEdit * edit)
|
|||||||
}
|
}
|
||||||
edit_save_block (edit, catstrs (home_dir, BLOCK_FILE, 0), start_mark, end_mark);
|
edit_save_block (edit, catstrs (home_dir, BLOCK_FILE, 0), start_mark, end_mark);
|
||||||
|
|
||||||
exp = old ? old : "";
|
|
||||||
|
|
||||||
exp = input_dialog (_(" Run Sort "),
|
exp = input_dialog (_(" Run Sort "),
|
||||||
/* Not essential to translate */
|
/* Not essential to translate */
|
||||||
_(" Enter sort options (see manpage) separated by whitespace: "), "");
|
_(" Enter sort options (see manpage) separated by whitespace: "), "");
|
||||||
@ -2877,25 +2876,25 @@ void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
|
|||||||
|
|
||||||
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 (_(""),
|
edit_error_dialog ("",
|
||||||
get_sys_error (catstrs (_ ("Error create script:"), h, 0)));
|
get_sys_error (catstrs (_ ("Error create script:"), h, 0)));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (! (script_src = fopen (o, "r"))) {
|
if (! (script_src = fopen (o, "r"))) {
|
||||||
fclose (script_home); unlink (h);
|
fclose (script_home); unlink (h);
|
||||||
edit_error_dialog (_(""),
|
edit_error_dialog ("",
|
||||||
get_sys_error (catstrs (_ ("Error read script:"), o, 0)));
|
get_sys_error (catstrs (_ ("Error read script:"), o, 0)));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
while (fgets(buf, sizeof(buf), script_src))
|
while (fgets(buf, sizeof(buf), script_src))
|
||||||
fprintf(script_home, "%s",buf);
|
fprintf(script_home, "%s",buf);
|
||||||
if (fclose(script_home)) {
|
if (fclose(script_home)) {
|
||||||
edit_error_dialog (_(""),
|
edit_error_dialog ("",
|
||||||
get_sys_error (catstrs (_ ("Error close script:"), h, 0)));
|
get_sys_error (catstrs (_ ("Error close script:"), h, 0)));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
chmod (h, 0700);
|
chmod (h, 0700);
|
||||||
edit_error_dialog (_(""),
|
edit_error_dialog ("",
|
||||||
get_sys_error (catstrs (_ ("Script created:"), h, 0)));
|
get_sys_error (catstrs (_ ("Script created:"), h, 0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2931,22 +2930,18 @@ void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block)
|
|||||||
if (edit_block_delete_cmd (edit))
|
if (edit_block_delete_cmd (edit))
|
||||||
return;
|
return;
|
||||||
edit_insert_file (edit, b);
|
edit_insert_file (edit, b);
|
||||||
if (block_file = fopen (b, "w")) fclose(block_file);
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
edit_insert_file (edit, e);
|
edit_insert_file (edit, e);
|
||||||
if (block_file = fopen (b, "w")) fclose(block_file);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Not essential to translate */
|
edit_error_dialog ("",
|
||||||
edit_error_dialog (_(""),
|
|
||||||
/* Not essential to translate */
|
/* Not essential to translate */
|
||||||
get_sys_error (catstrs (_ ("Error trying to stat file:"), e, 0)));
|
get_sys_error (catstrs (_ ("Error trying to stat file:"), e, 0)));
|
||||||
edit->force |= REDRAW_COMPLETELY;
|
edit->force |= REDRAW_COMPLETELY;
|
||||||
if (block_file = fopen (b, "w")) fclose(block_file);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if ((block_file = fopen (b, "w")))
|
||||||
|
fclose (block_file);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1156,11 +1156,8 @@ void edit_free_syntax_rules (WEdit * edit)
|
|||||||
syntax_free (edit->rules[i]->keyword_first_chars);
|
syntax_free (edit->rules[i]->keyword_first_chars);
|
||||||
syntax_free (edit->rules[i]);
|
syntax_free (edit->rules[i]);
|
||||||
}
|
}
|
||||||
for (;;) {
|
while (edit->syntax_marker) {
|
||||||
struct _syntax_marker *s;
|
struct _syntax_marker *s = edit->syntax_marker->next;
|
||||||
if (!edit->syntax_marker)
|
|
||||||
break;
|
|
||||||
s = edit->syntax_marker->next;
|
|
||||||
syntax_free (edit->syntax_marker);
|
syntax_free (edit->syntax_marker);
|
||||||
edit->syntax_marker = s;
|
edit->syntax_marker = s;
|
||||||
}
|
}
|
||||||
@ -1169,7 +1166,7 @@ void edit_free_syntax_rules (WEdit * edit)
|
|||||||
|
|
||||||
#define CURRENT_SYNTAX_RULES_VERSION "62"
|
#define CURRENT_SYNTAX_RULES_VERSION "62"
|
||||||
|
|
||||||
char *syntax_text[] = {
|
static const char * const syntax_text[] = {
|
||||||
"# syntax rules version " CURRENT_SYNTAX_RULES_VERSION,
|
"# syntax rules version " CURRENT_SYNTAX_RULES_VERSION,
|
||||||
"# (after the slash is a Cooledit color, 0-26 or any of the X colors in rgb.txt)",
|
"# (after the slash is a Cooledit color, 0-26 or any of the X colors in rgb.txt)",
|
||||||
"# black",
|
"# black",
|
||||||
@ -1346,7 +1343,7 @@ FILE *upgrade_syntax_file (char *syntax_file)
|
|||||||
char line[80];
|
char line[80];
|
||||||
f = fopen (syntax_file, "r");
|
f = fopen (syntax_file, "r");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
char **syntax_line;
|
const char * const *syntax_line;
|
||||||
f = fopen (syntax_file, "w");
|
f = fopen (syntax_file, "w");
|
||||||
if (!f)
|
if (!f)
|
||||||
return 0;
|
return 0;
|
||||||
@ -1363,6 +1360,7 @@ FILE *upgrade_syntax_file (char *syntax_file)
|
|||||||
if (atoi (p) < atoi (CURRENT_SYNTAX_RULES_VERSION)) {
|
if (atoi (p) < atoi (CURRENT_SYNTAX_RULES_VERSION)) {
|
||||||
char s[1024];
|
char s[1024];
|
||||||
rename_rule_file:
|
rename_rule_file:
|
||||||
|
fclose (f);
|
||||||
strcpy (s, syntax_file);
|
strcpy (s, syntax_file);
|
||||||
strcat (s, ".OLD");
|
strcat (s, ".OLD");
|
||||||
unlink (s);
|
unlink (s);
|
||||||
|
Loading…
Reference in New Issue
Block a user