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