From d70c7f3c1474cc3d309ebe397675bb111a0768d2 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Thu, 3 Jan 2013 03:36:20 +0000 Subject: [PATCH] Implement the modification bit of the .swp file, put it in the correct actual location (pos 1007). git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4551 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 7 +++---- src/files.c | 5 +++-- src/winio.c | 13 +++++++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5580ba55..5edc9228 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,8 @@ 2012-12-31 Chris Allegretta * src/*: Introduce (basic) vim-style file locks. Does not allow vim to recover - our files, and doesn't yet support setting the file as modified; just lets a - vim user know we're editing a file. Commands line "-G" or "--locking", nanorc - option "locking". New functions src/files.c:do_lockfile(), write_lockfile(), - and delete_lockfile(). + our changes, and just lets a vim user know we're editing a file. Commands line "-G" + or "--locking", nanorc option "locking". New functions + src/files.c:do_lockfile(), write_lockfile(), and delete_lockfile(). 2012-02-05 Chris Allegretta * src/*: Fix overlapping strings highlighting each other. new variables in edit_draw diff --git a/src/files.c b/src/files.c index f15a05f8..25609e12 100644 --- a/src/files.c +++ b/src/files.c @@ -182,8 +182,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi bytes 28-44 - username of who created the lock bytes 68-100 - hostname of where the lock was created bytes 108-876 - filename the lock is for - byte 1018 - 0x55 if file is modified - (TODO: set if 'modified' == TRUE) + byte 1007 - 0x55 if file is modified Looks like VIM also stores undo state in this file so we're gonna have to figure out how to slap a 'OMG don't use recover @@ -200,6 +199,8 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi strncpy(&lockdata[28], mypwuid->pw_name, 16); strncpy(&lockdata[68], myhostname, 31); strncpy(&lockdata[108], origfilename, 768); + if (modified == TRUE) + lockdata[1007] = 0x55; wroteamt = fwrite(lockdata, sizeof(char), lockdatalen, filestream); if (wroteamt < lockdatalen) { diff --git a/src/winio.c b/src/winio.c index 68692324..bd3c8033 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2259,11 +2259,16 @@ void set_modified(void) openfile->modified = TRUE; titlebar(NULL); #ifndef NANO_TINY - if (ISSET(LOCKING) && openfile->lock_filename == NULL) - /* Translators: Try to keep this at most 80 characters. */ - statusbar(_("Warning: Modifying a file which is not locked, check directory permission?")); + if (ISSET(LOCKING)) { + if (openfile->lock_filename == NULL) { + /* Translators: Try to keep this at most 80 characters. */ + statusbar(_("Warning: Modifying a file which is not locked, check directory permission?")); + } else { + write_lockfile(openfile->lock_filename, + get_full_path(openfile->filename), TRUE); + } + } #endif - } } -- 2.39.5