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