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