From 9be77996d60ca65750cb6dde34153780763e0788 Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Wed, 7 Sep 2005 08:54:11 +0000 Subject: [PATCH] Replaced the editor_option_backup_ext_int hack with a string configuration variable, which allows the backup extension to have more than just four characters. --- edit/ChangeLog | 5 +++++ edit/edit.c | 3 +-- edit/edit.h | 1 - edit/editcmd.c | 26 ++++++++++++++------------ edit/editwidget.c | 6 ------ 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/edit/ChangeLog b/edit/ChangeLog index f5b995c57..9f805827b 100644 --- a/edit/ChangeLog +++ b/edit/ChangeLog @@ -4,6 +4,11 @@ the possibility of saving editor options except calling the "Save setup..." function from within the file manager. + * edit.c, edit.h, editcmd.c, editwidget.c: Replaced the + editor_option_backup_ext_int hack with a string configuration + variable, which allows the backup extension to have more than + just four characters. + 2005-09-05 Roland Illig * editcmd.c: Fixed some of the gcc warnings. diff --git a/edit/edit.c b/edit/edit.c index 8bd00bbac..8780bc502 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -61,7 +61,6 @@ int option_backspace_through_tabs = 0; int option_fake_half_tabs = 1; int option_save_mode = EDIT_QUICK_SAVE; int option_save_position = 1; -int option_backup_ext_int = -1; int option_max_undo = 32768; int option_edit_right_extreme = 0; @@ -70,7 +69,7 @@ int option_edit_top_extreme = 0; int option_edit_bottom_extreme = 0; const char *option_whole_chars_search = "0123456789abcdefghijklmnopqrstuvwxyz_"; -char *option_backup_ext = "~"; +char *option_backup_ext = NULL; /*- * diff --git a/edit/edit.h b/edit/edit.h index b8f81126d..0b675a906 100644 --- a/edit/edit.h +++ b/edit/edit.h @@ -279,7 +279,6 @@ typedef enum { extern int option_save_mode; extern int option_save_position; -extern int option_backup_ext_int; extern int option_max_undo; extern int option_syntax_highlighting; extern int option_auto_syntax; diff --git a/edit/editcmd.c b/edit/editcmd.c index f13ff2825..c68618326 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -24,6 +24,8 @@ /* #define PIPE_BLOCKS_SO_READ_BYTE_BY_BYTE */ #include + +#include #include #include @@ -358,10 +360,14 @@ edit_save_file (WEdit *edit, const char *filename) if (filelen != edit->last_byte) goto error_save; - if (this_save_mode == EDIT_DO_BACKUP) - if (mc_rename (filename, catstrs (filename, option_backup_ext, (char *) NULL)) - == -1) + + if (this_save_mode == EDIT_DO_BACKUP) { + assert (option_backup_ext != NULL); + if (mc_rename (filename, catstrs (filename, option_backup_ext, + (char *) NULL)) == -1) goto error_save; + } + if (this_save_mode != EDIT_QUICK_SAVE) if (mc_rename (savename, filename) == -1) goto error_save; @@ -376,11 +382,6 @@ edit_save_file (WEdit *edit, const char *filename) return 0; } -/* - I changed this from Oleg's original routine so - that option_backup_ext works with coolwidgets as well. This - does mean there is a memory leak - paul. - */ void menu_save_mode_cmd (void) { #define DLG_X 38 @@ -441,15 +442,16 @@ void menu_save_mode_cmd (void) widgets[i].x_divisions = dlg_x; } + assert (option_backup_ext != NULL); widgets[2].text = option_backup_ext; widgets[4].value = option_save_mode; if (quick_dialog (&dialog) != B_ENTER) return; option_save_mode = save_mode_new; - option_backup_ext = str_result; /* this is a memory leak */ - option_backup_ext_int = 0; - str_result[min (strlen (str_result), sizeof (int))] = '\0'; - memcpy (&option_backup_ext_int, str_result, strlen (option_backup_ext)); + + g_free (option_backup_ext); + option_backup_ext = str_result; + str_result = NULL; } void diff --git a/edit/editwidget.c b/edit/editwidget.c index d9fac37cf..031be7b1c 100644 --- a/edit/editwidget.c +++ b/edit/editwidget.c @@ -185,12 +185,6 @@ edit_file (const char *_file, int line) Dlg_head *edit_dlg; WButtonBar *edit_bar; - if (option_backup_ext_int != -1) { - option_backup_ext = g_malloc (sizeof (int) + 1); - option_backup_ext[sizeof (int)] = '\0'; - memcpy (option_backup_ext, (char *) &option_backup_ext_int, - sizeof (int)); - } if (!made_directory) { char *dir = concat_dir_and_file (home_dir, EDIT_DIR); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);