diff --git a/gtkedit/ChangeLog b/gtkedit/ChangeLog new file mode 100644 index 000000000..e327d7907 --- /dev/null +++ b/gtkedit/ChangeLog @@ -0,0 +1,15 @@ +2000-07-20 Andrew V. Samoilov + + * 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 diff --git a/gtkedit/edit.c b/gtkedit/edit.c index 11aeb5d82..65e434a00 100644 --- a/gtkedit/edit.c +++ b/gtkedit/edit.c @@ -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 whether you read everything or not. */ /* 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; } all_filters[] = { @@ -226,7 +226,7 @@ char *edit_get_filter (const char *filename) return p; } -char *edit_get_write_filter (char *writename, char *filename) +char *edit_get_write_filter (char *writename, const char *filename) { int i, l; char *p; @@ -1811,9 +1811,7 @@ void edit_do_undo (WEdit * edit) static void edit_delete_to_line_end (WEdit * edit) { - for (;;) { - if (edit_get_byte (edit, edit->curs1) == '\n') - break; + while (edit_get_byte (edit, edit->curs1) != '\n') { if (!edit->curs2) break; 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) { - for (;;) { - if (edit_get_byte (edit, edit->curs1 - 1) == '\n') - break; + while (edit_get_byte (edit, edit->curs1 - 1) != '\n') { if (!edit->curs1) break; edit_backspace (edit); @@ -2765,7 +2761,7 @@ void user_menu (WEdit *edit) if (fd = fopen (block_file, "w")) fclose(fd); } } else { - edit_error_dialog (_(""), + edit_error_dialog ("", get_sys_error (catstrs (_ ("Error trying to stat file:"), error_file, 0))); return; diff --git a/gtkedit/edit.h b/gtkedit/edit.h index c0984d82d..744202048 100644 --- a/gtkedit/edit.h +++ b/gtkedit/edit.h @@ -379,6 +379,8 @@ void edit_push_action (WEdit * edit, long c,...); void edit_push_key_press (WEdit * edit); void edit_insert_ahead (WEdit * edit, int c); 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_confirm_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 user_menu (WEdit *edit); - +void edit_init_file(); #ifdef MIDNIGHT diff --git a/gtkedit/editcmd.c b/gtkedit/editcmd.c index 6affb1adb..a38d7af69 100644 --- a/gtkedit/editcmd.c +++ b/gtkedit/editcmd.c @@ -278,7 +278,7 @@ int edit_save_file (WEdit * edit, const char *filename) savename = (char *) tempnam (savedir, "cooledit"); free (savedir); if (!savename) - goto error_save; + return 0; } if ((file = fopen (savename, "w+")) == 0) goto error_save; @@ -309,7 +309,8 @@ int edit_save_file (WEdit * edit, const char *filename) #ifdef CR_LF_TRANSLATION } else { /* optimised save */ filelen = edit_write_stream (edit, f); - fclose (file); + if (fclose (file)) + filelen = -1; #else } else { long buf; @@ -317,8 +318,7 @@ int edit_save_file (WEdit * edit, const char *filename) filelen = edit->last_byte; while (buf <= (edit->curs1 >> S_EDIT_BUF_SIZE) - 1) { if (fwrite ((char *) edit->buffers1[buf], EDIT_BUF_SIZE, 1, file) != 1) { - filelen = -1; - break; + goto error_save; } buf++; } @@ -341,8 +341,9 @@ int edit_save_file (WEdit * edit, const char *filename) } edit->curs2++; } - fclose (file); -#endif + if (fclose (file)) + goto error_save; +#endif /* CR_LF_TRANSLATION */ } 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); - exp = old ? old : ""; - exp = input_dialog (_(" Run Sort "), /* Not essential to translate */ _(" 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, "w"))) { - edit_error_dialog (_(""), + edit_error_dialog ("", get_sys_error (catstrs (_ ("Error create script:"), h, 0))); return; } else { if (! (script_src = fopen (o, "r"))) { fclose (script_home); unlink (h); - edit_error_dialog (_(""), + edit_error_dialog ("", get_sys_error (catstrs (_ ("Error read script:"), o, 0))); return; } else { while (fgets(buf, sizeof(buf), script_src)) fprintf(script_home, "%s",buf); if (fclose(script_home)) { - edit_error_dialog (_(""), + edit_error_dialog ("", get_sys_error (catstrs (_ ("Error close script:"), h, 0))); return; } else { chmod (h, 0700); - edit_error_dialog (_(""), + edit_error_dialog ("", 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)) return; edit_insert_file (edit, b); - if (block_file = fopen (b, "w")) fclose(block_file); - return; } else { edit_insert_file (edit, e); - if (block_file = fopen (b, "w")) fclose(block_file); - return; } } else { -/* Not essential to translate */ - edit_error_dialog (_(""), + edit_error_dialog ("", /* Not essential to translate */ get_sys_error (catstrs (_ ("Error trying to stat file:"), e, 0))); 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; } diff --git a/gtkedit/syntax.c b/gtkedit/syntax.c index fedaa59b8..7397054d5 100644 --- a/gtkedit/syntax.c +++ b/gtkedit/syntax.c @@ -1156,11 +1156,8 @@ void edit_free_syntax_rules (WEdit * edit) syntax_free (edit->rules[i]->keyword_first_chars); syntax_free (edit->rules[i]); } - for (;;) { - struct _syntax_marker *s; - if (!edit->syntax_marker) - break; - s = edit->syntax_marker->next; + while (edit->syntax_marker) { + struct _syntax_marker *s = edit->syntax_marker->next; syntax_free (edit->syntax_marker); edit->syntax_marker = s; } @@ -1169,7 +1166,7 @@ void edit_free_syntax_rules (WEdit * edit) #define CURRENT_SYNTAX_RULES_VERSION "62" -char *syntax_text[] = { +static const char * const syntax_text[] = { "# 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)", "# black", @@ -1346,7 +1343,7 @@ FILE *upgrade_syntax_file (char *syntax_file) char line[80]; f = fopen (syntax_file, "r"); if (!f) { - char **syntax_line; + const char * const *syntax_line; f = fopen (syntax_file, "w"); if (!f) return 0; @@ -1363,6 +1360,7 @@ FILE *upgrade_syntax_file (char *syntax_file) if (atoi (p) < atoi (CURRENT_SYNTAX_RULES_VERSION)) { char s[1024]; rename_rule_file: + fclose (f); strcpy (s, syntax_file); strcat (s, ".OLD"); unlink (s);