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