1
1

Implemented file locking in hex editor.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2010-06-09 16:57:05 +04:00
родитель b2ee413f03
Коммит 0bd04ed34f
5 изменённых файлов: 36 добавлений и 15 удалений

Просмотреть файл

@ -53,6 +53,7 @@
#include "lib/tty/tty.h"
#include "lib/tty/key.h"
#include "lib/lock.h" /* lock_file() */
#include "src/dialog.h" /* cb_ret_t */
#include "src/panel.h"
@ -259,19 +260,19 @@ mcview_handle_editkey (mcview_t * view, int key)
{
struct hexedit_change_node *node;
int byte_val;
/* Has there been a change at this position? */
node = view->change_list;
while (node && (node->offset != view->hex_cursor))
while ((node != NULL) && (node->offset != view->hex_cursor))
node = node->next;
if (!view->hexview_in_text)
{
/* Hex editing */
unsigned int hexvalue = 0;
if (key >= '0' && key <= '9')
{
hexvalue = 0 + (key - '0');
}
else if (key >= 'A' && key <= 'F')
hexvalue = 10 + (key - 'A');
else if (key >= 'a' && key <= 'f')
@ -279,19 +280,15 @@ mcview_handle_editkey (mcview_t * view, int key)
else
return MSG_NOT_HANDLED;
if (node)
if (node != NULL)
byte_val = node->value;
else
mcview_get_byte (view, view->hex_cursor, &byte_val);
if (view->hexedit_lownibble)
{
byte_val = (byte_val & 0xf0) | (hexvalue);
}
else
{
byte_val = (byte_val & 0x0f) | (hexvalue << 4);
}
}
else
{
@ -301,7 +298,12 @@ mcview_handle_editkey (mcview_t * view, int key)
else
return MSG_NOT_HANDLED;
}
if (!node)
if ((view->filename != NULL) && (view->filename[0] != '\0')
&& (view->change_list == NULL))
view->locked = lock_file (view->filename);
if (node == NULL)
{
node = g_new (struct hexedit_change_node, 1);
node->offset = view->hex_cursor;
@ -309,11 +311,11 @@ mcview_handle_editkey (mcview_t * view, int key)
mcview_enqueue_change (&view->change_list, node);
}
else
{
node->value = byte_val;
}
view->dirty++;
mcview_move_right (view, 1);
return MSG_HANDLED;
}

Просмотреть файл

@ -43,12 +43,13 @@
#include "lib/global.h"
#include "lib/tty/tty.h"
#include "lib/skin.h"
#include "lib/lock.h" /* unlock_file() */
#include "lib/vfs/mc-vfs/vfs.h"
#include "src/main.h"
#include "src/wtools.h"
#include "src/charsets.h"
#include "lib/vfs/mc-vfs/vfs.h"
#include "internal.h"
/*** global variables ****************************************************************************/
@ -375,6 +376,14 @@ mcview_hexedit_save_changes (mcview_t * view)
g_free (curr);
}
view->change_list = NULL;
if (view->locked)
{
unlock_file (view->filename);
view->locked = FALSE;
}
if (mc_close (fp) == -1)
message (D_ERROR, _("Save file"),
_("Error while closing the file:\n%s\n"
@ -418,6 +427,13 @@ mcview_hexedit_free_change_list (mcview_t * view)
g_free (curr);
}
view->change_list = NULL;
if (view->locked)
{
unlock_file (view->filename);
view->locked = FALSE;
}
view->dirty++;
}

Просмотреть файл

@ -131,10 +131,11 @@ typedef struct mcview_struct
gboolean text_nroff_mode; /* Nroff-style highlighting */
gboolean text_wrap_mode; /* Wrap text lines to fit them on the screen */
gboolean magic_mode; /* Preprocess the file using external programs */
gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */
gboolean locked; /* We hold lock on current file */
gboolean utf8; /* It's multibyte file codeset */
/* Additional editor state */
gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */
coord_cache_t *coord_cache; /* Cache for mapping offsets to cursor positions */
/* Display information */

Просмотреть файл

@ -191,6 +191,7 @@ mcview_init (mcview_t * view)
/* leave the other growbuf fields uninitialized */
view->hexedit_lownibble = FALSE;
view->locked = FALSE;
view->coord_cache = NULL;
view->dpy_start = 0;

Просмотреть файл

@ -212,6 +212,7 @@ mcview_new (int y, int x, int lines, int cols, gboolean is_panel)
view->hex_mode = FALSE;
view->hexedit_mode = FALSE;
view->locked = FALSE;
view->hexview_in_text = FALSE;
view->text_nroff_mode = FALSE;
view->text_wrap_mode = FALSE;