0
|
1 /* File IO for XEmacs.
|
|
2 Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1996 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Mule 2.0, FSF 19.30. */
|
|
23
|
|
24 #include <config.h>
|
|
25 #include "lisp.h"
|
|
26
|
|
27 #include "buffer.h"
|
|
28 #include "events.h"
|
|
29 #include "frame.h"
|
|
30 #include "insdel.h"
|
|
31 #include "lstream.h"
|
|
32 #include "redisplay.h"
|
|
33 #include "sysdep.h"
|
|
34 #include "window.h" /* minibuf_level */
|
|
35
|
2
|
36 #ifdef HAVE_LIBGEN_H /* Must come before sysfile.h */
|
|
37 #include <libgen.h>
|
|
38 #endif
|
0
|
39 #include "sysfile.h"
|
|
40 #include "sysproc.h"
|
|
41 #include "syspwd.h"
|
|
42 #include "systime.h"
|
|
43 #include "sysdir.h"
|
|
44
|
|
45 #ifdef HPUX
|
|
46 #include <netio.h>
|
|
47 #ifdef HPUX_PRE_8_0
|
|
48 #include <errnet.h>
|
|
49 #endif
|
|
50 #endif
|
|
51
|
|
52 /* Nonzero during writing of auto-save files */
|
|
53 static int auto_saving;
|
|
54
|
|
55 /* Set by auto_save_1 to mode of original file so Fwrite_region_internal
|
|
56 will create a new file with the same mode as the original */
|
|
57 static int auto_save_mode_bits;
|
|
58
|
|
59 /* Alist of elements (REGEXP . HANDLER) for file names
|
|
60 whose I/O is done with a special handler. */
|
|
61 Lisp_Object Vfile_name_handler_alist;
|
|
62
|
|
63 /* Format for auto-save files */
|
|
64 Lisp_Object Vauto_save_file_format;
|
|
65
|
|
66 /* Lisp functions for translating file formats */
|
|
67 Lisp_Object Qformat_decode, Qformat_annotate_function;
|
|
68
|
|
69 /* Functions to be called to process text properties in inserted file. */
|
|
70 Lisp_Object Vafter_insert_file_functions;
|
|
71
|
|
72 /* Functions to be called to create text property annotations for file. */
|
|
73 Lisp_Object Vwrite_region_annotate_functions;
|
|
74
|
|
75 /* During build_annotations, each time an annotation function is called,
|
|
76 this holds the annotations made by the previous functions. */
|
|
77 Lisp_Object Vwrite_region_annotations_so_far;
|
|
78
|
|
79 /* File name in which we write a list of all our auto save files. */
|
|
80 Lisp_Object Vauto_save_list_file_name;
|
|
81
|
|
82 /* On VMS, nonzero means write new files with record format stmlf.
|
|
83 Zero means use var format. */
|
|
84 int vms_stmlf_recfm;
|
|
85
|
|
86 int disable_auto_save_when_buffer_shrinks;
|
|
87
|
|
88 Lisp_Object Qfile_name_handler_alist;
|
|
89
|
|
90 /* These variables describe handlers that have "already" had a chance
|
|
91 to handle the current operation.
|
|
92
|
|
93 Vinhibit_file_name_handlers is a list of file name handlers.
|
|
94 Vinhibit_file_name_operation is the operation being handled.
|
|
95 If we try to handle that operation, we ignore those handlers. */
|
|
96
|
|
97 static Lisp_Object Vinhibit_file_name_handlers;
|
|
98 static Lisp_Object Vinhibit_file_name_operation;
|
|
99
|
|
100 Lisp_Object Qfile_error, Qfile_already_exists;
|
|
101
|
|
102 Lisp_Object Qauto_save_hook;
|
|
103 Lisp_Object Qauto_save_error;
|
|
104 Lisp_Object Qauto_saving;
|
|
105
|
|
106 Lisp_Object Qcar_less_than_car;
|
|
107
|
|
108 Lisp_Object Qcompute_buffer_file_truename;
|
|
109
|
|
110 /* signal a file error when errno contains a meaningful value. */
|
|
111
|
|
112 DOESNT_RETURN
|
|
113 report_file_error (CONST char *string, Lisp_Object data)
|
|
114 {
|
40
|
115 /* #### dmoore - This uses current_buffer, better make sure no one
|
|
116 has GC'd the current buffer. File handlers are giving me a headache
|
|
117 maybe I'll just always protect current_buffer around all of those
|
|
118 calls. */
|
|
119
|
0
|
120 /* mrb: #### Needs to be fixed at a lower level; errstring needs to
|
|
121 be MULEized. The following at least prevents a crash... */
|
|
122 Lisp_Object errstring = build_ext_string (strerror (errno), FORMAT_BINARY);
|
|
123
|
|
124 /* System error messages are capitalized. Downcase the initial
|
|
125 unless it is followed by a slash. */
|
|
126 if (string_char (XSTRING (errstring), 1) != '/')
|
|
127 set_string_char (XSTRING (errstring), 0,
|
|
128 DOWNCASE (current_buffer,
|
|
129 string_char (XSTRING (errstring), 0)));
|
|
130
|
|
131 signal_error (Qfile_error,
|
|
132 Fcons (build_translated_string (string),
|
|
133 Fcons (errstring, data)));
|
|
134 }
|
|
135
|
|
136 void
|
|
137 maybe_report_file_error (CONST char *string, Lisp_Object data,
|
|
138 Lisp_Object class, Error_behavior errb)
|
|
139 {
|
|
140 Lisp_Object errstring;
|
|
141
|
|
142 /* Optimization: */
|
|
143 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
144 return;
|
|
145
|
|
146 errstring = build_string (strerror (errno));
|
|
147
|
|
148 /* System error messages are capitalized. Downcase the initial
|
|
149 unless it is followed by a slash. */
|
|
150 if (string_char (XSTRING (errstring), 1) != '/')
|
|
151 set_string_char (XSTRING (errstring), 0,
|
|
152 DOWNCASE (current_buffer,
|
|
153 string_char (XSTRING (errstring), 0)));
|
|
154
|
|
155 maybe_signal_error (Qfile_error,
|
|
156 Fcons (build_translated_string (string),
|
|
157 Fcons (errstring, data)),
|
|
158 class, errb);
|
|
159 }
|
|
160
|
|
161 /* signal a file error when errno does not contain a meaningful value. */
|
|
162
|
|
163 DOESNT_RETURN
|
|
164 signal_file_error (CONST char *string, Lisp_Object data)
|
|
165 {
|
|
166 signal_error (Qfile_error,
|
|
167 list2 (build_translated_string (string), data));
|
|
168 }
|
|
169
|
|
170 void
|
|
171 maybe_signal_file_error (CONST char *string, Lisp_Object data,
|
|
172 Lisp_Object class, Error_behavior errb)
|
|
173 {
|
|
174 /* Optimization: */
|
|
175 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
176 return;
|
|
177 maybe_signal_error (Qfile_error,
|
|
178 list2 (build_translated_string (string), data),
|
|
179 class, errb);
|
|
180 }
|
|
181
|
|
182 DOESNT_RETURN
|
|
183 signal_double_file_error (CONST char *string1, CONST char *string2,
|
|
184 Lisp_Object data)
|
|
185 {
|
|
186 signal_error (Qfile_error,
|
|
187 list3 (build_translated_string (string1),
|
|
188 build_translated_string (string2),
|
|
189 data));
|
|
190 }
|
|
191
|
|
192 void
|
|
193 maybe_signal_double_file_error (CONST char *string1, CONST char *string2,
|
|
194 Lisp_Object data, Lisp_Object class,
|
|
195 Error_behavior errb)
|
|
196 {
|
|
197 /* Optimization: */
|
|
198 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
199 return;
|
|
200 maybe_signal_error (Qfile_error,
|
|
201 list3 (build_translated_string (string1),
|
|
202 build_translated_string (string2),
|
|
203 data),
|
|
204 class, errb);
|
|
205 }
|
|
206
|
|
207 DOESNT_RETURN
|
|
208 signal_double_file_error_2 (CONST char *string1, CONST char *string2,
|
|
209 Lisp_Object data1, Lisp_Object data2)
|
|
210 {
|
|
211 signal_error (Qfile_error,
|
|
212 list4 (build_translated_string (string1),
|
|
213 build_translated_string (string2),
|
|
214 data1, data2));
|
|
215 }
|
|
216
|
|
217 void
|
|
218 maybe_signal_double_file_error_2 (CONST char *string1, CONST char *string2,
|
|
219 Lisp_Object data1, Lisp_Object data2,
|
|
220 Lisp_Object class, Error_behavior errb)
|
|
221 {
|
|
222 /* Optimization: */
|
|
223 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
224 return;
|
|
225 maybe_signal_error (Qfile_error,
|
|
226 list4 (build_translated_string (string1),
|
|
227 build_translated_string (string2),
|
|
228 data1, data2),
|
|
229 class, errb);
|
|
230 }
|
|
231
|
|
232 static Lisp_Object
|
|
233 close_file_unwind (Lisp_Object fd)
|
|
234 {
|
|
235 if (CONSP (fd))
|
|
236 {
|
|
237 if (INTP (XCAR (fd)))
|
|
238 close (XINT (XCAR (fd)));
|
|
239
|
|
240 free_cons (XCONS (fd));
|
|
241 }
|
|
242 else
|
|
243 close (XINT (fd));
|
|
244
|
|
245 return Qnil;
|
|
246 }
|
|
247
|
|
248 static Lisp_Object
|
|
249 close_stream_unwind (Lisp_Object stream)
|
|
250 {
|
|
251 Lstream_close (XLSTREAM (stream));
|
|
252 return Qnil;
|
|
253 }
|
|
254
|
|
255 /* Restore point, having saved it as a marker. */
|
|
256
|
|
257 static Lisp_Object
|
|
258 restore_point_unwind (Lisp_Object point_marker)
|
|
259 {
|
|
260 BUF_SET_PT (current_buffer, marker_position (point_marker));
|
|
261 return (Fset_marker (point_marker, Qnil, Qnil));
|
|
262 }
|
|
263
|
|
264 /* Versions of read() and write() that allow quitting out of the actual
|
|
265 I/O. We don't use immediate_quit (i.e. direct longjmp() out of the
|
|
266 signal handler) because that's way too losing.
|
|
267
|
|
268 (#### Actually, longjmp()ing out of the signal handler may not be
|
|
269 as losing as I thought. See sys_do_signal() in sysdep.c.)
|
|
270
|
|
271 Solaris include files declare the return value as ssize_t.
|
|
272 Is that standard? */
|
|
273 int
|
|
274 read_allowing_quit (int fildes, void *buf, unsigned int nbyte)
|
|
275 {
|
|
276 int nread;
|
|
277 QUIT;
|
|
278
|
|
279 nread = sys_read_1 (fildes, buf, nbyte, 1);
|
|
280 return nread;
|
|
281 }
|
|
282
|
|
283 int
|
|
284 write_allowing_quit (int fildes, CONST void *buf, unsigned int nbyte)
|
|
285 {
|
|
286 int nread;
|
|
287
|
|
288 QUIT;
|
|
289 nread = sys_write_1 (fildes, buf, nbyte, 1);
|
|
290 return nread;
|
|
291 }
|
|
292
|
|
293
|
|
294 Lisp_Object Qexpand_file_name;
|
|
295 Lisp_Object Qfile_truename;
|
|
296 Lisp_Object Qsubstitute_in_file_name;
|
|
297 Lisp_Object Qdirectory_file_name;
|
|
298 Lisp_Object Qfile_name_directory;
|
|
299 Lisp_Object Qfile_name_nondirectory;
|
|
300 Lisp_Object Qunhandled_file_name_directory;
|
|
301 Lisp_Object Qfile_name_as_directory;
|
|
302 Lisp_Object Qcopy_file;
|
|
303 Lisp_Object Qmake_directory_internal;
|
|
304 Lisp_Object Qdelete_directory;
|
|
305 Lisp_Object Qdelete_file;
|
|
306 Lisp_Object Qrename_file;
|
|
307 Lisp_Object Qadd_name_to_file;
|
|
308 Lisp_Object Qmake_symbolic_link;
|
|
309 Lisp_Object Qfile_exists_p;
|
|
310 Lisp_Object Qfile_executable_p;
|
|
311 Lisp_Object Qfile_readable_p;
|
|
312 Lisp_Object Qfile_symlink_p;
|
|
313 Lisp_Object Qfile_writable_p;
|
|
314 Lisp_Object Qfile_directory_p;
|
|
315 Lisp_Object Qfile_regular_p;
|
|
316 Lisp_Object Qfile_accessible_directory_p;
|
|
317 Lisp_Object Qfile_modes;
|
|
318 Lisp_Object Qset_file_modes;
|
|
319 Lisp_Object Qfile_newer_than_file_p;
|
|
320 Lisp_Object Qinsert_file_contents;
|
|
321 Lisp_Object Qwrite_region;
|
|
322 Lisp_Object Qverify_visited_file_modtime;
|
|
323 Lisp_Object Qset_visited_file_modtime;
|
|
324 Lisp_Object Qset_buffer_modtime;
|
|
325
|
|
326 /* If FILENAME is handled specially on account of its syntax,
|
|
327 return its handler function. Otherwise, return nil. */
|
|
328
|
20
|
329 DEFUN ("find-file-name-handler", Ffind_file_name_handler, 1, 2, 0, /*
|
0
|
330 Return FILENAME's handler function for OPERATION, if it has one.
|
|
331 Otherwise, return nil.
|
|
332 A file name is handled if one of the regular expressions in
|
|
333 `file-name-handler-alist' matches it.
|
|
334
|
|
335 If OPERATION equals `inhibit-file-name-operation', then we ignore
|
|
336 any handlers that are members of `inhibit-file-name-handlers',
|
|
337 but we still do run any other handlers. This lets handlers
|
|
338 use the standard functions without calling themselves recursively.
|
20
|
339 */
|
|
340 (filename, operation))
|
0
|
341 {
|
|
342 /* This function must not munge the match data. */
|
|
343 Lisp_Object chain, inhibited_handlers;
|
|
344
|
|
345 CHECK_STRING (filename);
|
|
346
|
|
347 if (EQ (operation, Vinhibit_file_name_operation))
|
|
348 inhibited_handlers = Vinhibit_file_name_handlers;
|
|
349 else
|
|
350 inhibited_handlers = Qnil;
|
|
351
|
|
352 for (chain = Vfile_name_handler_alist; CONSP (chain);
|
|
353 chain = XCDR (chain))
|
|
354 {
|
|
355 Lisp_Object elt = XCAR (chain);
|
|
356 if (CONSP (elt))
|
|
357 {
|
|
358 Lisp_Object string;
|
|
359 string = XCAR (elt);
|
|
360 if (STRINGP (string)
|
|
361 && (fast_lisp_string_match (string, filename) >= 0))
|
|
362 {
|
|
363 Lisp_Object handler = XCDR (elt);
|
|
364 if (NILP (Fmemq (handler, inhibited_handlers)))
|
|
365 return (handler);
|
|
366 }
|
|
367 }
|
|
368 QUIT;
|
|
369 }
|
|
370 return Qnil;
|
|
371 }
|
|
372
|
|
373 static Lisp_Object
|
|
374 call2_check_string (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1)
|
|
375 {
|
|
376 /* This function can GC */
|
|
377 Lisp_Object result = call2 (fn, arg0, arg1);
|
|
378 CHECK_STRING (result);
|
|
379 return (result);
|
|
380 }
|
|
381
|
|
382 static Lisp_Object
|
40
|
383 call2_check_string_or_nil (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1)
|
|
384 {
|
|
385 /* This function can GC */
|
|
386 Lisp_Object result = call2 (fn, arg0, arg1);
|
|
387 if (!NILP (result))
|
|
388 CHECK_STRING (result);
|
|
389 return (result);
|
|
390 }
|
|
391
|
|
392 static Lisp_Object
|
0
|
393 call3_check_string (Lisp_Object fn, Lisp_Object arg0,
|
|
394 Lisp_Object arg1, Lisp_Object arg2)
|
|
395 {
|
|
396 /* This function can GC */
|
|
397 Lisp_Object result = call3 (fn, arg0, arg1, arg2);
|
|
398 CHECK_STRING (result);
|
|
399 return (result);
|
|
400 }
|
|
401
|
|
402
|
20
|
403 DEFUN ("file-name-directory", Ffile_name_directory, 1, 1, 0, /*
|
0
|
404 Return the directory component in file name NAME.
|
|
405 Return nil if NAME does not include a directory.
|
|
406 Otherwise return a directory spec.
|
|
407 Given a Unix syntax file name, returns a string ending in slash;
|
|
408 on VMS, perhaps instead a string ending in `:', `]' or `>'.
|
20
|
409 */
|
|
410 (file))
|
0
|
411 {
|
|
412 /* This function can GC */
|
|
413 Bufbyte *beg;
|
|
414 Bufbyte *p;
|
|
415 Lisp_Object handler;
|
|
416
|
|
417 CHECK_STRING (file);
|
|
418
|
|
419 /* If the file name has special constructs in it,
|
|
420 call the corresponding file handler. */
|
|
421 handler = Ffind_file_name_handler (file, Qfile_name_directory);
|
|
422 if (!NILP (handler))
|
40
|
423 return (call2_check_string_or_nil (handler, Qfile_name_directory,
|
|
424 file));
|
0
|
425
|
|
426 #ifdef FILE_SYSTEM_CASE
|
|
427 file = FILE_SYSTEM_CASE (file);
|
|
428 #endif
|
16
|
429 beg = XSTRING_DATA (file);
|
|
430 p = beg + XSTRING_LENGTH (file);
|
0
|
431
|
|
432 while (p != beg && !IS_ANY_SEP (p[-1])
|
|
433 #ifdef VMS
|
|
434 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>'
|
|
435 #endif /* VMS */
|
|
436 ) p--;
|
|
437
|
|
438 if (p == beg)
|
|
439 return Qnil;
|
|
440 #ifdef DOS_NT
|
|
441 /* Expansion of "c:" to drive and default directory. */
|
|
442 /* (NT does the right thing.) */
|
|
443 if (p == beg + 2 && beg[1] == ':')
|
|
444 {
|
|
445 int drive = (*beg) - 'a';
|
|
446 /* MAXPATHLEN+1 is guaranteed to be enough space for getdefdir. */
|
|
447 Bufbyte *res = (Bufbyte *) alloca (MAXPATHLEN + 5);
|
|
448 unsigned char *res1;
|
|
449 #ifdef WINDOWSNT
|
|
450 res1 = res;
|
|
451 /* The NT version places the drive letter at the beginning already. */
|
|
452 #else /* not WINDOWSNT */
|
|
453 /* On MSDOG we must put the drive letter in by hand. */
|
|
454 res1 = res + 2;
|
|
455 #endif /* not WINDOWSNT */
|
|
456 if (getdefdir (drive + 1, res))
|
|
457 {
|
|
458 #ifdef MSDOS
|
|
459 res[0] = drive + 'a';
|
|
460 res[1] = ':';
|
|
461 #endif /* MSDOS */
|
|
462 if (IS_DIRECTORY_SEP (res[strlen ((char *) res) - 1]))
|
|
463 strcat ((char *) res, "/");
|
|
464 beg = res;
|
|
465 p = beg + strlen ((char *) beg);
|
|
466 }
|
|
467 }
|
|
468 #endif /* DOS_NT */
|
|
469 return make_string (beg, p - beg);
|
|
470 }
|
|
471
|
20
|
472 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, 1, 1, 0, /*
|
0
|
473 Return file name NAME sans its directory.
|
|
474 For example, in a Unix-syntax file name,
|
|
475 this is everything after the last slash,
|
|
476 or the entire name if it contains no slash.
|
20
|
477 */
|
|
478 (file))
|
0
|
479 {
|
|
480 /* This function can GC */
|
|
481 Bufbyte *beg, *p, *end;
|
|
482 Lisp_Object handler;
|
|
483
|
|
484 CHECK_STRING (file);
|
|
485
|
|
486 /* If the file name has special constructs in it,
|
|
487 call the corresponding file handler. */
|
|
488 handler = Ffind_file_name_handler (file, Qfile_name_nondirectory);
|
|
489 if (!NILP (handler))
|
|
490 return (call2_check_string (handler, Qfile_name_nondirectory,
|
|
491 file));
|
|
492
|
16
|
493 beg = XSTRING_DATA (file);
|
|
494 end = p = beg + XSTRING_LENGTH (file);
|
0
|
495
|
|
496 while (p != beg && !IS_ANY_SEP (p[-1])
|
|
497 #ifdef VMS
|
|
498 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>'
|
|
499 #endif /* VMS */
|
|
500 ) p--;
|
|
501
|
|
502 return make_string (p, end - p);
|
|
503 }
|
|
504
|
20
|
505 DEFUN ("unhandled-file-name-directory", Funhandled_file_name_directory, 1, 1, 0, /*
|
0
|
506 Return a directly usable directory name somehow associated with FILENAME.
|
|
507 A `directly usable' directory name is one that may be used without the
|
|
508 intervention of any file handler.
|
|
509 If FILENAME is a directly usable file itself, return
|
|
510 (file-name-directory FILENAME).
|
|
511 The `call-process' and `start-process' functions use this function to
|
|
512 get a current directory to run processes in.
|
20
|
513 */
|
|
514 (filename))
|
0
|
515 {
|
|
516 /* This function can GC */
|
|
517 Lisp_Object handler;
|
|
518
|
|
519 /* If the file name has special constructs in it,
|
|
520 call the corresponding file handler. */
|
|
521 handler = Ffind_file_name_handler (filename, Qunhandled_file_name_directory);
|
|
522 if (!NILP (handler))
|
|
523 return call2 (handler, Qunhandled_file_name_directory,
|
|
524 filename);
|
|
525
|
|
526 return Ffile_name_directory (filename);
|
|
527 }
|
|
528
|
|
529
|
|
530 static char *
|
|
531 file_name_as_directory (char *out, char *in)
|
|
532 {
|
|
533 int size = strlen (in) - 1;
|
|
534
|
|
535 strcpy (out, in);
|
|
536
|
|
537 #ifdef VMS
|
|
538 /* Is it already a directory string? */
|
|
539 if (in[size] == ':' || in[size] == ']' || in[size] == '>')
|
|
540 return out;
|
|
541 /* Is it a VMS directory file name? If so, hack VMS syntax. */
|
|
542 else if (! strchr (in, '/')
|
|
543 && ((size > 3 && ! strcmp (&in[size - 3], ".DIR"))
|
|
544 || (size > 3 && ! strcmp (&in[size - 3], ".dir"))
|
|
545 || (size > 5 && (! strncmp (&in[size - 5], ".DIR", 4)
|
|
546 || ! strncmp (&in[size - 5], ".dir", 4))
|
|
547 && (in[size - 1] == '.' || in[size - 1] == ';')
|
|
548 && in[size] == '1')))
|
|
549 {
|
|
550 char *p, *dot;
|
|
551 char brack;
|
|
552
|
|
553 /* x.dir -> [.x]
|
|
554 dir:x.dir --> dir:[x]
|
|
555 dir:[x]y.dir --> dir:[x.y] */
|
|
556 p = in + size;
|
|
557 while (p != in && *p != ':' && *p != '>' && *p != ']') p--;
|
|
558 if (p != in)
|
|
559 {
|
|
560 strncpy (out, in, p - in);
|
|
561 out[p - in] = '\0';
|
|
562 if (*p == ':')
|
|
563 {
|
|
564 brack = ']';
|
|
565 strcat (out, ":[");
|
|
566 }
|
|
567 else
|
|
568 {
|
|
569 brack = *p;
|
|
570 strcat (out, ".");
|
|
571 }
|
|
572 p++;
|
|
573 }
|
|
574 else
|
|
575 {
|
|
576 brack = ']';
|
|
577 strcpy (out, "[.");
|
|
578 }
|
|
579 dot = strchr (p, '.');
|
|
580 if (dot)
|
|
581 {
|
|
582 /* blindly remove any extension */
|
|
583 size = strlen (out) + (dot - p);
|
|
584 strncat (out, p, dot - p);
|
|
585 }
|
|
586 else
|
|
587 {
|
|
588 strcat (out, p);
|
|
589 size = strlen (out);
|
|
590 }
|
|
591 out[size++] = brack;
|
|
592 out[size] = '\0';
|
|
593 }
|
|
594 #else /* not VMS */
|
|
595 /* For Unix syntax, Append a slash if necessary */
|
|
596 if (!IS_ANY_SEP (out[size]))
|
|
597 {
|
|
598 out[size + 1] = DIRECTORY_SEP;
|
|
599 out[size + 2] = '\0';
|
|
600 }
|
|
601 #endif /* not VMS */
|
|
602 return out;
|
|
603 }
|
|
604
|
20
|
605 DEFUN ("file-name-as-directory", Ffile_name_as_directory, 1, 1, 0, /*
|
0
|
606 Return a string representing file FILENAME interpreted as a directory.
|
|
607 This operation exists because a directory is also a file, but its name as
|
|
608 a directory is different from its name as a file.
|
|
609 The result can be used as the value of `default-directory'
|
|
610 or passed as second argument to `expand-file-name'.
|
|
611 For a Unix-syntax file name, just appends a slash.
|
|
612 On VMS, converts \"[X]FOO.DIR\" to \"[X.FOO]\", etc.
|
20
|
613 */
|
|
614 (file))
|
0
|
615 {
|
|
616 /* This function can GC */
|
|
617 char *buf;
|
|
618 Lisp_Object handler;
|
|
619
|
|
620 CHECK_STRING (file);
|
|
621
|
|
622 /* If the file name has special constructs in it,
|
|
623 call the corresponding file handler. */
|
|
624 handler = Ffind_file_name_handler (file, Qfile_name_as_directory);
|
|
625 if (!NILP (handler))
|
|
626 return (call2_check_string (handler, Qfile_name_as_directory,
|
|
627 file));
|
|
628
|
16
|
629 buf = (char *) alloca (XSTRING_LENGTH (file) + 10);
|
0
|
630 return build_string (file_name_as_directory
|
16
|
631 (buf, (char *) XSTRING_DATA (file)));
|
0
|
632 }
|
|
633
|
|
634 /*
|
|
635 * Convert from directory name to filename.
|
|
636 * On VMS:
|
|
637 * xyzzy:[mukesh.emacs] => xyzzy:[mukesh]emacs.dir.1
|
|
638 * xyzzy:[mukesh] => xyzzy:[000000]mukesh.dir.1
|
|
639 * On UNIX, it's simple: just make sure there is a terminating /
|
|
640
|
|
641 * Value is nonzero if the string output is different from the input.
|
|
642 */
|
|
643
|
|
644 static int
|
|
645 directory_file_name (CONST char *src, char *dst)
|
|
646 {
|
|
647 long slen;
|
|
648 #ifdef VMS
|
|
649 long rlen;
|
|
650 char * ptr, * rptr;
|
|
651 char bracket;
|
|
652 struct FAB fab = cc$rms_fab;
|
|
653 struct NAM nam = cc$rms_nam;
|
|
654 char esa[NAM$C_MAXRSS];
|
|
655 #endif /* VMS */
|
|
656
|
|
657 slen = strlen (src);
|
|
658 #ifdef VMS
|
|
659 if (! strchr (src, '/')
|
|
660 && (src[slen - 1] == ']'
|
|
661 || src[slen - 1] == ':'
|
|
662 || src[slen - 1] == '>'))
|
|
663 {
|
|
664 /* VMS style - convert [x.y.z] to [x.y]z, [x] to [000000]x */
|
|
665 fab.fab$l_fna = src;
|
|
666 fab.fab$b_fns = slen;
|
|
667 fab.fab$l_nam = &nam;
|
|
668 fab.fab$l_fop = FAB$M_NAM;
|
|
669
|
|
670 nam.nam$l_esa = esa;
|
|
671 nam.nam$b_ess = sizeof esa;
|
|
672 nam.nam$b_nop |= NAM$M_SYNCHK;
|
|
673
|
|
674 /* We call SYS$PARSE to handle such things as [--] for us. */
|
|
675 if (SYS$PARSE(&fab, 0, 0) == RMS$_NORMAL)
|
|
676 {
|
|
677 slen = nam.nam$b_esl;
|
|
678 if (esa[slen - 1] == ';' && esa[slen - 2] == '.')
|
|
679 slen -= 2;
|
|
680 esa[slen] = '\0';
|
|
681 src = esa;
|
|
682 }
|
|
683 if (src[slen - 1] != ']' && src[slen - 1] != '>')
|
|
684 {
|
|
685 /* what about when we have logical_name:???? */
|
|
686 if (src[slen - 1] == ':')
|
|
687 { /* Xlate logical name and see what we get */
|
|
688 ptr = strcpy (dst, src); /* upper case for getenv */
|
|
689 while (*ptr)
|
|
690 {
|
|
691 *ptr = toupper ((unsigned char) *ptr);
|
|
692 ptr++;
|
|
693 }
|
|
694 dst[slen - 1] = 0; /* remove colon */
|
|
695 if (!(src = egetenv (dst)))
|
|
696 return 0;
|
|
697 /* should we jump to the beginning of this procedure?
|
|
698 Good points: allows us to use logical names that xlate
|
|
699 to Unix names,
|
|
700 Bad points: can be a problem if we just translated to a device
|
|
701 name...
|
|
702 For now, I'll punt and always expect VMS names, and hope for
|
|
703 the best! */
|
|
704 slen = strlen (src);
|
|
705 if (src[slen - 1] != ']' && src[slen - 1] != '>')
|
|
706 { /* no recursion here! */
|
|
707 strcpy (dst, src);
|
|
708 return 0;
|
|
709 }
|
|
710 }
|
|
711 else
|
|
712 { /* not a directory spec */
|
|
713 strcpy (dst, src);
|
|
714 return 0;
|
|
715 }
|
|
716 }
|
|
717 bracket = src[slen - 1];
|
|
718
|
|
719 /* If bracket is ']' or '>', bracket - 2 is the corresponding
|
|
720 opening bracket. */
|
|
721 ptr = strchr (src, bracket - 2);
|
|
722 if (ptr == 0)
|
|
723 { /* no opening bracket */
|
|
724 strcpy (dst, src);
|
|
725 return 0;
|
|
726 }
|
|
727 if (!(rptr = strrchr (src, '.')))
|
|
728 rptr = ptr;
|
|
729 slen = rptr - src;
|
|
730 strncpy (dst, src, slen);
|
|
731 dst[slen] = '\0';
|
|
732 if (*rptr == '.')
|
|
733 {
|
|
734 dst[slen++] = bracket;
|
|
735 dst[slen] = '\0';
|
|
736 }
|
|
737 else
|
|
738 {
|
|
739 /* If we have the top-level of a rooted directory (i.e. xx:[000000]),
|
|
740 then translate the device and recurse. */
|
|
741 if (dst[slen - 1] == ':'
|
|
742 && dst[slen - 2] != ':' /* skip decnet nodes */
|
|
743 && strcmp(src + slen, "[000000]") == 0)
|
|
744 {
|
|
745 dst[slen - 1] = '\0';
|
|
746 if ((ptr = egetenv (dst))
|
|
747 && (rlen = strlen (ptr) - 1) > 0
|
|
748 && (ptr[rlen] == ']' || ptr[rlen] == '>')
|
|
749 && ptr[rlen - 1] == '.')
|
|
750 {
|
|
751 char * buf = (char *) alloca (strlen (ptr) + 1);
|
|
752 strcpy (buf, ptr);
|
|
753 buf[rlen - 1] = ']';
|
|
754 buf[rlen] = '\0';
|
|
755 return directory_file_name (buf, dst);
|
|
756 }
|
|
757 else
|
|
758 dst[slen - 1] = ':';
|
|
759 }
|
|
760 strcat (dst, "[000000]");
|
|
761 slen += 8;
|
|
762 }
|
|
763 rptr++;
|
|
764 rlen = strlen (rptr) - 1;
|
|
765 strncat (dst, rptr, rlen);
|
|
766 dst[slen + rlen] = '\0';
|
|
767 strcat (dst, ".DIR.1");
|
|
768 return 1;
|
|
769 }
|
|
770 #endif /* VMS */
|
|
771 /* Process as Unix format: just remove any final slash.
|
|
772 But leave "/" unchanged; do not change it to "". */
|
|
773 strcpy (dst, src);
|
|
774 #ifdef APOLLO
|
|
775 /* Handle // as root for apollo's. */
|
|
776 if ((slen > 2 && dst[slen - 1] == '/')
|
|
777 || (slen > 1 && dst[0] != '/' && dst[slen - 1] == '/'))
|
|
778 dst[slen - 1] = 0;
|
|
779 #else
|
|
780 if (slen > 1
|
|
781 && IS_DIRECTORY_SEP (dst[slen - 1])
|
|
782 #ifdef DOS_NT
|
|
783 && !IS_ANY_SEP (dst[slen - 2])
|
|
784 #endif
|
|
785 )
|
|
786 dst[slen - 1] = 0;
|
|
787 #endif
|
|
788 return 1;
|
|
789 }
|
|
790
|
20
|
791 DEFUN ("directory-file-name", Fdirectory_file_name, 1, 1, 0, /*
|
0
|
792 Return the file name of the directory named DIR.
|
|
793 This is the name of the file that holds the data for the directory DIR.
|
|
794 This operation exists because a directory is also a file, but its name as
|
|
795 a directory is different from its name as a file.
|
|
796 In Unix-syntax, this function just removes the final slash.
|
|
797 On VMS, given a VMS-syntax directory name such as \"[X.Y]\",
|
|
798 it returns a file name such as \"[X]Y.DIR.1\".
|
20
|
799 */
|
|
800 (directory))
|
0
|
801 {
|
|
802 /* This function can GC */
|
|
803 char *buf;
|
|
804 Lisp_Object handler;
|
|
805
|
|
806 CHECK_STRING (directory);
|
|
807
|
|
808 #if 0 /* #### WTF? */
|
|
809 if (NILP (directory))
|
|
810 return Qnil;
|
|
811 #endif
|
|
812
|
|
813 /* If the file name has special constructs in it,
|
|
814 call the corresponding file handler. */
|
|
815 handler = Ffind_file_name_handler (directory, Qdirectory_file_name);
|
|
816 if (!NILP (handler))
|
|
817 return (call2_check_string (handler, Qdirectory_file_name,
|
|
818 directory));
|
|
819 #ifdef VMS
|
|
820 /* 20 extra chars is insufficient for VMS, since we might perform a
|
|
821 logical name translation. an equivalence string can be up to 255
|
|
822 chars long, so grab that much extra space... - sss */
|
16
|
823 buf = (char *) alloca (XSTRING_LENGTH (directory) + 20 + 255);
|
0
|
824 #else
|
16
|
825 buf = (char *) alloca (XSTRING_LENGTH (directory) + 20);
|
0
|
826 #endif
|
16
|
827 directory_file_name ((char *) XSTRING_DATA (directory), buf);
|
0
|
828 return build_string (buf);
|
|
829 }
|
|
830
|
20
|
831 DEFUN ("make-temp-name", Fmake_temp_name, 1, 1, 0, /*
|
0
|
832 Generate temporary file name (string) starting with PREFIX (a string).
|
|
833 The Emacs process number forms part of the result,
|
|
834 so there is no danger of generating a name being used by another process.
|
20
|
835 */
|
|
836 (prefix))
|
0
|
837 {
|
|
838 CONST char suffix[] = "XXXXXX";
|
|
839 Bufbyte *data;
|
|
840 Bytecount len;
|
|
841 Lisp_Object val;
|
|
842
|
|
843 CHECK_STRING (prefix);
|
16
|
844 len = XSTRING_LENGTH (prefix);
|
0
|
845 val = make_uninit_string (len + countof (suffix) - 1);
|
16
|
846 data = XSTRING_DATA (val);
|
|
847 memcpy (data, XSTRING_DATA (prefix), len);
|
0
|
848 memcpy (data + len, suffix, countof (suffix));
|
|
849 /* !!#### does mktemp() Mule-encapsulate? */
|
|
850 mktemp ((char *) data);
|
|
851
|
|
852 return val;
|
|
853 }
|
|
854
|
20
|
855 DEFUN ("expand-file-name", Fexpand_file_name, 1, 2, 0, /*
|
0
|
856 Convert FILENAME to absolute, and canonicalize it.
|
|
857 Second arg DEFAULT is directory to start with if FILENAME is relative
|
|
858 (does not start with slash); if DEFAULT is nil or missing,
|
|
859 the current buffer's value of default-directory is used.
|
|
860 Path components that are `.' are removed, and
|
|
861 path components followed by `..' are removed, along with the `..' itself;
|
|
862 note that these simplifications are done without checking the resulting
|
|
863 paths in the file system.
|
|
864 An initial `~/' expands to your home directory.
|
|
865 An initial `~USER/' expands to USER's home directory.
|
|
866 See also the function `substitute-in-file-name'.
|
20
|
867 */
|
|
868 (name, defalt))
|
0
|
869 {
|
|
870 /* This function can GC */
|
|
871 Bufbyte *nm;
|
|
872
|
|
873 Bufbyte *newdir, *p, *o;
|
|
874 int tlen;
|
|
875 Bufbyte *target;
|
|
876 struct passwd *pw;
|
|
877 #ifdef VMS
|
|
878 Bufbyte * colon = 0;
|
|
879 Bufbyte * close = 0;
|
|
880 Bufbyte * slash = 0;
|
|
881 Bufbyte * brack = 0;
|
|
882 int lbrack = 0, rbrack = 0;
|
|
883 int dots = 0;
|
|
884 #endif /* VMS */
|
|
885 #ifdef DOS_NT
|
|
886 /* Demacs 1.1.2 91/10/20 Manabu Higashida */
|
|
887 int drive = -1;
|
|
888 int relpath = 0;
|
|
889 Bufbyte *tmp, *defdir;
|
|
890 #endif /* DOS_NT */
|
|
891 Lisp_Object handler;
|
40
|
892 struct gcpro gcpro1;
|
0
|
893
|
|
894 CHECK_STRING (name);
|
|
895
|
|
896 /* If the file name has special constructs in it,
|
|
897 call the corresponding file handler. */
|
|
898 handler = Ffind_file_name_handler (name, Qexpand_file_name);
|
|
899 if (!NILP (handler))
|
|
900 return (call3_check_string (handler, Qexpand_file_name, name,
|
|
901 defalt));
|
|
902
|
|
903 /* Use the buffer's default-directory if DEFALT is omitted. */
|
|
904 if (NILP (defalt))
|
|
905 defalt = current_buffer->directory;
|
|
906 if (NILP (defalt)) /* this should be a meaningful error */
|
|
907 {
|
|
908 /* #### If we had a minibuffer-only frame up then current_buffer
|
|
909 is likely to not have a directory setting. We should
|
|
910 probably redo things to make sure that current_buffer stays
|
|
911 set to something sensible. */
|
|
912 if (!preparing_for_armageddon)
|
|
913 signal_simple_error ("default-directory is not set",
|
|
914 make_buffer (current_buffer));
|
|
915 }
|
|
916 else
|
|
917 CHECK_STRING (defalt);
|
|
918
|
|
919 if (!NILP (defalt))
|
|
920 {
|
40
|
921 struct gcpro gcpro1;
|
|
922
|
|
923 GCPRO1 (defalt); /* might be current_buffer->directory */
|
0
|
924 handler = Ffind_file_name_handler (defalt, Qexpand_file_name);
|
40
|
925 UNGCPRO;
|
0
|
926 if (!NILP (handler))
|
|
927 return call3 (handler, Qexpand_file_name, name, defalt);
|
|
928 }
|
|
929
|
|
930 /* Make sure DEFALT is properly expanded.
|
|
931 It would be better to do this down below where we actually use
|
|
932 defalt. Unfortunately, calling Fexpand_file_name recursively
|
|
933 could invoke GC, and the strings might be relocated. This would
|
|
934 be annoying because we have pointers into strings lying around
|
|
935 that would need adjusting, and people would add new pointers to
|
|
936 the code and forget to adjust them, resulting in intermittent bugs.
|
|
937 Putting this call here avoids all that crud.
|
|
938
|
|
939 The EQ test avoids infinite recursion. */
|
|
940 if (! NILP (defalt) && !EQ (defalt, name)
|
|
941 /* This saves time in a common case. */
|
16
|
942 && ! (XSTRING_LENGTH (defalt) >= 3
|
|
943 && IS_DIRECTORY_SEP (XSTRING_BYTE (defalt, 0))
|
|
944 && IS_DEVICE_SEP (XSTRING_BYTE (defalt, 1))))
|
0
|
945 {
|
|
946 struct gcpro gcpro1;
|
|
947
|
40
|
948 GCPRO1 (defalt); /* may be current_buffer->directory */
|
0
|
949 defalt = Fexpand_file_name (defalt, Qnil);
|
|
950 UNGCPRO;
|
|
951 }
|
|
952
|
|
953 #ifdef VMS
|
|
954 /* Filenames on VMS are always upper case. */
|
|
955 name = Fupcase (name, Fcurrent_buffer ());
|
|
956 #endif
|
|
957 #ifdef FILE_SYSTEM_CASE
|
|
958 name = FILE_SYSTEM_CASE (name);
|
|
959 #endif
|
|
960
|
40
|
961 /* #### dmoore - this is ugly, clean this up. Looks like nm
|
|
962 pointing into name should be safe during all of this, though. */
|
16
|
963 nm = XSTRING_DATA (name);
|
0
|
964
|
|
965 #ifdef MSDOS
|
|
966 /* First map all backslashes to slashes. */
|
|
967 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm));
|
|
968 #endif
|
|
969
|
|
970 #ifdef DOS_NT
|
|
971 /* Now strip drive name. */
|
|
972 {
|
|
973 Bufbyte *colon = strrchr (nm, ':');
|
|
974 if (colon)
|
|
975 if (nm == colon)
|
|
976 nm++;
|
|
977 else
|
|
978 {
|
|
979 drive = colon[-1];
|
|
980 nm = colon + 1;
|
|
981 if (!IS_DIRECTORY_SEP (*nm))
|
|
982 {
|
|
983 defdir = alloca (MAXPATHLEN + 1);
|
|
984 relpath = getdefdir (tolower (drive) - 'a' + 1, defdir);
|
|
985 }
|
|
986 }
|
|
987 }
|
|
988 #endif /* DOS_NT */
|
|
989
|
|
990 /* Handle // and /~ in middle of file name
|
|
991 by discarding everything through the first / of that sequence. */
|
|
992 p = nm;
|
|
993 while (*p)
|
|
994 {
|
|
995 /* Since we know the path is absolute, we can assume that each
|
|
996 element starts with a "/". */
|
|
997
|
|
998 /* "//" anywhere isn't necessarily hairy; we just start afresh
|
|
999 with the second slash. */
|
|
1000 if (IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1])
|
|
1001 #if defined (APOLLO) || defined (WINDOWSNT)
|
|
1002 /* // at start of filename is meaningful on Apollo
|
|
1003 and WindowsNT systems */
|
|
1004 && nm != p
|
|
1005 #endif /* APOLLO || WINDOWSNT */
|
|
1006 )
|
|
1007 nm = p + 1;
|
|
1008
|
|
1009 /* "~" is hairy as the start of any path element. */
|
|
1010 if (IS_DIRECTORY_SEP (p[0]) && p[1] == '~')
|
|
1011 nm = p + 1;
|
|
1012
|
|
1013 p++;
|
|
1014 }
|
|
1015
|
|
1016 /* If nm is absolute, flush ...// and detect /./ and /../.
|
|
1017 If no /./ or /../ we can return right away. */
|
|
1018 if (
|
|
1019 IS_DIRECTORY_SEP (nm[0])
|
|
1020 #ifdef VMS
|
|
1021 || strchr (nm, ':')
|
|
1022 #endif /* VMS */
|
|
1023 )
|
|
1024 {
|
|
1025 /* If it turns out that the filename we want to return is just a
|
|
1026 suffix of FILENAME, we don't need to go through and edit
|
|
1027 things; we just need to construct a new string using data
|
|
1028 starting at the middle of FILENAME. If we set lose to a
|
|
1029 non-zero value, that means we've discovered that we can't do
|
|
1030 that cool trick. */
|
|
1031 int lose = 0;
|
|
1032
|
|
1033 p = nm;
|
|
1034 while (*p)
|
|
1035 {
|
|
1036 /* Since we know the path is absolute, we can assume that each
|
|
1037 element starts with a "/". */
|
|
1038
|
|
1039 /* "." and ".." are hairy. */
|
|
1040 if (IS_DIRECTORY_SEP (p[0])
|
|
1041 && p[1] == '.'
|
|
1042 && (IS_DIRECTORY_SEP (p[2])
|
|
1043 || p[2] == 0
|
|
1044 || (p[2] == '.' && (IS_DIRECTORY_SEP (p[3])
|
|
1045 || p[3] == 0))))
|
|
1046 lose = 1;
|
|
1047 #ifdef VMS
|
|
1048 if (p[0] == '\\')
|
|
1049 lose = 1;
|
|
1050 if (p[0] == '/') {
|
|
1051 /* if dev:[dir]/, move nm to / */
|
|
1052 if (!slash && p > nm && (brack || colon)) {
|
|
1053 nm = (brack ? brack + 1 : colon + 1);
|
|
1054 lbrack = rbrack = 0;
|
|
1055 brack = 0;
|
|
1056 colon = 0;
|
|
1057 }
|
|
1058 slash = p;
|
|
1059 }
|
|
1060 if (p[0] == '-')
|
|
1061 #ifndef VMS4_4
|
|
1062 /* VMS pre V4.4,convert '-'s in filenames. */
|
|
1063 if (lbrack == rbrack)
|
|
1064 {
|
|
1065 if (dots < 2) /* this is to allow negative version numbers */
|
|
1066 p[0] = '_';
|
|
1067 }
|
|
1068 else
|
|
1069 #endif /* VMS4_4 */
|
|
1070 if (lbrack > rbrack &&
|
|
1071 ((p[-1] == '.' || p[-1] == '[' || p[-1] == '<') &&
|
|
1072 (p[1] == '.' || p[1] == ']' || p[1] == '>')))
|
|
1073 lose = 1;
|
|
1074 #ifndef VMS4_4
|
|
1075 else
|
|
1076 p[0] = '_';
|
|
1077 #endif /* VMS4_4 */
|
|
1078 /* count open brackets, reset close bracket pointer */
|
|
1079 if (p[0] == '[' || p[0] == '<')
|
|
1080 lbrack++, brack = 0;
|
|
1081 /* count close brackets, set close bracket pointer */
|
|
1082 if (p[0] == ']' || p[0] == '>')
|
|
1083 rbrack++, brack = p;
|
|
1084 /* detect ][ or >< */
|
|
1085 if ((p[0] == ']' || p[0] == '>') && (p[1] == '[' || p[1] == '<'))
|
|
1086 lose = 1;
|
|
1087 if ((p[0] == ':' || p[0] == ']' || p[0] == '>') && p[1] == '~')
|
|
1088 nm = p + 1, lose = 1;
|
|
1089 if (p[0] == ':' && (colon || slash))
|
|
1090 /* if dev1:[dir]dev2:, move nm to dev2: */
|
|
1091 if (brack)
|
|
1092 {
|
|
1093 nm = brack + 1;
|
|
1094 brack = 0;
|
|
1095 }
|
|
1096 /* if /pathname/dev:, move nm to dev: */
|
|
1097 else if (slash)
|
|
1098 nm = slash + 1;
|
|
1099 /* if node::dev:, move colon following dev */
|
|
1100 else if (colon && colon[-1] == ':')
|
|
1101 colon = p;
|
|
1102 /* if dev1:dev2:, move nm to dev2: */
|
|
1103 else if (colon && colon[-1] != ':')
|
|
1104 {
|
|
1105 nm = colon + 1;
|
|
1106 colon = 0;
|
|
1107 }
|
|
1108 if (p[0] == ':' && !colon)
|
|
1109 {
|
|
1110 if (p[1] == ':')
|
|
1111 p++;
|
|
1112 colon = p;
|
|
1113 }
|
|
1114 if (lbrack == rbrack)
|
|
1115 if (p[0] == ';')
|
|
1116 dots = 2;
|
|
1117 else if (p[0] == '.')
|
|
1118 dots++;
|
|
1119 #endif /* VMS */
|
|
1120 p++;
|
|
1121 }
|
|
1122 if (!lose)
|
|
1123 {
|
|
1124 #ifdef VMS
|
|
1125 if (strchr (nm, '/'))
|
|
1126 return build_string (sys_translate_unix (nm));
|
|
1127 #endif /* VMS */
|
|
1128 #ifndef DOS_NT
|
16
|
1129 if (nm == XSTRING_DATA (name))
|
0
|
1130 return name;
|
|
1131 return build_string ((char *) nm);
|
|
1132 #endif /* not DOS_NT */
|
|
1133 }
|
|
1134 }
|
|
1135
|
|
1136 /* Now determine directory to start with and put it in newdir */
|
|
1137
|
|
1138 newdir = 0;
|
|
1139
|
|
1140 if (nm[0] == '~') /* prefix ~ */
|
|
1141 {
|
|
1142 if (IS_DIRECTORY_SEP (nm[1])
|
|
1143 #ifdef VMS
|
|
1144 || nm[1] == ':'
|
|
1145 #endif /* VMS */
|
|
1146 || nm[1] == 0) /* ~ by itself */
|
|
1147 {
|
|
1148 if (!(newdir = (Bufbyte *) egetenv ("HOME")))
|
|
1149 newdir = (Bufbyte *) "";
|
|
1150 #ifdef DOS_NT
|
|
1151 /* Problem when expanding "~\" if HOME is not on current drive.
|
|
1152 Ulrich Leodolter, Wed Jan 11 10:20:35 1995 */
|
|
1153 if (newdir[1] == ':')
|
|
1154 drive = newdir[0];
|
|
1155 dostounix_filename (newdir);
|
|
1156 #endif
|
|
1157 nm++;
|
|
1158 #ifdef VMS
|
|
1159 nm++; /* Don't leave the slash in nm. */
|
|
1160 #endif /* VMS */
|
|
1161 }
|
|
1162 else /* ~user/filename */
|
|
1163 {
|
|
1164 for (p = nm; *p && (!IS_DIRECTORY_SEP (*p)
|
|
1165 #ifdef VMS
|
|
1166 && *p != ':'
|
|
1167 #endif /* VMS */
|
|
1168 ); p++);
|
|
1169 o = (Bufbyte *) alloca (p - nm + 1);
|
|
1170 memcpy (o, (char *) nm, p - nm);
|
|
1171 o [p - nm] = 0;
|
|
1172
|
|
1173 #ifdef WINDOWSNT
|
|
1174 newdir = (unsigned char *) egetenv ("HOME");
|
|
1175 dostounix_filename (newdir);
|
|
1176 #else /* not WINDOWSNT */
|
|
1177 /* Jamie reports that getpwnam() can get wedged by SIGIO/SIGALARM
|
|
1178 occurring in it. (It can call select()). */
|
|
1179 slow_down_interrupts ();
|
|
1180 pw = (struct passwd *) getpwnam ((char *) o + 1);
|
|
1181 speed_up_interrupts ();
|
|
1182 if (pw)
|
|
1183 {
|
|
1184 newdir = (Bufbyte *) pw -> pw_dir;
|
|
1185 #ifdef VMS
|
|
1186 nm = p + 1; /* skip the terminator */
|
|
1187 #else
|
|
1188 nm = p;
|
|
1189 #endif /* VMS */
|
|
1190 }
|
|
1191 #endif /* not WINDOWSNT */
|
|
1192
|
|
1193 /* If we don't find a user of that name, leave the name
|
|
1194 unchanged; don't move nm forward to p. */
|
|
1195 }
|
|
1196 }
|
|
1197
|
|
1198 if (!IS_ANY_SEP (nm[0])
|
|
1199 #ifdef VMS
|
|
1200 && !strchr (nm, ':')
|
|
1201 #endif /* not VMS */
|
|
1202 #ifdef DOS_NT
|
|
1203 && drive == -1
|
|
1204 #endif /* DOS_NT */
|
|
1205 && !newdir
|
|
1206 && STRINGP (defalt))
|
|
1207 {
|
16
|
1208 newdir = XSTRING_DATA (defalt);
|
0
|
1209 }
|
|
1210
|
|
1211 #ifdef DOS_NT
|
|
1212 if (newdir == 0 && relpath)
|
|
1213 newdir = defdir;
|
|
1214 #endif /* DOS_NT */
|
|
1215 if (newdir != 0)
|
|
1216 {
|
|
1217 /* Get rid of any slash at the end of newdir. */
|
|
1218 int length = strlen ((char *) newdir);
|
|
1219 /* Adding `length > 1 &&' makes ~ expand into / when homedir
|
|
1220 is the root dir. People disagree about whether that is right.
|
|
1221 Anyway, we can't take the risk of this change now. */
|
|
1222 #ifdef DOS_NT
|
|
1223 if (newdir[1] != ':' && length > 1)
|
|
1224 #endif
|
|
1225 if (IS_DIRECTORY_SEP (newdir[length - 1]))
|
|
1226 {
|
|
1227 Bufbyte *temp = (Bufbyte *) alloca (length);
|
|
1228 memcpy (temp, newdir, length - 1);
|
|
1229 temp[length - 1] = 0;
|
|
1230 newdir = temp;
|
|
1231 }
|
|
1232 tlen = length + 1;
|
|
1233 }
|
|
1234 else
|
|
1235 tlen = 0;
|
|
1236
|
|
1237 /* Now concatenate the directory and name to new space in the stack frame */
|
|
1238 tlen += strlen ((char *) nm) + 1;
|
|
1239 #ifdef DOS_NT
|
|
1240 /* Add reserved space for drive name. (The Microsoft x86 compiler
|
|
1241 produces incorrect code if the following two lines are combined.) */
|
|
1242 target = (Bufbyte *) alloca (tlen + 2);
|
|
1243 target += 2;
|
|
1244 #else /* not DOS_NT */
|
|
1245 target = (Bufbyte *) alloca (tlen);
|
|
1246 #endif /* not DOS_NT */
|
|
1247 *target = 0;
|
|
1248
|
|
1249 if (newdir)
|
|
1250 {
|
|
1251 #ifndef VMS
|
|
1252 if (nm[0] == 0 || IS_DIRECTORY_SEP (nm[0]))
|
|
1253 strcpy ((char *) target, (char *) newdir);
|
|
1254 else
|
|
1255 #endif
|
|
1256 file_name_as_directory ((char *) target, (char *) newdir);
|
|
1257 }
|
|
1258
|
|
1259 strcat ((char *) target, (char *) nm);
|
|
1260 #ifdef VMS
|
|
1261 if (strchr (target, '/'))
|
|
1262 strcpy (target, sys_translate_unix (target));
|
|
1263 #endif /* VMS */
|
|
1264
|
|
1265 /* Now canonicalize by removing /. and /foo/.. if they appear. */
|
|
1266
|
|
1267 p = target;
|
|
1268 o = target;
|
|
1269
|
|
1270 while (*p)
|
|
1271 {
|
|
1272 #ifdef VMS
|
|
1273 if (*p != ']' && *p != '>' && *p != '-')
|
|
1274 {
|
|
1275 if (*p == '\\')
|
|
1276 p++;
|
|
1277 *o++ = *p++;
|
|
1278 }
|
|
1279 else if ((p[0] == ']' || p[0] == '>') && p[0] == p[1] + 2)
|
|
1280 /* brackets are offset from each other by 2 */
|
|
1281 {
|
|
1282 p += 2;
|
|
1283 if (*p != '.' && *p != '-' && o[-1] != '.')
|
|
1284 /* convert [foo][bar] to [bar] */
|
|
1285 while (o[-1] != '[' && o[-1] != '<')
|
|
1286 o--;
|
|
1287 else if (*p == '-' && *o != '.')
|
|
1288 *--p = '.';
|
|
1289 }
|
|
1290 else if (p[0] == '-' && o[-1] == '.' &&
|
|
1291 (p[1] == '.' || p[1] == ']' || p[1] == '>'))
|
|
1292 /* flush .foo.- ; leave - if stopped by '[' or '<' */
|
|
1293 {
|
|
1294 do
|
|
1295 o--;
|
|
1296 while (o[-1] != '.' && o[-1] != '[' && o[-1] != '<');
|
|
1297 if (p[1] == '.') /* foo.-.bar ==> bar. */
|
|
1298 p += 2;
|
|
1299 else if (o[-1] == '.') /* '.foo.-]' ==> ']' */
|
|
1300 p++, o--;
|
|
1301 /* else [foo.-] ==> [-] */
|
|
1302 }
|
|
1303 else
|
|
1304 {
|
|
1305 #ifndef VMS4_4
|
|
1306 if (*p == '-' &&
|
|
1307 o[-1] != '[' && o[-1] != '<' && o[-1] != '.' &&
|
|
1308 p[1] != ']' && p[1] != '>' && p[1] != '.')
|
|
1309 *p = '_';
|
|
1310 #endif /* VMS4_4 */
|
|
1311 *o++ = *p++;
|
|
1312 }
|
|
1313 #else /* not VMS */
|
|
1314 if (!IS_DIRECTORY_SEP (*p))
|
|
1315 {
|
|
1316 *o++ = *p++;
|
|
1317 }
|
|
1318 else if (IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1])
|
|
1319 #if defined (APOLLO) || defined (WINDOWSNT)
|
|
1320 /* // at start of filename is meaningful in Apollo
|
|
1321 and WindowsNT systems */
|
|
1322 && o != target
|
|
1323 #endif /* APOLLO */
|
|
1324 )
|
|
1325 {
|
|
1326 o = target;
|
|
1327 p++;
|
|
1328 }
|
|
1329 else if (IS_DIRECTORY_SEP (p[0])
|
|
1330 && p[1] == '.'
|
|
1331 && (IS_DIRECTORY_SEP (p[2])
|
|
1332 || p[2] == 0))
|
|
1333 {
|
|
1334 /* If "/." is the entire filename, keep the "/". Otherwise,
|
|
1335 just delete the whole "/.". */
|
|
1336 if (o == target && p[2] == '\0')
|
|
1337 *o++ = *p;
|
|
1338 p += 2;
|
|
1339 }
|
|
1340 else if (IS_DIRECTORY_SEP (p[0]) && p[1] == '.' && p[2] == '.'
|
|
1341 /* `/../' is the "superroot" on certain file systems. */
|
|
1342 && o != target
|
|
1343 && (IS_DIRECTORY_SEP (p[3]) || p[3] == 0))
|
|
1344 {
|
|
1345 while (o != target && (--o) && !IS_DIRECTORY_SEP (*o))
|
|
1346 ;
|
|
1347 #if defined (APOLLO) || defined (WINDOWSNT)
|
|
1348 if (o == target + 1
|
|
1349 && IS_DIRECTORY_SEP (o[-1]) && IS_DIRECTORY_SEP (o[0]))
|
|
1350 ++o;
|
|
1351 else
|
|
1352 #endif /* APOLLO || WINDOWSNT */
|
|
1353 if (o == target && IS_ANY_SEP (*o))
|
|
1354 ++o;
|
|
1355 p += 3;
|
|
1356 }
|
|
1357 else
|
|
1358 {
|
|
1359 *o++ = *p++;
|
|
1360 }
|
|
1361 #endif /* not VMS */
|
|
1362 }
|
|
1363
|
|
1364 #ifdef DOS_NT
|
|
1365 /* at last, set drive name. */
|
|
1366 if (target[1] != ':'
|
|
1367 #ifdef WINDOWSNT
|
|
1368 /* Allow network paths that look like "\\foo" */
|
|
1369 && !(IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1]))
|
|
1370 #endif /* WINDOWSNT */
|
|
1371 )
|
|
1372 {
|
|
1373 target -= 2;
|
|
1374 target[0] = (drive < 0 ? getdisk () + 'A' : drive);
|
|
1375 target[1] = ':';
|
|
1376 }
|
|
1377 #endif /* DOS_NT */
|
|
1378
|
|
1379 return make_string (target, o - target);
|
|
1380 }
|
|
1381
|
|
1382 #if 0 /* FSFmacs */
|
|
1383 another older version of expand-file-name;
|
|
1384 #endif
|
|
1385
|
|
1386 /* not a full declaration because realpath() is typed differently
|
|
1387 on different systems */
|
|
1388 extern char *realpath ();
|
|
1389
|
20
|
1390 DEFUN ("file-truename", Ffile_truename, 1, 2, 0, /*
|
0
|
1391 Return the canonical name of the given FILE.
|
|
1392 Second arg DEFAULT is directory to start with if FILE is relative
|
|
1393 (does not start with slash); if DEFAULT is nil or missing,
|
|
1394 the current buffer's value of default-directory is used.
|
|
1395 No component of the resulting pathname will be a symbolic link, as
|
|
1396 in the realpath() function.
|
20
|
1397 */
|
|
1398 (filename, defalt))
|
0
|
1399 {
|
|
1400 /* This function can GC */
|
|
1401 struct gcpro gcpro1;
|
|
1402 Lisp_Object expanded_name;
|
|
1403 Lisp_Object handler;
|
|
1404
|
|
1405 CHECK_STRING (filename);
|
|
1406
|
|
1407 expanded_name = Fexpand_file_name (filename, defalt);
|
|
1408
|
|
1409 if (!STRINGP (expanded_name))
|
|
1410 return Qnil;
|
|
1411
|
|
1412 GCPRO1 (expanded_name);
|
|
1413 handler = Ffind_file_name_handler (expanded_name, Qfile_truename);
|
|
1414 UNGCPRO;
|
|
1415
|
|
1416 if (!NILP (handler))
|
|
1417 return (call2_check_string (handler, Qfile_truename,
|
|
1418 expanded_name));
|
|
1419
|
|
1420 #ifdef VMS
|
|
1421 return (expanded_name);
|
|
1422 #else
|
|
1423 {
|
|
1424 char resolved_path[MAXPATHLEN];
|
|
1425 char path[MAXPATHLEN];
|
|
1426 char *p = path;
|
16
|
1427 int elen = XSTRING_LENGTH (expanded_name);
|
0
|
1428
|
|
1429 if (elen >= countof (path))
|
|
1430 goto toolong;
|
|
1431
|
16
|
1432 memcpy (path, XSTRING_DATA (expanded_name), elen + 1);
|
0
|
1433 /* memset (resolved_path, 0, sizeof (resolved_path)); */
|
|
1434
|
|
1435 /* Try doing it all at once. */
|
|
1436 /* !!#### Does realpath() Mule-encapsulate? */
|
|
1437 if (!realpath (path, resolved_path))
|
|
1438 {
|
|
1439 /* Didn't resolve it -- have to do it one component at a time. */
|
|
1440 /* "realpath" is a typically useless, stupid un*x piece of crap.
|
|
1441 It claims to return a useful value in the "error" case, but since
|
|
1442 there is no indication provided of how far along the pathname
|
|
1443 the function went before erring, there is no way to use the
|
|
1444 partial result returned. What a piece of junk. */
|
|
1445 for (;;)
|
|
1446 {
|
|
1447 p = (char *) memchr (p + 1, '/', elen - (p + 1 - path));
|
|
1448 if (p)
|
|
1449 *p = 0;
|
|
1450
|
|
1451 /* memset (resolved_path, 0, sizeof (resolved_path)); */
|
|
1452 if (realpath (path, resolved_path))
|
|
1453 {
|
|
1454 if (p)
|
|
1455 *p = '/';
|
|
1456 else
|
|
1457 break;
|
|
1458
|
|
1459 }
|
|
1460 else if (errno == ENOENT)
|
|
1461 {
|
|
1462 /* Failed on this component. Just tack on the rest of
|
|
1463 the string and we are done. */
|
|
1464 int rlen = strlen (resolved_path);
|
|
1465
|
|
1466 /* "On failure, it returns NULL, sets errno to indicate
|
|
1467 the error, and places in resolved_path the absolute pathname
|
|
1468 of the path component which could not be resolved." */
|
|
1469 if (p)
|
|
1470 {
|
|
1471 int plen = elen - (p - path);
|
|
1472
|
|
1473 if (rlen > 1 && resolved_path[rlen - 1] == '/')
|
|
1474 rlen = rlen - 1;
|
|
1475
|
|
1476 if (plen + rlen + 1 > countof (resolved_path))
|
|
1477 goto toolong;
|
|
1478
|
|
1479 resolved_path[rlen] = '/';
|
|
1480 memcpy (resolved_path + rlen + 1, p + 1, plen + 1 - 1);
|
|
1481 }
|
|
1482 break;
|
|
1483 }
|
|
1484 else
|
|
1485 goto lose;
|
|
1486 }
|
|
1487 }
|
|
1488
|
|
1489 {
|
|
1490 int rlen = strlen (resolved_path);
|
16
|
1491 if (elen > 0 && XSTRING_BYTE (expanded_name, elen - 1) == '/'
|
0
|
1492 && !(rlen > 0 && resolved_path[rlen - 1] == '/'))
|
|
1493 {
|
|
1494 if (rlen + 1 > countof (resolved_path))
|
|
1495 goto toolong;
|
|
1496 resolved_path[rlen] = '/';
|
|
1497 resolved_path[rlen + 1] = 0;
|
|
1498 rlen = rlen + 1;
|
|
1499 }
|
|
1500 return make_string ((Bufbyte *) resolved_path, rlen);
|
|
1501 }
|
|
1502
|
|
1503 toolong:
|
|
1504 errno = ENAMETOOLONG;
|
|
1505 goto lose;
|
|
1506 lose:
|
|
1507 report_file_error ("Finding truename", list1 (expanded_name));
|
|
1508 }
|
|
1509 return Qnil; /* suppress compiler warning */
|
|
1510 #endif /* not VMS */
|
|
1511 }
|
|
1512
|
|
1513
|
20
|
1514 DEFUN ("substitute-in-file-name", Fsubstitute_in_file_name, 1, 1, 0, /*
|
0
|
1515 Substitute environment variables referred to in FILENAME.
|
|
1516 `$FOO' where FOO is an environment variable name means to substitute
|
|
1517 the value of that variable. The variable name should be terminated
|
|
1518 with a character not a letter, digit or underscore; otherwise, enclose
|
|
1519 the entire variable name in braces.
|
|
1520 If `/~' appears, all of FILENAME through that `/' is discarded.
|
|
1521
|
|
1522 On VMS, `$' substitution is not done; this function does little and only
|
|
1523 duplicates what `expand-file-name' does.
|
20
|
1524 */
|
|
1525 (string))
|
0
|
1526 {
|
|
1527 Bufbyte *nm;
|
|
1528
|
|
1529 Bufbyte *s, *p, *o, *x, *endp;
|
|
1530 Bufbyte *target = 0;
|
|
1531 int total = 0;
|
|
1532 int substituted = 0;
|
|
1533 Bufbyte *xnm;
|
|
1534 Lisp_Object handler;
|
|
1535
|
|
1536 CHECK_STRING (string);
|
|
1537
|
|
1538 /* If the file name has special constructs in it,
|
|
1539 call the corresponding file handler. */
|
|
1540 handler = Ffind_file_name_handler (string, Qsubstitute_in_file_name);
|
|
1541 if (!NILP (handler))
|
40
|
1542 return (call2_check_string_or_nil (handler, Qsubstitute_in_file_name,
|
|
1543 string));
|
0
|
1544
|
16
|
1545 nm = XSTRING_DATA (string);
|
0
|
1546 #ifdef MSDOS
|
|
1547 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm));
|
16
|
1548 substituted = !strcmp (nm, XSTRING_DATA (string));
|
0
|
1549 #endif
|
16
|
1550 endp = nm + XSTRING_LENGTH (string);
|
0
|
1551
|
|
1552 /* If /~ or // appears, discard everything through first slash. */
|
|
1553
|
|
1554 for (p = nm; p != endp; p++)
|
|
1555 {
|
|
1556 if ((p[0] == '~' ||
|
|
1557 #ifdef APOLLO
|
|
1558 /* // at start of file name is meaningful in Apollo system */
|
|
1559 (p[0] == '/' && p - 1 != nm)
|
|
1560 #else /* not APOLLO */
|
|
1561 #ifdef WINDOWSNT
|
|
1562 (IS_DIRECTORY_SEP (p[0]) && p - 1 != nm)
|
|
1563 #else /* not WINDOWSNT */
|
|
1564 p[0] == '/'
|
|
1565 #endif /* not WINDOWSNT */
|
|
1566 #endif /* not APOLLO */
|
|
1567 )
|
|
1568 && p != nm
|
|
1569 && (0
|
|
1570 #ifdef VMS
|
|
1571 || p[-1] == ':' || p[-1] == ']' || p[-1] == '>'
|
|
1572 #endif /* VMS */
|
|
1573 || IS_DIRECTORY_SEP (p[-1])))
|
|
1574 {
|
|
1575 nm = p;
|
|
1576 substituted = 1;
|
|
1577 }
|
|
1578 #ifdef DOS_NT
|
|
1579 if (p[0] && p[1] == ':')
|
|
1580 {
|
|
1581 nm = p;
|
|
1582 substituted = 1;
|
|
1583 }
|
|
1584 #endif /* DOS_NT */
|
|
1585 }
|
|
1586
|
|
1587 #ifdef VMS
|
|
1588 return build_string (nm);
|
|
1589 #else
|
|
1590
|
|
1591 /* See if any variables are substituted into the string
|
|
1592 and find the total length of their values in `total' */
|
|
1593
|
|
1594 for (p = nm; p != endp;)
|
|
1595 if (*p != '$')
|
|
1596 p++;
|
|
1597 else
|
|
1598 {
|
|
1599 p++;
|
|
1600 if (p == endp)
|
|
1601 goto badsubst;
|
|
1602 else if (*p == '$')
|
|
1603 {
|
|
1604 /* "$$" means a single "$" */
|
|
1605 p++;
|
|
1606 total -= 1;
|
|
1607 substituted = 1;
|
|
1608 continue;
|
|
1609 }
|
|
1610 else if (*p == '{')
|
|
1611 {
|
|
1612 o = ++p;
|
|
1613 while (p != endp && *p != '}') p++;
|
|
1614 if (*p != '}') goto missingclose;
|
|
1615 s = p;
|
|
1616 }
|
|
1617 else
|
|
1618 {
|
|
1619 o = p;
|
|
1620 while (p != endp && (isalnum (*p) || *p == '_')) p++;
|
|
1621 s = p;
|
|
1622 }
|
|
1623
|
|
1624 /* Copy out the variable name */
|
|
1625 target = (Bufbyte *) alloca (s - o + 1);
|
|
1626 strncpy ((char *) target, (char *) o, s - o);
|
|
1627 target[s - o] = 0;
|
|
1628 #ifdef DOS_NT
|
|
1629 strupr (target); /* $home == $HOME etc. */
|
|
1630 #endif /* DOS_NT */
|
|
1631
|
|
1632 /* Get variable value */
|
|
1633 o = (Bufbyte *) egetenv ((char *) target);
|
|
1634 if (!o) goto badvar;
|
|
1635 total += strlen ((char *) o);
|
|
1636 substituted = 1;
|
|
1637 }
|
|
1638
|
|
1639 if (!substituted)
|
|
1640 return string;
|
|
1641
|
|
1642 /* If substitution required, recopy the string and do it */
|
|
1643 /* Make space in stack frame for the new copy */
|
16
|
1644 xnm = (Bufbyte *) alloca (XSTRING_LENGTH (string) + total + 1);
|
0
|
1645 x = xnm;
|
|
1646
|
|
1647 /* Copy the rest of the name through, replacing $ constructs with values */
|
|
1648 for (p = nm; *p;)
|
|
1649 if (*p != '$')
|
|
1650 *x++ = *p++;
|
|
1651 else
|
|
1652 {
|
|
1653 p++;
|
|
1654 if (p == endp)
|
|
1655 goto badsubst;
|
|
1656 else if (*p == '$')
|
|
1657 {
|
|
1658 *x++ = *p++;
|
|
1659 continue;
|
|
1660 }
|
|
1661 else if (*p == '{')
|
|
1662 {
|
|
1663 o = ++p;
|
|
1664 while (p != endp && *p != '}') p++;
|
|
1665 if (*p != '}') goto missingclose;
|
|
1666 s = p++;
|
|
1667 }
|
|
1668 else
|
|
1669 {
|
|
1670 o = p;
|
|
1671 while (p != endp && (isalnum (*p) || *p == '_')) p++;
|
|
1672 s = p;
|
|
1673 }
|
|
1674
|
|
1675 /* Copy out the variable name */
|
|
1676 target = (Bufbyte *) alloca (s - o + 1);
|
|
1677 strncpy ((char *) target, (char *) o, s - o);
|
|
1678 target[s - o] = 0;
|
|
1679 #ifdef DOS_NT
|
|
1680 strupr (target); /* $home == $HOME etc. */
|
|
1681 #endif /* DOS_NT */
|
|
1682
|
|
1683 /* Get variable value */
|
|
1684 o = (Bufbyte *) egetenv ((char *) target);
|
|
1685 if (!o)
|
|
1686 goto badvar;
|
|
1687
|
|
1688 strcpy ((char *) x, (char *) o);
|
|
1689 x += strlen ((char *) o);
|
|
1690 }
|
|
1691
|
|
1692 *x = 0;
|
|
1693
|
|
1694 /* If /~ or // appears, discard everything through first slash. */
|
|
1695
|
|
1696 for (p = xnm; p != x; p++)
|
|
1697 if ((p[0] == '~'
|
|
1698 #ifdef APOLLO
|
|
1699 /* // at start of file name is meaningful in Apollo system */
|
|
1700 || (p[0] == '/' && p - 1 != xnm)
|
|
1701 #else /* not APOLLO */
|
|
1702 #ifdef WINDOWSNT
|
|
1703 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != xnm)
|
|
1704 #else /* not WINDOWSNT */
|
|
1705 || p[0] == '/'
|
|
1706 #endif /* not WINDOWSNT */
|
|
1707 #endif /* not APOLLO */
|
|
1708 )
|
|
1709 /* don't do p[-1] if that would go off the beginning --jwz */
|
|
1710 && p != nm && p > xnm && IS_DIRECTORY_SEP (p[-1]))
|
|
1711 xnm = p;
|
|
1712 #ifdef DOS_NT
|
|
1713 else if (p[0] && p[1] == ':')
|
|
1714 xnm = p;
|
|
1715 #endif
|
|
1716
|
|
1717 return make_string (xnm, x - xnm);
|
|
1718
|
|
1719 badsubst:
|
|
1720 error ("Bad format environment-variable substitution");
|
|
1721 missingclose:
|
|
1722 error ("Missing \"}\" in environment-variable substitution");
|
|
1723 badvar:
|
|
1724 error ("Substituting nonexistent environment variable \"%s\"",
|
|
1725 target);
|
|
1726
|
|
1727 /* NOTREACHED */
|
|
1728 return Qnil; /* suppress compiler warning */
|
|
1729 #endif /* not VMS */
|
|
1730 }
|
|
1731
|
|
1732 /* (directory-file-name (expand-file-name FOO)) */
|
|
1733
|
|
1734 Lisp_Object
|
|
1735 expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir)
|
|
1736 {
|
|
1737 /* This function can GC */
|
|
1738 Lisp_Object abspath;
|
|
1739 struct gcpro gcpro1;
|
|
1740
|
|
1741 GCPRO1 (filename);
|
|
1742 abspath = Fexpand_file_name (filename, defdir);
|
|
1743 #ifdef VMS
|
|
1744 {
|
|
1745 Bufbyte c =
|
16
|
1746 XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 1);
|
0
|
1747 if (c == ':' || c == ']' || c == '>')
|
|
1748 abspath = Fdirectory_file_name (abspath);
|
|
1749 }
|
|
1750 #else
|
|
1751 /* Remove final slash, if any (unless path is root).
|
|
1752 stat behaves differently depending! */
|
16
|
1753 if (XSTRING_LENGTH (abspath) > 1
|
|
1754 && IS_DIRECTORY_SEP (XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 1))
|
|
1755 && !IS_DEVICE_SEP (XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 2)))
|
0
|
1756 /* We cannot take shortcuts; they might be wrong for magic file names. */
|
|
1757 abspath = Fdirectory_file_name (abspath);
|
|
1758 #endif
|
|
1759 UNGCPRO;
|
|
1760 return abspath;
|
|
1761 }
|
|
1762
|
|
1763 /* Signal an error if the file ABSNAME already exists.
|
|
1764 If INTERACTIVE is nonzero, ask the user whether to proceed,
|
|
1765 and bypass the error if the user says to go ahead.
|
|
1766 QUERYSTRING is a name for the action that is being considered
|
|
1767 to alter the file.
|
|
1768 *STATPTR is used to store the stat information if the file exists.
|
|
1769 If the file does not exist, STATPTR->st_mode is set to 0. */
|
|
1770
|
|
1771 static void
|
|
1772 barf_or_query_if_file_exists (Lisp_Object absname, CONST char *querystring,
|
|
1773 int interactive, struct stat *statptr)
|
|
1774 {
|
|
1775 struct stat statbuf;
|
|
1776
|
|
1777 /* stat is a good way to tell whether the file exists,
|
|
1778 regardless of what access permissions it has. */
|
16
|
1779 if (stat ((char *) XSTRING_DATA (absname), &statbuf) >= 0)
|
0
|
1780 {
|
|
1781 Lisp_Object tem;
|
|
1782 struct gcpro gcpro1;
|
|
1783
|
|
1784 GCPRO1 (absname);
|
|
1785 if (interactive)
|
|
1786 tem = call1
|
|
1787 (Qyes_or_no_p,
|
|
1788 (emacs_doprnt_string_c
|
|
1789 ((CONST Bufbyte *) GETTEXT ("File %s already exists; %s anyway? "),
|
16
|
1790 Qnil, -1, XSTRING_DATA (absname),
|
0
|
1791 GETTEXT (querystring))));
|
|
1792 else
|
|
1793 tem = Qnil;
|
|
1794 UNGCPRO;
|
|
1795 if (NILP (tem))
|
|
1796 Fsignal (Qfile_already_exists,
|
|
1797 list2 (build_translated_string ("File already exists"),
|
|
1798 absname));
|
|
1799 if (statptr)
|
|
1800 *statptr = statbuf;
|
|
1801 }
|
|
1802 else
|
|
1803 {
|
|
1804 if (statptr)
|
|
1805 statptr->st_mode = 0;
|
|
1806 }
|
|
1807 return;
|
|
1808 }
|
|
1809
|
20
|
1810 DEFUN ("copy-file", Fcopy_file, 2, 4,
|
|
1811 "fCopy file: \nFCopy %s to file: \np\nP", /*
|
0
|
1812 Copy FILE to NEWNAME. Both args must be strings.
|
|
1813 Signals a `file-already-exists' error if file NEWNAME already exists,
|
|
1814 unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil.
|
|
1815 A number as third arg means request confirmation if NEWNAME already exists.
|
|
1816 This is what happens in interactive use with M-x.
|
|
1817 Fourth arg KEEP-TIME non-nil means give the new file the same
|
|
1818 last-modified time as the old one. (This works on only some systems.)
|
|
1819 A prefix arg makes KEEP-TIME non-nil.
|
20
|
1820 */
|
|
1821 (filename, newname, ok_if_already_exists, keep_time))
|
0
|
1822 {
|
|
1823 /* This function can GC */
|
|
1824 int ifd, ofd, n;
|
|
1825 char buf[16 * 1024];
|
|
1826 struct stat st, out_st;
|
|
1827 Lisp_Object handler;
|
|
1828 int speccount = specpdl_depth ();
|
|
1829 struct gcpro gcpro1, gcpro2;
|
|
1830 /* Lisp_Object args[6]; */
|
|
1831 int input_file_statable_p;
|
|
1832
|
|
1833 GCPRO2 (filename, newname);
|
|
1834 CHECK_STRING (filename);
|
|
1835 CHECK_STRING (newname);
|
|
1836 filename = Fexpand_file_name (filename, Qnil);
|
|
1837 newname = Fexpand_file_name (newname, Qnil);
|
|
1838
|
|
1839 /* If the input file name has special constructs in it,
|
|
1840 call the corresponding file handler. */
|
|
1841 handler = Ffind_file_name_handler (filename, Qcopy_file);
|
|
1842 /* Likewise for output file name. */
|
|
1843 if (NILP (handler))
|
|
1844 handler = Ffind_file_name_handler (newname, Qcopy_file);
|
|
1845 if (!NILP (handler))
|
|
1846 {
|
|
1847 UNGCPRO;
|
|
1848 return call5 (handler, Qcopy_file, filename, newname,
|
16
|
1849 ok_if_already_exists, keep_time);
|
0
|
1850 }
|
|
1851
|
|
1852 /* When second argument is a directory, copy the file into it.
|
|
1853 (copy-file "foo" "bar/") == (copy-file "foo" "bar/foo")
|
|
1854 */
|
|
1855 if (!NILP (Ffile_directory_p (newname)))
|
|
1856 {
|
|
1857 Lisp_Object args[3];
|
|
1858 struct gcpro ngcpro1;
|
|
1859 int i = 1;
|
|
1860
|
|
1861 args[0] = newname;
|
|
1862 args[1] = Qnil; args[2] = Qnil;
|
|
1863 NGCPRO1 (*args);
|
|
1864 ngcpro1.nvars = 3;
|
16
|
1865 if (XSTRING_BYTE (newname, XSTRING_LENGTH (newname) - 1) != '/')
|
0
|
1866 args[i++] = build_string ("/");
|
|
1867 args[i++] = Ffile_name_nondirectory (filename);
|
|
1868 newname = Fconcat (i, args);
|
|
1869 NUNGCPRO;
|
|
1870 }
|
|
1871
|
|
1872 if (NILP (ok_if_already_exists)
|
|
1873 || INTP (ok_if_already_exists))
|
|
1874 barf_or_query_if_file_exists (newname, "copy to it",
|
|
1875 INTP (ok_if_already_exists), &out_st);
|
16
|
1876 else if (stat ((CONST char *) XSTRING_DATA (newname), &out_st) < 0)
|
0
|
1877 out_st.st_mode = 0;
|
|
1878
|
16
|
1879 ifd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0);
|
0
|
1880 if (ifd < 0)
|
|
1881 report_file_error ("Opening input file", Fcons (filename, Qnil));
|
|
1882
|
|
1883 record_unwind_protect (close_file_unwind, make_int (ifd));
|
|
1884
|
|
1885 /* We can only copy regular files and symbolic links. Other files are not
|
|
1886 copyable by us. */
|
|
1887 input_file_statable_p = (fstat (ifd, &st) >= 0);
|
|
1888
|
|
1889 #ifndef DOS_NT
|
|
1890 if (out_st.st_mode != 0
|
|
1891 && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino)
|
|
1892 {
|
|
1893 errno = 0;
|
|
1894 report_file_error ("Input and output files are the same",
|
|
1895 Fcons (filename, Fcons (newname, Qnil)));
|
|
1896 }
|
|
1897 #endif
|
|
1898
|
|
1899 #if defined (S_ISREG) && defined (S_ISLNK)
|
|
1900 if (input_file_statable_p)
|
|
1901 {
|
|
1902 if (!(S_ISREG (st.st_mode))
|
|
1903 /* XEmacs: have to allow S_ISCHR in order to copy /dev/null */
|
|
1904 #ifdef S_ISCHR
|
|
1905 && !(S_ISCHR (st.st_mode))
|
|
1906 #endif
|
|
1907 && !(S_ISLNK (st.st_mode)))
|
|
1908 {
|
|
1909 #if defined (EISDIR)
|
|
1910 /* Get a better looking error message. */
|
|
1911 errno = EISDIR;
|
|
1912 #endif /* EISDIR */
|
|
1913 report_file_error ("Non-regular file", Fcons (filename, Qnil));
|
|
1914 }
|
|
1915 }
|
|
1916 #endif /* S_ISREG && S_ISLNK */
|
|
1917
|
|
1918 #ifdef VMS
|
|
1919 /* Create the copy file with the same record format as the input file */
|
16
|
1920 ofd = sys_creat ((char *) XSTRING_DATA (newname), 0666, ifd);
|
0
|
1921 #else
|
|
1922 #ifdef MSDOS
|
|
1923 /* System's default file type was set to binary by _fmode in emacs.c. */
|
16
|
1924 ofd = creat ((char *) XSTRING_DATA (newname), S_IREAD | S_IWRITE);
|
0
|
1925 #else /* not MSDOS */
|
16
|
1926 ofd = creat ((char *) XSTRING_DATA (newname), 0666);
|
0
|
1927 #endif /* not MSDOS */
|
|
1928 #endif /* VMS */
|
|
1929 if (ofd < 0)
|
|
1930 report_file_error ("Opening output file", list1 (newname));
|
|
1931
|
|
1932 {
|
|
1933 Lisp_Object ofd_locative = noseeum_cons (make_int (ofd), Qnil);
|
|
1934
|
|
1935 record_unwind_protect (close_file_unwind, ofd_locative);
|
|
1936
|
|
1937 while ((n = read_allowing_quit (ifd, buf, sizeof (buf))) > 0)
|
|
1938 {
|
|
1939 if (write_allowing_quit (ofd, buf, n) != n)
|
|
1940 report_file_error ("I/O error", list1 (newname));
|
|
1941 }
|
|
1942
|
|
1943 /* Closing the output clobbers the file times on some systems. */
|
|
1944 if (close (ofd) < 0)
|
|
1945 report_file_error ("I/O error", Fcons (newname, Qnil));
|
|
1946
|
|
1947 if (input_file_statable_p)
|
|
1948 {
|
16
|
1949 if (!NILP (keep_time))
|
0
|
1950 {
|
|
1951 EMACS_TIME atime, mtime;
|
|
1952 EMACS_SET_SECS_USECS (atime, st.st_atime, 0);
|
|
1953 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0);
|
16
|
1954 if (set_file_times ((char *) XSTRING_DATA (newname), atime,
|
0
|
1955 mtime))
|
|
1956 report_file_error ("I/O error", Fcons (newname, Qnil));
|
|
1957 }
|
|
1958 #ifndef MSDOS
|
16
|
1959 chmod ((CONST char *) XSTRING_DATA (newname),
|
0
|
1960 st.st_mode & 07777);
|
|
1961 #else /* MSDOS */
|
|
1962 #if defined (__DJGPP__) && __DJGPP__ > 1
|
|
1963 /* In DJGPP v2.0 and later, fstat usually returns true file mode bits,
|
|
1964 and if it can't, it tells so. Otherwise, under MSDOS we usually
|
|
1965 get only the READ bit, which will make the copied file read-only,
|
|
1966 so it's better not to chmod at all. */
|
|
1967 if ((_djstat_flags & _STFAIL_WRITEBIT) == 0)
|
16
|
1968 chmod ((char *) XSTRING_DATA (newname), st.st_mode & 07777);
|
0
|
1969 #endif /* DJGPP version 2 or newer */
|
|
1970 #endif /* MSDOS */
|
|
1971 }
|
|
1972
|
|
1973 /* We'll close it by hand */
|
|
1974 XCAR (ofd_locative) = Qnil;
|
|
1975
|
|
1976 /* Close ifd */
|
|
1977 unbind_to (speccount, Qnil);
|
|
1978 }
|
|
1979
|
|
1980 UNGCPRO;
|
|
1981 return Qnil;
|
|
1982 }
|
|
1983
|
20
|
1984 DEFUN ("make-directory-internal", Fmake_directory_internal, 1, 1, 0, /*
|
0
|
1985 Create a directory. One argument, a file name string.
|
20
|
1986 */
|
|
1987 (dirname))
|
0
|
1988 {
|
|
1989 /* This function can GC */
|
|
1990 char dir [MAXPATHLEN];
|
|
1991 Lisp_Object handler;
|
|
1992 struct gcpro gcpro1;
|
|
1993
|
|
1994 CHECK_STRING (dirname);
|
|
1995 dirname = Fexpand_file_name (dirname, Qnil);
|
|
1996
|
40
|
1997 GCPRO1 (dirname);
|
0
|
1998 handler = Ffind_file_name_handler (dirname, Qmake_directory_internal);
|
|
1999 UNGCPRO;
|
|
2000 if (!NILP (handler))
|
40
|
2001 return (call2 (handler, Qmake_directory_internal, dirname));
|
0
|
2002
|
16
|
2003 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1))
|
0
|
2004 {
|
|
2005 return Fsignal (Qfile_error,
|
|
2006 list3 (build_translated_string ("Creating directory"),
|
|
2007 build_translated_string ("pathame too long"),
|
|
2008 dirname));
|
|
2009 }
|
16
|
2010 strncpy (dir, (char *) XSTRING_DATA (dirname),
|
|
2011 XSTRING_LENGTH (dirname) + 1);
|
0
|
2012
|
|
2013 #ifndef VMS
|
16
|
2014 if (dir [XSTRING_LENGTH (dirname) - 1] == '/')
|
|
2015 dir [XSTRING_LENGTH (dirname) - 1] = 0;
|
0
|
2016 #endif
|
|
2017
|
|
2018 #ifdef WINDOWSNT
|
|
2019 if (mkdir (dir) != 0)
|
|
2020 #else
|
|
2021 if (mkdir (dir, 0777) != 0)
|
|
2022 #endif
|
|
2023 report_file_error ("Creating directory", list1 (dirname));
|
|
2024
|
|
2025 return Qnil;
|
|
2026 }
|
|
2027
|
20
|
2028 DEFUN ("delete-directory", Fdelete_directory, 1, 1, "FDelete directory: ", /*
|
0
|
2029 Delete a directory. One argument, a file name or directory name string.
|
20
|
2030 */
|
|
2031 (dirname))
|
0
|
2032 {
|
|
2033 /* This function can GC */
|
|
2034 Lisp_Object handler;
|
|
2035 struct gcpro gcpro1;
|
|
2036
|
40
|
2037 CHECK_STRING (dirname);
|
|
2038
|
0
|
2039 GCPRO1 (dirname);
|
40
|
2040 dirname = Fexpand_file_name (dirname, Qnil);
|
|
2041 dirname = Fdirectory_file_name (dirname);
|
0
|
2042
|
|
2043 handler = Ffind_file_name_handler (dirname, Qdelete_directory);
|
|
2044 UNGCPRO;
|
|
2045 if (!NILP (handler))
|
|
2046 return (call2 (handler, Qdelete_directory, dirname));
|
|
2047
|
16
|
2048 if (rmdir ((char *) XSTRING_DATA (dirname)) != 0)
|
0
|
2049 report_file_error ("Removing directory", list1 (dirname));
|
|
2050
|
|
2051 return Qnil;
|
|
2052 }
|
|
2053
|
20
|
2054 DEFUN ("delete-file", Fdelete_file, 1, 1, "fDelete file: ", /*
|
0
|
2055 Delete specified file. One argument, a file name string.
|
|
2056 If file has multiple names, it continues to exist with the other names.
|
20
|
2057 */
|
|
2058 (filename))
|
0
|
2059 {
|
|
2060 /* This function can GC */
|
|
2061 Lisp_Object handler;
|
|
2062 struct gcpro gcpro1;
|
|
2063
|
|
2064 CHECK_STRING (filename);
|
|
2065 filename = Fexpand_file_name (filename, Qnil);
|
|
2066
|
40
|
2067 GCPRO1 (filename);
|
0
|
2068 handler = Ffind_file_name_handler (filename, Qdelete_file);
|
|
2069 UNGCPRO;
|
|
2070 if (!NILP (handler))
|
|
2071 return call2 (handler, Qdelete_file, filename);
|
|
2072
|
16
|
2073 if (0 > unlink ((char *) XSTRING_DATA (filename)))
|
0
|
2074 report_file_error ("Removing old name", list1 (filename));
|
|
2075 return Qnil;
|
|
2076 }
|
|
2077
|
|
2078 static Lisp_Object
|
|
2079 internal_delete_file_1 (Lisp_Object ignore, Lisp_Object ignore2)
|
|
2080 {
|
|
2081 return Qt;
|
|
2082 }
|
|
2083
|
|
2084 /* Delete file FILENAME, returning 1 if successful and 0 if failed. */
|
|
2085
|
|
2086 int
|
|
2087 internal_delete_file (Lisp_Object filename)
|
|
2088 {
|
|
2089 return NILP (condition_case_1 (Qt, Fdelete_file, filename,
|
|
2090 internal_delete_file_1, Qnil));
|
|
2091 }
|
|
2092
|
20
|
2093 DEFUN ("rename-file", Frename_file, 2, 3,
|
|
2094 "fRename file: \nFRename %s to file: \np", /*
|
0
|
2095 Rename FILE as NEWNAME. Both args strings.
|
|
2096 If file has names other than FILE, it continues to have those names.
|
|
2097 Signals a `file-already-exists' error if a file NEWNAME already exists
|
|
2098 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.
|
|
2099 A number as third arg means request confirmation if NEWNAME already exists.
|
|
2100 This is what happens in interactive use with M-x.
|
20
|
2101 */
|
|
2102 (filename, newname, ok_if_already_exists))
|
0
|
2103 {
|
|
2104 /* This function can GC */
|
|
2105 Lisp_Object handler;
|
|
2106 struct gcpro gcpro1, gcpro2;
|
|
2107
|
|
2108 GCPRO2 (filename, newname);
|
|
2109 CHECK_STRING (filename);
|
|
2110 CHECK_STRING (newname);
|
|
2111 filename = Fexpand_file_name (filename, Qnil);
|
|
2112 newname = Fexpand_file_name (newname, Qnil);
|
|
2113
|
|
2114 /* If the file name has special constructs in it,
|
|
2115 call the corresponding file handler. */
|
|
2116 handler = Ffind_file_name_handler (filename, Qrename_file);
|
|
2117 if (NILP (handler))
|
|
2118 handler = Ffind_file_name_handler (newname, Qrename_file);
|
|
2119 if (!NILP (handler))
|
|
2120 {
|
|
2121 UNGCPRO;
|
|
2122 return call4 (handler, Qrename_file,
|
|
2123 filename, newname, ok_if_already_exists);
|
|
2124 }
|
|
2125
|
|
2126 /* When second argument is a directory, rename the file into it.
|
|
2127 (rename-file "foo" "bar/") == (rename-file "foo" "bar/foo")
|
|
2128 */
|
|
2129 if (!NILP (Ffile_directory_p (newname)))
|
|
2130 {
|
|
2131 Lisp_Object args[3];
|
|
2132 struct gcpro ngcpro1;
|
|
2133 int i = 1;
|
|
2134
|
|
2135 args[0] = newname;
|
|
2136 args[1] = Qnil; args[2] = Qnil;
|
|
2137 NGCPRO1 (*args);
|
|
2138 ngcpro1.nvars = 3;
|
16
|
2139 if (XSTRING_BYTE (newname, XSTRING_LENGTH (newname) - 1) != '/')
|
0
|
2140 args[i++] = build_string ("/");
|
|
2141 args[i++] = Ffile_name_nondirectory (filename);
|
|
2142 newname = Fconcat (i, args);
|
|
2143 NUNGCPRO;
|
|
2144 }
|
|
2145
|
|
2146 if (NILP (ok_if_already_exists)
|
|
2147 || INTP (ok_if_already_exists))
|
|
2148 barf_or_query_if_file_exists (newname, "rename to it",
|
|
2149 INTP (ok_if_already_exists), 0);
|
|
2150
|
|
2151 #ifdef WINDOWSNT
|
|
2152 if (!MoveFile (XSTRING (filename)->data, XSTRING (newname)->data))
|
|
2153 #else /* not WINDOWSNT */
|
|
2154 /* FSFmacs only calls rename() here under BSD 4.1, and calls
|
|
2155 link() and unlink() otherwise, but that's bogus. Sometimes
|
|
2156 rename() succeeds where link()/unlink() fail, and we have
|
|
2157 configure check for rename() and emulate using link()/unlink()
|
|
2158 if necessary. */
|
16
|
2159 if (0 > rename ((char *) XSTRING_DATA (filename),
|
|
2160 (char *) XSTRING_DATA (newname)))
|
0
|
2161 #endif /* not WINDOWSNT */
|
|
2162 {
|
|
2163 #ifdef WINDOWSNT
|
|
2164 /* Why two? And why doesn't MS document what MoveFile will return? */
|
|
2165 if (GetLastError () == ERROR_FILE_EXISTS
|
|
2166 || GetLastError () == ERROR_ALREADY_EXISTS)
|
|
2167 #else /* not WINDOWSNT */
|
|
2168 if (errno == EXDEV)
|
|
2169 #endif /* not WINDOWSNT */
|
|
2170 {
|
|
2171 Fcopy_file (filename, newname,
|
|
2172 /* We have already prompted if it was an integer,
|
|
2173 so don't have copy-file prompt again. */
|
|
2174 ((NILP (ok_if_already_exists)) ? Qnil : Qt),
|
|
2175 Qt);
|
|
2176 Fdelete_file (filename);
|
|
2177 }
|
|
2178 else
|
|
2179 {
|
|
2180 report_file_error ("Renaming", list2 (filename, newname));
|
|
2181 }
|
|
2182 }
|
|
2183 UNGCPRO;
|
|
2184 return Qnil;
|
|
2185 }
|
|
2186
|
20
|
2187 DEFUN ("add-name-to-file", Fadd_name_to_file, 2, 3,
|
|
2188 "fAdd name to file: \nFName to add to %s: \np", /*
|
0
|
2189 Give FILE additional name NEWNAME. Both args strings.
|
|
2190 Signals a `file-already-exists' error if a file NEWNAME already exists
|
|
2191 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.
|
|
2192 A number as third arg means request confirmation if NEWNAME already exists.
|
|
2193 This is what happens in interactive use with M-x.
|
20
|
2194 */
|
|
2195 (filename, newname, ok_if_already_exists))
|
0
|
2196 {
|
|
2197 /* This function can GC */
|
|
2198 Lisp_Object handler;
|
|
2199 struct gcpro gcpro1, gcpro2;
|
|
2200
|
|
2201 GCPRO2 (filename, newname);
|
|
2202 CHECK_STRING (filename);
|
|
2203 CHECK_STRING (newname);
|
|
2204 filename = Fexpand_file_name (filename, Qnil);
|
|
2205 newname = Fexpand_file_name (newname, Qnil);
|
|
2206
|
|
2207 /* If the file name has special constructs in it,
|
|
2208 call the corresponding file handler. */
|
|
2209 handler = Ffind_file_name_handler (filename, Qadd_name_to_file);
|
|
2210 if (!NILP (handler))
|
|
2211 RETURN_UNGCPRO (call4 (handler, Qadd_name_to_file, filename,
|
|
2212 newname, ok_if_already_exists));
|
|
2213
|
|
2214 /* If the new name has special constructs in it,
|
|
2215 call the corresponding file handler. */
|
|
2216 handler = Ffind_file_name_handler (newname, Qadd_name_to_file);
|
|
2217 if (!NILP (handler))
|
|
2218 RETURN_UNGCPRO (call4 (handler, Qadd_name_to_file, filename,
|
|
2219 newname, ok_if_already_exists));
|
|
2220
|
|
2221 if (NILP (ok_if_already_exists)
|
|
2222 || INTP (ok_if_already_exists))
|
|
2223 barf_or_query_if_file_exists (newname, "make it a new name",
|
|
2224 INTP (ok_if_already_exists), 0);
|
|
2225 #ifdef WINDOWSNT
|
|
2226 /* Windows does not support this operation. */
|
|
2227 report_file_error ("Adding new name", Flist (2, &filename));
|
|
2228 #else /* not WINDOWSNT */
|
|
2229
|
16
|
2230 unlink ((char *) XSTRING_DATA (newname));
|
|
2231 if (0 > link ((char *) XSTRING_DATA (filename),
|
|
2232 (char *) XSTRING_DATA (newname)))
|
0
|
2233 {
|
|
2234 report_file_error ("Adding new name",
|
|
2235 list2 (filename, newname));
|
|
2236 }
|
|
2237 #endif /* not WINDOWSNT */
|
|
2238
|
|
2239 UNGCPRO;
|
|
2240 return Qnil;
|
|
2241 }
|
|
2242
|
|
2243 #ifdef S_IFLNK
|
20
|
2244 DEFUN ("make-symbolic-link", Fmake_symbolic_link, 2, 3,
|
|
2245 "FMake symbolic link to file: \nFMake symbolic link to file %s: \np", /*
|
0
|
2246 Make a symbolic link to FILENAME, named LINKNAME. Both args strings.
|
|
2247 Signals a `file-already-exists' error if a file LINKNAME already exists
|
|
2248 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.
|
|
2249 A number as third arg means request confirmation if LINKNAME already exists.
|
|
2250 This happens for interactive use with M-x.
|
20
|
2251 */
|
|
2252 (filename, linkname, ok_if_already_exists))
|
0
|
2253 {
|
|
2254 /* This function can GC */
|
|
2255 Lisp_Object handler;
|
|
2256 struct gcpro gcpro1, gcpro2;
|
|
2257
|
|
2258 GCPRO2 (filename, linkname);
|
|
2259 CHECK_STRING (filename);
|
|
2260 CHECK_STRING (linkname);
|
|
2261 /* If the link target has a ~, we must expand it to get
|
|
2262 a truly valid file name. Otherwise, do not expand;
|
|
2263 we want to permit links to relative file names. */
|
16
|
2264 if (XSTRING_BYTE (filename, 0) == '~') /* #### Un*x-specific */
|
0
|
2265 filename = Fexpand_file_name (filename, Qnil);
|
|
2266 linkname = Fexpand_file_name (linkname, Qnil);
|
|
2267
|
|
2268 /* If the file name has special constructs in it,
|
|
2269 call the corresponding file handler. */
|
|
2270 handler = Ffind_file_name_handler (filename, Qmake_symbolic_link);
|
|
2271 if (!NILP (handler))
|
|
2272 RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename, linkname,
|
|
2273 ok_if_already_exists));
|
|
2274
|
|
2275 /* If the new link name has special constructs in it,
|
|
2276 call the corresponding file handler. */
|
|
2277 handler = Ffind_file_name_handler (linkname, Qmake_symbolic_link);
|
|
2278 if (!NILP (handler))
|
|
2279 RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename,
|
|
2280 linkname, ok_if_already_exists));
|
|
2281
|
|
2282 if (NILP (ok_if_already_exists)
|
|
2283 || INTP (ok_if_already_exists))
|
|
2284 barf_or_query_if_file_exists (linkname, "make it a link",
|
|
2285 INTP (ok_if_already_exists), 0);
|
|
2286
|
16
|
2287 unlink ((char *) XSTRING_DATA (linkname));
|
|
2288 if (0 > symlink ((char *) XSTRING_DATA (filename),
|
|
2289 (char *) XSTRING_DATA (linkname)))
|
0
|
2290 {
|
|
2291 report_file_error ("Making symbolic link",
|
|
2292 list2 (filename, linkname));
|
|
2293 }
|
|
2294 UNGCPRO;
|
|
2295 return Qnil;
|
|
2296 }
|
|
2297 #endif /* S_IFLNK */
|
|
2298
|
|
2299 #ifdef VMS
|
|
2300
|
20
|
2301 DEFUN ("define-logical-name", Fdefine_logical_name, 2, 2,
|
|
2302 "sDefine logical name: \nsDefine logical name %s as: ", /*
|
0
|
2303 Define the job-wide logical name NAME to have the value STRING.
|
|
2304 If STRING is nil or a null string, the logical name NAME is deleted.
|
20
|
2305 */
|
|
2306 (varname, string))
|
0
|
2307 {
|
|
2308 CHECK_STRING (varname);
|
|
2309 if (NILP (string))
|
16
|
2310 delete_logical_name ((char *) XSTRING_DATA (varname));
|
0
|
2311 else
|
|
2312 {
|
|
2313 CHECK_STRING (string);
|
|
2314
|
16
|
2315 if (XSTRING_LENGTH (string) == 0)
|
|
2316 delete_logical_name ((char *) XSTRING_DATA (varname));
|
0
|
2317 else
|
16
|
2318 define_logical_name ((char *) XSTRING_DATA (varname), (char *) XSTRING_DATA (string));
|
0
|
2319 }
|
|
2320
|
|
2321 return string;
|
|
2322 }
|
|
2323 #endif /* VMS */
|
|
2324
|
|
2325 #ifdef HPUX_NET
|
|
2326
|
20
|
2327 DEFUN ("sysnetunam", Fsysnetunam, 2, 2, 0, /*
|
0
|
2328 Open a network connection to PATH using LOGIN as the login string.
|
20
|
2329 */
|
|
2330 (path, login))
|
0
|
2331 {
|
|
2332 int netresult;
|
|
2333
|
|
2334 CHECK_STRING (path);
|
|
2335 CHECK_STRING (login);
|
|
2336
|
|
2337 /* netunam, being a strange-o system call only used once, is not
|
|
2338 encapsulated. */
|
|
2339 {
|
|
2340 char *path_ext;
|
|
2341 char *login_ext;
|
|
2342
|
|
2343 GET_C_STRING_FILENAME_DATA_ALLOCA (path, path_ext);
|
|
2344 GET_C_STRING_EXT_DATA_ALLOCA (login, FORMAT_OS, login_ext);
|
|
2345
|
|
2346 netresult = netunam (path_ext, login_ext);
|
|
2347 }
|
|
2348
|
|
2349 if (netresult == -1)
|
|
2350 return Qnil;
|
|
2351 else
|
|
2352 return Qt;
|
|
2353 }
|
|
2354 #endif /* HPUX_NET */
|
|
2355
|
20
|
2356 DEFUN ("file-name-absolute-p", Ffile_name_absolute_p, 1, 1, 0, /*
|
0
|
2357 Return t if file FILENAME specifies an absolute path name.
|
|
2358 On Unix, this is a name starting with a `/' or a `~'.
|
20
|
2359 */
|
|
2360 (filename))
|
0
|
2361 {
|
|
2362 Bufbyte *ptr;
|
|
2363
|
|
2364 CHECK_STRING (filename);
|
16
|
2365 ptr = XSTRING_DATA (filename);
|
0
|
2366 if (IS_DIRECTORY_SEP (*ptr) || *ptr == '~'
|
|
2367 #ifdef VMS
|
|
2368 /* ??? This criterion is probably wrong for '<'. */
|
|
2369 || strchr (ptr, ':') || strchr (ptr, '<')
|
|
2370 || (*ptr == '[' && (ptr[1] != '-' || (ptr[2] != '.' && ptr[2] != ']'))
|
|
2371 && ptr[1] != '.')
|
|
2372 #endif /* VMS */
|
|
2373 #ifdef DOS_NT
|
|
2374 || (*ptr != 0 && ptr[1] == ':' && (ptr[2] == '/' || ptr[2] == '\\'))
|
|
2375 #endif
|
|
2376 )
|
|
2377 return Qt;
|
|
2378 else
|
|
2379 return Qnil;
|
|
2380 }
|
|
2381
|
|
2382 /* Return nonzero if file FILENAME exists and can be executed. */
|
|
2383
|
|
2384 static int
|
|
2385 check_executable (char *filename)
|
|
2386 {
|
|
2387 #ifdef DOS_NT
|
|
2388 int len = strlen (filename);
|
|
2389 char *suffix;
|
|
2390 struct stat st;
|
|
2391 if (stat (filename, &st) < 0)
|
|
2392 return 0;
|
|
2393 return (S_ISREG (st.st_mode)
|
|
2394 && len >= 5
|
|
2395 && (stricmp ((suffix = filename + len-4), ".com") == 0
|
|
2396 || stricmp (suffix, ".exe") == 0
|
|
2397 || stricmp (suffix, ".bat") == 0)
|
|
2398 || (st.st_mode & S_IFMT) == S_IFDIR);
|
|
2399 #else /* not DOS_NT */
|
|
2400 #ifdef HAVE_EACCESS
|
|
2401 return (eaccess (filename, 1) >= 0);
|
|
2402 #else
|
|
2403 /* Access isn't quite right because it uses the real uid
|
|
2404 and we really want to test with the effective uid.
|
|
2405 But Unix doesn't give us a right way to do it. */
|
|
2406 return (access (filename, 1) >= 0);
|
|
2407 #endif
|
|
2408 #endif /* not DOS_NT */
|
|
2409 }
|
|
2410
|
|
2411 /* Return nonzero if file FILENAME exists and can be written. */
|
|
2412
|
|
2413 static int
|
|
2414 check_writable (CONST char *filename)
|
|
2415 {
|
|
2416 #ifdef MSDOS
|
|
2417 struct stat st;
|
|
2418 if (stat (filename, &st) < 0)
|
|
2419 return 0;
|
|
2420 return (st.st_mode & S_IWRITE || (st.st_mode & S_IFMT) == S_IFDIR);
|
|
2421 #else /* not MSDOS */
|
|
2422 #ifdef HAVE_EACCESS
|
|
2423 return (eaccess (filename, 2) >= 0);
|
|
2424 #else
|
|
2425 /* Access isn't quite right because it uses the real uid
|
|
2426 and we really want to test with the effective uid.
|
|
2427 But Unix doesn't give us a right way to do it.
|
|
2428 Opening with O_WRONLY could work for an ordinary file,
|
|
2429 but would lose for directories. */
|
|
2430 return (access (filename, 2) >= 0);
|
|
2431 #endif
|
|
2432 #endif /* not MSDOS */
|
|
2433 }
|
|
2434
|
20
|
2435 DEFUN ("file-exists-p", Ffile_exists_p, 1, 1, 0, /*
|
0
|
2436 Return t if file FILENAME exists. (This does not mean you can read it.)
|
|
2437 See also `file-readable-p' and `file-attributes'.
|
20
|
2438 */
|
|
2439 (filename))
|
0
|
2440 {
|
|
2441 /* This function can GC */
|
|
2442 Lisp_Object abspath;
|
|
2443 Lisp_Object handler;
|
|
2444 struct stat statbuf;
|
|
2445 struct gcpro gcpro1;
|
|
2446
|
|
2447 GCPRO1 (filename);
|
|
2448 CHECK_STRING (filename);
|
|
2449 abspath = Fexpand_file_name (filename, Qnil);
|
|
2450 UNGCPRO;
|
|
2451
|
|
2452 /* If the file name has special constructs in it,
|
|
2453 call the corresponding file handler. */
|
|
2454 GCPRO1 (abspath);
|
|
2455 handler = Ffind_file_name_handler (abspath, Qfile_exists_p);
|
|
2456 UNGCPRO;
|
|
2457 if (!NILP (handler))
|
|
2458 return call2 (handler, Qfile_exists_p, abspath);
|
|
2459
|
16
|
2460 if (stat ((char *) XSTRING_DATA (abspath), &statbuf) >= 0)
|
0
|
2461 return (Qt);
|
|
2462 else
|
|
2463 return (Qnil);
|
|
2464 }
|
|
2465
|
20
|
2466 DEFUN ("file-executable-p", Ffile_executable_p, 1, 1, 0, /*
|
0
|
2467 Return t if FILENAME can be executed by you.
|
|
2468 For a directory, this means you can access files in that directory.
|
20
|
2469 */
|
|
2470 (filename))
|
0
|
2471 {
|
|
2472 /* This function can GC */
|
|
2473 Lisp_Object abspath;
|
|
2474 Lisp_Object handler;
|
|
2475 struct gcpro gcpro1;
|
|
2476
|
|
2477 GCPRO1 (filename);
|
|
2478 CHECK_STRING (filename);
|
|
2479 abspath = Fexpand_file_name (filename, Qnil);
|
|
2480 UNGCPRO;
|
|
2481
|
|
2482 /* If the file name has special constructs in it,
|
|
2483 call the corresponding file handler. */
|
|
2484 GCPRO1 (abspath);
|
|
2485 handler = Ffind_file_name_handler (abspath, Qfile_executable_p);
|
|
2486 UNGCPRO;
|
|
2487 if (!NILP (handler))
|
|
2488 return call2 (handler, Qfile_executable_p, abspath);
|
|
2489
|
16
|
2490 return (check_executable ((char *) XSTRING_DATA (abspath))
|
0
|
2491 ? Qt : Qnil);
|
|
2492 }
|
|
2493
|
20
|
2494 DEFUN ("file-readable-p", Ffile_readable_p, 1, 1, 0, /*
|
0
|
2495 Return t if file FILENAME exists and you can read it.
|
|
2496 See also `file-exists-p' and `file-attributes'.
|
20
|
2497 */
|
|
2498 (filename))
|
0
|
2499 {
|
|
2500 /* This function can GC */
|
|
2501 Lisp_Object abspath;
|
|
2502 Lisp_Object handler;
|
|
2503 int desc;
|
|
2504 struct gcpro gcpro1;
|
|
2505
|
|
2506 GCPRO1 (filename);
|
|
2507 CHECK_STRING (filename);
|
|
2508 abspath = Fexpand_file_name (filename, Qnil);
|
|
2509 UNGCPRO;
|
|
2510
|
|
2511 /* If the file name has special constructs in it,
|
|
2512 call the corresponding file handler. */
|
|
2513 GCPRO1 (abspath);
|
|
2514 handler = Ffind_file_name_handler (abspath, Qfile_readable_p);
|
|
2515 UNGCPRO;
|
|
2516 if (!NILP (handler))
|
|
2517 return call2 (handler, Qfile_readable_p, abspath);
|
|
2518
|
16
|
2519 desc = open ((char *) XSTRING_DATA (abspath), O_RDONLY, 0);
|
0
|
2520 if (desc < 0)
|
|
2521 return Qnil;
|
|
2522 close (desc);
|
|
2523 return Qt;
|
|
2524 }
|
|
2525
|
|
2526 /* Having this before file-symlink-p mysteriously caused it to be forgotten
|
|
2527 on the RT/PC. */
|
20
|
2528 DEFUN ("file-writable-p", Ffile_writable_p, 1, 1, 0, /*
|
0
|
2529 Return t if file FILENAME can be written or created by you.
|
20
|
2530 */
|
|
2531 (filename))
|
0
|
2532 {
|
|
2533 /* This function can GC */
|
|
2534 Lisp_Object abspath, dir;
|
|
2535 Lisp_Object handler;
|
|
2536 struct stat statbuf;
|
|
2537 struct gcpro gcpro1;
|
|
2538
|
|
2539 GCPRO1 (filename);
|
|
2540 CHECK_STRING (filename);
|
|
2541 abspath = Fexpand_file_name (filename, Qnil);
|
|
2542 UNGCPRO;
|
|
2543
|
|
2544 /* If the file name has special constructs in it,
|
|
2545 call the corresponding file handler. */
|
|
2546 GCPRO1 (abspath);
|
|
2547 handler = Ffind_file_name_handler (abspath, Qfile_writable_p);
|
|
2548 UNGCPRO;
|
|
2549 if (!NILP (handler))
|
|
2550 return call2 (handler, Qfile_writable_p, abspath);
|
|
2551
|
16
|
2552 if (stat ((char *) XSTRING_DATA (abspath), &statbuf) >= 0)
|
|
2553 return (check_writable ((char *) XSTRING_DATA (abspath))
|
0
|
2554 ? Qt : Qnil);
|
|
2555
|
|
2556
|
40
|
2557 GCPRO1 (abspath);
|
0
|
2558 dir = Ffile_name_directory (abspath);
|
40
|
2559 UNGCPRO;
|
0
|
2560 #if defined (VMS) || defined (MSDOS)
|
|
2561 if (!NILP (dir))
|
40
|
2562 {
|
|
2563 GCPRO1(dir);
|
|
2564 dir = Fdirectory_file_name (dir);
|
|
2565 UNGCPRO;
|
|
2566 }
|
0
|
2567 #endif /* VMS or MSDOS */
|
16
|
2568 return (check_writable (!NILP (dir) ? (char *) XSTRING_DATA (dir)
|
0
|
2569 : "")
|
|
2570 ? Qt : Qnil);
|
|
2571 }
|
|
2572
|
20
|
2573 DEFUN ("file-symlink-p", Ffile_symlink_p, 1, 1, 0, /*
|
0
|
2574 Return non-nil if file FILENAME is the name of a symbolic link.
|
|
2575 The value is the name of the file to which it is linked.
|
|
2576 Otherwise returns nil.
|
20
|
2577 */
|
|
2578 (filename))
|
0
|
2579 {
|
|
2580 /* This function can GC */
|
|
2581 #ifdef S_IFLNK
|
|
2582 char *buf;
|
|
2583 int bufsize;
|
|
2584 int valsize;
|
|
2585 Lisp_Object val;
|
|
2586 Lisp_Object handler;
|
|
2587 struct gcpro gcpro1;
|
|
2588
|
|
2589 GCPRO1 (filename);
|
|
2590 CHECK_STRING (filename);
|
|
2591 filename = Fexpand_file_name (filename, Qnil);
|
|
2592 UNGCPRO;
|
|
2593
|
|
2594 /* If the file name has special constructs in it,
|
|
2595 call the corresponding file handler. */
|
|
2596 handler = Ffind_file_name_handler (filename, Qfile_symlink_p);
|
|
2597 if (!NILP (handler))
|
|
2598 return call2 (handler, Qfile_symlink_p, filename);
|
|
2599
|
|
2600 bufsize = 100;
|
|
2601 while (1)
|
|
2602 {
|
|
2603 buf = (char *) xmalloc (bufsize);
|
|
2604 memset (buf, 0, bufsize);
|
16
|
2605 valsize = readlink ((char *) XSTRING_DATA (filename),
|
0
|
2606 buf, bufsize);
|
|
2607 if (valsize < bufsize) break;
|
|
2608 /* Buffer was not long enough */
|
|
2609 xfree (buf);
|
|
2610 bufsize *= 2;
|
|
2611 }
|
|
2612 if (valsize == -1)
|
|
2613 {
|
|
2614 xfree (buf);
|
|
2615 return Qnil;
|
|
2616 }
|
|
2617 val = make_string ((Bufbyte *) buf, valsize);
|
|
2618 xfree (buf);
|
|
2619 return val;
|
|
2620 #else /* not S_IFLNK */
|
|
2621 return Qnil;
|
|
2622 #endif /* not S_IFLNK */
|
|
2623 }
|
|
2624
|
20
|
2625 DEFUN ("file-directory-p", Ffile_directory_p, 1, 1, 0, /*
|
0
|
2626 Return t if file FILENAME is the name of a directory as a file.
|
|
2627 A directory name spec may be given instead; then the value is t
|
|
2628 if the directory so specified exists and really is a directory.
|
20
|
2629 */
|
|
2630 (filename))
|
0
|
2631 {
|
|
2632 /* This function can GC */
|
|
2633 Lisp_Object abspath;
|
|
2634 struct stat st;
|
|
2635 Lisp_Object handler;
|
|
2636 struct gcpro gcpro1;
|
|
2637
|
40
|
2638 GCPRO1 (current_buffer->directory);
|
0
|
2639 abspath = expand_and_dir_to_file (filename,
|
|
2640 current_buffer->directory);
|
|
2641 UNGCPRO;
|
|
2642
|
|
2643 /* If the file name has special constructs in it,
|
|
2644 call the corresponding file handler. */
|
|
2645 GCPRO1 (abspath);
|
|
2646 handler = Ffind_file_name_handler (abspath, Qfile_directory_p);
|
|
2647 UNGCPRO;
|
|
2648 if (!NILP (handler))
|
|
2649 return call2 (handler, Qfile_directory_p, abspath);
|
|
2650
|
16
|
2651 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0)
|
0
|
2652 return Qnil;
|
|
2653 return (st.st_mode & S_IFMT) == S_IFDIR ? Qt : Qnil;
|
|
2654 }
|
|
2655
|
20
|
2656 DEFUN ("file-accessible-directory-p", Ffile_accessible_directory_p, 1, 1, 0, /*
|
0
|
2657 Return t if file FILENAME is the name of a directory as a file,
|
|
2658 and files in that directory can be opened by you. In order to use a
|
|
2659 directory as a buffer's current directory, this predicate must return true.
|
|
2660 A directory name spec may be given instead; then the value is t
|
|
2661 if the directory so specified exists and really is a readable and
|
|
2662 searchable directory.
|
20
|
2663 */
|
|
2664 (filename))
|
0
|
2665 {
|
|
2666 /* This function can GC */
|
|
2667 Lisp_Object handler;
|
|
2668 struct gcpro gcpro1;
|
|
2669
|
|
2670 /* If the file name has special constructs in it,
|
|
2671 call the corresponding file handler. */
|
|
2672 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p);
|
|
2673 if (!NILP (handler))
|
|
2674 return call2 (handler, Qfile_accessible_directory_p,
|
|
2675 filename);
|
|
2676
|
40
|
2677 /* #### dmoore - this gcpro on filename should be unneccesary since
|
|
2678 the caller should ahve already protected it. */
|
0
|
2679 GCPRO1 (filename);
|
|
2680 if (NILP (Ffile_directory_p (filename)))
|
|
2681 {
|
|
2682 UNGCPRO;
|
|
2683 return (Qnil);
|
|
2684 }
|
|
2685 handler = Ffile_executable_p (filename);
|
|
2686 UNGCPRO;
|
|
2687 return (handler);
|
|
2688 }
|
|
2689
|
20
|
2690 DEFUN ("file-regular-p", Ffile_regular_p, 1, 1, 0, /*
|
0
|
2691 "Return t if file FILENAME is the name of a regular file.
|
|
2692 This is the sort of file that holds an ordinary stream of data bytes.
|
20
|
2693 */
|
|
2694 (filename))
|
0
|
2695 {
|
40
|
2696 Lisp_Object abspath;
|
0
|
2697 struct stat st;
|
|
2698 Lisp_Object handler;
|
40
|
2699 struct gcpro gcpro1;
|
|
2700
|
|
2701 GCPRO1 (current_buffer->directory);
|
0
|
2702 abspath = expand_and_dir_to_file (filename, current_buffer->directory);
|
40
|
2703 UNGCPRO;
|
0
|
2704
|
|
2705 /* If the file name has special constructs in it,
|
|
2706 call the corresponding file handler. */
|
40
|
2707 GCPRO1 (abspath);
|
0
|
2708 handler = Ffind_file_name_handler (abspath, Qfile_regular_p);
|
40
|
2709 UNGCPRO;
|
0
|
2710 if (!NILP (handler))
|
|
2711 return call2 (handler, Qfile_regular_p, abspath);
|
|
2712
|
16
|
2713 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0)
|
0
|
2714 return Qnil;
|
|
2715 return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil;
|
|
2716 }
|
|
2717
|
20
|
2718 DEFUN ("file-modes", Ffile_modes, 1, 1, 0, /*
|
0
|
2719 Return mode bits of FILE, as an integer.
|
20
|
2720 */
|
|
2721 (filename))
|
0
|
2722 {
|
|
2723 /* This function can GC */
|
|
2724 Lisp_Object abspath;
|
|
2725 struct stat st;
|
|
2726 Lisp_Object handler;
|
|
2727 struct gcpro gcpro1;
|
|
2728
|
40
|
2729 GCPRO1 (current_buffer->directory);
|
0
|
2730 abspath = expand_and_dir_to_file (filename,
|
|
2731 current_buffer->directory);
|
|
2732 UNGCPRO;
|
|
2733
|
|
2734 /* If the file name has special constructs in it,
|
|
2735 call the corresponding file handler. */
|
|
2736 GCPRO1 (abspath);
|
|
2737 handler = Ffind_file_name_handler (abspath, Qfile_modes);
|
|
2738 UNGCPRO;
|
|
2739 if (!NILP (handler))
|
|
2740 return call2 (handler, Qfile_modes, abspath);
|
|
2741
|
16
|
2742 if (stat ((char *) XSTRING_DATA (abspath), &st) < 0)
|
0
|
2743 return Qnil;
|
|
2744 #ifdef DOS_NT
|
|
2745 if (check_executable (XSTRING (abspath)->data))
|
|
2746 st.st_mode |= S_IEXEC;
|
|
2747 #endif /* DOS_NT */
|
|
2748
|
|
2749 return make_int (st.st_mode & 07777);
|
|
2750 }
|
|
2751
|
20
|
2752 DEFUN ("set-file-modes", Fset_file_modes, 2, 2, 0, /*
|
0
|
2753 Set mode bits of FILE to MODE (an integer).
|
|
2754 Only the 12 low bits of MODE are used.
|
20
|
2755 */
|
|
2756 (filename, mode))
|
0
|
2757 {
|
|
2758 /* This function can GC */
|
|
2759 Lisp_Object abspath;
|
|
2760 Lisp_Object handler;
|
40
|
2761 struct gcpro gcpro1;
|
0
|
2762
|
40
|
2763 GCPRO1 (current_buffer->directory);
|
0
|
2764 abspath = Fexpand_file_name (filename, current_buffer->directory);
|
|
2765 CHECK_INT (mode);
|
|
2766 UNGCPRO;
|
|
2767
|
|
2768 /* If the file name has special constructs in it,
|
|
2769 call the corresponding file handler. */
|
|
2770 GCPRO1 (abspath);
|
|
2771 handler = Ffind_file_name_handler (abspath, Qset_file_modes);
|
|
2772 UNGCPRO;
|
|
2773 if (!NILP (handler))
|
|
2774 return call3 (handler, Qset_file_modes, abspath, mode);
|
|
2775
|
16
|
2776 if (chmod ((char *) XSTRING_DATA (abspath), XINT (mode)) < 0)
|
0
|
2777 report_file_error ("Doing chmod", Fcons (abspath, Qnil));
|
|
2778
|
|
2779 return Qnil;
|
|
2780 }
|
|
2781
|
20
|
2782 DEFUN ("set-default-file-modes", Fset_default_file_modes, 1, 1, 0, /*
|
0
|
2783 Set the file permission bits for newly created files.
|
|
2784 MASK should be an integer; if a permission's bit in MASK is 1,
|
|
2785 subsequently created files will not have that permission enabled.
|
|
2786 Only the low 9 bits are used.
|
|
2787 This setting is inherited by subprocesses.
|
20
|
2788 */
|
|
2789 (mode))
|
0
|
2790 {
|
|
2791 CHECK_INT (mode);
|
|
2792
|
|
2793 umask ((~ XINT (mode)) & 0777);
|
|
2794
|
|
2795 return Qnil;
|
|
2796 }
|
|
2797
|
20
|
2798 DEFUN ("default-file-modes", Fdefault_file_modes, 0, 0, 0, /*
|
0
|
2799 Return the default file protection for created files.
|
|
2800 The umask value determines which permissions are enabled in newly
|
|
2801 created files. If a permission's bit in the umask is 1, subsequently
|
|
2802 created files will not have that permission enabled.
|
20
|
2803 */
|
|
2804 ())
|
0
|
2805 {
|
|
2806 int mode;
|
|
2807
|
|
2808 mode = umask (0);
|
|
2809 umask (mode);
|
|
2810
|
|
2811 return make_int ((~ mode) & 0777);
|
|
2812 }
|
|
2813
|
|
2814 #ifndef VMS
|
20
|
2815 DEFUN ("unix-sync", Funix_sync, 0, 0, "", /*
|
0
|
2816 Tell Unix to finish all pending disk updates.
|
20
|
2817 */
|
|
2818 ())
|
0
|
2819 {
|
|
2820 sync ();
|
|
2821 return Qnil;
|
|
2822 }
|
|
2823 #endif /* !VMS */
|
|
2824
|
|
2825
|
20
|
2826 DEFUN ("file-newer-than-file-p", Ffile_newer_than_file_p, 2, 2, 0, /*
|
0
|
2827 Return t if file FILE1 is newer than file FILE2.
|
|
2828 If FILE1 does not exist, the answer is nil;
|
|
2829 otherwise, if FILE2 does not exist, the answer is t.
|
20
|
2830 */
|
|
2831 (file1, file2))
|
0
|
2832 {
|
|
2833 /* This function can GC */
|
|
2834 Lisp_Object abspath1, abspath2;
|
|
2835 struct stat st;
|
|
2836 int mtime1;
|
|
2837 Lisp_Object handler;
|
40
|
2838 struct gcpro gcpro1, gcpro2, gcpro3;
|
0
|
2839
|
|
2840 CHECK_STRING (file1);
|
|
2841 CHECK_STRING (file2);
|
|
2842
|
|
2843 abspath1 = Qnil;
|
40
|
2844 abspath2 = Qnil;
|
|
2845
|
|
2846 GCPRO3 (abspath1, abspath2, current_buffer->directory);
|
|
2847 abspath1 = expand_and_dir_to_file (file1, current_buffer->directory);
|
|
2848 abspath2 = expand_and_dir_to_file (file2, current_buffer->directory);
|
0
|
2849
|
|
2850 /* If the file name has special constructs in it,
|
|
2851 call the corresponding file handler. */
|
|
2852 handler = Ffind_file_name_handler (abspath1, Qfile_newer_than_file_p);
|
|
2853 if (NILP (handler))
|
|
2854 handler = Ffind_file_name_handler (abspath2, Qfile_newer_than_file_p);
|
|
2855 UNGCPRO;
|
|
2856 if (!NILP (handler))
|
|
2857 return call3 (handler, Qfile_newer_than_file_p, abspath1,
|
|
2858 abspath2);
|
|
2859
|
16
|
2860 if (stat ((char *) XSTRING_DATA (abspath1), &st) < 0)
|
0
|
2861 return Qnil;
|
|
2862
|
|
2863 mtime1 = st.st_mtime;
|
|
2864
|
16
|
2865 if (stat ((char *) XSTRING_DATA (abspath2), &st) < 0)
|
0
|
2866 return Qt;
|
|
2867
|
|
2868 return (mtime1 > st.st_mtime) ? Qt : Qnil;
|
|
2869 }
|
|
2870
|
|
2871
|
|
2872 #ifdef DOS_NT
|
|
2873 Lisp_Object Qfind_buffer_file_type;
|
|
2874 #endif /* DOS_NT */
|
|
2875
|
2
|
2876 /* Stack sizes > 2**16 is a good way to elicit compiler bugs */
|
|
2877 /* #define READ_BUF_SIZE (2 << 16) */
|
|
2878 #define READ_BUF_SIZE (1 << 15)
|
0
|
2879
|
20
|
2880 DEFUN ("insert-file-contents-internal",
|
|
2881 Finsert_file_contents_internal, 1, 5, 0, /*
|
0
|
2882 Insert contents of file FILENAME after point.
|
|
2883 Returns list of absolute file name and length of data inserted.
|
|
2884 If second argument VISIT is non-nil, the buffer's visited filename
|
|
2885 and last save file modtime are set, and it is marked unmodified.
|
|
2886 If visiting and the file does not exist, visiting is completed
|
|
2887 before the error is signaled.
|
|
2888
|
|
2889 The optional third and fourth arguments BEG and END
|
|
2890 specify what portion of the file to insert.
|
|
2891 If VISIT is non-nil, BEG and END must be nil.
|
|
2892 If optional fifth argument REPLACE is non-nil,
|
|
2893 it means replace the current buffer contents (in the accessible portion)
|
|
2894 with the file contents. This is better than simply deleting and inserting
|
|
2895 the whole thing because (1) it preserves some marker positions
|
|
2896 and (2) it puts less data in the undo list.
|
20
|
2897 */
|
|
2898 (filename, visit, beg, end, replace))
|
0
|
2899 {
|
|
2900 /* This function can GC */
|
|
2901 struct stat st;
|
|
2902 int fd;
|
|
2903 int saverrno = 0;
|
|
2904 Charcount inserted = 0;
|
|
2905 int speccount;
|
40
|
2906 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
0
|
2907 Lisp_Object handler = Qnil, val;
|
|
2908 int total;
|
|
2909 Bufbyte read_buf[READ_BUF_SIZE];
|
|
2910 int mc_count;
|
|
2911 struct buffer *buf = current_buffer;
|
40
|
2912 Lisp_Object curbuf;
|
0
|
2913 int not_regular = 0;
|
|
2914
|
|
2915 if (buf->base_buffer && ! NILP (visit))
|
|
2916 error ("Cannot do file visiting in an indirect buffer");
|
|
2917
|
|
2918 /* No need to call Fbarf_if_buffer_read_only() here.
|
|
2919 That's called in begin_multiple_change() or wherever. */
|
|
2920
|
|
2921 val = Qnil;
|
|
2922
|
40
|
2923 /* #### dmoore - should probably check in various places to see if
|
|
2924 curbuf was killed and if so signal an error? */
|
|
2925
|
|
2926 XSETBUFFER (curbuf, buf);
|
|
2927
|
|
2928 GCPRO5 (filename, val, visit, handler, curbuf);
|
0
|
2929
|
|
2930 mc_count = (NILP (replace)) ?
|
|
2931 begin_multiple_change (buf, BUF_PT (buf), BUF_PT (buf)) :
|
|
2932 begin_multiple_change (buf, BUF_BEG (buf), BUF_Z (buf));
|
|
2933
|
|
2934 speccount = specpdl_depth (); /* begin_multiple_change also adds
|
|
2935 an unwind_protect */
|
|
2936
|
|
2937 filename = Fexpand_file_name (filename, Qnil);
|
|
2938
|
|
2939 /* If the file name has special constructs in it,
|
|
2940 call the corresponding file handler. */
|
|
2941 handler = Ffind_file_name_handler (filename, Qinsert_file_contents);
|
|
2942 if (!NILP (handler))
|
|
2943 {
|
|
2944 val = call6 (handler, Qinsert_file_contents, filename,
|
16
|
2945 visit, beg, end, replace);
|
0
|
2946 goto handled;
|
|
2947 }
|
|
2948
|
|
2949 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) )
|
|
2950 error ("Attempt to visit less than an entire file");
|
|
2951
|
|
2952 if (!NILP (beg))
|
|
2953 CHECK_INT (beg);
|
|
2954 else
|
|
2955 beg = Qzero;
|
|
2956
|
|
2957 if (!NILP (end))
|
|
2958 CHECK_INT (end);
|
|
2959
|
|
2960 fd = -1;
|
|
2961
|
|
2962 #ifndef APOLLO
|
16
|
2963 if (stat ((char *) XSTRING_DATA (filename), &st) < 0)
|
0
|
2964 #else /* APOLLO */
|
16
|
2965 if ((fd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0)) < 0
|
0
|
2966 || fstat (fd, &st) < 0)
|
|
2967 #endif /* APOLLO */
|
|
2968 {
|
|
2969 if (fd >= 0) close (fd);
|
|
2970 badopen:
|
|
2971 if (NILP (visit))
|
|
2972 report_file_error ("Opening input file",
|
|
2973 Fcons (filename, Qnil));
|
|
2974 st.st_mtime = -1;
|
|
2975 goto notfound;
|
|
2976 }
|
|
2977
|
|
2978 #ifdef S_IFREG
|
|
2979 /* This code will need to be changed in order to work on named
|
|
2980 pipes, and it's probably just not worth it. So we should at
|
|
2981 least signal an error. */
|
|
2982 if (!S_ISREG (st.st_mode))
|
|
2983 {
|
|
2984 if (NILP (visit))
|
|
2985 {
|
|
2986 end_multiple_change (buf, mc_count);
|
|
2987
|
|
2988 return Fsignal (Qfile_error,
|
|
2989 list2 (build_translated_string("not a regular file"),
|
|
2990 filename));
|
|
2991 }
|
|
2992 else
|
|
2993 {
|
|
2994 not_regular = 1;
|
|
2995 goto notfound;
|
|
2996 }
|
|
2997 }
|
|
2998 #endif
|
|
2999
|
|
3000 if (fd < 0)
|
16
|
3001 if ((fd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0)) < 0)
|
0
|
3002 goto badopen;
|
|
3003
|
|
3004 /* Replacement should preserve point as it preserves markers. */
|
|
3005 if (!NILP (replace))
|
|
3006 record_unwind_protect (restore_point_unwind, Fpoint_marker (Qnil, Qnil));
|
|
3007
|
|
3008 record_unwind_protect (close_file_unwind, make_int (fd));
|
|
3009
|
|
3010 /* Supposedly happens on VMS. */
|
|
3011 if (st.st_size < 0)
|
|
3012 error ("File size is negative");
|
|
3013
|
|
3014 if (NILP (end))
|
|
3015 {
|
|
3016 end = make_int (st.st_size);
|
|
3017 if (XINT (end) != st.st_size)
|
|
3018 error ("maximum buffer size exceeded");
|
|
3019 }
|
|
3020
|
|
3021 /* If requested, replace the accessible part of the buffer
|
|
3022 with the file contents. Avoid replacing text at the
|
|
3023 beginning or end of the buffer that matches the file contents;
|
|
3024 that preserves markers pointing to the unchanged parts. */
|
16
|
3025 #if !defined (DOS_NT) && !defined (MULE)
|
0
|
3026 /* The replace-mode code currently only works when the assumption
|
|
3027 'one byte == one char' holds true. This fails under MSDOS and
|
|
3028 Windows NT (because newlines are represented as CR-LF in text
|
20
|
3029 files) and under Mule because files may contain multibyte characters. */
|
0
|
3030 # define FSFMACS_SPEEDY_INSERT
|
|
3031 #endif
|
|
3032 #ifndef FSFMACS_SPEEDY_INSERT
|
|
3033 if (!NILP (replace))
|
|
3034 {
|
|
3035 buffer_delete_range (buf, BUF_BEG (buf), BUF_Z (buf),
|
|
3036 !NILP (visit) ? INSDEL_NO_LOCKING : 0);
|
|
3037 }
|
|
3038 #else /* FSFMACS_SPEEDY_INSERT */
|
|
3039 if (!NILP (replace))
|
|
3040 {
|
|
3041 char buffer[1 << 14];
|
|
3042 Bufpos same_at_start = BUF_BEGV (buf);
|
|
3043 Bufpos same_at_end = BUF_ZV (buf);
|
|
3044 int overlap;
|
|
3045
|
|
3046 /* Count how many chars at the start of the file
|
|
3047 match the text at the beginning of the buffer. */
|
|
3048 while (1)
|
|
3049 {
|
|
3050 int nread;
|
|
3051 Bufpos bufpos;
|
|
3052
|
|
3053 nread = read_allowing_quit (fd, buffer, sizeof buffer);
|
|
3054 if (nread < 0)
|
|
3055 error ("IO error reading %s: %s",
|
16
|
3056 XSTRING_DATA (filename), strerror (errno));
|
0
|
3057 else if (nread == 0)
|
|
3058 break;
|
|
3059 bufpos = 0;
|
|
3060 while (bufpos < nread && same_at_start < BUF_ZV (buf)
|
|
3061 && BUF_FETCH_CHAR (buf, same_at_start) == buffer[bufpos])
|
|
3062 same_at_start++, bufpos++;
|
|
3063 /* If we found a discrepancy, stop the scan.
|
|
3064 Otherwise loop around and scan the next bufferfull. */
|
|
3065 if (bufpos != nread)
|
|
3066 break;
|
|
3067 }
|
|
3068 /* If the file matches the buffer completely,
|
|
3069 there's no need to replace anything. */
|
|
3070 if (same_at_start - BUF_BEGV (buf) == st.st_size)
|
|
3071 {
|
|
3072 close (fd);
|
|
3073 unbind_to (speccount, Qnil);
|
|
3074 /* Truncate the buffer to the size of the file. */
|
|
3075 buffer_delete_range (buf, same_at_start, same_at_end,
|
|
3076 !NILP (visit) ? INSDEL_NO_LOCKING : 0);
|
|
3077 goto handled;
|
|
3078 }
|
|
3079 /* Count how many chars at the end of the file
|
|
3080 match the text at the end of the buffer. */
|
|
3081 while (1)
|
|
3082 {
|
|
3083 int total_read, nread;
|
|
3084 Bufpos bufpos, curpos, trial;
|
|
3085
|
|
3086 /* At what file position are we now scanning? */
|
|
3087 curpos = st.st_size - (BUF_ZV (buf) - same_at_end);
|
|
3088 /* If the entire file matches the buffer tail, stop the scan. */
|
|
3089 if (curpos == 0)
|
|
3090 break;
|
|
3091 /* How much can we scan in the next step? */
|
|
3092 trial = min (curpos, sizeof buffer);
|
|
3093 if (lseek (fd, curpos - trial, 0) < 0)
|
|
3094 report_file_error ("Setting file position",
|
|
3095 Fcons (filename, Qnil));
|
|
3096
|
|
3097 total_read = 0;
|
|
3098 while (total_read < trial)
|
|
3099 {
|
|
3100 nread = read_allowing_quit (fd, buffer + total_read,
|
|
3101 trial - total_read);
|
|
3102 if (nread <= 0)
|
|
3103 error ("IO error reading %s: %s",
|
16
|
3104 XSTRING_DATA (filename), strerror (errno));
|
0
|
3105 total_read += nread;
|
|
3106 }
|
|
3107 /* Scan this bufferfull from the end, comparing with
|
|
3108 the Emacs buffer. */
|
|
3109 bufpos = total_read;
|
|
3110 /* Compare with same_at_start to avoid counting some buffer text
|
|
3111 as matching both at the file's beginning and at the end. */
|
|
3112 while (bufpos > 0 && same_at_end > same_at_start
|
|
3113 && BUF_FETCH_CHAR (buf, same_at_end - 1) ==
|
|
3114 buffer[bufpos - 1])
|
|
3115 same_at_end--, bufpos--;
|
|
3116 /* If we found a discrepancy, stop the scan.
|
|
3117 Otherwise loop around and scan the preceding bufferfull. */
|
|
3118 if (bufpos != 0)
|
|
3119 break;
|
|
3120 /* If display current starts at beginning of line,
|
|
3121 keep it that way. */
|
|
3122 if (XBUFFER (XWINDOW (Fselected_window (Qnil))->buffer) == buf)
|
|
3123 XWINDOW (Fselected_window (Qnil))->start_at_line_beg =
|
|
3124 !NILP (Fbolp (make_buffer (buf)));
|
|
3125 }
|
|
3126
|
|
3127 /* Don't try to reuse the same piece of text twice. */
|
|
3128 overlap = same_at_start - BUF_BEGV (buf) -
|
|
3129 (same_at_end + st.st_size - BUF_ZV (buf));
|
|
3130 if (overlap > 0)
|
|
3131 same_at_end += overlap;
|
|
3132
|
|
3133 /* Arrange to read only the nonmatching middle part of the file. */
|
|
3134 beg = make_int (same_at_start - BUF_BEGV (buf));
|
|
3135 end = make_int (st.st_size - (BUF_ZV (buf) - same_at_end));
|
|
3136
|
|
3137 buffer_delete_range (buf, same_at_start, same_at_end,
|
|
3138 !NILP (visit) ? INSDEL_NO_LOCKING : 0);
|
|
3139 /* Insert from the file at the proper position. */
|
|
3140 BUF_SET_PT (buf, same_at_start);
|
|
3141 }
|
|
3142 #endif /* FSFMACS_SPEEDY_INSERT */
|
|
3143
|
|
3144 total = XINT (end) - XINT (beg);
|
|
3145
|
|
3146 if (XINT (beg) != 0
|
|
3147 #ifdef FSFMACS_SPEEDY_INSERT
|
|
3148 /* why was this here? asked jwz. The reason is that the replace-mode
|
|
3149 connivings above will normally put the file pointer other than
|
|
3150 where it should be. */
|
|
3151 || !NILP (replace)
|
|
3152 #endif /* !FSFMACS_SPEEDY_INSERT */
|
|
3153 )
|
|
3154 {
|
|
3155 if (lseek (fd, XINT (beg), 0) < 0)
|
|
3156 report_file_error ("Setting file position",
|
|
3157 Fcons (filename, Qnil));
|
|
3158 }
|
|
3159
|
|
3160 {
|
|
3161 Bufpos cur_point = BUF_PT (buf);
|
|
3162 struct gcpro ngcpro1;
|
|
3163 Lisp_Object stream = make_filedesc_input_stream (fd, 0, total,
|
|
3164 LSTR_ALLOW_QUIT);
|
|
3165
|
|
3166 NGCPRO1 (stream);
|
|
3167 Lstream_set_buffering (XLSTREAM (stream), LSTREAM_BLOCKN_BUFFERED, 65536);
|
|
3168
|
|
3169 record_unwind_protect (close_stream_unwind, stream);
|
|
3170
|
16
|
3171 /* No need to limit the amount of stuff we attempt to read. (It would
|
|
3172 be incorrect, anyway, when Mule is enabled.) Instead, the limiting
|
|
3173 occurs inside of the filedesc stream. */
|
0
|
3174 while (1)
|
|
3175 {
|
|
3176 Bytecount this_len;
|
|
3177 Charcount cc_inserted;
|
|
3178
|
|
3179 QUIT;
|
|
3180 this_len = Lstream_read (XLSTREAM (stream), read_buf,
|
|
3181 sizeof (read_buf));
|
|
3182
|
|
3183 if (this_len <= 0)
|
|
3184 {
|
|
3185 if (this_len < 0)
|
|
3186 saverrno = errno;
|
|
3187 break;
|
|
3188 }
|
|
3189
|
|
3190 cc_inserted = buffer_insert_raw_string_1 (buf, cur_point, read_buf,
|
|
3191 this_len,
|
|
3192 !NILP (visit)
|
|
3193 ? INSDEL_NO_LOCKING : 0);
|
|
3194 inserted += cc_inserted;
|
|
3195 cur_point += cc_inserted;
|
|
3196 }
|
|
3197 NUNGCPRO;
|
|
3198 }
|
|
3199
|
|
3200 #ifdef DOS_NT
|
|
3201 /* Determine file type from name and remove LFs from CR-LFs if the file
|
|
3202 is deemed to be a text file. */
|
|
3203 {
|
|
3204 struct gcpro gcpro1;
|
|
3205 GCPRO1 (filename);
|
|
3206 buf->buffer_file_type
|
|
3207 = call1_in_buffer (buf, Qfind_buffer_file_type, filename);
|
|
3208 UNGCPRO;
|
|
3209 if (NILP (buf->buffer_file_type))
|
|
3210 {
|
|
3211 buffer_do_msdos_crlf_to_lf (buf, ####);
|
|
3212 }
|
|
3213 }
|
|
3214 #endif
|
|
3215
|
|
3216 /* Close the file/stream */
|
|
3217 unbind_to (speccount, Qnil);
|
|
3218
|
|
3219 if (saverrno != 0)
|
|
3220 {
|
|
3221 error ("IO error reading %s: %s",
|
16
|
3222 XSTRING_DATA (filename), strerror (saverrno));
|
0
|
3223 }
|
|
3224
|
|
3225 notfound:
|
|
3226 handled:
|
|
3227
|
|
3228 end_multiple_change (buf, mc_count);
|
|
3229
|
|
3230 if (!NILP (visit))
|
|
3231 {
|
|
3232 if (!EQ (buf->undo_list, Qt))
|
|
3233 buf->undo_list = Qnil;
|
|
3234 #ifdef APOLLO
|
16
|
3235 stat ((char *) XSTRING_DATA (filename), &st);
|
0
|
3236 #endif
|
|
3237 if (NILP (handler))
|
|
3238 {
|
|
3239 buf->modtime = st.st_mtime;
|
|
3240 buf->filename = filename;
|
|
3241 /* XEmacs addition: */
|
|
3242 /* This function used to be in C, ostensibly so that
|
|
3243 it could be called here. But that's just silly.
|
|
3244 There's no reason C code can't call out to Lisp
|
|
3245 code, and it's a lot cleaner this way. */
|
|
3246 if (!NILP (Ffboundp (Qcompute_buffer_file_truename)))
|
|
3247 call1 (Qcompute_buffer_file_truename, make_buffer (buf));
|
|
3248 }
|
|
3249 BUF_SAVE_MODIFF (buf) = BUF_MODIFF (buf);
|
|
3250 buf->auto_save_modified = BUF_MODIFF (buf);
|
|
3251 buf->save_length = make_int (BUF_SIZE (buf));
|
|
3252 #ifdef CLASH_DETECTION
|
|
3253 if (NILP (handler))
|
|
3254 {
|
|
3255 if (!NILP (buf->file_truename))
|
|
3256 unlock_file (buf->file_truename);
|
|
3257 unlock_file (filename);
|
|
3258 }
|
|
3259 #endif /* CLASH_DETECTION */
|
|
3260 if (not_regular)
|
|
3261 RETURN_UNGCPRO (Fsignal (Qfile_error,
|
|
3262 list2 (build_string ("not a regular file"),
|
|
3263 filename)));
|
|
3264
|
|
3265 /* If visiting nonexistent file, return nil. */
|
|
3266 if (buf->modtime == -1)
|
|
3267 report_file_error ("Opening input file",
|
|
3268 list1 (filename));
|
|
3269 }
|
|
3270
|
|
3271 /* Decode file format */
|
|
3272 if (inserted > 0)
|
|
3273 {
|
|
3274 Lisp_Object insval = call3 (Qformat_decode,
|
|
3275 Qnil, make_int (inserted), visit);
|
|
3276 CHECK_INT (insval);
|
|
3277 inserted = XINT (insval);
|
|
3278 }
|
|
3279
|
|
3280 if (inserted > 0)
|
|
3281 {
|
|
3282 Lisp_Object p = Vafter_insert_file_functions;
|
|
3283 struct gcpro ngcpro1;
|
|
3284
|
|
3285 NGCPRO1 (p);
|
|
3286 while (!NILP (p))
|
|
3287 {
|
|
3288 Lisp_Object insval =
|
|
3289 call1 (Fcar (p), make_int (inserted));
|
|
3290 if (!NILP (insval))
|
|
3291 {
|
|
3292 CHECK_NATNUM (insval);
|
|
3293 inserted = XINT (insval);
|
|
3294 }
|
|
3295 QUIT;
|
|
3296 p = Fcdr (p);
|
|
3297 }
|
|
3298 NUNGCPRO;
|
|
3299 }
|
|
3300
|
|
3301 UNGCPRO;
|
|
3302
|
|
3303 if (!NILP (val))
|
|
3304 return (val);
|
|
3305 else
|
|
3306 return (list2 (filename, make_int (inserted)));
|
|
3307 }
|
|
3308
|
|
3309
|
|
3310 static int a_write (Lisp_Object outstream, Lisp_Object instream, int pos,
|
|
3311 Lisp_Object *annot);
|
|
3312 static Lisp_Object build_annotations (Lisp_Object start, Lisp_Object end);
|
|
3313
|
|
3314 /* If build_annotations switched buffers, switch back to BUF.
|
|
3315 Kill the temporary buffer that was selected in the meantime. */
|
|
3316
|
|
3317 static Lisp_Object
|
|
3318 build_annotations_unwind (Lisp_Object buf)
|
|
3319 {
|
|
3320 Lisp_Object tembuf;
|
|
3321
|
|
3322 if (XBUFFER (buf) == current_buffer)
|
|
3323 return Qnil;
|
|
3324 tembuf = Fcurrent_buffer ();
|
|
3325 Fset_buffer (buf);
|
|
3326 Fkill_buffer (tembuf);
|
|
3327 return Qnil;
|
|
3328 }
|
|
3329
|
20
|
3330 DEFUN ("write-region-internal", Fwrite_region_internal, 3, 6,
|
|
3331 "r\nFWrite region to file: ", /*
|
0
|
3332 Write current region into specified file.
|
|
3333 When called from a program, takes three arguments:
|
|
3334 START, END and FILENAME. START and END are buffer positions.
|
|
3335 Optional fourth argument APPEND if non-nil means
|
|
3336 append to existing file contents (if any).
|
|
3337 Optional fifth argument VISIT if t means
|
|
3338 set the last-save-file-modtime of buffer to this file's modtime
|
|
3339 and mark buffer not modified.
|
|
3340 If VISIT is a string, it is a second file name;
|
|
3341 the output goes to FILENAME, but the buffer is marked as visiting VISIT.
|
|
3342 VISIT is also the file name to lock and unlock for clash detection.
|
|
3343 If VISIT is neither t nor nil nor a string,
|
|
3344 that means do not print the \"Wrote file\" message.
|
|
3345 Kludgy feature: if START is a string, then that string is written
|
|
3346 to the file, instead of any buffer contents, and END is ignored.
|
20
|
3347 */
|
|
3348 (start, end, filename, append, visit, lockname))
|
0
|
3349 {
|
|
3350 /* This function can GC */
|
|
3351 int desc;
|
|
3352 int failure;
|
|
3353 int save_errno = 0;
|
|
3354 struct stat st;
|
|
3355 Lisp_Object fn;
|
|
3356 int speccount = specpdl_depth ();
|
|
3357 #ifdef VMS
|
|
3358 unsigned char *fname = 0; /* If non-0, original filename (must rename) */
|
|
3359 #endif /* VMS */
|
|
3360 int visiting_other = STRINGP (visit);
|
|
3361 int visiting = (EQ (visit, Qt) || visiting_other);
|
|
3362 int quietly = (!visiting && !NILP (visit));
|
|
3363 Lisp_Object visit_file = Qnil;
|
|
3364 Lisp_Object annotations = Qnil;
|
|
3365 struct buffer *given_buffer;
|
|
3366 Bufpos start1, end1;
|
|
3367
|
40
|
3368 /* #### dmoore - if Fexpand_file_name or handlers kill the buffer,
|
|
3369 we should signal an error rather than blissfully continuing
|
|
3370 along. ARGH, this function is going to lose lose lose. We need
|
|
3371 to protect the current_buffer from being destroyed, but the
|
|
3372 multiple return points make this a pain in the butt. */
|
|
3373
|
0
|
3374 #ifdef DOS_NT
|
|
3375 int buffer_file_type
|
|
3376 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY;
|
|
3377 #endif /* DOS_NT */
|
|
3378
|
|
3379 if (current_buffer->base_buffer && ! NILP (visit))
|
|
3380 error ("Cannot do file visiting in an indirect buffer");
|
|
3381
|
|
3382 if (!NILP (start) && !STRINGP (start))
|
|
3383 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0);
|
|
3384
|
|
3385 {
|
|
3386 Lisp_Object handler;
|
|
3387 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
40
|
3388
|
0
|
3389 GCPRO5 (start, filename, visit, visit_file, lockname);
|
|
3390
|
|
3391 if (visiting_other)
|
|
3392 visit_file = Fexpand_file_name (visit, Qnil);
|
|
3393 else
|
|
3394 visit_file = filename;
|
|
3395 filename = Fexpand_file_name (filename, Qnil);
|
|
3396
|
|
3397 UNGCPRO;
|
|
3398
|
|
3399 if (NILP (lockname))
|
|
3400 lockname = visit_file;
|
|
3401
|
|
3402 /* If the file name has special constructs in it,
|
|
3403 call the corresponding file handler. */
|
|
3404 handler = Ffind_file_name_handler (filename, Qwrite_region);
|
|
3405 /* If FILENAME has no handler, see if VISIT has one. */
|
|
3406 if (NILP (handler) && STRINGP (visit))
|
|
3407 handler = Ffind_file_name_handler (visit, Qwrite_region);
|
|
3408
|
|
3409 if (!NILP (handler))
|
|
3410 {
|
|
3411 Lisp_Object val = call6 (handler, Qwrite_region, start, end,
|
|
3412 filename, append, visit);
|
|
3413 if (visiting)
|
|
3414 {
|
|
3415 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer);
|
|
3416 current_buffer->save_length =
|
|
3417 make_int (BUF_SIZE (current_buffer));
|
|
3418 current_buffer->filename = visit_file;
|
|
3419 MARK_MODELINE_CHANGED;
|
|
3420 }
|
|
3421 return val;
|
|
3422 }
|
|
3423 }
|
|
3424
|
|
3425 #ifdef CLASH_DETECTION
|
|
3426 if (!auto_saving)
|
|
3427 {
|
40
|
3428 Lisp_Object curbuf;
|
|
3429 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
|
3430
|
|
3431 XSETBUFFER (curbuf, current_buffer);
|
|
3432 GCPRO5 (start, filename, visit_file, lockname, curbuf);
|
0
|
3433 lock_file (lockname);
|
|
3434 UNGCPRO;
|
|
3435 }
|
|
3436 #endif /* CLASH_DETECTION */
|
|
3437
|
|
3438 /* Special kludge to simplify auto-saving. */
|
|
3439 if (NILP (start))
|
|
3440 {
|
|
3441 start1 = BUF_BEG (current_buffer);
|
|
3442 end1 = BUF_Z (current_buffer);
|
|
3443 }
|
|
3444
|
|
3445 record_unwind_protect (build_annotations_unwind, Fcurrent_buffer ());
|
|
3446
|
|
3447 given_buffer = current_buffer;
|
|
3448 annotations = build_annotations (start, end);
|
|
3449 if (current_buffer != given_buffer)
|
|
3450 {
|
|
3451 start1 = BUF_BEGV (current_buffer);
|
|
3452 end1 = BUF_ZV (current_buffer);
|
|
3453 }
|
|
3454
|
|
3455 fn = filename;
|
|
3456 desc = -1;
|
|
3457 if (!NILP (append))
|
|
3458 #ifdef DOS_NT
|
16
|
3459 desc = open ((char *) XSTRING_DATA (fn),
|
0
|
3460 (O_WRONLY | buffer_file_type), 0);
|
|
3461 #else /* not DOS_NT */
|
16
|
3462 desc = open ((char *) XSTRING_DATA (fn), O_WRONLY, 0);
|
0
|
3463 #endif /* not DOS_NT */
|
|
3464
|
|
3465 if (desc < 0)
|
|
3466 #ifndef VMS
|
|
3467 {
|
|
3468 #ifdef DOS_NT
|
16
|
3469 desc = open ((char *) XSTRING_DATA (fn),
|
0
|
3470 (O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type),
|
|
3471 (S_IREAD | S_IWRITE));
|
|
3472 #else /* not DOS_NT */
|
16
|
3473 desc = creat ((char *) XSTRING_DATA (fn),
|
0
|
3474 ((auto_saving) ? auto_save_mode_bits : 0666));
|
|
3475 #endif /* DOS_NT */
|
|
3476 }
|
|
3477 #else /* VMS */
|
|
3478 {
|
|
3479 if (auto_saving) /* Overwrite any previous version of autosave file */
|
|
3480 {
|
16
|
3481 char *fn_data = XSTRING_DATA (fn);
|
0
|
3482 /* if fn exists, truncate to zero length */
|
|
3483 vms_truncate (fn_data);
|
|
3484 desc = open (fn_data, O_RDWR, 0);
|
|
3485 if (desc < 0)
|
|
3486 desc = creat_copy_attrs ((STRINGP (current_buffer->filename)
|
16
|
3487 ? (char *)
|
|
3488 XSTRING_DATA (current_buffer->filename)
|
0
|
3489 : 0),
|
|
3490 fn_data);
|
|
3491 }
|
|
3492 else /* Write to temporary name and rename if no errors */
|
|
3493 {
|
|
3494 Lisp_Object temp_name;
|
|
3495
|
|
3496 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3497 GCPRO3 (start, filename, visit_file);
|
|
3498 {
|
|
3499 struct gcpro gcpro1, gcpro2, gcpro3; /* Don't have GCPRO6 */
|
|
3500
|
|
3501 GCPRO3 (fn, fname, annotations);
|
|
3502
|
|
3503 temp_name = Ffile_name_directory (filename);
|
|
3504
|
|
3505 if (NILP (temp_name))
|
16
|
3506 desc = creat ((char *) XSTRING_DATA (fn), 0666);
|
0
|
3507 else
|
|
3508 {
|
|
3509 temp_name =
|
|
3510 Fmake_temp_name (concat2 (temp_name,
|
|
3511 build_string ("$$SAVE$$")));
|
|
3512 fname = filename;
|
|
3513 fn = temp_name;
|
|
3514 desc = creat_copy_attrs (fname,
|
16
|
3515 (char *) XSTRING_DATA (fn));
|
0
|
3516 if (desc < 0)
|
|
3517 {
|
|
3518 char *fn_data;
|
|
3519 /* If we can't open the temporary file, try creating a new
|
|
3520 version of the original file. VMS "creat" creates a
|
|
3521 new version rather than truncating an existing file. */
|
|
3522 fn = fname;
|
|
3523 fname = Qnil;
|
16
|
3524 fn_data = XSTRING_DATA (fn);
|
0
|
3525 desc = creat (fn_data, 0666);
|
|
3526 #if 0 /* This can clobber an existing file and fail
|
|
3527 to replace it, if the user runs out of
|
|
3528 space. */
|
|
3529 if (desc < 0)
|
|
3530 {
|
|
3531 /* We can't make a new version;
|
|
3532 try to truncate and rewrite existing version if any.
|
|
3533 */
|
|
3534 vms_truncate (fn_data);
|
|
3535 desc = open (fn_data, O_RDWR, 0);
|
|
3536 }
|
|
3537 #endif
|
|
3538 }
|
|
3539 }
|
|
3540 UNGCPRO;
|
|
3541 }
|
|
3542 UNGCPRO;
|
|
3543 }
|
|
3544 }
|
|
3545 #endif /* VMS */
|
|
3546
|
|
3547 if (desc < 0)
|
|
3548 {
|
|
3549 #ifdef CLASH_DETECTION
|
|
3550 save_errno = errno;
|
|
3551 if (!auto_saving) unlock_file (lockname);
|
|
3552 errno = save_errno;
|
|
3553 #endif /* CLASH_DETECTION */
|
|
3554 report_file_error ("Opening output file",
|
|
3555 Fcons (filename, Qnil));
|
|
3556 }
|
|
3557
|
|
3558 {
|
|
3559 Lisp_Object desc_locative = Fcons (make_int (desc), Qnil);
|
|
3560 Lisp_Object instream = Qnil, outstream = Qnil;
|
|
3561 struct gcpro gcpro1, gcpro2;
|
|
3562 /* need to gcpro; QUIT could happen out of call to write() */
|
|
3563 GCPRO2 (instream, outstream);
|
|
3564
|
|
3565 record_unwind_protect (close_file_unwind, desc_locative);
|
|
3566
|
|
3567 if (!NILP (append))
|
|
3568 {
|
|
3569 if (lseek (desc, 0, 2) < 0)
|
|
3570 {
|
|
3571 #ifdef CLASH_DETECTION
|
|
3572 if (!auto_saving) unlock_file (lockname);
|
|
3573 #endif /* CLASH_DETECTION */
|
|
3574 report_file_error ("Lseek error",
|
|
3575 list1 (filename));
|
|
3576 }
|
|
3577 }
|
|
3578
|
|
3579 #ifdef VMS
|
|
3580 /*
|
|
3581 * Kludge Warning: The VMS C RTL likes to insert carriage returns
|
|
3582 * if we do writes that don't end with a carriage return. Furthermore
|
|
3583 * it cannot handle writes of more then 16K. The modified
|
|
3584 * version of "sys_write" in SYSDEP.C (see comment there) copes with
|
|
3585 * this EXCEPT for the last record (iff it doesn't end with a carriage
|
|
3586 * return). This implies that if your buffer doesn't end with a carriage
|
|
3587 * return, you get one free... tough. However it also means that if
|
|
3588 * we make two calls to sys_write (a la the following code) you can
|
|
3589 * get one at the gap as well. The easiest way to fix this (honest)
|
|
3590 * is to move the gap to the next newline (or the end of the buffer).
|
|
3591 * Thus this change.
|
|
3592 *
|
|
3593 * Yech!
|
|
3594 */
|
|
3595 you lose -- fix this
|
|
3596 if (GPT > BUF_BEG (current_buffer) && *GPT_ADDR[-1] != '\n')
|
|
3597 move_gap (find_next_newline (current_buffer, GPT, 1));
|
|
3598 #endif
|
|
3599
|
|
3600 failure = 0;
|
|
3601
|
|
3602 /* Note: I tried increasing the buffering size, along with
|
|
3603 various other tricks, but nothing seemed to make much of
|
|
3604 a difference in the time it took to save a large file.
|
|
3605 (Actually that's not true. With a local disk, changing
|
|
3606 the buffer size doesn't seem to make much difference.
|
|
3607 With an NFS-mounted disk, it could make a lot of difference
|
|
3608 because you're affecting the number of network requests
|
|
3609 that need to be made, and there could be a large latency
|
|
3610 for each request. So I've increased the buffer size
|
|
3611 to 64K.) */
|
|
3612 outstream = make_filedesc_output_stream (desc, 0, -1, 0);
|
|
3613 Lstream_set_buffering (XLSTREAM (outstream),
|
|
3614 LSTREAM_BLOCKN_BUFFERED, 65536);
|
|
3615 if (STRINGP (start))
|
|
3616 {
|
|
3617 instream = make_lisp_string_input_stream (start, 0, -1);
|
|
3618 start1 = 0;
|
|
3619 }
|
|
3620 else
|
|
3621 instream = make_lisp_buffer_input_stream (current_buffer, start1, end1,
|
|
3622 LSTR_SELECTIVE |
|
|
3623 LSTR_IGNORE_ACCESSIBLE);
|
|
3624 failure = (0 > (a_write (outstream, instream, start1,
|
|
3625 &annotations)));
|
|
3626 save_errno = errno;
|
|
3627 /* Note that this doesn't close the desc since we created the
|
|
3628 stream without the LSTR_CLOSING flag, but it does
|
|
3629 flush out any buffered data. */
|
|
3630 if (Lstream_close (XLSTREAM (outstream)) < 0)
|
|
3631 {
|
|
3632 failure = 1;
|
|
3633 save_errno = errno;
|
|
3634 }
|
|
3635 Lstream_close (XLSTREAM (instream));
|
|
3636 UNGCPRO;
|
|
3637
|
|
3638 #ifdef HAVE_FSYNC
|
|
3639 /* Note fsync appears to change the modtime on BSD4.2 (both vax and sun).
|
|
3640 Disk full in NFS may be reported here. */
|
|
3641 /* mib says that closing the file will try to write as fast as NFS can do
|
|
3642 it, and that means the fsync here is not crucial for autosave files. */
|
|
3643 if (!auto_saving && fsync (desc) < 0
|
|
3644 /* If fsync fails with EINTR, don't treat that as serious. */
|
|
3645 && errno != EINTR)
|
|
3646 {
|
|
3647 failure = 1;
|
|
3648 save_errno = errno;
|
|
3649 }
|
|
3650 #endif
|
|
3651
|
|
3652 /* Spurious "file has changed on disk" warnings have been
|
|
3653 observed on Suns as well.
|
|
3654 It seems that `close' can change the modtime, under nfs.
|
|
3655
|
|
3656 (This has supposedly been fixed in Sunos 4,
|
|
3657 but who knows about all the other machines with NFS?) */
|
|
3658 /* On VMS and APOLLO, must do the stat after the close
|
|
3659 since closing changes the modtime. */
|
|
3660 #if 0 /* !defined (VMS) && !defined (APOLLO) */
|
|
3661 fstat (desc, &st);
|
|
3662 #endif
|
|
3663
|
|
3664 /* NFS can report a write failure now. */
|
|
3665 if (close (desc) < 0)
|
|
3666 {
|
|
3667 failure = 1;
|
|
3668 save_errno = errno;
|
|
3669 }
|
|
3670
|
|
3671 /* Discard the close unwind-protect. Execute the one for
|
|
3672 build_annotations (switches back to the original current buffer
|
|
3673 as necessary). */
|
|
3674 XCAR (desc_locative) = Qnil;
|
|
3675 unbind_to (speccount, Qnil);
|
|
3676 }
|
|
3677
|
|
3678
|
|
3679 #ifdef VMS
|
|
3680 /* If we wrote to a temporary name and had no errors, rename to real name. */
|
|
3681 if (!NILP (fname))
|
|
3682 {
|
|
3683 if (!failure)
|
|
3684 {
|
16
|
3685 failure = (rename ((char *) XSTRING_DATA (fn),
|
|
3686 (char *) XSTRING_DATA (fname))
|
0
|
3687 != 0);
|
|
3688 save_errno = errno;
|
|
3689 }
|
|
3690 fn = fname;
|
|
3691 }
|
|
3692 #endif /* VMS */
|
|
3693
|
|
3694 #if 1 /* defined (VMS) || defined (APOLLO) */
|
16
|
3695 stat ((char *) XSTRING_DATA (fn), &st);
|
0
|
3696 #endif
|
|
3697
|
|
3698 #ifdef CLASH_DETECTION
|
|
3699 if (!auto_saving)
|
|
3700 unlock_file (lockname);
|
|
3701 #endif /* CLASH_DETECTION */
|
|
3702
|
|
3703 /* Do this before reporting IO error
|
|
3704 to avoid a "file has changed on disk" warning on
|
|
3705 next attempt to save. */
|
|
3706 if (visiting)
|
|
3707 current_buffer->modtime = st.st_mtime;
|
|
3708
|
|
3709 if (failure)
|
|
3710 error ("IO error writing %s: %s",
|
16
|
3711 XSTRING_DATA (fn),
|
0
|
3712 strerror (save_errno));
|
|
3713
|
|
3714 if (visiting)
|
|
3715 {
|
|
3716 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer);
|
|
3717 current_buffer->save_length = make_int (BUF_SIZE (current_buffer));
|
|
3718 current_buffer->filename = visit_file;
|
|
3719 MARK_MODELINE_CHANGED;
|
|
3720 }
|
|
3721 else if (quietly)
|
|
3722 {
|
|
3723 return Qnil;
|
|
3724 }
|
|
3725
|
|
3726 if (!auto_saving)
|
|
3727 {
|
|
3728 if (visiting_other)
|
16
|
3729 message ("Wrote %s", XSTRING_DATA (visit_file));
|
0
|
3730 else
|
|
3731 {
|
|
3732 struct gcpro gcpro1;
|
|
3733 Lisp_Object fsp;
|
|
3734 GCPRO1 (fn);
|
|
3735
|
|
3736 fsp = Ffile_symlink_p (fn);
|
|
3737 if (NILP (fsp))
|
16
|
3738 message ("Wrote %s", XSTRING_DATA (fn));
|
0
|
3739 else
|
|
3740 message ("Wrote %s (symlink to %s)",
|
16
|
3741 XSTRING_DATA (fn), XSTRING_DATA (fsp));
|
0
|
3742 UNGCPRO;
|
|
3743 }
|
|
3744 }
|
|
3745 return Qnil;
|
|
3746 }
|
|
3747
|
|
3748 /* #### This is such a load of shit!!!! There is no way we should define
|
|
3749 something so stupid as a subr, just sort the fucking list more
|
|
3750 intelligently. */
|
20
|
3751 DEFUN ("car-less-than-car", Fcar_less_than_car, 2, 2, 0, /*
|
0
|
3752 Return t if (car A) is numerically less than (car B).
|
20
|
3753 */
|
|
3754 (a, b))
|
0
|
3755 {
|
|
3756 return Flss (Fcar (a), Fcar (b));
|
|
3757 }
|
|
3758
|
|
3759 /* Heh heh heh, let's define this too, just to aggravate the person who
|
|
3760 wrote the above comment. */
|
20
|
3761 DEFUN ("cdr-less-than-cdr", Fcdr_less_than_cdr, 2, 2, 0, /*
|
0
|
3762 Return t if (cdr A) is numerically less than (cdr B).
|
20
|
3763 */
|
|
3764 (a, b))
|
0
|
3765 {
|
|
3766 return Flss (Fcdr (a), Fcdr (b));
|
|
3767 }
|
|
3768
|
|
3769 /* Build the complete list of annotations appropriate for writing out
|
|
3770 the text between START and END, by calling all the functions in
|
|
3771 write-region-annotate-functions and merging the lists they return.
|
|
3772 If one of these functions switches to a different buffer, we assume
|
|
3773 that buffer contains altered text. Therefore, the caller must
|
|
3774 make sure to restore the current buffer in all cases,
|
|
3775 as save-excursion would do. */
|
|
3776
|
|
3777 static Lisp_Object
|
|
3778 build_annotations (Lisp_Object start, Lisp_Object end)
|
|
3779 {
|
|
3780 /* This function can GC */
|
|
3781 Lisp_Object annotations;
|
|
3782 Lisp_Object p, res;
|
|
3783 struct gcpro gcpro1, gcpro2;
|
|
3784
|
|
3785 annotations = Qnil;
|
|
3786 p = Vwrite_region_annotate_functions;
|
|
3787 GCPRO2 (annotations, p);
|
|
3788 while (!NILP (p))
|
|
3789 {
|
|
3790 struct buffer *given_buffer = current_buffer;
|
|
3791 Vwrite_region_annotations_so_far = annotations;
|
|
3792 res = call2 (Fcar (p), start, end);
|
|
3793 /* If the function makes a different buffer current,
|
|
3794 assume that means this buffer contains altered text to be output.
|
|
3795 Reset START and END from the buffer bounds
|
|
3796 and discard all previous annotations because they should have
|
|
3797 been dealt with by this function. */
|
|
3798 if (current_buffer != given_buffer)
|
|
3799 {
|
|
3800 start = make_int (BUF_BEGV (current_buffer));
|
|
3801 end = make_int (BUF_ZV (current_buffer));
|
|
3802 annotations = Qnil;
|
|
3803 }
|
|
3804 (void) Flength (res); /* Check basic validity of return value */
|
|
3805 annotations = merge (annotations, res, Qcar_less_than_car);
|
|
3806 p = Fcdr (p);
|
|
3807 }
|
|
3808
|
|
3809 /* Now do the same for annotation functions implied by the file-format */
|
|
3810 if (auto_saving && (!EQ (Vauto_save_file_format, Qt)))
|
|
3811 p = Vauto_save_file_format;
|
|
3812 else
|
|
3813 p = current_buffer->file_format;
|
|
3814 while (!NILP (p))
|
|
3815 {
|
|
3816 struct buffer *given_buffer = current_buffer;
|
|
3817 Vwrite_region_annotations_so_far = annotations;
|
|
3818 res = call3 (Qformat_annotate_function, Fcar (p), start, end);
|
|
3819 if (current_buffer != given_buffer)
|
|
3820 {
|
|
3821 start = make_int (BUF_BEGV (current_buffer));
|
|
3822 end = make_int (BUF_ZV (current_buffer));
|
|
3823 annotations = Qnil;
|
|
3824 }
|
|
3825 (void) Flength (res);
|
|
3826 annotations = merge (annotations, res, Qcar_less_than_car);
|
|
3827 p = Fcdr (p);
|
|
3828 }
|
|
3829 UNGCPRO;
|
|
3830 return annotations;
|
|
3831 }
|
|
3832
|
|
3833 /* Write to stream OUTSTREAM the characters from INSTREAM (it is read until
|
|
3834 EOF is encountered), assuming they start at position POS in the buffer
|
|
3835 of string that STREAM refers to. Intersperse with them the annotations
|
|
3836 from *ANNOT that fall into the range of positions we are reading from,
|
|
3837 each at its appropriate position.
|
|
3838
|
|
3839 Modify *ANNOT by discarding elements as we output them.
|
|
3840 The return value is negative in case of system call failure. */
|
|
3841
|
|
3842 /* 4K should probably be fine. We just need to reduce the number of
|
|
3843 function calls to reasonable level. The Lstream stuff itself will
|
|
3844 batch to 64K to reduce the number of system calls. */
|
|
3845
|
|
3846 #define A_WRITE_BATCH_SIZE 4096
|
|
3847
|
|
3848 static int
|
|
3849 a_write (Lisp_Object outstream, Lisp_Object instream, int pos,
|
|
3850 Lisp_Object *annot)
|
|
3851 {
|
|
3852 Lisp_Object tem;
|
|
3853 int nextpos;
|
|
3854 unsigned char largebuf[A_WRITE_BATCH_SIZE];
|
|
3855 Lstream *instr = XLSTREAM (instream);
|
|
3856 Lstream *outstr = XLSTREAM (outstream);
|
|
3857
|
|
3858 while (NILP (*annot) || CONSP (*annot))
|
|
3859 {
|
|
3860 tem = Fcar_safe (Fcar (*annot));
|
|
3861 if (INTP (tem))
|
|
3862 nextpos = XINT (tem);
|
|
3863 else
|
|
3864 nextpos = INT_MAX;
|
|
3865 {
|
|
3866 while (pos != nextpos)
|
|
3867 {
|
|
3868 /* Otherwise there is no point to that. Just go in batches. */
|
|
3869 int chunk = min (nextpos - pos, A_WRITE_BATCH_SIZE);
|
|
3870
|
|
3871 chunk = Lstream_read (instr, largebuf, chunk);
|
|
3872 if (chunk < 0)
|
|
3873 return -1;
|
|
3874 if (chunk == 0) /* EOF */
|
|
3875 break;
|
|
3876 if (Lstream_write (outstr, largebuf, chunk) < chunk)
|
|
3877 return -1;
|
|
3878 pos += chunk;
|
|
3879 }
|
|
3880 }
|
|
3881 if (pos == nextpos)
|
|
3882 {
|
|
3883 tem = Fcdr (Fcar (*annot));
|
|
3884 if (STRINGP (tem))
|
|
3885 {
|
16
|
3886 if (Lstream_write (outstr, XSTRING_DATA (tem),
|
|
3887 XSTRING_LENGTH (tem)) < 0)
|
0
|
3888 return -1;
|
|
3889 }
|
|
3890 *annot = Fcdr (*annot);
|
|
3891 }
|
|
3892 else
|
|
3893 return 0;
|
|
3894 }
|
|
3895 return -1;
|
|
3896 }
|
|
3897
|
|
3898
|
|
3899
|
|
3900 #if 0
|
|
3901 #include <des_crypt.h>
|
|
3902
|
|
3903 #define CRYPT_BLOCK_SIZE 8 /* bytes */
|
|
3904 #define CRYPT_KEY_SIZE 8 /* bytes */
|
|
3905
|
20
|
3906 DEFUN ("encrypt-string", Fencrypt_string, 2, 2, 0, /*
|
0
|
3907 Encrypt STRING using KEY.
|
20
|
3908 */
|
|
3909 (string, key))
|
0
|
3910 {
|
|
3911 char *encrypted_string, *raw_key;
|
|
3912 int rounded_size, extra, key_size;
|
|
3913
|
|
3914 /* !!#### May produce bogus data under Mule. */
|
|
3915 CHECK_STRING (string);
|
|
3916 CHECK_STRING (key);
|
|
3917
|
16
|
3918 extra = XSTRING_LENGTH (string) % CRYPT_BLOCK_SIZE;
|
|
3919 rounded_size = XSTRING_LENGTH (string) + extra;
|
0
|
3920 encrypted_string = alloca (rounded_size + 1);
|
16
|
3921 memcpy (encrypted_string, XSTRING_DATA (string), XSTRING_LENGTH (string));
|
0
|
3922 memset (encrypted_string + rounded_size - extra, 0, extra + 1);
|
|
3923
|
16
|
3924 if (XSTRING_LENGTH (key) > CRYPT_KEY_SIZE)
|
0
|
3925 key_size = CRYPT_KEY_SIZE;
|
|
3926 else
|
16
|
3927 key_size = XSTRING_LENGTH (key);
|
0
|
3928
|
|
3929 raw_key = alloca (CRYPT_KEY_SIZE + 1);
|
16
|
3930 memcpy (raw_key, XSTRING_DATA (key), key_size);
|
0
|
3931 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size);
|
|
3932
|
|
3933 (void) ecb_crypt (raw_key, encrypted_string, rounded_size,
|
|
3934 DES_ENCRYPT | DES_SW);
|
|
3935 return make_string (encrypted_string, rounded_size);
|
|
3936 }
|
|
3937
|
20
|
3938 DEFUN ("decrypt-string", Fdecrypt_string, 2, 2, 0, /*
|
0
|
3939 Decrypt STRING using KEY.
|
20
|
3940 */
|
|
3941 (string, key))
|
0
|
3942 {
|
|
3943 char *decrypted_string, *raw_key;
|
|
3944 int string_size, key_size;
|
|
3945
|
|
3946 CHECK_STRING (string);
|
|
3947 CHECK_STRING (key);
|
|
3948
|
16
|
3949 string_size = XSTRING_LENGTH (string) + 1;
|
0
|
3950 decrypted_string = alloca (string_size);
|
16
|
3951 memcpy (decrypted_string, XSTRING_DATA (string), string_size);
|
0
|
3952 decrypted_string[string_size - 1] = '\0';
|
|
3953
|
16
|
3954 if (XSTRING_LENGTH (key) > CRYPT_KEY_SIZE)
|
0
|
3955 key_size = CRYPT_KEY_SIZE;
|
|
3956 else
|
16
|
3957 key_size = XSTRING_LENGTH (key);
|
0
|
3958
|
|
3959 raw_key = alloca (CRYPT_KEY_SIZE + 1);
|
16
|
3960 memcpy (raw_key, XSTRING_DATA (key), key_size);
|
0
|
3961 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size);
|
|
3962
|
|
3963
|
|
3964 (void) ecb_crypt (raw_key, decrypted_string, string_size,
|
|
3965 DES_DECRYPT | DES_SW);
|
|
3966 return make_string (decrypted_string, string_size - 1);
|
|
3967 }
|
|
3968 #endif
|
|
3969
|
|
3970
|
20
|
3971 DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, 1, 1, 0, /*
|
0
|
3972 Return t if last mod time of BUF's visited file matches what BUF records.
|
|
3973 This means that the file has not been changed since it was visited or saved.
|
20
|
3974 */
|
|
3975 (buf))
|
0
|
3976 {
|
|
3977 /* This function can GC */
|
|
3978 struct buffer *b;
|
|
3979 struct stat st;
|
|
3980 Lisp_Object handler;
|
|
3981
|
|
3982 CHECK_BUFFER (buf);
|
|
3983 b = XBUFFER (buf);
|
|
3984
|
|
3985 if (!STRINGP (b->filename)) return Qt;
|
|
3986 if (b->modtime == 0) return Qt;
|
|
3987
|
|
3988 /* If the file name has special constructs in it,
|
|
3989 call the corresponding file handler. */
|
|
3990 handler = Ffind_file_name_handler (b->filename,
|
|
3991 Qverify_visited_file_modtime);
|
|
3992 if (!NILP (handler))
|
|
3993 return call2 (handler, Qverify_visited_file_modtime, buf);
|
|
3994
|
16
|
3995 if (stat ((char *) XSTRING_DATA (b->filename), &st) < 0)
|
0
|
3996 {
|
|
3997 /* If the file doesn't exist now and didn't exist before,
|
|
3998 we say that it isn't modified, provided the error is a tame one. */
|
|
3999 if (errno == ENOENT || errno == EACCES || errno == ENOTDIR)
|
|
4000 st.st_mtime = -1;
|
|
4001 else
|
|
4002 st.st_mtime = 0;
|
|
4003 }
|
|
4004 if (st.st_mtime == b->modtime
|
|
4005 /* If both are positive, accept them if they are off by one second. */
|
|
4006 || (st.st_mtime > 0 && b->modtime > 0
|
|
4007 && (st.st_mtime == b->modtime + 1
|
|
4008 || st.st_mtime == b->modtime - 1)))
|
|
4009 return Qt;
|
|
4010 return Qnil;
|
|
4011 }
|
|
4012
|
20
|
4013 DEFUN ("clear-visited-file-modtime", Fclear_visited_file_modtime, 0, 0, 0, /*
|
0
|
4014 Clear out records of last mod time of visited file.
|
|
4015 Next attempt to save will certainly not complain of a discrepancy.
|
20
|
4016 */
|
|
4017 ())
|
0
|
4018 {
|
|
4019 current_buffer->modtime = 0;
|
|
4020 return Qnil;
|
|
4021 }
|
|
4022
|
20
|
4023 DEFUN ("visited-file-modtime", Fvisited_file_modtime, 0, 0, 0, /*
|
0
|
4024 Return the current buffer's recorded visited file modification time.
|
|
4025 The value is a list of the form (HIGH . LOW), like the time values
|
|
4026 that `file-attributes' returns.
|
20
|
4027 */
|
|
4028 ())
|
0
|
4029 {
|
|
4030 return time_to_lisp ((time_t) current_buffer->modtime);
|
|
4031 }
|
|
4032
|
20
|
4033 DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime, 0, 1, 0, /*
|
0
|
4034 Update buffer's recorded modification time from the visited file's time.
|
|
4035 Useful if the buffer was not read from the file normally
|
|
4036 or if the file itself has been changed for some known benign reason.
|
|
4037 An argument specifies the modification time value to use
|
|
4038 (instead of that of the visited file), in the form of a list
|
|
4039 (HIGH . LOW) or (HIGH LOW).
|
20
|
4040 */
|
|
4041 (time_list))
|
0
|
4042 {
|
|
4043 /* This function can GC */
|
|
4044 if (!NILP (time_list))
|
|
4045 {
|
|
4046 time_t the_time;
|
|
4047 lisp_to_time (time_list, &the_time);
|
|
4048 current_buffer->modtime = (int) the_time;
|
|
4049 }
|
|
4050 else
|
|
4051 {
|
|
4052 Lisp_Object filename;
|
|
4053 struct stat st;
|
|
4054 Lisp_Object handler;
|
40
|
4055 struct gcpro gcpro1, gcpro2, gcpro3;
|
0
|
4056
|
40
|
4057 GCPRO3 (filename, time_list, current_buffer->filename);
|
|
4058 filename = Fexpand_file_name (current_buffer->filename, Qnil);
|
0
|
4059
|
|
4060 /* If the file name has special constructs in it,
|
|
4061 call the corresponding file handler. */
|
|
4062 handler = Ffind_file_name_handler (filename, Qset_visited_file_modtime);
|
|
4063 UNGCPRO;
|
|
4064 if (!NILP (handler))
|
|
4065 /* The handler can find the file name the same way we did. */
|
|
4066 return call2 (handler, Qset_visited_file_modtime, Qnil);
|
16
|
4067 else if (stat ((char *) XSTRING_DATA (filename), &st) >= 0)
|
0
|
4068 current_buffer->modtime = st.st_mtime;
|
|
4069 }
|
|
4070
|
|
4071 return Qnil;
|
|
4072 }
|
|
4073
|
20
|
4074 DEFUN ("set-buffer-modtime", Fset_buffer_modtime, 1, 2, 0, /*
|
0
|
4075 Update BUFFER's recorded modification time from the associated
|
|
4076 file's modtime, if there is an associated file. If not, use the
|
|
4077 current time. In either case, if the optional arg TIME is supplied,
|
|
4078 it will be used if it is either an integer or a cons of two integers.
|
20
|
4079 */
|
|
4080 (buf, in_time))
|
0
|
4081 {
|
|
4082 /* This function can GC */
|
|
4083 unsigned long time_to_use = 0;
|
|
4084 int set_time_to_use = 0;
|
|
4085 struct stat st;
|
|
4086
|
|
4087 CHECK_BUFFER (buf);
|
|
4088
|
|
4089 if (!NILP (in_time))
|
|
4090 {
|
|
4091 if (INTP (in_time))
|
|
4092 {
|
|
4093 time_to_use = XINT (in_time);
|
|
4094 set_time_to_use = 1;
|
|
4095 }
|
|
4096 else if ((CONSP (in_time)) &&
|
|
4097 (INTP (Fcar (in_time))) &&
|
|
4098 (INTP (Fcdr (in_time))))
|
|
4099 {
|
|
4100 time_t the_time;
|
|
4101 lisp_to_time (in_time, &the_time);
|
|
4102 time_to_use = (unsigned long) the_time;
|
|
4103 set_time_to_use = 1;
|
|
4104 }
|
|
4105 }
|
|
4106
|
|
4107 if (!set_time_to_use)
|
|
4108 {
|
|
4109 Lisp_Object filename = Qnil;
|
40
|
4110 struct gcpro gcpro1;
|
|
4111 GCPRO1 (filename);
|
|
4112 /* #### dmoore - do we need to protect XBUFFER (buf)->filename?
|
|
4113 What if a ^(*&^&*^*& handler renames a buffer? I think I'm
|
|
4114 getting a headache now. */
|
0
|
4115
|
|
4116 if (STRINGP (XBUFFER (buf)->filename))
|
40
|
4117 filename = Fexpand_file_name (XBUFFER (buf)->filename, Qnil);
|
0
|
4118 else
|
|
4119 filename = Qnil;
|
|
4120
|
|
4121 if (!NILP (filename) && !NILP (Ffile_exists_p (filename)))
|
|
4122 {
|
|
4123 Lisp_Object handler;
|
|
4124
|
|
4125 /* If the file name has special constructs in it,
|
|
4126 call the corresponding file handler. */
|
|
4127 handler = Ffind_file_name_handler (filename, Qset_buffer_modtime);
|
|
4128 UNGCPRO;
|
|
4129 if (!NILP (handler))
|
|
4130 /* The handler can find the file name the same way we did. */
|
|
4131 return (call2 (handler, Qset_buffer_modtime, Qnil));
|
|
4132 else
|
|
4133 {
|
16
|
4134 if (stat ((char *) XSTRING_DATA (filename), &st) >= 0)
|
0
|
4135 time_to_use = st.st_mtime;
|
|
4136 else
|
|
4137 time_to_use = time ((time_t *) 0);
|
|
4138 }
|
|
4139 }
|
|
4140 else
|
40
|
4141 {
|
|
4142 UNGCPRO;
|
|
4143 time_to_use = time ((time_t *) 0);
|
|
4144 }
|
0
|
4145 }
|
|
4146
|
|
4147 XBUFFER (buf)->modtime = time_to_use;
|
40
|
4148
|
0
|
4149 return Qnil;
|
|
4150 }
|
|
4151
|
|
4152
|
|
4153 static Lisp_Object
|
|
4154 auto_save_error (Lisp_Object condition_object, Lisp_Object ignored)
|
|
4155 {
|
|
4156 /* This function can GC */
|
|
4157 if (gc_in_progress)
|
|
4158 return Qnil;
|
32
|
4159 /* Don't try printing an error message after everything is gone! */
|
|
4160 if (preparing_for_armageddon)
|
|
4161 return Qnil;
|
0
|
4162 clear_echo_area (selected_frame (), Qauto_saving, 1);
|
|
4163 Fding (Qt, Qauto_save_error, Qnil);
|
16
|
4164 message ("Auto-saving...error for %s", XSTRING_DATA (current_buffer->name));
|
0
|
4165 Fsleep_for (make_int (1));
|
16
|
4166 message ("Auto-saving...error!for %s", XSTRING_DATA (current_buffer->name));
|
0
|
4167 Fsleep_for (make_int (1));
|
16
|
4168 message ("Auto-saving...error for %s", XSTRING_DATA (current_buffer->name));
|
0
|
4169 Fsleep_for (make_int (1));
|
|
4170 return Qnil;
|
|
4171 }
|
|
4172
|
|
4173 static Lisp_Object
|
|
4174 auto_save_1 (Lisp_Object ignored)
|
|
4175 {
|
|
4176 /* This function can GC */
|
|
4177 struct stat st;
|
|
4178 Lisp_Object fn = current_buffer->filename;
|
|
4179 Lisp_Object a = current_buffer->auto_save_file_name;
|
|
4180
|
|
4181 if (!STRINGP (a))
|
|
4182 return (Qnil);
|
|
4183
|
|
4184 /* Get visited file's mode to become the auto save file's mode. */
|
|
4185 if (STRINGP (fn) &&
|
16
|
4186 stat ((char *) XSTRING_DATA (fn), &st) >= 0)
|
0
|
4187 /* But make sure we can overwrite it later! */
|
|
4188 auto_save_mode_bits = st.st_mode | 0600;
|
|
4189 else
|
|
4190 /* default mode for auto-save files of buffers with no file is
|
|
4191 readable by owner only. This may annoy some small number of
|
|
4192 people, but the alternative removes all privacy from email. */
|
|
4193 auto_save_mode_bits = 0600;
|
|
4194
|
|
4195 return
|
|
4196 Fwrite_region_internal (Qnil, Qnil, a, Qnil, Qlambda, Qnil);
|
|
4197 }
|
|
4198
|
|
4199
|
|
4200 static Lisp_Object
|
|
4201 do_auto_save_unwind (Lisp_Object fd)
|
|
4202 {
|
|
4203 close (XINT (fd));
|
|
4204 return (fd);
|
|
4205 }
|
|
4206
|
|
4207 static Lisp_Object
|
|
4208 do_auto_save_unwind_2 (Lisp_Object old_auto_saving)
|
|
4209 {
|
|
4210 auto_saving = XINT (old_auto_saving);
|
|
4211 return Qnil;
|
|
4212 }
|
|
4213
|
|
4214 /* Fdo_auto_save() checks whether a GC is in progress when it is called,
|
|
4215 and if so, tries to avoid touching lisp objects.
|
|
4216
|
|
4217 The only time that Fdo_auto_save() is called while GC is in progress
|
|
4218 is if we're going down, as a result of an abort() or a kill signal.
|
|
4219 It's fairly important that we generate autosave files in that case!
|
|
4220 */
|
|
4221
|
20
|
4222 DEFUN ("do-auto-save", Fdo_auto_save, 0, 2, "", /*
|
0
|
4223 Auto-save all buffers that need it.
|
|
4224 This is all buffers that have auto-saving enabled
|
|
4225 and are changed since last auto-saved.
|
|
4226 Auto-saving writes the buffer into a file
|
|
4227 so that your editing is not lost if the system crashes.
|
|
4228 This file is not the file you visited; that changes only when you save.
|
|
4229 Normally we run the normal hook `auto-save-hook' before saving.
|
|
4230
|
|
4231 Non-nil first argument means do not print any message if successful.
|
|
4232 Non-nil second argument means save only current buffer.
|
20
|
4233 */
|
|
4234 (no_message, current_only))
|
0
|
4235 {
|
|
4236 /* This function can GC */
|
32
|
4237 struct buffer *b;
|
0
|
4238 Lisp_Object tail, buf;
|
|
4239 int auto_saved = 0;
|
|
4240 int do_handled_files;
|
|
4241 Lisp_Object oquit = Qnil;
|
|
4242 Lisp_Object listfile = Qnil;
|
32
|
4243 Lisp_Object old;
|
0
|
4244 int listdesc = -1;
|
|
4245 int speccount = specpdl_depth ();
|
32
|
4246 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
4247
|
|
4248 XSETBUFFER (old, current_buffer);
|
|
4249 GCPRO3 (oquit, listfile, old);
|
0
|
4250 check_quit (); /* make Vquit_flag accurate */
|
|
4251 /* Ordinarily don't quit within this function,
|
|
4252 but don't make it impossible to quit (in case we get hung in I/O). */
|
|
4253 oquit = Vquit_flag;
|
|
4254 Vquit_flag = Qnil;
|
|
4255
|
|
4256 /* No further GCPRO needed, because (when it matters) all Lisp_Object
|
|
4257 variables point to non-strings reached from Vbuffer_alist. */
|
|
4258
|
|
4259 if (minibuf_level != 0 || preparing_for_armageddon)
|
|
4260 no_message = Qt;
|
|
4261
|
|
4262 run_hook (Qauto_save_hook);
|
|
4263
|
|
4264 if (GC_STRINGP (Vauto_save_list_file_name))
|
|
4265 listfile = Fexpand_file_name (Vauto_save_list_file_name, Qnil);
|
|
4266
|
|
4267 /* Make sure auto_saving is reset. */
|
|
4268 record_unwind_protect (do_auto_save_unwind_2, make_int (auto_saving));
|
|
4269
|
|
4270 auto_saving = 1;
|
|
4271
|
|
4272 /* First, save all files which don't have handlers. If Emacs is
|
|
4273 crashing, the handlers may tweak what is causing Emacs to crash
|
|
4274 in the first place, and it would be a shame if Emacs failed to
|
|
4275 autosave perfectly ordinary files because it couldn't handle some
|
|
4276 ange-ftp'd file. */
|
|
4277 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++)
|
|
4278 {
|
|
4279 for (tail = Vbuffer_alist;
|
|
4280 GC_CONSP (tail);
|
|
4281 tail = XCDR (tail))
|
|
4282 {
|
|
4283 buf = XCDR (XCAR (tail));
|
|
4284 b = XBUFFER (buf);
|
|
4285
|
|
4286 if (!GC_NILP (current_only)
|
|
4287 && b != current_buffer)
|
|
4288 continue;
|
|
4289
|
|
4290 /* Don't auto-save indirect buffers.
|
|
4291 The base buffer takes care of it. */
|
|
4292 if (b->base_buffer)
|
|
4293 continue;
|
|
4294
|
|
4295 /* Check for auto save enabled
|
|
4296 and file changed since last auto save
|
|
4297 and file changed since last real save. */
|
|
4298 if (GC_STRINGP (b->auto_save_file_name)
|
|
4299 && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)
|
|
4300 && b->auto_save_modified < BUF_MODIFF (b)
|
|
4301 /* -1 means we've turned off autosaving for a while--see below. */
|
|
4302 && XINT (b->save_length) >= 0
|
|
4303 && (do_handled_files
|
|
4304 || NILP (Ffind_file_name_handler (b->auto_save_file_name,
|
|
4305 Qwrite_region))))
|
|
4306 {
|
|
4307 EMACS_TIME before_time, after_time;
|
|
4308
|
|
4309 EMACS_GET_TIME (before_time);
|
|
4310 /* If we had a failure, don't try again for 20 minutes. */
|
|
4311 if (!preparing_for_armageddon
|
|
4312 && b->auto_save_failure_time >= 0
|
|
4313 && (EMACS_SECS (before_time) - b->auto_save_failure_time <
|
|
4314 1200))
|
|
4315 continue;
|
|
4316
|
|
4317 if (!preparing_for_armageddon &&
|
|
4318 (XINT (b->save_length) * 10
|
|
4319 > (BUF_Z (b) - BUF_BEG (b)) * 13)
|
|
4320 /* A short file is likely to change a large fraction;
|
|
4321 spare the user annoying messages. */
|
|
4322 && XINT (b->save_length) > 5000
|
|
4323 /* These messages are frequent and annoying for `*mail*'. */
|
|
4324 && !EQ (b->filename, Qnil)
|
|
4325 && NILP (no_message)
|
|
4326 && disable_auto_save_when_buffer_shrinks)
|
|
4327 {
|
|
4328 /* It has shrunk too much; turn off auto-saving here.
|
|
4329 Unless we're about to crash, in which case auto-save it
|
|
4330 anyway.
|
|
4331 */
|
|
4332 message
|
|
4333 ("Buffer %s has shrunk a lot; auto save turned off there",
|
16
|
4334 XSTRING_DATA (b->name));
|
0
|
4335 /* Turn off auto-saving until there's a real save,
|
|
4336 and prevent any more warnings. */
|
|
4337 b->save_length = make_int (-1);
|
|
4338 if (!gc_in_progress)
|
|
4339 Fsleep_for (make_int (1));
|
|
4340 continue;
|
|
4341 }
|
|
4342 set_buffer_internal (b);
|
|
4343 if (!auto_saved && GC_NILP (no_message))
|
|
4344 {
|
|
4345 static CONST unsigned char *msg
|
|
4346 = (CONST unsigned char *) "Auto-saving...";
|
|
4347 echo_area_message (selected_frame (), msg, Qnil,
|
|
4348 0, strlen ((CONST char *) msg),
|
|
4349 Qauto_saving);
|
|
4350 }
|
|
4351
|
|
4352 /* Open the auto-save list file, if necessary.
|
|
4353 We only do this now so that the file only exists
|
|
4354 if we actually auto-saved any files. */
|
|
4355 if (!auto_saved && GC_STRINGP (listfile) && listdesc < 0)
|
|
4356 {
|
|
4357 #ifdef DOS_NT
|
16
|
4358 listdesc = open ((char *) XSTRING_DATA (listfile),
|
0
|
4359 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
|
|
4360 S_IREAD | S_IWRITE);
|
|
4361 #else /* not DOS_NT */
|
16
|
4362 listdesc = creat ((char *) XSTRING_DATA (listfile), 0666);
|
0
|
4363 #endif /* not DOS_NT */
|
|
4364
|
|
4365 /* Arrange to close that file whether or not we get
|
|
4366 an error. */
|
|
4367 if (listdesc >= 0)
|
|
4368 record_unwind_protect (do_auto_save_unwind,
|
|
4369 make_int (listdesc));
|
|
4370 }
|
|
4371
|
|
4372 /* Record all the buffers that we are auto-saving in
|
|
4373 the special file that lists them. For each of
|
|
4374 these buffers, record visited name (if any) and
|
|
4375 auto save name. */
|
|
4376 if (listdesc >= 0)
|
|
4377 {
|
|
4378 Extbyte *auto_save_file_name_ext;
|
|
4379 Extcount auto_save_file_name_ext_len;
|
|
4380
|
|
4381 GET_STRING_FILENAME_DATA_ALLOCA
|
|
4382 (b->auto_save_file_name,
|
|
4383 auto_save_file_name_ext,
|
|
4384 auto_save_file_name_ext_len);
|
|
4385 if (!NILP (b->filename))
|
|
4386 {
|
|
4387 Extbyte *filename_ext;
|
|
4388 Extcount filename_ext_len;
|
|
4389
|
|
4390 GET_STRING_FILENAME_DATA_ALLOCA (b->filename,
|
|
4391 filename_ext,
|
|
4392 filename_ext_len);
|
|
4393 write (listdesc, filename_ext, filename_ext_len);
|
|
4394 }
|
|
4395 write (listdesc, "\n", 1);
|
|
4396 write (listdesc, auto_save_file_name_ext,
|
|
4397 auto_save_file_name_ext_len);
|
|
4398 write (listdesc, "\n", 1);
|
|
4399 }
|
|
4400
|
32
|
4401 /* dmoore - In a bad scenario we've set b=XBUFFER(buf)
|
|
4402 based on values in Vbuffer_alist. auto_save_1 may
|
|
4403 cause lisp handlers to run. Those handlers may kill
|
|
4404 the buffer and then GC. Since the buffer is killed,
|
|
4405 it's no longer in Vbuffer_alist so it might get reaped
|
|
4406 by the GC. We also need to protect tail. */
|
|
4407 /* #### There is probably a lot of other code which has
|
|
4408 pointers into buffers which may get blown away by
|
|
4409 handlers. */
|
|
4410 {
|
|
4411 struct gcpro gcpro1, gcpro2;
|
|
4412 GCPRO2 (buf, tail);
|
|
4413 condition_case_1 (Qt,
|
|
4414 auto_save_1, Qnil,
|
|
4415 auto_save_error, Qnil);
|
|
4416 UNGCPRO;
|
|
4417 }
|
|
4418 /* Handler killed our saved current-buffer! Pick any. */
|
|
4419 if (!BUFFER_LIVE_P (XBUFFER (old)))
|
|
4420 XSETBUFFER (old, current_buffer);
|
|
4421
|
|
4422 set_buffer_internal (XBUFFER (old));
|
0
|
4423 auto_saved++;
|
32
|
4424
|
|
4425 /* Handler killed their own buffer! */
|
|
4426 if (!BUFFER_LIVE_P(b))
|
|
4427 continue;
|
|
4428
|
0
|
4429 b->auto_save_modified = BUF_MODIFF (b);
|
|
4430 b->save_length = make_int (BUF_SIZE (b));
|
|
4431 EMACS_GET_TIME (after_time);
|
|
4432 /* If auto-save took more than 60 seconds,
|
|
4433 assume it was an NFS failure that got a timeout. */
|
|
4434 if (EMACS_SECS (after_time) - EMACS_SECS (before_time) > 60)
|
|
4435 b->auto_save_failure_time = EMACS_SECS (after_time);
|
|
4436 }
|
|
4437 }
|
|
4438 }
|
|
4439
|
|
4440 /* Prevent another auto save till enough input events come in. */
|
|
4441 if (auto_saved)
|
|
4442 record_auto_save ();
|
|
4443
|
|
4444 /* If we didn't save anything into the listfile, remove the old
|
|
4445 one because nothing needed to be auto-saved. Do this afterwards
|
|
4446 rather than before in case we get a crash attempting to autosave
|
|
4447 (in that case we'd still want the old one around). */
|
|
4448 if (listdesc < 0 && !auto_saved && GC_STRINGP (listfile))
|
16
|
4449 unlink ((char *) XSTRING_DATA (listfile));
|
0
|
4450
|
|
4451 /* Show "...done" only if the echo area would otherwise be empty. */
|
|
4452 if (auto_saved && NILP (no_message)
|
|
4453 && NILP (clear_echo_area (selected_frame (), Qauto_saving, 0)))
|
|
4454 {
|
|
4455 static CONST unsigned char *msg
|
|
4456 = (CONST unsigned char *)"Auto-saving...done";
|
|
4457 echo_area_message (selected_frame (), msg, Qnil, 0,
|
|
4458 strlen ((CONST char *) msg), Qauto_saving);
|
|
4459 }
|
|
4460
|
|
4461 Vquit_flag = oquit;
|
|
4462
|
|
4463 RETURN_UNGCPRO (unbind_to (speccount, Qnil));
|
|
4464 }
|
|
4465
|
20
|
4466 DEFUN ("set-buffer-auto-saved", Fset_buffer_auto_saved, 0, 0, 0, /*
|
0
|
4467 Mark current buffer as auto-saved with its current text.
|
|
4468 No auto-save file will be written until the buffer changes again.
|
20
|
4469 */
|
|
4470 ())
|
0
|
4471 {
|
|
4472 current_buffer->auto_save_modified = BUF_MODIFF (current_buffer);
|
|
4473 current_buffer->save_length = make_int (BUF_SIZE (current_buffer));
|
|
4474 current_buffer->auto_save_failure_time = -1;
|
|
4475 return Qnil;
|
|
4476 }
|
|
4477
|
20
|
4478 DEFUN ("clear-buffer-auto-save-failure", Fclear_buffer_auto_save_failure, 0, 0, 0, /*
|
0
|
4479 Clear any record of a recent auto-save failure in the current buffer.
|
20
|
4480 */
|
|
4481 ())
|
0
|
4482 {
|
|
4483 current_buffer->auto_save_failure_time = -1;
|
|
4484 return Qnil;
|
|
4485 }
|
|
4486
|
20
|
4487 DEFUN ("recent-auto-save-p", Frecent_auto_save_p, 0, 0, 0, /*
|
0
|
4488 Return t if buffer has been auto-saved since last read in or saved.
|
20
|
4489 */
|
|
4490 ())
|
0
|
4491 {
|
|
4492 return (BUF_SAVE_MODIFF (current_buffer) <
|
|
4493 current_buffer->auto_save_modified) ? Qt : Qnil;
|
|
4494 }
|
|
4495
|
|
4496
|
|
4497 /************************************************************************/
|
|
4498 /* initialization */
|
|
4499 /************************************************************************/
|
|
4500
|
|
4501 void
|
|
4502 syms_of_fileio (void)
|
|
4503 {
|
|
4504 defsymbol (&Qexpand_file_name, "expand-file-name");
|
|
4505 defsymbol (&Qfile_truename, "file-truename");
|
|
4506 defsymbol (&Qsubstitute_in_file_name, "substitute-in-file-name");
|
|
4507 defsymbol (&Qdirectory_file_name, "directory-file-name");
|
|
4508 defsymbol (&Qfile_name_directory, "file-name-directory");
|
|
4509 defsymbol (&Qfile_name_nondirectory, "file-name-nondirectory");
|
|
4510 defsymbol (&Qunhandled_file_name_directory, "unhandled-file-name-directory");
|
|
4511 defsymbol (&Qfile_name_as_directory, "file-name-as-directory");
|
|
4512 defsymbol (&Qcopy_file, "copy-file");
|
|
4513 defsymbol (&Qmake_directory_internal, "make-directory-internal");
|
|
4514 defsymbol (&Qdelete_directory, "delete-directory");
|
|
4515 defsymbol (&Qdelete_file, "delete-file");
|
|
4516 defsymbol (&Qrename_file, "rename-file");
|
|
4517 defsymbol (&Qadd_name_to_file, "add-name-to-file");
|
|
4518 defsymbol (&Qmake_symbolic_link, "make-symbolic-link");
|
|
4519 defsymbol (&Qfile_exists_p, "file-exists-p");
|
|
4520 defsymbol (&Qfile_executable_p, "file-executable-p");
|
|
4521 defsymbol (&Qfile_readable_p, "file-readable-p");
|
|
4522 defsymbol (&Qfile_symlink_p, "file-symlink-p");
|
|
4523 defsymbol (&Qfile_writable_p, "file-writable-p");
|
|
4524 defsymbol (&Qfile_directory_p, "file-directory-p");
|
|
4525 defsymbol (&Qfile_regular_p, "file-regular-p");
|
|
4526 defsymbol (&Qfile_accessible_directory_p, "file-accessible-directory-p");
|
|
4527 defsymbol (&Qfile_modes, "file-modes");
|
|
4528 defsymbol (&Qset_file_modes, "set-file-modes");
|
|
4529 defsymbol (&Qfile_newer_than_file_p, "file-newer-than-file-p");
|
|
4530 defsymbol (&Qinsert_file_contents, "insert-file-contents");
|
|
4531 defsymbol (&Qwrite_region, "write-region");
|
|
4532 defsymbol (&Qverify_visited_file_modtime, "verify-visited-file-modtime");
|
|
4533 defsymbol (&Qset_visited_file_modtime, "set-visited-file-modtime");
|
|
4534 defsymbol (&Qset_buffer_modtime, "set-buffer-modtime");
|
|
4535 #ifdef DOS_NT
|
|
4536 defsymbol (&Qfind_buffer_file_type, "find-buffer-file-type");
|
|
4537 #endif /* DOS_NT */
|
|
4538 defsymbol (&Qcar_less_than_car, "car-less-than-car"); /* Vomitous! */
|
|
4539
|
|
4540 defsymbol (&Qfile_name_handler_alist, "file-name-handler-alist");
|
|
4541 defsymbol (&Qauto_save_hook, "auto-save-hook");
|
|
4542 defsymbol (&Qauto_save_error, "auto-save-error");
|
|
4543 defsymbol (&Qauto_saving, "auto-saving");
|
|
4544
|
|
4545 defsymbol (&Qformat_decode, "format-decode");
|
|
4546 defsymbol (&Qformat_annotate_function, "format-annotate-function");
|
|
4547
|
|
4548 defsymbol (&Qcompute_buffer_file_truename, "compute-buffer-file-truename");
|
|
4549 deferror (&Qfile_error, "file-error", "File error", Qio_error);
|
|
4550 deferror (&Qfile_already_exists, "file-already-exists",
|
|
4551 "File already exists", Qfile_error);
|
|
4552
|
20
|
4553 DEFSUBR (Ffind_file_name_handler);
|
|
4554
|
|
4555 DEFSUBR (Ffile_name_directory);
|
|
4556 DEFSUBR (Ffile_name_nondirectory);
|
|
4557 DEFSUBR (Funhandled_file_name_directory);
|
|
4558 DEFSUBR (Ffile_name_as_directory);
|
|
4559 DEFSUBR (Fdirectory_file_name);
|
|
4560 DEFSUBR (Fmake_temp_name);
|
|
4561 DEFSUBR (Fexpand_file_name);
|
|
4562 DEFSUBR (Ffile_truename);
|
|
4563 DEFSUBR (Fsubstitute_in_file_name);
|
|
4564 DEFSUBR (Fcopy_file);
|
|
4565 DEFSUBR (Fmake_directory_internal);
|
|
4566 DEFSUBR (Fdelete_directory);
|
|
4567 DEFSUBR (Fdelete_file);
|
|
4568 DEFSUBR (Frename_file);
|
|
4569 DEFSUBR (Fadd_name_to_file);
|
0
|
4570 #ifdef S_IFLNK
|
20
|
4571 DEFSUBR (Fmake_symbolic_link);
|
0
|
4572 #endif /* S_IFLNK */
|
|
4573 #ifdef VMS
|
20
|
4574 DEFSUBR (Fdefine_logical_name);
|
0
|
4575 #endif /* VMS */
|
|
4576 #ifdef HPUX_NET
|
20
|
4577 DEFSUBR (Fsysnetunam);
|
0
|
4578 #endif /* HPUX_NET */
|
20
|
4579 DEFSUBR (Ffile_name_absolute_p);
|
|
4580 DEFSUBR (Ffile_exists_p);
|
|
4581 DEFSUBR (Ffile_executable_p);
|
|
4582 DEFSUBR (Ffile_readable_p);
|
|
4583 DEFSUBR (Ffile_writable_p);
|
|
4584 DEFSUBR (Ffile_symlink_p);
|
|
4585 DEFSUBR (Ffile_directory_p);
|
|
4586 DEFSUBR (Ffile_accessible_directory_p);
|
|
4587 DEFSUBR (Ffile_regular_p);
|
|
4588 DEFSUBR (Ffile_modes);
|
|
4589 DEFSUBR (Fset_file_modes);
|
|
4590 DEFSUBR (Fset_default_file_modes);
|
|
4591 DEFSUBR (Fdefault_file_modes);
|
|
4592 DEFSUBR (Funix_sync);
|
|
4593 DEFSUBR (Ffile_newer_than_file_p);
|
|
4594 DEFSUBR (Finsert_file_contents_internal);
|
|
4595 DEFSUBR (Fwrite_region_internal);
|
|
4596 DEFSUBR (Fcar_less_than_car); /* Vomitous! */
|
|
4597 DEFSUBR (Fcdr_less_than_cdr); /* Yeah oh yeah bucko .... */
|
0
|
4598 #if 0
|
20
|
4599 DEFSUBR (Fencrypt_string);
|
|
4600 DEFSUBR (Fdecrypt_string);
|
0
|
4601 #endif
|
20
|
4602 DEFSUBR (Fverify_visited_file_modtime);
|
|
4603 DEFSUBR (Fclear_visited_file_modtime);
|
|
4604 DEFSUBR (Fvisited_file_modtime);
|
|
4605 DEFSUBR (Fset_visited_file_modtime);
|
|
4606 DEFSUBR (Fset_buffer_modtime);
|
|
4607
|
|
4608 DEFSUBR (Fdo_auto_save);
|
|
4609 DEFSUBR (Fset_buffer_auto_saved);
|
|
4610 DEFSUBR (Fclear_buffer_auto_save_failure);
|
|
4611 DEFSUBR (Frecent_auto_save_p);
|
0
|
4612 }
|
|
4613
|
|
4614 void
|
|
4615 vars_of_fileio (void)
|
|
4616 {
|
|
4617 DEFVAR_LISP ("auto-save-file-format", &Vauto_save_file_format /*
|
|
4618 *Format in which to write auto-save files.
|
|
4619 Should be a list of symbols naming formats that are defined in `format-alist'.
|
|
4620 If it is t, which is the default, auto-save files are written in the
|
|
4621 same format as a regular save would use.
|
|
4622 */ );
|
|
4623 Vauto_save_file_format = Qt;
|
|
4624
|
|
4625 DEFVAR_BOOL ("vms-stmlf-recfm", &vms_stmlf_recfm /*
|
|
4626 *Non-nil means write new files with record format `stmlf'.
|
|
4627 nil means use format `var'. This variable is meaningful only on VMS.
|
|
4628 */ );
|
|
4629 vms_stmlf_recfm = 0;
|
|
4630
|
|
4631 DEFVAR_LISP ("file-name-handler-alist", &Vfile_name_handler_alist /*
|
|
4632 *Alist of elements (REGEXP . HANDLER) for file names handled specially.
|
|
4633 If a file name matches REGEXP, then all I/O on that file is done by calling
|
|
4634 HANDLER.
|
|
4635
|
|
4636 The first argument given to HANDLER is the name of the I/O primitive
|
|
4637 to be handled; the remaining arguments are the arguments that were
|
|
4638 passed to that primitive. For example, if you do
|
|
4639 (file-exists-p FILENAME)
|
|
4640 and FILENAME is handled by HANDLER, then HANDLER is called like this:
|
|
4641 (funcall HANDLER 'file-exists-p FILENAME)
|
|
4642 The function `find-file-name-handler' checks this list for a handler
|
|
4643 for its argument.
|
|
4644 */ );
|
|
4645 Vfile_name_handler_alist = Qnil;
|
|
4646
|
|
4647 DEFVAR_LISP ("after-insert-file-functions", &Vafter_insert_file_functions /*
|
|
4648 A list of functions to be called at the end of `insert-file-contents'.
|
|
4649 Each is passed one argument, the number of bytes inserted. It should return
|
|
4650 the new byte count, and leave point the same. If `insert-file-contents' is
|
|
4651 intercepted by a handler from `file-name-handler-alist', that handler is
|
|
4652 responsible for calling the after-insert-file-functions if appropriate.
|
|
4653 */ );
|
|
4654 Vafter_insert_file_functions = Qnil;
|
|
4655
|
|
4656 DEFVAR_LISP ("write-region-annotate-functions",
|
|
4657 &Vwrite_region_annotate_functions /*
|
|
4658 A list of functions to be called at the start of `write-region'.
|
|
4659 Each is passed two arguments, START and END as for `write-region'.
|
|
4660 It should return a list of pairs (POSITION . STRING) of strings to be
|
|
4661 effectively inserted at the specified positions of the file being written
|
|
4662 \(1 means to insert before the first byte written). The POSITIONs must be
|
|
4663 sorted into increasing order. If there are several functions in the list,
|
|
4664 the several lists are merged destructively.
|
|
4665 */ );
|
|
4666 Vwrite_region_annotate_functions = Qnil;
|
|
4667
|
|
4668 DEFVAR_LISP ("write-region-annotations-so-far",
|
|
4669 &Vwrite_region_annotations_so_far /*
|
|
4670 When an annotation function is called, this holds the previous annotations.
|
|
4671 These are the annotations made by other annotation functions
|
|
4672 that were already called. See also `write-region-annotate-functions'.
|
|
4673 */ );
|
|
4674 Vwrite_region_annotations_so_far = Qnil;
|
|
4675
|
|
4676 DEFVAR_LISP ("inhibit-file-name-handlers", &Vinhibit_file_name_handlers /*
|
|
4677 A list of file name handlers that temporarily should not be used.
|
|
4678 This applies only to the operation `inhibit-file-name-operation'.
|
|
4679 */ );
|
|
4680 Vinhibit_file_name_handlers = Qnil;
|
|
4681
|
|
4682 DEFVAR_LISP ("inhibit-file-name-operation", &Vinhibit_file_name_operation /*
|
|
4683 The operation for which `inhibit-file-name-handlers' is applicable.
|
|
4684 */ );
|
|
4685 Vinhibit_file_name_operation = Qnil;
|
|
4686
|
|
4687 DEFVAR_LISP ("auto-save-list-file-name", &Vauto_save_list_file_name /*
|
|
4688 File name in which we write a list of all auto save file names.
|
|
4689 */ );
|
|
4690 Vauto_save_list_file_name = Qnil;
|
|
4691
|
|
4692 DEFVAR_BOOL ("disable-auto-save-when-buffer-shrinks",
|
|
4693 &disable_auto_save_when_buffer_shrinks /*
|
|
4694 If non-nil, auto-saving is disabled when a buffer shrinks too much.
|
|
4695 This is to prevent you from losing your edits if you accidentally
|
|
4696 delete a large chunk of the buffer and don't notice it until too late.
|
|
4697 Saving the buffer normally turns auto-save back on.
|
|
4698 */ );
|
|
4699 disable_auto_save_when_buffer_shrinks = 1;
|
|
4700 }
|