diff --git a/lib/Makefile.am b/lib/Makefile.am index e92eb506a..3109f321a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -23,6 +23,7 @@ libmc_la_SOURCES = \ fs.h \ glibcompat.c glibcompat.h \ global.h \ + lock.c lock.h \ timefmt.h if USE_MAINTAINER_MODE diff --git a/src/editor/editlock.c b/lib/lock.c similarity index 92% rename from src/editor/editlock.c rename to lib/lock.c index 7447290ec..fd2db1531 100644 --- a/src/editor/editlock.c +++ b/lib/lock.c @@ -1,4 +1,4 @@ -/* editor file locking. +/* file locking Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. @@ -22,11 +22,11 @@ */ /** \file - * \brief Source: editor file locking + * \brief Source: file locking * \author Adam Byrtek * \date 2003 * - * Locking scheme used in mcedit is based on a documentation found + * Locking scheme is based on a documentation found * in JED editor sources. Abstract from lock.c file (by John E. Davis): * * The basic idea here is quite simple. Whenever a buffer is attached to @@ -54,13 +54,9 @@ #include "lib/global.h" #include "lib/vfs/mc-vfs/vfs.h" -#include "lib/strutil.h" /* utf string functions */ +#include "lib/lock.h" - -#include "edit-impl.h" -#include "editlock.h" - -#include "src/wtools.h" /* edit_query_dialog () */ +#include "src/wtools.h" /* query_dialog() */ #define BUF_SIZE 255 #define PID_BUF_SIZE 10 @@ -164,7 +160,7 @@ lock_get_info (const char *lockfname) Returns 1 on success, 0 on failure, -1 if abort Warning: Might do screen refresh and lose edit->force */ int -edit_lock_file (const char *fname) +lock_file (const char *fname) { char *lockfname, *newlock, *msg, *lock; struct stat statbuf; @@ -199,8 +195,8 @@ edit_lock_file (const char *fname) "User: %s\nProcess ID: %d"), x_basename (lockfname) + 2, lockinfo->who, (int) lockinfo->pid); /* TODO: Implement "Abort" - needs to rewind undo stack */ - switch (edit_query_dialog2 - (_("File locked"), msg, _("&Grab lock"), + switch (query_dialog + (_("File locked"), msg, D_NORMAL, 2, _("&Grab lock"), _("&Ignore lock"))) { case 0: break; @@ -229,9 +225,9 @@ edit_lock_file (const char *fname) } /* Lowers file lock if possible - Always returns 0 to make 'lock = edit_unlock_file (f)' possible */ + Always returns 0 */ int -edit_unlock_file (const char *fname) +unlock_file (const char *fname) { char *lockfname, *lock; struct stat statbuf; diff --git a/lib/lock.h b/lib/lock.h new file mode 100644 index 000000000..98bebac6f --- /dev/null +++ b/lib/lock.h @@ -0,0 +1,15 @@ + +/** \file + * \brief Header: file locking + * \author Adam Byrtek + * \date 2003 + * Look at lock.c for more details + */ + +#ifndef MC_LOCK_H +#define MC_LOCK_H + +int lock_file (const char *fname); +int unlock_file (const char *fname); + +#endif /* MC_LOCK_H */ diff --git a/src/Makefile.am b/src/Makefile.am index 828674c6f..8af25cb7c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,20 +41,18 @@ if CHARSET SRC_USE_charset=$(SRC_charset) endif - mc_LDADD = \ - ../lib/libmc.la \ viewer/libmcviewer.la \ - $(MCLIBS) $(DIFFLIB) $(EDITLIB) $(SLANGLIB) \ - $(GLIB_LIBS) $(PCRE_LIBS) \ - $(LIBICONV) $(INTLLIBS) + $(DIFFLIB) $(EDITLIB) \ + ../lib/libmc.la \ + $(MCLIBS) $(SLANGLIB) $(GLIB_LIBS) \ + $(PCRE_LIBS) $(LIBICONV) $(INTLLIBS) if USE_SAMBA_FS # this is a hack for linking with own samba library in simple way mc_LDADD += ../lib/vfs/mc-vfs/samba/libsamba.a endif - SRC_mc_widgets = \ dialog.c dialog.h \ dialog-switch.c dialog-switch.h \ diff --git a/src/editor/Makefile.am b/src/editor/Makefile.am index ad9bde33a..20c1abe09 100644 --- a/src/editor/Makefile.am +++ b/src/editor/Makefile.am @@ -9,7 +9,7 @@ endif libedit_la_SOURCES = \ bookmark.c edit.c editcmd.c editwidget.c editdraw.c editkeys.c \ editmenu.c editoptions.c edit-impl.h edit.h edit-widget.h \ - editlock.c editlock.h syntax.c wordproc.c \ + syntax.c wordproc.c \ choosesyntax.c etags.c etags.h editcmd_dialogs.c editcmd_dialogs.h libedit_la_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) $(PCRE_CFLAGS) diff --git a/src/editor/edit.c b/src/editor/edit.c index 152a0666a..c78ced4b8 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -47,6 +47,7 @@ #include "lib/skin.h" /* EDITOR_NORMAL_COLOR */ #include "lib/vfs/mc-vfs/vfs.h" #include "lib/strutil.h" /* utf string functions */ +#include "lib/lock.h" #include "src/widget.h" #include "src/cmd.h" /* view_other_cmd() */ @@ -61,7 +62,6 @@ #include "src/keybind.h" #include "edit-impl.h" -#include "editlock.h" #include "edit-widget.h" int option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH; @@ -952,7 +952,7 @@ edit_clean (WEdit * edit) /* a stale lock, remove it */ if (edit->locked) - edit->locked = edit_unlock_file (edit->filename); + edit->locked = unlock_file (edit->filename); /* save cursor position */ if (option_save_position) @@ -1273,7 +1273,7 @@ edit_modification (WEdit * edit) /* raise lock when file modified */ if (!edit->modified && !edit->delete_file) - edit->locked = edit_lock_file (edit->filename); + edit->locked = lock_file (edit->filename); edit->modified = 1; } diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 9a7cee449..6d5b1f5ec 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -51,6 +51,7 @@ #include "lib/mcconfig.h" #include "lib/skin.h" #include "lib/strutil.h" /* utf string functions */ +#include "lib/lock.h" #include "lib/vfs/mc-vfs/vfs.h" #include "src/history.h" @@ -66,7 +67,6 @@ #include "src/clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */ #include "src/editor/edit-impl.h" -#include "src/editor/editlock.h" #include "src/editor/edit-widget.h" #include "src/editor/editcmd_dialogs.h" #include "src/editor/etags.h" @@ -623,13 +623,13 @@ edit_save_as_cmd (WEdit * edit) { edit->stat1.st_mode |= S_IWUSR; } - save_lock = edit_lock_file (exp); + save_lock = lock_file (exp); } else { /* filenames equal, check if already locked */ if (!edit->locked && !edit->delete_file) - save_lock = edit_lock_file (exp); + save_lock = lock_file (exp); } if (different_filename) @@ -649,14 +649,14 @@ edit_save_as_cmd (WEdit * edit) if (different_filename) { if (save_lock) - edit_unlock_file (exp); + unlock_file (exp); if (edit->locked) - edit->locked = edit_unlock_file (edit->filename); + edit->locked = unlock_file (edit->filename); } else { if (edit->locked || save_lock) - edit->locked = edit_unlock_file (edit->filename); + edit->locked = unlock_file (edit->filename); } edit_set_filename (edit, exp); @@ -675,7 +675,7 @@ edit_save_as_cmd (WEdit * edit) case -1: /* Failed, so maintain modify (not save) lock */ if (save_lock) - edit_unlock_file (exp); + unlock_file (exp); g_free (exp); edit->force |= REDRAW_COMPLETELY; return 0; @@ -932,12 +932,12 @@ edit_save_cmd (WEdit * edit) int res, save_lock = 0; if (!edit->locked && !edit->delete_file) - save_lock = edit_lock_file (edit->filename); + save_lock = lock_file (edit->filename); res = edit_save_file (edit, edit->filename); /* Maintain modify (not save) lock on failure */ if ((res > 0 && edit->locked) || save_lock) - edit->locked = edit_unlock_file (edit->filename); + edit->locked = unlock_file (edit->filename); /* On failure try 'save as', it does locking on its own */ if (!res) @@ -988,7 +988,7 @@ edit_load_file_from_filename (WEdit * edit, char *exp) } if (prev_locked) - edit_unlock_file (prev_filename); + unlock_file (prev_filename); g_free (prev_filename); return 0; } diff --git a/src/editor/editlock.h b/src/editor/editlock.h deleted file mode 100644 index 5ddeeefd4..000000000 --- a/src/editor/editlock.h +++ /dev/null @@ -1,15 +0,0 @@ - -/** \file - * \brief Header: editor file locking - * \author Adam Byrtek - * \date 2003 - * Look at editlock.c for more details - */ - -#ifndef MC_EDIT_LOCK_H -#define MC_EDIT_LOCK_H - -int edit_lock_file (const char *fname); -int edit_unlock_file (const char *fname); - -#endif