comparison src/filelock.c @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 7e54bd776075
children 1ce6082ce73f
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
67 MAKE_LOCK_NAME assumes you have already verified that Vlock_directory 67 MAKE_LOCK_NAME assumes you have already verified that Vlock_directory
68 is a string. */ 68 is a string. */
69 69
70 #ifndef HAVE_LONG_FILE_NAMES 70 #ifndef HAVE_LONG_FILE_NAMES
71 71
72 #define MAKE_LOCK_NAME(lock, file) \ 72 #define MAKE_LOCK_NAME(lock, file) \
73 (lock = (char *) alloca (14 + XSTRING_LENGTH (Vlock_directory) + 1), \ 73 (lock = (char *) alloca (14 + XSTRING_LENGTH (Vlock_directory) + \
74 1), \
74 fill_in_lock_short_file_name (lock, (file))) 75 fill_in_lock_short_file_name (lock, (file)))
75 76
76 static void 77 static void
77 fill_in_lock_short_file_name (REGISTER char *lockfile, REGISTER Lisp_Object fn) 78 fill_in_lock_short_file_name (REGISTER char *lockfile, REGISTER Lisp_Object fn)
78 { 79 {
104 105
105 { 106 {
106 int need_slash = 0; 107 int need_slash = 0;
107 108
108 /* in case lock-directory doesn't end in / */ 109 /* in case lock-directory doesn't end in / */
109 if (XSTRING_BYTE (Vlock_directory, 110 if (string_byte (XSTRING (Vlock_directory),
110 XSTRING_LENGTH (Vlock_directory) - 1) != '/') 111 XSTRING_LENGTH (Vlock_directory) - 1) != '/')
111 need_slash = 1; 112 need_slash = 1;
112 113
113 sprintf (lockfile, "%s%s%.2x%.2x%.2x%.2x%.2x%.2x%.2x", 114 sprintf (lockfile, "%s%s%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
114 (char *) XSTRING_DATA (Vlock_directory), 115 (char *) XSTRING_DATA (Vlock_directory),
119 } 120 }
120 121
121 #else /* defined HAVE_LONG_FILE_NAMES */ 122 #else /* defined HAVE_LONG_FILE_NAMES */
122 123
123 /* +2 for terminating null and possible extra slash */ 124 /* +2 for terminating null and possible extra slash */
124 #define MAKE_LOCK_NAME(lock, file) \ 125 #define MAKE_LOCK_NAME(lock, file) \
125 (lock = (char *) alloca (XSTRING_LENGTH (file) + \ 126 (lock = (char *) alloca (XSTRING_LENGTH (file) + \
126 XSTRING_LENGTH (Vlock_directory) + 2), \ 127 XSTRING_LENGTH (Vlock_directory) + 2),\
127 fill_in_lock_file_name (lock, (file))) 128 fill_in_lock_file_name (lock, (file)))
128 129
129 static void 130 static void
130 fill_in_lock_file_name (REGISTER char *lockfile, REGISTER Lisp_Object fn) 131 fill_in_lock_file_name (REGISTER char *lockfile, REGISTER Lisp_Object fn)
131 /* fn must be a Lisp_String! */ 132 /* fn must be a Lisp_String! */
194 (ie., /ka/king/junk.tex -> /!/12a82c62f1c6da). */ 195 (ie., /ka/king/junk.tex -> /!/12a82c62f1c6da). */
195 196
196 void 197 void
197 lock_file (Lisp_Object fn) 198 lock_file (Lisp_Object fn)
198 { 199 {
199 /* This function can GC. */ 200 /* This function can GC */
200 /* dmoore - and can destroy current_buffer and all sorts of other
201 mean nasty things with pointy teeth. If you call this make sure
202 you protect things right. */
203
204 REGISTER Lisp_Object attack, orig_fn; 201 REGISTER Lisp_Object attack, orig_fn;
205 REGISTER char *lfname; 202 REGISTER char *lfname;
206 struct gcpro gcpro1, gcpro2; 203 struct gcpro gcpro1, gcpro2;
207 Lisp_Object subject_buf = Qnil; 204 Lisp_Object subject_buf = Qnil;
208 205
337 334
338 335
339 void 336 void
340 unlock_file (Lisp_Object fn) 337 unlock_file (Lisp_Object fn)
341 { 338 {
342 /* This function can GC. */
343 /* dmoore - and can destroy current_buffer and all sorts of other
344 mean nasty things with pointy teeth. If you call this make sure
345 you protect things right. */
346
347 REGISTER char *lfname; 339 REGISTER char *lfname;
348 if (NILP (Vlock_directory) || NILP (Vsuperlock_file)) return; 340 if (NILP (Vlock_directory) || NILP (Vsuperlock_file)) return;
349 CHECK_STRING (fn); 341 CHECK_STRING (fn);
350 CHECK_STRING (Vlock_directory); 342 CHECK_STRING (Vlock_directory);
351 CHECK_STRING (Vsuperlock_file); 343 CHECK_STRING (Vsuperlock_file);
398 } 390 }
399 391
400 void 392 void
401 unlock_all_files (void) 393 unlock_all_files (void)
402 { 394 {
403 /* This function can GC. */ 395 REGISTER Lisp_Object tail;
404
405 Lisp_Object tail;
406 REGISTER struct buffer *b; 396 REGISTER struct buffer *b;
407 struct gcpro gcpro1; 397
408
409 GCPRO1 (tail);
410 for (tail = Vbuffer_alist; GC_CONSP (tail); 398 for (tail = Vbuffer_alist; GC_CONSP (tail);
411 tail = XCDR (tail)) 399 tail = XCDR (tail))
412 { 400 {
413 b = XBUFFER (XCDR (XCAR (tail))); 401 b = XBUFFER (XCDR (XCAR (tail)));
414 if (STRINGP (b->file_truename) && 402 if (STRINGP (b->file_truename) &&
415 BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)) 403 BUF_SAVE_MODIFF (b) < BUF_MODIFF (b))
416 unlock_file (b->file_truename); 404 unlock_file (b->file_truename);
417 } 405 }
418 UNGCPRO;
419 } 406 }
420 407
421 408
422 DEFUN ("lock-buffer", Flock_buffer, 0, 1, 0, /* 409 DEFUN ("lock-buffer", Flock_buffer, 0, 1, 0, /*
423 Lock FILE, if current buffer is modified. 410 Lock FILE, if current buffer is modified.
425 or else nothing is done if current buffer isn't visiting a file. 412 or else nothing is done if current buffer isn't visiting a file.
426 */ 413 */
427 (fn)) 414 (fn))
428 { 415 {
429 /* This function can GC */ 416 /* This function can GC */
430 /* dmoore - and can destroy current_buffer and all sorts of other
431 mean nasty things with pointy teeth. If you call this make sure
432 you protect things right. */
433
434 if (NILP (fn)) 417 if (NILP (fn))
435 fn = current_buffer->file_truename; 418 fn = current_buffer->file_truename;
436 CHECK_STRING (fn); 419 CHECK_STRING (fn);
437 if (BUF_SAVE_MODIFF (current_buffer) < BUF_MODIFF (current_buffer) 420 if (BUF_SAVE_MODIFF (current_buffer) < BUF_MODIFF (current_buffer)
438 && !NILP (fn)) 421 && !NILP (fn))
444 Unlock the file visited in the current buffer, 427 Unlock the file visited in the current buffer,
445 if it should normally be locked. 428 if it should normally be locked.
446 */ 429 */
447 ()) 430 ())
448 { 431 {
449 /* This function can GC */
450 /* dmoore - and can destroy current_buffer and all sorts of other
451 mean nasty things with pointy teeth. If you call this make sure
452 you protect things right. */
453
454 if (BUF_SAVE_MODIFF (current_buffer) < BUF_MODIFF (current_buffer) 432 if (BUF_SAVE_MODIFF (current_buffer) < BUF_MODIFF (current_buffer)
455 && STRINGP (current_buffer->file_truename)) 433 && STRINGP (current_buffer->file_truename))
456 unlock_file (current_buffer->file_truename); 434 unlock_file (current_buffer->file_truename);
457 return Qnil; 435 return Qnil;
458 } 436 }
461 /* Unlock the file visited in buffer BUFFER. */ 439 /* Unlock the file visited in buffer BUFFER. */
462 440
463 void 441 void
464 unlock_buffer (struct buffer *buffer) 442 unlock_buffer (struct buffer *buffer)
465 { 443 {
466 /* This function can GC */
467 /* dmoore - and can destroy current_buffer and all sorts of other
468 mean nasty things with pointy teeth. If you call this make sure
469 you protect things right. */
470 if (BUF_SAVE_MODIFF (buffer) < BUF_MODIFF (buffer) 444 if (BUF_SAVE_MODIFF (buffer) < BUF_MODIFF (buffer)
471 && STRINGP (buffer->file_truename)) 445 && STRINGP (buffer->file_truename))
472 unlock_file (buffer->file_truename); 446 unlock_file (buffer->file_truename);
473 } 447 }
474 448