Просмотр исходного кода

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.

Roland Illig 19 лет назад
Родитель
Сommit
9be77996d6
5 измененных файлов с 20 добавлено и 21 удалено
  1. 5 0
      edit/ChangeLog
  2. 1 2
      edit/edit.c
  3. 0 1
      edit/edit.h
  4. 14 12
      edit/editcmd.c
  5. 0 6
      edit/editwidget.c

+ 5 - 0
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  <roland.illig@gmx.de>
 
 	* editcmd.c: Fixed some of the gcc warnings.

+ 1 - 2
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;
 
 /*-
  *

+ 0 - 1
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;

+ 14 - 12
edit/editcmd.c

@@ -24,6 +24,8 @@
 /* #define PIPE_BLOCKS_SO_READ_BYTE_BY_BYTE */
 
 #include <config.h>
+
+#include <assert.h>
 #include <ctype.h>
 
 #include <stdio.h>
@@ -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

+ 0 - 6
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);