Mercurial > emacs
annotate src/fileio.c @ 5520:66bda5c15609
Add #undef HAVE_STRERROR.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Sat, 08 Jan 1994 21:39:04 +0000 |
parents | 8b2b6a296cda |
children | 708b422cf8df |
rev | line source |
---|---|
230 | 1 /* File IO for GNU Emacs. |
5517
8b2b6a296cda
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
5494
diff
changeset
|
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994 Free Software Foundation, Inc. |
230 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
621 | 8 the Free Software Foundation; either version 2, or (at your option) |
230 | 9 any later version. |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4483
diff
changeset
|
20 #include <config.h> |
230 | 21 |
22 #include <sys/types.h> | |
23 #include <sys/stat.h> | |
372 | 24 |
4879
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
25 #if !defined (S_ISLNK) && defined (S_IFLNK) |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
26 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
27 #endif |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
28 |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
29 #if !defined (S_ISREG) && defined (S_IFREG) |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
30 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
31 #endif |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
32 |
372 | 33 #ifdef VMS |
564 | 34 #include "vms-pwd.h" |
372 | 35 #else |
230 | 36 #include <pwd.h> |
372 | 37 #endif |
38 | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
39 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
40 #include "msdos.h" |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
41 #include <sys/param.h> |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
42 #endif |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
43 |
230 | 44 #include <ctype.h> |
372 | 45 |
46 #ifdef VMS | |
47 #include "dir.h" | |
48 #include <perror.h> | |
49 #include <stddef.h> | |
50 #include <string.h> | |
51 #endif | |
52 | |
230 | 53 #include <errno.h> |
54 | |
372 | 55 #ifndef vax11c |
230 | 56 extern int errno; |
57 #endif | |
58 | |
5517
8b2b6a296cda
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
5494
diff
changeset
|
59 extern char *strerror (); |
230 | 60 |
61 #ifdef APOLLO | |
62 #include <sys/time.h> | |
63 #endif | |
64 | |
2280
bd56d208ed22
* fileio.c (HAVE_FSYNC): Define, if appropriate.
Jim Blandy <jimb@redhat.com>
parents:
2257
diff
changeset
|
65 #ifndef USG |
bd56d208ed22
* fileio.c (HAVE_FSYNC): Define, if appropriate.
Jim Blandy <jimb@redhat.com>
parents:
2257
diff
changeset
|
66 #ifndef VMS |
bd56d208ed22
* fileio.c (HAVE_FSYNC): Define, if appropriate.
Jim Blandy <jimb@redhat.com>
parents:
2257
diff
changeset
|
67 #ifndef BSD4_1 |
bd56d208ed22
* fileio.c (HAVE_FSYNC): Define, if appropriate.
Jim Blandy <jimb@redhat.com>
parents:
2257
diff
changeset
|
68 #define HAVE_FSYNC |
bd56d208ed22
* fileio.c (HAVE_FSYNC): Define, if appropriate.
Jim Blandy <jimb@redhat.com>
parents:
2257
diff
changeset
|
69 #endif |
bd56d208ed22
* fileio.c (HAVE_FSYNC): Define, if appropriate.
Jim Blandy <jimb@redhat.com>
parents:
2257
diff
changeset
|
70 #endif |
bd56d208ed22
* fileio.c (HAVE_FSYNC): Define, if appropriate.
Jim Blandy <jimb@redhat.com>
parents:
2257
diff
changeset
|
71 #endif |
bd56d208ed22
* fileio.c (HAVE_FSYNC): Define, if appropriate.
Jim Blandy <jimb@redhat.com>
parents:
2257
diff
changeset
|
72 |
230 | 73 #include "lisp.h" |
1299
b8337cdf2e8b
* fileio.c (Finsert_file_contents): Call offset_intervals() if
Joseph Arceneaux <jla@gnu.org>
parents:
1240
diff
changeset
|
74 #include "intervals.h" |
230 | 75 #include "buffer.h" |
76 #include "window.h" | |
77 | |
78 #ifdef VMS | |
79 #include <file.h> | |
80 #include <rmsdef.h> | |
81 #include <fab.h> | |
82 #include <nam.h> | |
83 #endif | |
84 | |
564 | 85 #include "systime.h" |
230 | 86 |
87 #ifdef HPUX | |
88 #include <netio.h> | |
350 | 89 #ifndef HPUX8 |
3410
47b51faf6c4e
[HPUX9]: Don't include errnet.h.
Richard M. Stallman <rms@gnu.org>
parents:
3032
diff
changeset
|
90 #ifndef HPUX9 |
230 | 91 #include <errnet.h> |
92 #endif | |
350 | 93 #endif |
3410
47b51faf6c4e
[HPUX9]: Don't include errnet.h.
Richard M. Stallman <rms@gnu.org>
parents:
3032
diff
changeset
|
94 #endif |
230 | 95 |
96 #ifndef O_WRONLY | |
97 #define O_WRONLY 1 | |
98 #endif | |
99 | |
100 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
101 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
102 | |
103 /* Nonzero during writing of auto-save files */ | |
104 int auto_saving; | |
105 | |
106 /* Set by auto_save_1 to mode of original file so Fwrite_region will create | |
107 a new file with the same mode as the original */ | |
108 int auto_save_mode_bits; | |
109 | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
110 /* Alist of elements (REGEXP . HANDLER) for file names |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
111 whose I/O is done with a special handler. */ |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
112 Lisp_Object Vfile_name_handler_alist; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
113 |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
114 /* Functions to be called to process text properties in inserted file. */ |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
115 Lisp_Object Vafter_insert_file_functions; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
116 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
117 /* Functions to be called to create text property annotations for file. */ |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
118 Lisp_Object Vwrite_region_annotate_functions; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
119 |
230 | 120 /* Nonzero means, when reading a filename in the minibuffer, |
121 start out by inserting the default directory into the minibuffer. */ | |
122 int insert_default_directory; | |
123 | |
124 /* On VMS, nonzero means write new files with record format stmlf. | |
125 Zero means use var format. */ | |
126 int vms_stmlf_recfm; | |
127 | |
128 Lisp_Object Qfile_error, Qfile_already_exists; | |
129 | |
863
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
130 Lisp_Object Qfile_name_history; |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
131 |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
132 Lisp_Object Qcar_less_than_car; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
133 |
230 | 134 report_file_error (string, data) |
135 char *string; | |
136 Lisp_Object data; | |
137 { | |
138 Lisp_Object errstring; | |
139 | |
140 if (errno >= 0 && errno < sys_nerr) | |
141 errstring = build_string (sys_errlist[errno]); | |
142 else | |
143 errstring = build_string ("undocumented error code"); | |
144 | |
145 /* System error messages are capitalized. Downcase the initial | |
146 unless it is followed by a slash. */ | |
147 if (XSTRING (errstring)->data[1] != '/') | |
148 XSTRING (errstring)->data[0] = DOWNCASE (XSTRING (errstring)->data[0]); | |
149 | |
150 while (1) | |
151 Fsignal (Qfile_error, | |
152 Fcons (build_string (string), Fcons (errstring, data))); | |
153 } | |
592
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
154 |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
155 close_file_unwind (fd) |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
156 Lisp_Object fd; |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
157 { |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
158 close (XFASTINT (fd)); |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
159 } |
230 | 160 |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
161 Lisp_Object Qexpand_file_name; |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
162 Lisp_Object Qdirectory_file_name; |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
163 Lisp_Object Qfile_name_directory; |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
164 Lisp_Object Qfile_name_nondirectory; |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
165 Lisp_Object Qunhandled_file_name_directory; |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
166 Lisp_Object Qfile_name_as_directory; |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
167 Lisp_Object Qcopy_file; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
168 Lisp_Object Qmake_directory; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
169 Lisp_Object Qdelete_directory; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
170 Lisp_Object Qdelete_file; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
171 Lisp_Object Qrename_file; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
172 Lisp_Object Qadd_name_to_file; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
173 Lisp_Object Qmake_symbolic_link; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
174 Lisp_Object Qfile_exists_p; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
175 Lisp_Object Qfile_executable_p; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
176 Lisp_Object Qfile_readable_p; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
177 Lisp_Object Qfile_symlink_p; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
178 Lisp_Object Qfile_writable_p; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
179 Lisp_Object Qfile_directory_p; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
180 Lisp_Object Qfile_accessible_directory_p; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
181 Lisp_Object Qfile_modes; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
182 Lisp_Object Qset_file_modes; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
183 Lisp_Object Qfile_newer_than_file_p; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
184 Lisp_Object Qinsert_file_contents; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
185 Lisp_Object Qwrite_region; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
186 Lisp_Object Qverify_visited_file_modtime; |
3560
95021dcb923b
(syms_of_fileio): Set up Qset_visited_file_modtime.
Richard M. Stallman <rms@gnu.org>
parents:
3415
diff
changeset
|
187 Lisp_Object Qset_visited_file_modtime; |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
188 |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
189 DEFUN ("find-file-name-handler", Ffind_file_name_handler, Sfind_file_name_handler, 1, 1, 0, |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
190 "Return FILENAME's handler function, if its syntax is handled specially.\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
191 Otherwise, return nil.\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
192 A file name is handled if one of the regular expressions in\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
193 `file-name-handler-alist' matches it.") |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
194 (filename) |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
195 Lisp_Object filename; |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
196 { |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
197 /* This function must not munge the match data. */ |
2897 | 198 Lisp_Object chain; |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
199 |
2895
1ed91566882a
* fileio.c (Ffind_file_name_handler): Check that FILENAME is a
Jim Blandy <jimb@redhat.com>
parents:
2741
diff
changeset
|
200 CHECK_STRING (filename, 0); |
1ed91566882a
* fileio.c (Ffind_file_name_handler): Check that FILENAME is a
Jim Blandy <jimb@redhat.com>
parents:
2741
diff
changeset
|
201 |
848 | 202 for (chain = Vfile_name_handler_alist; XTYPE (chain) == Lisp_Cons; |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
203 chain = XCONS (chain)->cdr) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
204 { |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
205 Lisp_Object elt; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
206 elt = XCONS (chain)->car; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
207 if (XTYPE (elt) == Lisp_Cons) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
208 { |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
209 Lisp_Object string; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
210 string = XCONS (elt)->car; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
211 if (XTYPE (string) == Lisp_String |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
212 && fast_string_match (string, filename) >= 0) |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
213 return XCONS (elt)->cdr; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
214 } |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
215 |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
216 QUIT; |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
217 } |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
218 return Qnil; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
219 } |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
220 |
230 | 221 DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, |
222 1, 1, 0, | |
223 "Return the directory component in file name NAME.\n\ | |
224 Return nil if NAME does not include a directory.\n\ | |
225 Otherwise return a directory spec.\n\ | |
226 Given a Unix syntax file name, returns a string ending in slash;\n\ | |
227 on VMS, perhaps instead a string ending in `:', `]' or `>'.") | |
228 (file) | |
229 Lisp_Object file; | |
230 { | |
231 register unsigned char *beg; | |
232 register unsigned char *p; | |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
233 Lisp_Object handler; |
230 | 234 |
235 CHECK_STRING (file, 0); | |
236 | |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
237 /* If the file name has special constructs in it, |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
238 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
239 handler = Ffind_file_name_handler (file); |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
240 if (!NILP (handler)) |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
241 return call2 (handler, Qfile_name_directory, file); |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
242 |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
243 #ifdef FILE_SYSTEM_CASE |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
244 file = FILE_SYSTEM_CASE (file); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
245 #endif |
230 | 246 beg = XSTRING (file)->data; |
247 p = beg + XSTRING (file)->size; | |
248 | |
249 while (p != beg && p[-1] != '/' | |
250 #ifdef VMS | |
251 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>' | |
252 #endif /* VMS */ | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
253 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
254 && p[-1] != ':' |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
255 #endif |
230 | 256 ) p--; |
257 | |
258 if (p == beg) | |
259 return Qnil; | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
260 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
261 /* Expansion of "c:" to drive and default directory. */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
262 if (p == beg + 2 && beg[1] == ':') |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
263 { |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
264 int drive = (*beg) - 'a'; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
265 /* MAXPATHLEN+1 is guaranteed to be enough space for getdefdir. */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
266 unsigned char *res = alloca (MAXPATHLEN + 5); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
267 if (getdefdir (drive + 1, res + 2)) |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
268 { |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
269 res[0] = drive + 'a'; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
270 res[1] = ':'; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
271 if (res[strlen (res) - 1] != '/') |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
272 strcat (res, "/"); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
273 beg = res; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
274 p = beg + strlen (beg); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
275 } |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
276 } |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
277 #endif |
230 | 278 return make_string (beg, p - beg); |
279 } | |
280 | |
281 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, Sfile_name_nondirectory, | |
282 1, 1, 0, | |
283 "Return file name NAME sans its directory.\n\ | |
284 For example, in a Unix-syntax file name,\n\ | |
285 this is everything after the last slash,\n\ | |
286 or the entire name if it contains no slash.") | |
287 (file) | |
288 Lisp_Object file; | |
289 { | |
290 register unsigned char *beg, *p, *end; | |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
291 Lisp_Object handler; |
230 | 292 |
293 CHECK_STRING (file, 0); | |
294 | |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
295 /* If the file name has special constructs in it, |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
296 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
297 handler = Ffind_file_name_handler (file); |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
298 if (!NILP (handler)) |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
299 return call2 (handler, Qfile_name_nondirectory, file); |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
300 |
230 | 301 beg = XSTRING (file)->data; |
302 end = p = beg + XSTRING (file)->size; | |
303 | |
304 while (p != beg && p[-1] != '/' | |
305 #ifdef VMS | |
306 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>' | |
307 #endif /* VMS */ | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
308 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
309 && p[-1] != ':' |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
310 #endif |
230 | 311 ) p--; |
312 | |
313 return make_string (p, end - p); | |
314 } | |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
315 |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
316 DEFUN ("unhandled-file-name-directory", Funhandled_file_name_directory, Sunhandled_file_name_directory, 1, 1, 0, |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
317 "Return a directly usable directory name somehow associated with FILENAME.\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
318 A `directly usable' directory name is one that may be used without the\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
319 intervention of any file handler.\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
320 If FILENAME is a directly usable file itself, return\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
321 (file-name-directory FILENAME).\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
322 The `call-process' and `start-process' functions use this function to\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
323 get a current directory to run processes in.") |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
324 (filename) |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
325 Lisp_Object filename; |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
326 { |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
327 Lisp_Object handler; |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
328 |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
329 /* If the file name has special constructs in it, |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
330 call the corresponding file handler. */ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
331 handler = Ffind_file_name_handler (filename); |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
332 if (!NILP (handler)) |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
333 return call2 (handler, Qunhandled_file_name_directory, filename); |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
334 |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
335 return Ffile_name_directory (filename); |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
336 } |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
337 |
230 | 338 |
339 char * | |
340 file_name_as_directory (out, in) | |
341 char *out, *in; | |
342 { | |
343 int size = strlen (in) - 1; | |
344 | |
345 strcpy (out, in); | |
346 | |
347 #ifdef VMS | |
348 /* Is it already a directory string? */ | |
349 if (in[size] == ':' || in[size] == ']' || in[size] == '>') | |
350 return out; | |
351 /* Is it a VMS directory file name? If so, hack VMS syntax. */ | |
352 else if (! index (in, '/') | |
353 && ((size > 3 && ! strcmp (&in[size - 3], ".DIR")) | |
354 || (size > 3 && ! strcmp (&in[size - 3], ".dir")) | |
355 || (size > 5 && (! strncmp (&in[size - 5], ".DIR", 4) | |
356 || ! strncmp (&in[size - 5], ".dir", 4)) | |
357 && (in[size - 1] == '.' || in[size - 1] == ';') | |
358 && in[size] == '1'))) | |
359 { | |
360 register char *p, *dot; | |
361 char brack; | |
362 | |
363 /* x.dir -> [.x] | |
364 dir:x.dir --> dir:[x] | |
365 dir:[x]y.dir --> dir:[x.y] */ | |
366 p = in + size; | |
367 while (p != in && *p != ':' && *p != '>' && *p != ']') p--; | |
368 if (p != in) | |
369 { | |
370 strncpy (out, in, p - in); | |
371 out[p - in] = '\0'; | |
372 if (*p == ':') | |
373 { | |
374 brack = ']'; | |
375 strcat (out, ":["); | |
376 } | |
377 else | |
378 { | |
379 brack = *p; | |
380 strcat (out, "."); | |
381 } | |
382 p++; | |
383 } | |
384 else | |
385 { | |
386 brack = ']'; | |
387 strcpy (out, "[."); | |
388 } | |
372 | 389 dot = index (p, '.'); |
390 if (dot) | |
230 | 391 { |
392 /* blindly remove any extension */ | |
393 size = strlen (out) + (dot - p); | |
394 strncat (out, p, dot - p); | |
395 } | |
396 else | |
397 { | |
398 strcat (out, p); | |
399 size = strlen (out); | |
400 } | |
401 out[size++] = brack; | |
402 out[size] = '\0'; | |
403 } | |
404 #else /* not VMS */ | |
405 /* For Unix syntax, Append a slash if necessary */ | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
406 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
407 if (out[size] != ':' && out[size] != '/') |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
408 #else |
230 | 409 if (out[size] != '/') |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
410 #endif |
230 | 411 strcat (out, "/"); |
412 #endif /* not VMS */ | |
413 return out; | |
414 } | |
415 | |
416 DEFUN ("file-name-as-directory", Ffile_name_as_directory, | |
417 Sfile_name_as_directory, 1, 1, 0, | |
418 "Return a string representing file FILENAME interpreted as a directory.\n\ | |
419 This operation exists because a directory is also a file, but its name as\n\ | |
420 a directory is different from its name as a file.\n\ | |
421 The result can be used as the value of `default-directory'\n\ | |
422 or passed as second argument to `expand-file-name'.\n\ | |
423 For a Unix-syntax file name, just appends a slash.\n\ | |
424 On VMS, converts \"[X]FOO.DIR\" to \"[X.FOO]\", etc.") | |
425 (file) | |
426 Lisp_Object file; | |
427 { | |
428 char *buf; | |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
429 Lisp_Object handler; |
230 | 430 |
431 CHECK_STRING (file, 0); | |
485 | 432 if (NILP (file)) |
230 | 433 return Qnil; |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
434 |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
435 /* If the file name has special constructs in it, |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
436 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
437 handler = Ffind_file_name_handler (file); |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
438 if (!NILP (handler)) |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
439 return call2 (handler, Qfile_name_as_directory, file); |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
440 |
230 | 441 buf = (char *) alloca (XSTRING (file)->size + 10); |
442 return build_string (file_name_as_directory (buf, XSTRING (file)->data)); | |
443 } | |
444 | |
445 /* | |
446 * Convert from directory name to filename. | |
447 * On VMS: | |
448 * xyzzy:[mukesh.emacs] => xyzzy:[mukesh]emacs.dir.1 | |
449 * xyzzy:[mukesh] => xyzzy:[000000]mukesh.dir.1 | |
450 * On UNIX, it's simple: just make sure there is a terminating / | |
451 | |
452 * Value is nonzero if the string output is different from the input. | |
453 */ | |
454 | |
455 directory_file_name (src, dst) | |
456 char *src, *dst; | |
457 { | |
458 long slen; | |
459 #ifdef VMS | |
460 long rlen; | |
461 char * ptr, * rptr; | |
462 char bracket; | |
463 struct FAB fab = cc$rms_fab; | |
464 struct NAM nam = cc$rms_nam; | |
465 char esa[NAM$C_MAXRSS]; | |
466 #endif /* VMS */ | |
467 | |
468 slen = strlen (src); | |
469 #ifdef VMS | |
470 if (! index (src, '/') | |
471 && (src[slen - 1] == ']' | |
472 || src[slen - 1] == ':' | |
473 || src[slen - 1] == '>')) | |
474 { | |
475 /* VMS style - convert [x.y.z] to [x.y]z, [x] to [000000]x */ | |
476 fab.fab$l_fna = src; | |
477 fab.fab$b_fns = slen; | |
478 fab.fab$l_nam = &nam; | |
479 fab.fab$l_fop = FAB$M_NAM; | |
480 | |
481 nam.nam$l_esa = esa; | |
482 nam.nam$b_ess = sizeof esa; | |
483 nam.nam$b_nop |= NAM$M_SYNCHK; | |
484 | |
485 /* We call SYS$PARSE to handle such things as [--] for us. */ | |
486 if (SYS$PARSE(&fab, 0, 0) == RMS$_NORMAL) | |
487 { | |
488 slen = nam.nam$b_esl; | |
489 if (esa[slen - 1] == ';' && esa[slen - 2] == '.') | |
490 slen -= 2; | |
491 esa[slen] = '\0'; | |
492 src = esa; | |
493 } | |
494 if (src[slen - 1] != ']' && src[slen - 1] != '>') | |
495 { | |
496 /* what about when we have logical_name:???? */ | |
497 if (src[slen - 1] == ':') | |
498 { /* Xlate logical name and see what we get */ | |
499 ptr = strcpy (dst, src); /* upper case for getenv */ | |
500 while (*ptr) | |
501 { | |
502 if ('a' <= *ptr && *ptr <= 'z') | |
503 *ptr -= 040; | |
504 ptr++; | |
505 } | |
506 dst[slen - 1] = 0; /* remove colon */ | |
507 if (!(src = egetenv (dst))) | |
508 return 0; | |
509 /* should we jump to the beginning of this procedure? | |
510 Good points: allows us to use logical names that xlate | |
511 to Unix names, | |
512 Bad points: can be a problem if we just translated to a device | |
513 name... | |
514 For now, I'll punt and always expect VMS names, and hope for | |
515 the best! */ | |
516 slen = strlen (src); | |
517 if (src[slen - 1] != ']' && src[slen - 1] != '>') | |
518 { /* no recursion here! */ | |
519 strcpy (dst, src); | |
520 return 0; | |
521 } | |
522 } | |
523 else | |
524 { /* not a directory spec */ | |
525 strcpy (dst, src); | |
526 return 0; | |
527 } | |
528 } | |
529 bracket = src[slen - 1]; | |
530 | |
531 /* If bracket is ']' or '>', bracket - 2 is the corresponding | |
532 opening bracket. */ | |
372 | 533 ptr = index (src, bracket - 2); |
534 if (ptr == 0) | |
230 | 535 { /* no opening bracket */ |
536 strcpy (dst, src); | |
537 return 0; | |
538 } | |
539 if (!(rptr = rindex (src, '.'))) | |
540 rptr = ptr; | |
541 slen = rptr - src; | |
542 strncpy (dst, src, slen); | |
543 dst[slen] = '\0'; | |
544 if (*rptr == '.') | |
545 { | |
546 dst[slen++] = bracket; | |
547 dst[slen] = '\0'; | |
548 } | |
549 else | |
550 { | |
551 /* If we have the top-level of a rooted directory (i.e. xx:[000000]), | |
552 then translate the device and recurse. */ | |
553 if (dst[slen - 1] == ':' | |
554 && dst[slen - 2] != ':' /* skip decnet nodes */ | |
555 && strcmp(src + slen, "[000000]") == 0) | |
556 { | |
557 dst[slen - 1] = '\0'; | |
558 if ((ptr = egetenv (dst)) | |
559 && (rlen = strlen (ptr) - 1) > 0 | |
560 && (ptr[rlen] == ']' || ptr[rlen] == '>') | |
561 && ptr[rlen - 1] == '.') | |
562 { | |
1358
aa32c275cbf9
(directory_file_name): Don't clobber the envvar
Richard M. Stallman <rms@gnu.org>
parents:
1299
diff
changeset
|
563 char * buf = (char *) alloca (strlen (ptr) + 1); |
aa32c275cbf9
(directory_file_name): Don't clobber the envvar
Richard M. Stallman <rms@gnu.org>
parents:
1299
diff
changeset
|
564 strcpy (buf, ptr); |
aa32c275cbf9
(directory_file_name): Don't clobber the envvar
Richard M. Stallman <rms@gnu.org>
parents:
1299
diff
changeset
|
565 buf[rlen - 1] = ']'; |
aa32c275cbf9
(directory_file_name): Don't clobber the envvar
Richard M. Stallman <rms@gnu.org>
parents:
1299
diff
changeset
|
566 buf[rlen] = '\0'; |
aa32c275cbf9
(directory_file_name): Don't clobber the envvar
Richard M. Stallman <rms@gnu.org>
parents:
1299
diff
changeset
|
567 return directory_file_name (buf, dst); |
230 | 568 } |
569 else | |
570 dst[slen - 1] = ':'; | |
571 } | |
572 strcat (dst, "[000000]"); | |
573 slen += 8; | |
574 } | |
575 rptr++; | |
576 rlen = strlen (rptr) - 1; | |
577 strncat (dst, rptr, rlen); | |
578 dst[slen + rlen] = '\0'; | |
579 strcat (dst, ".DIR.1"); | |
580 return 1; | |
581 } | |
582 #endif /* VMS */ | |
583 /* Process as Unix format: just remove any final slash. | |
584 But leave "/" unchanged; do not change it to "". */ | |
585 strcpy (dst, src); | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
586 if (slen > 1 |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
587 && dst[slen - 1] == '/' |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
588 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
589 && dst[slen - 2] != ':' |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
590 #endif |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
591 ) |
230 | 592 dst[slen - 1] = 0; |
593 return 1; | |
594 } | |
595 | |
596 DEFUN ("directory-file-name", Fdirectory_file_name, Sdirectory_file_name, | |
597 1, 1, 0, | |
598 "Returns the file name of the directory named DIR.\n\ | |
599 This is the name of the file that holds the data for the directory DIR.\n\ | |
600 This operation exists because a directory is also a file, but its name as\n\ | |
601 a directory is different from its name as a file.\n\ | |
602 In Unix-syntax, this function just removes the final slash.\n\ | |
603 On VMS, given a VMS-syntax directory name such as \"[X.Y]\",\n\ | |
604 it returns a file name such as \"[X]Y.DIR.1\".") | |
605 (directory) | |
606 Lisp_Object directory; | |
607 { | |
608 char *buf; | |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
609 Lisp_Object handler; |
230 | 610 |
611 CHECK_STRING (directory, 0); | |
612 | |
485 | 613 if (NILP (directory)) |
230 | 614 return Qnil; |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
615 |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
616 /* If the file name has special constructs in it, |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
617 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
618 handler = Ffind_file_name_handler (directory); |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
619 if (!NILP (handler)) |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
620 return call2 (handler, Qdirectory_file_name, directory); |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
621 |
230 | 622 #ifdef VMS |
623 /* 20 extra chars is insufficient for VMS, since we might perform a | |
624 logical name translation. an equivalence string can be up to 255 | |
625 chars long, so grab that much extra space... - sss */ | |
626 buf = (char *) alloca (XSTRING (directory)->size + 20 + 255); | |
627 #else | |
628 buf = (char *) alloca (XSTRING (directory)->size + 20); | |
629 #endif | |
630 directory_file_name (XSTRING (directory)->data, buf); | |
631 return build_string (buf); | |
632 } | |
633 | |
634 DEFUN ("make-temp-name", Fmake_temp_name, Smake_temp_name, 1, 1, 0, | |
635 "Generate temporary file name (string) starting with PREFIX (a string).\n\ | |
636 The Emacs process number forms part of the result,\n\ | |
637 so there is no danger of generating a name being used by another process.") | |
638 (prefix) | |
639 Lisp_Object prefix; | |
640 { | |
641 Lisp_Object val; | |
642 val = concat2 (prefix, build_string ("XXXXXX")); | |
643 mktemp (XSTRING (val)->data); | |
644 return val; | |
645 } | |
646 | |
647 DEFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, | |
648 "Convert FILENAME to absolute, and canonicalize it.\n\ | |
649 Second arg DEFAULT is directory to start with if FILENAME is relative\n\ | |
650 (does not start with slash); if DEFAULT is nil or missing,\n\ | |
651 the current buffer's value of default-directory is used.\n\ | |
536 | 652 Path components that are `.' are removed, and \n\ |
653 path components followed by `..' are removed, along with the `..' itself;\n\ | |
654 note that these simplifications are done without checking the resulting\n\ | |
655 paths in the file system.\n\ | |
656 An initial `~/' expands to your home directory.\n\ | |
657 An initial `~USER/' expands to USER's home directory.\n\ | |
230 | 658 See also the function `substitute-in-file-name'.") |
659 (name, defalt) | |
660 Lisp_Object name, defalt; | |
661 { | |
662 unsigned char *nm; | |
663 | |
664 register unsigned char *newdir, *p, *o; | |
665 int tlen; | |
666 unsigned char *target; | |
667 struct passwd *pw; | |
668 #ifdef VMS | |
669 unsigned char * colon = 0; | |
670 unsigned char * close = 0; | |
671 unsigned char * slash = 0; | |
672 unsigned char * brack = 0; | |
673 int lbrack = 0, rbrack = 0; | |
674 int dots = 0; | |
675 #endif /* VMS */ | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
676 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
677 int drive = -1; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
678 int relpath = 0; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
679 unsigned char *tmp, *defdir; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
680 #endif |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
681 Lisp_Object handler; |
230 | 682 |
683 CHECK_STRING (name, 0); | |
684 | |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
685 /* If the file name has special constructs in it, |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
686 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
687 handler = Ffind_file_name_handler (name); |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
688 if (!NILP (handler)) |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
689 return call3 (handler, Qexpand_file_name, name, defalt); |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
690 |
2407
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
691 /* Use the buffer's default-directory if DEFALT is omitted. */ |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
692 if (NILP (defalt)) |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
693 defalt = current_buffer->directory; |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
694 CHECK_STRING (defalt, 1); |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
695 |
1869
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
696 /* Make sure DEFALT is properly expanded. |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
697 It would be better to do this down below where we actually use |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
698 defalt. Unfortunately, calling Fexpand_file_name recursively |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
699 could invoke GC, and the strings might be relocated. This would |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
700 be annoying because we have pointers into strings lying around |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
701 that would need adjusting, and people would add new pointers to |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
702 the code and forget to adjust them, resulting in intermittent bugs. |
2407
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
703 Putting this call here avoids all that crud. |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
704 |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
705 The EQ test avoids infinite recursion. */ |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
706 if (! NILP (defalt) && !EQ (defalt, name) |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
707 /* This saves time in a common case. */ |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
708 && XSTRING (defalt)->data[0] != '/') |
1869
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
709 { |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
710 struct gcpro gcpro1; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
711 |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
712 GCPRO1 (name); |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
713 defalt = Fexpand_file_name (defalt, Qnil); |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
714 UNGCPRO; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
715 } |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
716 |
230 | 717 #ifdef VMS |
718 /* Filenames on VMS are always upper case. */ | |
719 name = Fupcase (name); | |
720 #endif | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
721 #ifdef FILE_SYSTEM_CASE |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
722 name = FILE_SYSTEM_CASE (name); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
723 #endif |
230 | 724 |
725 nm = XSTRING (name)->data; | |
726 | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
727 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
728 /* firstly, strip drive name. */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
729 { |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
730 unsigned char *colon = rindex (nm, ':'); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
731 if (colon) |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
732 if (nm == colon) |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
733 nm++; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
734 else |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
735 { |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
736 drive = tolower (colon[-1]) - 'a'; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
737 nm = colon + 1; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
738 if (*nm != '/') |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
739 { |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
740 defdir = alloca (MAXPATHLEN + 1); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
741 relpath = getdefdir (drive + 1, defdir); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
742 } |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
743 } |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
744 } |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
745 #endif |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
746 |
230 | 747 /* If nm is absolute, flush ...// and detect /./ and /../. |
748 If no /./ or /../ we can return right away. */ | |
749 if ( | |
750 nm[0] == '/' | |
751 #ifdef VMS | |
752 || index (nm, ':') | |
753 #endif /* VMS */ | |
754 ) | |
755 { | |
1869
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
756 /* If it turns out that the filename we want to return is just a |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
757 suffix of FILENAME, we don't need to go through and edit |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
758 things; we just need to construct a new string using data |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
759 starting at the middle of FILENAME. If we set lose to a |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
760 non-zero value, that means we've discovered that we can't do |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
761 that cool trick. */ |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
762 int lose = 0; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
763 |
230 | 764 p = nm; |
765 while (*p) | |
766 { | |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
767 /* Since we know the path is absolute, we can assume that each |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
768 element starts with a "/". */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
769 |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
770 /* "//" anywhere isn't necessarily hairy; we just start afresh |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
771 with the second slash. */ |
230 | 772 if (p[0] == '/' && p[1] == '/' |
773 #ifdef APOLLO | |
774 /* // at start of filename is meaningful on Apollo system */ | |
775 && nm != p | |
776 #endif /* APOLLO */ | |
777 ) | |
778 nm = p + 1; | |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
779 |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
780 /* "~" is hairy as the start of any path element. */ |
230 | 781 if (p[0] == '/' && p[1] == '~') |
782 nm = p + 1, lose = 1; | |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
783 |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
784 /* "." and ".." are hairy. */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
785 if (p[0] == '/' |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
786 && p[1] == '.' |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
787 && (p[2] == '/' |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
788 || p[2] == 0 |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
789 || (p[2] == '.' && (p[3] == '/' |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
790 || p[3] == 0)))) |
230 | 791 lose = 1; |
792 #ifdef VMS | |
793 if (p[0] == '\\') | |
794 lose = 1; | |
795 if (p[0] == '/') { | |
796 /* if dev:[dir]/, move nm to / */ | |
797 if (!slash && p > nm && (brack || colon)) { | |
798 nm = (brack ? brack + 1 : colon + 1); | |
799 lbrack = rbrack = 0; | |
800 brack = 0; | |
801 colon = 0; | |
802 } | |
803 slash = p; | |
804 } | |
805 if (p[0] == '-') | |
806 #ifndef VMS4_4 | |
807 /* VMS pre V4.4,convert '-'s in filenames. */ | |
808 if (lbrack == rbrack) | |
809 { | |
810 if (dots < 2) /* this is to allow negative version numbers */ | |
811 p[0] = '_'; | |
812 } | |
813 else | |
814 #endif /* VMS4_4 */ | |
815 if (lbrack > rbrack && | |
816 ((p[-1] == '.' || p[-1] == '[' || p[-1] == '<') && | |
817 (p[1] == '.' || p[1] == ']' || p[1] == '>'))) | |
818 lose = 1; | |
819 #ifndef VMS4_4 | |
820 else | |
821 p[0] = '_'; | |
822 #endif /* VMS4_4 */ | |
823 /* count open brackets, reset close bracket pointer */ | |
824 if (p[0] == '[' || p[0] == '<') | |
825 lbrack++, brack = 0; | |
826 /* count close brackets, set close bracket pointer */ | |
827 if (p[0] == ']' || p[0] == '>') | |
828 rbrack++, brack = p; | |
829 /* detect ][ or >< */ | |
830 if ((p[0] == ']' || p[0] == '>') && (p[1] == '[' || p[1] == '<')) | |
831 lose = 1; | |
832 if ((p[0] == ':' || p[0] == ']' || p[0] == '>') && p[1] == '~') | |
833 nm = p + 1, lose = 1; | |
834 if (p[0] == ':' && (colon || slash)) | |
835 /* if dev1:[dir]dev2:, move nm to dev2: */ | |
836 if (brack) | |
837 { | |
838 nm = brack + 1; | |
839 brack = 0; | |
840 } | |
841 /* if /pathname/dev:, move nm to dev: */ | |
842 else if (slash) | |
843 nm = slash + 1; | |
844 /* if node::dev:, move colon following dev */ | |
845 else if (colon && colon[-1] == ':') | |
846 colon = p; | |
847 /* if dev1:dev2:, move nm to dev2: */ | |
848 else if (colon && colon[-1] != ':') | |
849 { | |
850 nm = colon + 1; | |
851 colon = 0; | |
852 } | |
853 if (p[0] == ':' && !colon) | |
854 { | |
855 if (p[1] == ':') | |
856 p++; | |
857 colon = p; | |
858 } | |
859 if (lbrack == rbrack) | |
860 if (p[0] == ';') | |
861 dots = 2; | |
862 else if (p[0] == '.') | |
863 dots++; | |
864 #endif /* VMS */ | |
865 p++; | |
866 } | |
867 if (!lose) | |
868 { | |
869 #ifdef VMS | |
870 if (index (nm, '/')) | |
871 return build_string (sys_translate_unix (nm)); | |
872 #endif /* VMS */ | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
873 #ifndef MSDOS |
230 | 874 if (nm == XSTRING (name)->data) |
875 return name; | |
876 return build_string (nm); | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
877 #endif |
230 | 878 } |
879 } | |
880 | |
881 /* Now determine directory to start with and put it in newdir */ | |
882 | |
883 newdir = 0; | |
884 | |
885 if (nm[0] == '~') /* prefix ~ */ | |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
886 { |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
887 if (nm[1] == '/' |
230 | 888 #ifdef VMS |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
889 || nm[1] == ':' |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
890 #endif /* VMS */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
891 || nm[1] == 0) /* ~ by itself */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
892 { |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
893 if (!(newdir = (unsigned char *) egetenv ("HOME"))) |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
894 newdir = (unsigned char *) ""; |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
895 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
896 dostounix_filename (newdir); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
897 #endif |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
898 nm++; |
230 | 899 #ifdef VMS |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
900 nm++; /* Don't leave the slash in nm. */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
901 #endif /* VMS */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
902 } |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
903 else /* ~user/filename */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
904 { |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
905 for (p = nm; *p && (*p != '/' |
230 | 906 #ifdef VMS |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
907 && *p != ':' |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
908 #endif /* VMS */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
909 ); p++); |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
910 o = (unsigned char *) alloca (p - nm + 1); |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
911 bcopy ((char *) nm, o, p - nm); |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
912 o [p - nm] = 0; |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
913 |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
914 pw = (struct passwd *) getpwnam (o + 1); |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
915 if (pw) |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
916 { |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
917 newdir = (unsigned char *) pw -> pw_dir; |
230 | 918 #ifdef VMS |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
919 nm = p + 1; /* skip the terminator */ |
230 | 920 #else |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
921 nm = p; |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
922 #endif /* VMS */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
923 } |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
924 |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
925 /* If we don't find a user of that name, leave the name |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
926 unchanged; don't move nm forward to p. */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
927 } |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
928 } |
230 | 929 |
930 if (nm[0] != '/' | |
931 #ifdef VMS | |
932 && !index (nm, ':') | |
933 #endif /* not VMS */ | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
934 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
935 && drive == -1 |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
936 #endif |
230 | 937 && !newdir) |
938 { | |
939 newdir = XSTRING (defalt)->data; | |
940 } | |
941 | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
942 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
943 if (newdir == 0 && relpath) |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
944 newdir = defdir; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
945 #endif |
372 | 946 if (newdir != 0) |
947 { | |
948 /* Get rid of any slash at the end of newdir. */ | |
949 int length = strlen (newdir); | |
2607
fcf578723758
(Fexpand_file_name): Undo last change--too risky for now.
Richard M. Stallman <rms@gnu.org>
parents:
2591
diff
changeset
|
950 /* Adding `length > 1 &&' makes ~ expand into / when homedir |
fcf578723758
(Fexpand_file_name): Undo last change--too risky for now.
Richard M. Stallman <rms@gnu.org>
parents:
2591
diff
changeset
|
951 is the root dir. People disagree about whether that is right. |
fcf578723758
(Fexpand_file_name): Undo last change--too risky for now.
Richard M. Stallman <rms@gnu.org>
parents:
2591
diff
changeset
|
952 Anyway, we can't take the risk of this change now. */ |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
953 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
954 if (newdir[1] != ':' && length > 1) |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
955 #endif |
2607
fcf578723758
(Fexpand_file_name): Undo last change--too risky for now.
Richard M. Stallman <rms@gnu.org>
parents:
2591
diff
changeset
|
956 if (newdir[length - 1] == '/') |
372 | 957 { |
958 unsigned char *temp = (unsigned char *) alloca (length); | |
959 bcopy (newdir, temp, length - 1); | |
960 temp[length - 1] = 0; | |
961 newdir = temp; | |
962 } | |
963 tlen = length + 1; | |
964 } | |
965 else | |
966 tlen = 0; | |
230 | 967 |
372 | 968 /* Now concatenate the directory and name to new space in the stack frame */ |
969 tlen += strlen (nm) + 1; | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
970 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
971 /* Add reserved space for drive name. */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
972 target = (unsigned char *) alloca (tlen + 2) + 2; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
973 #else |
230 | 974 target = (unsigned char *) alloca (tlen); |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
975 #endif |
230 | 976 *target = 0; |
977 | |
978 if (newdir) | |
979 { | |
980 #ifndef VMS | |
981 if (nm[0] == 0 || nm[0] == '/') | |
982 strcpy (target, newdir); | |
983 else | |
984 #endif | |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
985 file_name_as_directory (target, newdir); |
230 | 986 } |
987 | |
988 strcat (target, nm); | |
989 #ifdef VMS | |
990 if (index (target, '/')) | |
991 strcpy (target, sys_translate_unix (target)); | |
992 #endif /* VMS */ | |
993 | |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
994 /* Now canonicalize by removing /. and /foo/.. if they appear. */ |
230 | 995 |
996 p = target; | |
997 o = target; | |
998 | |
999 while (*p) | |
1000 { | |
1001 #ifdef VMS | |
1002 if (*p != ']' && *p != '>' && *p != '-') | |
1003 { | |
1004 if (*p == '\\') | |
1005 p++; | |
1006 *o++ = *p++; | |
1007 } | |
1008 else if ((p[0] == ']' || p[0] == '>') && p[0] == p[1] + 2) | |
1009 /* brackets are offset from each other by 2 */ | |
1010 { | |
1011 p += 2; | |
1012 if (*p != '.' && *p != '-' && o[-1] != '.') | |
1013 /* convert [foo][bar] to [bar] */ | |
1014 while (o[-1] != '[' && o[-1] != '<') | |
1015 o--; | |
1016 else if (*p == '-' && *o != '.') | |
1017 *--p = '.'; | |
1018 } | |
1019 else if (p[0] == '-' && o[-1] == '.' && | |
1020 (p[1] == '.' || p[1] == ']' || p[1] == '>')) | |
1021 /* flush .foo.- ; leave - if stopped by '[' or '<' */ | |
1022 { | |
1023 do | |
1024 o--; | |
1025 while (o[-1] != '.' && o[-1] != '[' && o[-1] != '<'); | |
1026 if (p[1] == '.') /* foo.-.bar ==> bar*/ | |
1027 p += 2; | |
1028 else if (o[-1] == '.') /* '.foo.-]' ==> ']' */ | |
1029 p++, o--; | |
1030 /* else [foo.-] ==> [-] */ | |
1031 } | |
1032 else | |
1033 { | |
1034 #ifndef VMS4_4 | |
1035 if (*p == '-' && | |
1036 o[-1] != '[' && o[-1] != '<' && o[-1] != '.' && | |
1037 p[1] != ']' && p[1] != '>' && p[1] != '.') | |
1038 *p = '_'; | |
1039 #endif /* VMS4_4 */ | |
1040 *o++ = *p++; | |
1041 } | |
1042 #else /* not VMS */ | |
1043 if (*p != '/') | |
1044 { | |
1045 *o++ = *p++; | |
1046 } | |
1047 else if (!strncmp (p, "//", 2) | |
1048 #ifdef APOLLO | |
1049 /* // at start of filename is meaningful in Apollo system */ | |
1050 && o != target | |
1051 #endif /* APOLLO */ | |
1052 ) | |
1053 { | |
1054 o = target; | |
1055 p++; | |
1056 } | |
1589
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1057 else if (p[0] == '/' |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1058 && p[1] == '.' |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1059 && (p[2] == '/' |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1060 || p[2] == 0)) |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1061 { |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1062 /* If "/." is the entire filename, keep the "/". Otherwise, |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1063 just delete the whole "/.". */ |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1064 if (o == target && p[2] == '\0') |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1065 *o++ = *p; |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1066 p += 2; |
6168f42d716c
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
Jim Blandy <jimb@redhat.com>
parents:
1536
diff
changeset
|
1067 } |
230 | 1068 else if (!strncmp (p, "/..", 3) |
1069 /* `/../' is the "superroot" on certain file systems. */ | |
1070 && o != target | |
1071 && (p[3] == '/' || p[3] == 0)) | |
1072 { | |
1073 while (o != target && *--o != '/') | |
1074 ; | |
1075 #ifdef APOLLO | |
1076 if (o == target + 1 && o[-1] == '/' && o[0] == '/') | |
1077 ++o; | |
1078 else | |
1079 #endif /* APOLLO */ | |
1080 if (o == target && *o == '/') | |
1081 ++o; | |
1082 p += 3; | |
1083 } | |
1084 else | |
1085 { | |
1086 *o++ = *p++; | |
1087 } | |
1088 #endif /* not VMS */ | |
1089 } | |
1090 | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1091 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1092 /* at last, set drive name. */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1093 if (target[1] != ':') |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1094 { |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1095 target -= 2; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1096 target[0] = (drive < 0 ? getdisk () : drive) + 'a'; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1097 target[1] = ':'; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1098 } |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1099 #endif |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1100 |
230 | 1101 return make_string (target, o - target); |
1102 } | |
1103 #if 0 | |
732 | 1104 /* Changed this DEFUN to a DEAFUN, so as not to confuse `make-docfile'. |
1105 DEAFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, | |
230 | 1106 "Convert FILENAME to absolute, and canonicalize it.\n\ |
1107 Second arg DEFAULT is directory to start with if FILENAME is relative\n\ | |
1108 (does not start with slash); if DEFAULT is nil or missing,\n\ | |
1109 the current buffer's value of default-directory is used.\n\ | |
1110 Filenames containing `.' or `..' as components are simplified;\n\ | |
1111 initial `~/' expands to your home directory.\n\ | |
1112 See also the function `substitute-in-file-name'.") | |
1113 (name, defalt) | |
1114 Lisp_Object name, defalt; | |
1115 { | |
1116 unsigned char *nm; | |
1117 | |
1118 register unsigned char *newdir, *p, *o; | |
1119 int tlen; | |
1120 unsigned char *target; | |
1121 struct passwd *pw; | |
1122 int lose; | |
1123 #ifdef VMS | |
1124 unsigned char * colon = 0; | |
1125 unsigned char * close = 0; | |
1126 unsigned char * slash = 0; | |
1127 unsigned char * brack = 0; | |
1128 int lbrack = 0, rbrack = 0; | |
1129 int dots = 0; | |
1130 #endif /* VMS */ | |
1131 | |
1132 CHECK_STRING (name, 0); | |
1133 | |
1134 #ifdef VMS | |
1135 /* Filenames on VMS are always upper case. */ | |
1136 name = Fupcase (name); | |
1137 #endif | |
1138 | |
1139 nm = XSTRING (name)->data; | |
1140 | |
1141 /* If nm is absolute, flush ...// and detect /./ and /../. | |
1142 If no /./ or /../ we can return right away. */ | |
1143 if ( | |
1144 nm[0] == '/' | |
1145 #ifdef VMS | |
1146 || index (nm, ':') | |
1147 #endif /* VMS */ | |
1148 ) | |
1149 { | |
1150 p = nm; | |
1151 lose = 0; | |
1152 while (*p) | |
1153 { | |
1154 if (p[0] == '/' && p[1] == '/' | |
1155 #ifdef APOLLO | |
1156 /* // at start of filename is meaningful on Apollo system */ | |
1157 && nm != p | |
1158 #endif /* APOLLO */ | |
1159 ) | |
1160 nm = p + 1; | |
1161 if (p[0] == '/' && p[1] == '~') | |
1162 nm = p + 1, lose = 1; | |
1163 if (p[0] == '/' && p[1] == '.' | |
1164 && (p[2] == '/' || p[2] == 0 | |
1165 || (p[2] == '.' && (p[3] == '/' || p[3] == 0)))) | |
1166 lose = 1; | |
1167 #ifdef VMS | |
1168 if (p[0] == '\\') | |
1169 lose = 1; | |
1170 if (p[0] == '/') { | |
1171 /* if dev:[dir]/, move nm to / */ | |
1172 if (!slash && p > nm && (brack || colon)) { | |
1173 nm = (brack ? brack + 1 : colon + 1); | |
1174 lbrack = rbrack = 0; | |
1175 brack = 0; | |
1176 colon = 0; | |
1177 } | |
1178 slash = p; | |
1179 } | |
1180 if (p[0] == '-') | |
1181 #ifndef VMS4_4 | |
1182 /* VMS pre V4.4,convert '-'s in filenames. */ | |
1183 if (lbrack == rbrack) | |
1184 { | |
1185 if (dots < 2) /* this is to allow negative version numbers */ | |
1186 p[0] = '_'; | |
1187 } | |
1188 else | |
1189 #endif /* VMS4_4 */ | |
1190 if (lbrack > rbrack && | |
1191 ((p[-1] == '.' || p[-1] == '[' || p[-1] == '<') && | |
1192 (p[1] == '.' || p[1] == ']' || p[1] == '>'))) | |
1193 lose = 1; | |
1194 #ifndef VMS4_4 | |
1195 else | |
1196 p[0] = '_'; | |
1197 #endif /* VMS4_4 */ | |
1198 /* count open brackets, reset close bracket pointer */ | |
1199 if (p[0] == '[' || p[0] == '<') | |
1200 lbrack++, brack = 0; | |
1201 /* count close brackets, set close bracket pointer */ | |
1202 if (p[0] == ']' || p[0] == '>') | |
1203 rbrack++, brack = p; | |
1204 /* detect ][ or >< */ | |
1205 if ((p[0] == ']' || p[0] == '>') && (p[1] == '[' || p[1] == '<')) | |
1206 lose = 1; | |
1207 if ((p[0] == ':' || p[0] == ']' || p[0] == '>') && p[1] == '~') | |
1208 nm = p + 1, lose = 1; | |
1209 if (p[0] == ':' && (colon || slash)) | |
1210 /* if dev1:[dir]dev2:, move nm to dev2: */ | |
1211 if (brack) | |
1212 { | |
1213 nm = brack + 1; | |
1214 brack = 0; | |
1215 } | |
1216 /* if /pathname/dev:, move nm to dev: */ | |
1217 else if (slash) | |
1218 nm = slash + 1; | |
1219 /* if node::dev:, move colon following dev */ | |
1220 else if (colon && colon[-1] == ':') | |
1221 colon = p; | |
1222 /* if dev1:dev2:, move nm to dev2: */ | |
1223 else if (colon && colon[-1] != ':') | |
1224 { | |
1225 nm = colon + 1; | |
1226 colon = 0; | |
1227 } | |
1228 if (p[0] == ':' && !colon) | |
1229 { | |
1230 if (p[1] == ':') | |
1231 p++; | |
1232 colon = p; | |
1233 } | |
1234 if (lbrack == rbrack) | |
1235 if (p[0] == ';') | |
1236 dots = 2; | |
1237 else if (p[0] == '.') | |
1238 dots++; | |
1239 #endif /* VMS */ | |
1240 p++; | |
1241 } | |
1242 if (!lose) | |
1243 { | |
1244 #ifdef VMS | |
1245 if (index (nm, '/')) | |
1246 return build_string (sys_translate_unix (nm)); | |
1247 #endif /* VMS */ | |
1248 if (nm == XSTRING (name)->data) | |
1249 return name; | |
1250 return build_string (nm); | |
1251 } | |
1252 } | |
1253 | |
1254 /* Now determine directory to start with and put it in NEWDIR */ | |
1255 | |
1256 newdir = 0; | |
1257 | |
1258 if (nm[0] == '~') /* prefix ~ */ | |
1259 if (nm[1] == '/' | |
1260 #ifdef VMS | |
1261 || nm[1] == ':' | |
1262 #endif /* VMS */ | |
1263 || nm[1] == 0)/* ~/filename */ | |
1264 { | |
1265 if (!(newdir = (unsigned char *) egetenv ("HOME"))) | |
1266 newdir = (unsigned char *) ""; | |
1267 nm++; | |
1268 #ifdef VMS | |
1269 nm++; /* Don't leave the slash in nm. */ | |
1270 #endif /* VMS */ | |
1271 } | |
1272 else /* ~user/filename */ | |
1273 { | |
1274 /* Get past ~ to user */ | |
1275 unsigned char *user = nm + 1; | |
1276 /* Find end of name. */ | |
1277 unsigned char *ptr = (unsigned char *) index (user, '/'); | |
1278 int len = ptr ? ptr - user : strlen (user); | |
1279 #ifdef VMS | |
1280 unsigned char *ptr1 = index (user, ':'); | |
1281 if (ptr1 != 0 && ptr1 - user < len) | |
1282 len = ptr1 - user; | |
1283 #endif /* VMS */ | |
1284 /* Copy the user name into temp storage. */ | |
1285 o = (unsigned char *) alloca (len + 1); | |
1286 bcopy ((char *) user, o, len); | |
1287 o[len] = 0; | |
1288 | |
1289 /* Look up the user name. */ | |
1290 pw = (struct passwd *) getpwnam (o + 1); | |
1291 if (!pw) | |
1292 error ("\"%s\" isn't a registered user", o + 1); | |
1293 | |
1294 newdir = (unsigned char *) pw->pw_dir; | |
1295 | |
1296 /* Discard the user name from NM. */ | |
1297 nm += len; | |
1298 } | |
1299 | |
1300 if (nm[0] != '/' | |
1301 #ifdef VMS | |
1302 && !index (nm, ':') | |
1303 #endif /* not VMS */ | |
1304 && !newdir) | |
1305 { | |
485 | 1306 if (NILP (defalt)) |
230 | 1307 defalt = current_buffer->directory; |
1308 CHECK_STRING (defalt, 1); | |
1309 newdir = XSTRING (defalt)->data; | |
1310 } | |
1311 | |
1312 /* Now concatenate the directory and name to new space in the stack frame */ | |
1313 | |
1314 tlen = (newdir ? strlen (newdir) + 1 : 0) + strlen (nm) + 1; | |
1315 target = (unsigned char *) alloca (tlen); | |
1316 *target = 0; | |
1317 | |
1318 if (newdir) | |
1319 { | |
1320 #ifndef VMS | |
1321 if (nm[0] == 0 || nm[0] == '/') | |
1322 strcpy (target, newdir); | |
1323 else | |
1324 #endif | |
1325 file_name_as_directory (target, newdir); | |
1326 } | |
1327 | |
1328 strcat (target, nm); | |
1329 #ifdef VMS | |
1330 if (index (target, '/')) | |
1331 strcpy (target, sys_translate_unix (target)); | |
1332 #endif /* VMS */ | |
1333 | |
1334 /* Now canonicalize by removing /. and /foo/.. if they appear */ | |
1335 | |
1336 p = target; | |
1337 o = target; | |
1338 | |
1339 while (*p) | |
1340 { | |
1341 #ifdef VMS | |
1342 if (*p != ']' && *p != '>' && *p != '-') | |
1343 { | |
1344 if (*p == '\\') | |
1345 p++; | |
1346 *o++ = *p++; | |
1347 } | |
1348 else if ((p[0] == ']' || p[0] == '>') && p[0] == p[1] + 2) | |
1349 /* brackets are offset from each other by 2 */ | |
1350 { | |
1351 p += 2; | |
1352 if (*p != '.' && *p != '-' && o[-1] != '.') | |
1353 /* convert [foo][bar] to [bar] */ | |
1354 while (o[-1] != '[' && o[-1] != '<') | |
1355 o--; | |
1356 else if (*p == '-' && *o != '.') | |
1357 *--p = '.'; | |
1358 } | |
1359 else if (p[0] == '-' && o[-1] == '.' && | |
1360 (p[1] == '.' || p[1] == ']' || p[1] == '>')) | |
1361 /* flush .foo.- ; leave - if stopped by '[' or '<' */ | |
1362 { | |
1363 do | |
1364 o--; | |
1365 while (o[-1] != '.' && o[-1] != '[' && o[-1] != '<'); | |
1366 if (p[1] == '.') /* foo.-.bar ==> bar*/ | |
1367 p += 2; | |
1368 else if (o[-1] == '.') /* '.foo.-]' ==> ']' */ | |
1369 p++, o--; | |
1370 /* else [foo.-] ==> [-] */ | |
1371 } | |
1372 else | |
1373 { | |
1374 #ifndef VMS4_4 | |
1375 if (*p == '-' && | |
1376 o[-1] != '[' && o[-1] != '<' && o[-1] != '.' && | |
1377 p[1] != ']' && p[1] != '>' && p[1] != '.') | |
1378 *p = '_'; | |
1379 #endif /* VMS4_4 */ | |
1380 *o++ = *p++; | |
1381 } | |
1382 #else /* not VMS */ | |
1383 if (*p != '/') | |
1384 { | |
1385 *o++ = *p++; | |
1386 } | |
1387 else if (!strncmp (p, "//", 2) | |
1388 #ifdef APOLLO | |
1389 /* // at start of filename is meaningful in Apollo system */ | |
1390 && o != target | |
1391 #endif /* APOLLO */ | |
1392 ) | |
1393 { | |
1394 o = target; | |
1395 p++; | |
1396 } | |
1397 else if (p[0] == '/' && p[1] == '.' && | |
1398 (p[2] == '/' || p[2] == 0)) | |
1399 p += 2; | |
1400 else if (!strncmp (p, "/..", 3) | |
1401 /* `/../' is the "superroot" on certain file systems. */ | |
1402 && o != target | |
1403 && (p[3] == '/' || p[3] == 0)) | |
1404 { | |
1405 while (o != target && *--o != '/') | |
1406 ; | |
1407 #ifdef APOLLO | |
1408 if (o == target + 1 && o[-1] == '/' && o[0] == '/') | |
1409 ++o; | |
1410 else | |
1411 #endif /* APOLLO */ | |
1412 if (o == target && *o == '/') | |
1413 ++o; | |
1414 p += 3; | |
1415 } | |
1416 else | |
1417 { | |
1418 *o++ = *p++; | |
1419 } | |
1420 #endif /* not VMS */ | |
1421 } | |
1422 | |
1423 return make_string (target, o - target); | |
1424 } | |
1425 #endif | |
1426 | |
1427 DEFUN ("substitute-in-file-name", Fsubstitute_in_file_name, | |
1428 Ssubstitute_in_file_name, 1, 1, 0, | |
1429 "Substitute environment variables referred to in FILENAME.\n\ | |
1430 `$FOO' where FOO is an environment variable name means to substitute\n\ | |
1431 the value of that variable. The variable name should be terminated\n\ | |
1432 with a character not a letter, digit or underscore; otherwise, enclose\n\ | |
1433 the entire variable name in braces.\n\ | |
1434 If `/~' appears, all of FILENAME through that `/' is discarded.\n\n\ | |
1435 On VMS, `$' substitution is not done; this function does little and only\n\ | |
1436 duplicates what `expand-file-name' does.") | |
1437 (string) | |
1438 Lisp_Object string; | |
1439 { | |
1440 unsigned char *nm; | |
1441 | |
1442 register unsigned char *s, *p, *o, *x, *endp; | |
1443 unsigned char *target; | |
1444 int total = 0; | |
1445 int substituted = 0; | |
1446 unsigned char *xnm; | |
1447 | |
1448 CHECK_STRING (string, 0); | |
1449 | |
1450 nm = XSTRING (string)->data; | |
1451 endp = nm + XSTRING (string)->size; | |
1452 | |
1453 /* If /~ or // appears, discard everything through first slash. */ | |
1454 | |
1455 for (p = nm; p != endp; p++) | |
1456 { | |
1457 if ((p[0] == '~' || | |
1458 #ifdef APOLLO | |
1459 /* // at start of file name is meaningful in Apollo system */ | |
1460 (p[0] == '/' && p - 1 != nm) | |
1461 #else /* not APOLLO */ | |
1462 p[0] == '/' | |
1463 #endif /* not APOLLO */ | |
1464 ) | |
1465 && p != nm && | |
1466 #ifdef VMS | |
1467 (p[-1] == ':' || p[-1] == ']' || p[-1] == '>' || | |
1468 #endif /* VMS */ | |
1469 p[-1] == '/') | |
1470 #ifdef VMS | |
1471 ) | |
1472 #endif /* VMS */ | |
1473 { | |
1474 nm = p; | |
1475 substituted = 1; | |
1476 } | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1477 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1478 if (p[0] && p[1] == ':') |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1479 { |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1480 nm = p; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1481 substituted = 1; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1482 } |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1483 #endif /* MSDOS */ |
230 | 1484 } |
1485 | |
1486 #ifdef VMS | |
1487 return build_string (nm); | |
1488 #else | |
1489 | |
1490 /* See if any variables are substituted into the string | |
1491 and find the total length of their values in `total' */ | |
1492 | |
1493 for (p = nm; p != endp;) | |
1494 if (*p != '$') | |
1495 p++; | |
1496 else | |
1497 { | |
1498 p++; | |
1499 if (p == endp) | |
1500 goto badsubst; | |
1501 else if (*p == '$') | |
1502 { | |
1503 /* "$$" means a single "$" */ | |
1504 p++; | |
1505 total -= 1; | |
1506 substituted = 1; | |
1507 continue; | |
1508 } | |
1509 else if (*p == '{') | |
1510 { | |
1511 o = ++p; | |
1512 while (p != endp && *p != '}') p++; | |
1513 if (*p != '}') goto missingclose; | |
1514 s = p; | |
1515 } | |
1516 else | |
1517 { | |
1518 o = p; | |
1519 while (p != endp && (isalnum (*p) || *p == '_')) p++; | |
1520 s = p; | |
1521 } | |
1522 | |
1523 /* Copy out the variable name */ | |
1524 target = (unsigned char *) alloca (s - o + 1); | |
1525 strncpy (target, o, s - o); | |
1526 target[s - o] = 0; | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1527 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1528 strupr (target); /* $home == $HOME etc. */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1529 #endif |
230 | 1530 |
1531 /* Get variable value */ | |
1532 o = (unsigned char *) egetenv (target); | |
1533 /* The presence of this code makes vax 5.0 crash, for reasons yet unknown */ | |
1534 #if 0 | |
1535 #ifdef USG | |
1536 if (!o && !strcmp (target, "USER")) | |
1537 o = egetenv ("LOGNAME"); | |
1538 #endif /* USG */ | |
1539 #endif /* 0 */ | |
1540 if (!o) goto badvar; | |
1541 total += strlen (o); | |
1542 substituted = 1; | |
1543 } | |
1544 | |
1545 if (!substituted) | |
1546 return string; | |
1547 | |
1548 /* If substitution required, recopy the string and do it */ | |
1549 /* Make space in stack frame for the new copy */ | |
1550 xnm = (unsigned char *) alloca (XSTRING (string)->size + total + 1); | |
1551 x = xnm; | |
1552 | |
1553 /* Copy the rest of the name through, replacing $ constructs with values */ | |
1554 for (p = nm; *p;) | |
1555 if (*p != '$') | |
1556 *x++ = *p++; | |
1557 else | |
1558 { | |
1559 p++; | |
1560 if (p == endp) | |
1561 goto badsubst; | |
1562 else if (*p == '$') | |
1563 { | |
1564 *x++ = *p++; | |
1565 continue; | |
1566 } | |
1567 else if (*p == '{') | |
1568 { | |
1569 o = ++p; | |
1570 while (p != endp && *p != '}') p++; | |
1571 if (*p != '}') goto missingclose; | |
1572 s = p++; | |
1573 } | |
1574 else | |
1575 { | |
1576 o = p; | |
1577 while (p != endp && (isalnum (*p) || *p == '_')) p++; | |
1578 s = p; | |
1579 } | |
1580 | |
1581 /* Copy out the variable name */ | |
1582 target = (unsigned char *) alloca (s - o + 1); | |
1583 strncpy (target, o, s - o); | |
1584 target[s - o] = 0; | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1585 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1586 strupr (target); /* $home == $HOME etc. */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1587 #endif |
230 | 1588 |
1589 /* Get variable value */ | |
1590 o = (unsigned char *) egetenv (target); | |
1591 /* The presence of this code makes vax 5.0 crash, for reasons yet unknown */ | |
1592 #if 0 | |
1593 #ifdef USG | |
1594 if (!o && !strcmp (target, "USER")) | |
1595 o = egetenv ("LOGNAME"); | |
1596 #endif /* USG */ | |
1597 #endif /* 0 */ | |
1598 if (!o) | |
1599 goto badvar; | |
1600 | |
1601 strcpy (x, o); | |
1602 x += strlen (o); | |
1603 } | |
1604 | |
1605 *x = 0; | |
1606 | |
1607 /* If /~ or // appears, discard everything through first slash. */ | |
1608 | |
1609 for (p = xnm; p != x; p++) | |
1610 if ((p[0] == '~' || | |
1611 #ifdef APOLLO | |
1612 /* // at start of file name is meaningful in Apollo system */ | |
1613 (p[0] == '/' && p - 1 != xnm) | |
1614 #else /* not APOLLO */ | |
1615 p[0] == '/' | |
1616 #endif /* not APOLLO */ | |
1617 ) | |
1618 && p != nm && p[-1] == '/') | |
1619 xnm = p; | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1620 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1621 else if (p[0] && p[1] == ':') |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1622 xnm = p; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1623 #endif |
230 | 1624 |
1625 return make_string (xnm, x - xnm); | |
1626 | |
1627 badsubst: | |
1628 error ("Bad format environment-variable substitution"); | |
1629 missingclose: | |
1630 error ("Missing \"}\" in environment-variable substitution"); | |
1631 badvar: | |
1632 error ("Substituting nonexistent environment variable \"%s\"", target); | |
1633 | |
1634 /* NOTREACHED */ | |
1635 #endif /* not VMS */ | |
1636 } | |
1637 | |
853 | 1638 /* A slightly faster and more convenient way to get |
4451
73b91cd2c55e
(expand_and_dir_to_file): Remove final / by copying abspath.
Richard M. Stallman <rms@gnu.org>
parents:
4395
diff
changeset
|
1639 (directory-file-name (expand-file-name FOO)). */ |
853 | 1640 |
230 | 1641 Lisp_Object |
1642 expand_and_dir_to_file (filename, defdir) | |
1643 Lisp_Object filename, defdir; | |
1644 { | |
1645 register Lisp_Object abspath; | |
1646 | |
1647 abspath = Fexpand_file_name (filename, defdir); | |
1648 #ifdef VMS | |
1649 { | |
1650 register int c = XSTRING (abspath)->data[XSTRING (abspath)->size - 1]; | |
1651 if (c == ':' || c == ']' || c == '>') | |
1652 abspath = Fdirectory_file_name (abspath); | |
1653 } | |
1654 #else | |
1655 /* Remove final slash, if any (unless path is root). | |
1656 stat behaves differently depending! */ | |
1657 if (XSTRING (abspath)->size > 1 | |
1658 && XSTRING (abspath)->data[XSTRING (abspath)->size - 1] == '/') | |
4483
6894dd27c9ec
(expand_and_dir_to_file): Use Fdirectory_file_name.
Richard M. Stallman <rms@gnu.org>
parents:
4451
diff
changeset
|
1659 /* We cannot take shortcuts; they might be wrong for magic file names. */ |
6894dd27c9ec
(expand_and_dir_to_file): Use Fdirectory_file_name.
Richard M. Stallman <rms@gnu.org>
parents:
4451
diff
changeset
|
1660 abspath = Fdirectory_file_name (abspath); |
230 | 1661 #endif |
1662 return abspath; | |
1663 } | |
1664 | |
1665 barf_or_query_if_file_exists (absname, querystring, interactive) | |
1666 Lisp_Object absname; | |
1667 unsigned char *querystring; | |
1668 int interactive; | |
1669 { | |
1670 register Lisp_Object tem; | |
1671 struct gcpro gcpro1; | |
1672 | |
1673 if (access (XSTRING (absname)->data, 4) >= 0) | |
1674 { | |
1675 if (! interactive) | |
1676 Fsignal (Qfile_already_exists, | |
1677 Fcons (build_string ("File already exists"), | |
1678 Fcons (absname, Qnil))); | |
1679 GCPRO1 (absname); | |
1680 tem = do_yes_or_no_p (format1 ("File %s already exists; %s anyway? ", | |
1681 XSTRING (absname)->data, querystring)); | |
1682 UNGCPRO; | |
485 | 1683 if (NILP (tem)) |
230 | 1684 Fsignal (Qfile_already_exists, |
1685 Fcons (build_string ("File already exists"), | |
1686 Fcons (absname, Qnil))); | |
1687 } | |
1688 return; | |
1689 } | |
1690 | |
1691 DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 4, | |
410 | 1692 "fCopy file: \nFCopy %s to file: \np\nP", |
230 | 1693 "Copy FILE to NEWNAME. Both args must be strings.\n\ |
1694 Signals a `file-already-exists' error if file NEWNAME already exists,\n\ | |
1695 unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil.\n\ | |
1696 A number as third arg means request confirmation if NEWNAME already exists.\n\ | |
1697 This is what happens in interactive use with M-x.\n\ | |
410 | 1698 Fourth arg KEEP-TIME non-nil means give the new file the same\n\ |
1699 last-modified time as the old one. (This works on only some systems.)\n\ | |
1700 A prefix arg makes KEEP-TIME non-nil.") | |
230 | 1701 (filename, newname, ok_if_already_exists, keep_date) |
1702 Lisp_Object filename, newname, ok_if_already_exists, keep_date; | |
1703 { | |
1704 int ifd, ofd, n; | |
1705 char buf[16 * 1024]; | |
1706 struct stat st; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1707 Lisp_Object handler; |
230 | 1708 struct gcpro gcpro1, gcpro2; |
592
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1709 int count = specpdl_ptr - specpdl; |
3705
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1710 Lisp_Object args[6]; |
4879
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1711 int input_file_statable_p; |
230 | 1712 |
1713 GCPRO2 (filename, newname); | |
1714 CHECK_STRING (filename, 0); | |
1715 CHECK_STRING (newname, 1); | |
1716 filename = Fexpand_file_name (filename, Qnil); | |
1717 newname = Fexpand_file_name (newname, Qnil); | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1718 |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
1719 /* If the input file name has special constructs in it, |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1720 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
1721 handler = Ffind_file_name_handler (filename); |
3705
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1722 /* Likewise for output file name. */ |
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1723 if (NILP (handler)) |
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1724 handler = Ffind_file_name_handler (newname); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1725 if (!NILP (handler)) |
3705
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1726 return call5 (handler, Qcopy_file, filename, newname, |
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1727 ok_if_already_exists, keep_date); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1728 |
485 | 1729 if (NILP (ok_if_already_exists) |
230 | 1730 || XTYPE (ok_if_already_exists) == Lisp_Int) |
1731 barf_or_query_if_file_exists (newname, "copy to it", | |
1732 XTYPE (ok_if_already_exists) == Lisp_Int); | |
1733 | |
1734 ifd = open (XSTRING (filename)->data, 0); | |
1735 if (ifd < 0) | |
1736 report_file_error ("Opening input file", Fcons (filename, Qnil)); | |
1737 | |
592
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1738 record_unwind_protect (close_file_unwind, make_number (ifd)); |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1739 |
4879
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1740 /* We can only copy regular files and symbolic links. Other files are not |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1741 copyable by us. */ |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1742 input_file_statable_p = (fstat (ifd, &st) >= 0); |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1743 |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1744 #if defined (S_ISREG) && defined (S_ISLNK) |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1745 if (input_file_statable_p) |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1746 { |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1747 if (!(S_ISREG (st.st_mode)) && !(S_ISLNK (st.st_mode))) |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1748 { |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1749 #if defined (EISDIR) |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1750 /* Get a better looking error message. */ |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1751 errno = EISDIR; |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1752 #endif /* EISDIR */ |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1753 report_file_error ("Non-regular file", Fcons (filename, Qnil)); |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1754 } |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1755 } |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1756 #endif /* S_ISREG && S_ISLNK */ |
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1757 |
230 | 1758 #ifdef VMS |
1759 /* Create the copy file with the same record format as the input file */ | |
1760 ofd = sys_creat (XSTRING (newname)->data, 0666, ifd); | |
1761 #else | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1762 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1763 /* System's default file type was set to binary by _fmode in emacs.c. */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1764 ofd = creat (XSTRING (newname)->data, S_IREAD | S_IWRITE); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1765 #else /* not MSDOS */ |
230 | 1766 ofd = creat (XSTRING (newname)->data, 0666); |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
1767 #endif /* not MSDOS */ |
230 | 1768 #endif /* VMS */ |
1769 if (ofd < 0) | |
595 | 1770 report_file_error ("Opening output file", Fcons (newname, Qnil)); |
230 | 1771 |
592
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1772 record_unwind_protect (close_file_unwind, make_number (ofd)); |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1773 |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1774 immediate_quit = 1; |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1775 QUIT; |
230 | 1776 while ((n = read (ifd, buf, sizeof buf)) > 0) |
1777 if (write (ofd, buf, n) != n) | |
595 | 1778 report_file_error ("I/O error", Fcons (newname, Qnil)); |
592
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1779 immediate_quit = 0; |
230 | 1780 |
4879
1774c84aca2e
(Fcopy_file): Don't allow the copying of anything other than regular
Brian Fox <bfox@gnu.org>
parents:
4853
diff
changeset
|
1781 if (input_file_statable_p) |
230 | 1782 { |
485 | 1783 if (!NILP (keep_date)) |
230 | 1784 { |
564 | 1785 EMACS_TIME atime, mtime; |
1786 EMACS_SET_SECS_USECS (atime, st.st_atime, 0); | |
1787 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); | |
1788 EMACS_SET_UTIMES (XSTRING (newname)->data, atime, mtime); | |
230 | 1789 } |
1790 #ifdef APOLLO | |
1791 if (!egetenv ("USE_DOMAIN_ACLS")) | |
1792 #endif | |
564 | 1793 chmod (XSTRING (newname)->data, st.st_mode & 07777); |
230 | 1794 } |
1795 | |
592
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1796 /* Discard the unwind protects. */ |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1797 specpdl_ptr = specpdl + count; |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
1798 |
230 | 1799 close (ifd); |
1800 if (close (ofd) < 0) | |
1801 report_file_error ("I/O error", Fcons (newname, Qnil)); | |
1802 | |
1803 UNGCPRO; | |
1804 return Qnil; | |
1805 } | |
1806 | |
1533
b86ef0432100
(Fmake_directory_internal): Renamed from Fmake_directory.
Richard M. Stallman <rms@gnu.org>
parents:
1377
diff
changeset
|
1807 DEFUN ("make-directory-internal", Fmake_directory_internal, |
1536
0877009e6324
* fileio.c (Fmake_directory_internal): Remove extra paren before the
Jim Blandy <jimb@redhat.com>
parents:
1533
diff
changeset
|
1808 Smake_directory_internal, 1, 1, 0, |
230 | 1809 "Create a directory. One argument, a file name string.") |
1810 (dirname) | |
1811 Lisp_Object dirname; | |
1812 { | |
1813 unsigned char *dir; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1814 Lisp_Object handler; |
230 | 1815 |
1816 CHECK_STRING (dirname, 0); | |
1817 dirname = Fexpand_file_name (dirname, Qnil); | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1818 |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
1819 handler = Ffind_file_name_handler (dirname); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1820 if (!NILP (handler)) |
1533
b86ef0432100
(Fmake_directory_internal): Renamed from Fmake_directory.
Richard M. Stallman <rms@gnu.org>
parents:
1377
diff
changeset
|
1821 return call3 (handler, Qmake_directory, dirname, Qnil); |
b86ef0432100
(Fmake_directory_internal): Renamed from Fmake_directory.
Richard M. Stallman <rms@gnu.org>
parents:
1377
diff
changeset
|
1822 |
230 | 1823 dir = XSTRING (dirname)->data; |
1824 | |
1825 if (mkdir (dir, 0777) != 0) | |
1826 report_file_error ("Creating directory", Flist (1, &dirname)); | |
1827 | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1828 return Qnil; |
230 | 1829 } |
1830 | |
686
bd3068742807
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
1831 DEFUN ("delete-directory", Fdelete_directory, Sdelete_directory, 1, 1, "FDelete directory: ", |
bd3068742807
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
1832 "Delete a directory. One argument, a file name string.") |
230 | 1833 (dirname) |
1834 Lisp_Object dirname; | |
1835 { | |
1836 unsigned char *dir; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1837 Lisp_Object handler; |
230 | 1838 |
1839 CHECK_STRING (dirname, 0); | |
1840 dirname = Fexpand_file_name (dirname, Qnil); | |
1841 dir = XSTRING (dirname)->data; | |
1842 | |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
1843 handler = Ffind_file_name_handler (dirname); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1844 if (!NILP (handler)) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1845 return call2 (handler, Qdelete_directory, dirname); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1846 |
230 | 1847 if (rmdir (dir) != 0) |
1848 report_file_error ("Removing directory", Flist (1, &dirname)); | |
1849 | |
1850 return Qnil; | |
1851 } | |
1852 | |
1853 DEFUN ("delete-file", Fdelete_file, Sdelete_file, 1, 1, "fDelete file: ", | |
1854 "Delete specified file. One argument, a file name string.\n\ | |
1855 If file has multiple names, it continues to exist with the other names.") | |
1856 (filename) | |
1857 Lisp_Object filename; | |
1858 { | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1859 Lisp_Object handler; |
230 | 1860 CHECK_STRING (filename, 0); |
1861 filename = Fexpand_file_name (filename, Qnil); | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1862 |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
1863 handler = Ffind_file_name_handler (filename); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1864 if (!NILP (handler)) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1865 return call2 (handler, Qdelete_file, filename); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1866 |
230 | 1867 if (0 > unlink (XSTRING (filename)->data)) |
1868 report_file_error ("Removing old name", Flist (1, &filename)); | |
1869 return Qnil; | |
1870 } | |
1871 | |
1872 DEFUN ("rename-file", Frename_file, Srename_file, 2, 3, | |
1873 "fRename file: \nFRename %s to file: \np", | |
1874 "Rename FILE as NEWNAME. Both args strings.\n\ | |
1875 If file has names other than FILE, it continues to have those names.\n\ | |
1876 Signals a `file-already-exists' error if a file NEWNAME already exists\n\ | |
1877 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.\n\ | |
1878 A number as third arg means request confirmation if NEWNAME already exists.\n\ | |
1879 This is what happens in interactive use with M-x.") | |
1880 (filename, newname, ok_if_already_exists) | |
1881 Lisp_Object filename, newname, ok_if_already_exists; | |
1882 { | |
1883 #ifdef NO_ARG_ARRAY | |
1884 Lisp_Object args[2]; | |
1885 #endif | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1886 Lisp_Object handler; |
230 | 1887 struct gcpro gcpro1, gcpro2; |
1888 | |
1889 GCPRO2 (filename, newname); | |
1890 CHECK_STRING (filename, 0); | |
1891 CHECK_STRING (newname, 1); | |
1892 filename = Fexpand_file_name (filename, Qnil); | |
1893 newname = Fexpand_file_name (newname, Qnil); | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1894 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1895 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1896 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
1897 handler = Ffind_file_name_handler (filename); |
3705
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1898 if (NILP (handler)) |
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1899 handler = Ffind_file_name_handler (newname); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1900 if (!NILP (handler)) |
3598
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
3560
diff
changeset
|
1901 return call4 (handler, Qrename_file, |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
3560
diff
changeset
|
1902 filename, newname, ok_if_already_exists); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1903 |
485 | 1904 if (NILP (ok_if_already_exists) |
230 | 1905 || XTYPE (ok_if_already_exists) == Lisp_Int) |
1906 barf_or_query_if_file_exists (newname, "rename to it", | |
1907 XTYPE (ok_if_already_exists) == Lisp_Int); | |
1908 #ifndef BSD4_1 | |
1909 if (0 > rename (XSTRING (filename)->data, XSTRING (newname)->data)) | |
1910 #else | |
1911 if (0 > link (XSTRING (filename)->data, XSTRING (newname)->data) | |
1912 || 0 > unlink (XSTRING (filename)->data)) | |
1913 #endif | |
1914 { | |
1915 if (errno == EXDEV) | |
1916 { | |
3963
39caef7a70c2
(Frename_file): After prompting for ok-if-already-exists, pass only nil or
Roland McGrath <roland@gnu.org>
parents:
3829
diff
changeset
|
1917 Fcopy_file (filename, newname, |
39caef7a70c2
(Frename_file): After prompting for ok-if-already-exists, pass only nil or
Roland McGrath <roland@gnu.org>
parents:
3829
diff
changeset
|
1918 /* We have already prompted if it was an integer, |
39caef7a70c2
(Frename_file): After prompting for ok-if-already-exists, pass only nil or
Roland McGrath <roland@gnu.org>
parents:
3829
diff
changeset
|
1919 so don't have copy-file prompt again. */ |
39caef7a70c2
(Frename_file): After prompting for ok-if-already-exists, pass only nil or
Roland McGrath <roland@gnu.org>
parents:
3829
diff
changeset
|
1920 NILP (ok_if_already_exists) ? Qnil : Qt, Qt); |
230 | 1921 Fdelete_file (filename); |
1922 } | |
1923 else | |
1924 #ifdef NO_ARG_ARRAY | |
1925 { | |
1926 args[0] = filename; | |
1927 args[1] = newname; | |
1928 report_file_error ("Renaming", Flist (2, args)); | |
1929 } | |
1930 #else | |
1931 report_file_error ("Renaming", Flist (2, &filename)); | |
1932 #endif | |
1933 } | |
1934 UNGCPRO; | |
1935 return Qnil; | |
1936 } | |
1937 | |
1938 DEFUN ("add-name-to-file", Fadd_name_to_file, Sadd_name_to_file, 2, 3, | |
1939 "fAdd name to file: \nFName to add to %s: \np", | |
1940 "Give FILE additional name NEWNAME. Both args strings.\n\ | |
1941 Signals a `file-already-exists' error if a file NEWNAME already exists\n\ | |
1942 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.\n\ | |
1943 A number as third arg means request confirmation if NEWNAME already exists.\n\ | |
1944 This is what happens in interactive use with M-x.") | |
1945 (filename, newname, ok_if_already_exists) | |
1946 Lisp_Object filename, newname, ok_if_already_exists; | |
1947 { | |
1948 #ifdef NO_ARG_ARRAY | |
1949 Lisp_Object args[2]; | |
1950 #endif | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1951 Lisp_Object handler; |
230 | 1952 struct gcpro gcpro1, gcpro2; |
1953 | |
1954 GCPRO2 (filename, newname); | |
1955 CHECK_STRING (filename, 0); | |
1956 CHECK_STRING (newname, 1); | |
1957 filename = Fexpand_file_name (filename, Qnil); | |
1958 newname = Fexpand_file_name (newname, Qnil); | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1959 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1960 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1961 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
1962 handler = Ffind_file_name_handler (filename); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1963 if (!NILP (handler)) |
3705
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1964 return call4 (handler, Qadd_name_to_file, filename, newname, |
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1965 ok_if_already_exists); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
1966 |
485 | 1967 if (NILP (ok_if_already_exists) |
230 | 1968 || XTYPE (ok_if_already_exists) == Lisp_Int) |
1969 barf_or_query_if_file_exists (newname, "make it a new name", | |
1970 XTYPE (ok_if_already_exists) == Lisp_Int); | |
1971 unlink (XSTRING (newname)->data); | |
1972 if (0 > link (XSTRING (filename)->data, XSTRING (newname)->data)) | |
1973 { | |
1974 #ifdef NO_ARG_ARRAY | |
1975 args[0] = filename; | |
1976 args[1] = newname; | |
1977 report_file_error ("Adding new name", Flist (2, args)); | |
1978 #else | |
1979 report_file_error ("Adding new name", Flist (2, &filename)); | |
1980 #endif | |
1981 } | |
1982 | |
1983 UNGCPRO; | |
1984 return Qnil; | |
1985 } | |
1986 | |
1987 #ifdef S_IFLNK | |
1988 DEFUN ("make-symbolic-link", Fmake_symbolic_link, Smake_symbolic_link, 2, 3, | |
1989 "FMake symbolic link to file: \nFMake symbolic link to file %s: \np", | |
1990 "Make a symbolic link to FILENAME, named LINKNAME. Both args strings.\n\ | |
1991 Signals a `file-already-exists' error if a file NEWNAME already exists\n\ | |
1992 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.\n\ | |
1993 A number as third arg means request confirmation if NEWNAME already exists.\n\ | |
1994 This happens for interactive use with M-x.") | |
732 | 1995 (filename, linkname, ok_if_already_exists) |
1996 Lisp_Object filename, linkname, ok_if_already_exists; | |
230 | 1997 { |
1998 #ifdef NO_ARG_ARRAY | |
1999 Lisp_Object args[2]; | |
2000 #endif | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2001 Lisp_Object handler; |
230 | 2002 struct gcpro gcpro1, gcpro2; |
2003 | |
732 | 2004 GCPRO2 (filename, linkname); |
230 | 2005 CHECK_STRING (filename, 0); |
732 | 2006 CHECK_STRING (linkname, 1); |
5245
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
2007 /* If the link target has a ~, we must expand it to get |
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
2008 a truly valid file name. Otherwise, do not expand; |
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
2009 we want to permit links to relative file names. */ |
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
2010 if (XSTRING (filename)->data[0] == '~') |
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
2011 filename = Fexpand_file_name (filename, Qnil); |
732 | 2012 linkname = Fexpand_file_name (linkname, Qnil); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2013 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2014 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2015 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2016 handler = Ffind_file_name_handler (filename); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2017 if (!NILP (handler)) |
3705
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
2018 return call4 (handler, Qmake_symbolic_link, filename, linkname, |
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
2019 ok_if_already_exists); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2020 |
485 | 2021 if (NILP (ok_if_already_exists) |
230 | 2022 || XTYPE (ok_if_already_exists) == Lisp_Int) |
732 | 2023 barf_or_query_if_file_exists (linkname, "make it a link", |
230 | 2024 XTYPE (ok_if_already_exists) == Lisp_Int); |
732 | 2025 if (0 > symlink (XSTRING (filename)->data, XSTRING (linkname)->data)) |
230 | 2026 { |
2027 /* If we didn't complain already, silently delete existing file. */ | |
2028 if (errno == EEXIST) | |
2029 { | |
2650
f378d89945e1
* fileio.c (Fmake_symbolic_link): If a file already exists under
Jim Blandy <jimb@redhat.com>
parents:
2607
diff
changeset
|
2030 unlink (XSTRING (linkname)->data); |
732 | 2031 if (0 <= symlink (XSTRING (filename)->data, XSTRING (linkname)->data)) |
230 | 2032 return Qnil; |
2033 } | |
2034 | |
2035 #ifdef NO_ARG_ARRAY | |
2036 args[0] = filename; | |
732 | 2037 args[1] = linkname; |
230 | 2038 report_file_error ("Making symbolic link", Flist (2, args)); |
2039 #else | |
2040 report_file_error ("Making symbolic link", Flist (2, &filename)); | |
2041 #endif | |
2042 } | |
2043 UNGCPRO; | |
2044 return Qnil; | |
2045 } | |
2046 #endif /* S_IFLNK */ | |
2047 | |
2048 #ifdef VMS | |
2049 | |
2050 DEFUN ("define-logical-name", Fdefine_logical_name, Sdefine_logical_name, | |
2051 2, 2, "sDefine logical name: \nsDefine logical name %s as: ", | |
2052 "Define the job-wide logical name NAME to have the value STRING.\n\ | |
2053 If STRING is nil or a null string, the logical name NAME is deleted.") | |
2054 (varname, string) | |
2055 Lisp_Object varname; | |
2056 Lisp_Object string; | |
2057 { | |
2058 CHECK_STRING (varname, 0); | |
485 | 2059 if (NILP (string)) |
230 | 2060 delete_logical_name (XSTRING (varname)->data); |
2061 else | |
2062 { | |
2063 CHECK_STRING (string, 1); | |
2064 | |
2065 if (XSTRING (string)->size == 0) | |
2066 delete_logical_name (XSTRING (varname)->data); | |
2067 else | |
2068 define_logical_name (XSTRING (varname)->data, XSTRING (string)->data); | |
2069 } | |
2070 | |
2071 return string; | |
2072 } | |
2073 #endif /* VMS */ | |
2074 | |
2075 #ifdef HPUX_NET | |
2076 | |
2077 DEFUN ("sysnetunam", Fsysnetunam, Ssysnetunam, 2, 2, 0, | |
2078 "Open a network connection to PATH using LOGIN as the login string.") | |
2079 (path, login) | |
2080 Lisp_Object path, login; | |
2081 { | |
2082 int netresult; | |
2083 | |
2084 CHECK_STRING (path, 0); | |
2085 CHECK_STRING (login, 0); | |
2086 | |
2087 netresult = netunam (XSTRING (path)->data, XSTRING (login)->data); | |
2088 | |
2089 if (netresult == -1) | |
2090 return Qnil; | |
2091 else | |
2092 return Qt; | |
2093 } | |
2094 #endif /* HPUX_NET */ | |
2095 | |
2096 DEFUN ("file-name-absolute-p", Ffile_name_absolute_p, Sfile_name_absolute_p, | |
2097 1, 1, 0, | |
2098 "Return t if file FILENAME specifies an absolute path name.\n\ | |
2099 On Unix, this is a name starting with a `/' or a `~'.") | |
2100 (filename) | |
2101 Lisp_Object filename; | |
2102 { | |
2103 unsigned char *ptr; | |
2104 | |
2105 CHECK_STRING (filename, 0); | |
2106 ptr = XSTRING (filename)->data; | |
2107 if (*ptr == '/' || *ptr == '~' | |
2108 #ifdef VMS | |
2109 /* ??? This criterion is probably wrong for '<'. */ | |
2110 || index (ptr, ':') || index (ptr, '<') | |
2111 || (*ptr == '[' && (ptr[1] != '-' || (ptr[2] != '.' && ptr[2] != ']')) | |
2112 && ptr[1] != '.') | |
2113 #endif /* VMS */ | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2114 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2115 || (*ptr != 0 && ptr[1] == ':' && ptr[2] == '/') |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2116 #endif |
230 | 2117 ) |
2118 return Qt; | |
2119 else | |
2120 return Qnil; | |
2121 } | |
2122 | |
2123 DEFUN ("file-exists-p", Ffile_exists_p, Sfile_exists_p, 1, 1, 0, | |
2124 "Return t if file FILENAME exists. (This does not mean you can read it.)\n\ | |
2125 See also `file-readable-p' and `file-attributes'.") | |
2126 (filename) | |
2127 Lisp_Object filename; | |
2128 { | |
2129 Lisp_Object abspath; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2130 Lisp_Object handler; |
230 | 2131 |
2132 CHECK_STRING (filename, 0); | |
2133 abspath = Fexpand_file_name (filename, Qnil); | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2134 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2135 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2136 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2137 handler = Ffind_file_name_handler (abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2138 if (!NILP (handler)) |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2139 return call2 (handler, Qfile_exists_p, abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2140 |
230 | 2141 return (access (XSTRING (abspath)->data, 0) >= 0) ? Qt : Qnil; |
2142 } | |
2143 | |
2144 DEFUN ("file-executable-p", Ffile_executable_p, Sfile_executable_p, 1, 1, 0, | |
2145 "Return t if FILENAME can be executed by you.\n\ | |
2236 | 2146 For a directory, this means you can access files in that directory.") |
230 | 2147 (filename) |
2148 Lisp_Object filename; | |
2149 | |
2150 { | |
2151 Lisp_Object abspath; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2152 Lisp_Object handler; |
230 | 2153 |
2154 CHECK_STRING (filename, 0); | |
2155 abspath = Fexpand_file_name (filename, Qnil); | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2156 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2157 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2158 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2159 handler = Ffind_file_name_handler (abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2160 if (!NILP (handler)) |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2161 return call2 (handler, Qfile_executable_p, abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2162 |
230 | 2163 return (access (XSTRING (abspath)->data, 1) >= 0) ? Qt : Qnil; |
2164 } | |
2165 | |
2166 DEFUN ("file-readable-p", Ffile_readable_p, Sfile_readable_p, 1, 1, 0, | |
2167 "Return t if file FILENAME exists and you can read it.\n\ | |
2168 See also `file-exists-p' and `file-attributes'.") | |
2169 (filename) | |
2170 Lisp_Object filename; | |
2171 { | |
2172 Lisp_Object abspath; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2173 Lisp_Object handler; |
230 | 2174 |
2175 CHECK_STRING (filename, 0); | |
2176 abspath = Fexpand_file_name (filename, Qnil); | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2177 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2178 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2179 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2180 handler = Ffind_file_name_handler (abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2181 if (!NILP (handler)) |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2182 return call2 (handler, Qfile_readable_p, abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2183 |
230 | 2184 return (access (XSTRING (abspath)->data, 4) >= 0) ? Qt : Qnil; |
2185 } | |
2186 | |
2187 DEFUN ("file-symlink-p", Ffile_symlink_p, Sfile_symlink_p, 1, 1, 0, | |
2188 "If file FILENAME is the name of a symbolic link\n\ | |
2189 returns the name of the file to which it is linked.\n\ | |
2190 Otherwise returns NIL.") | |
2191 (filename) | |
2192 Lisp_Object filename; | |
2193 { | |
2194 #ifdef S_IFLNK | |
2195 char *buf; | |
2196 int bufsize; | |
2197 int valsize; | |
2198 Lisp_Object val; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2199 Lisp_Object handler; |
230 | 2200 |
2201 CHECK_STRING (filename, 0); | |
2202 filename = Fexpand_file_name (filename, Qnil); | |
2203 | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2204 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2205 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2206 handler = Ffind_file_name_handler (filename); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2207 if (!NILP (handler)) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2208 return call2 (handler, Qfile_symlink_p, filename); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2209 |
230 | 2210 bufsize = 100; |
2211 while (1) | |
2212 { | |
2213 buf = (char *) xmalloc (bufsize); | |
2214 bzero (buf, bufsize); | |
2215 valsize = readlink (XSTRING (filename)->data, buf, bufsize); | |
2216 if (valsize < bufsize) break; | |
2217 /* Buffer was not long enough */ | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2435
diff
changeset
|
2218 xfree (buf); |
230 | 2219 bufsize *= 2; |
2220 } | |
2221 if (valsize == -1) | |
2222 { | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2435
diff
changeset
|
2223 xfree (buf); |
230 | 2224 return Qnil; |
2225 } | |
2226 val = make_string (buf, valsize); | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2435
diff
changeset
|
2227 xfree (buf); |
230 | 2228 return val; |
2229 #else /* not S_IFLNK */ | |
2230 return Qnil; | |
2231 #endif /* not S_IFLNK */ | |
2232 } | |
2233 | |
2741
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2234 #ifdef SOLARIS_BROKEN_ACCESS |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2235 /* In Solaris 2.1, the readonly-ness of the filesystem is not |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2236 considered by the access system call. This is Sun's bug, but we |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2237 still have to make Emacs work. */ |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2238 |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2239 #include <sys/statvfs.h> |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2240 |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2241 static int |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2242 ro_fsys (path) |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2243 char *path; |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2244 { |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2245 struct statvfs statvfsb; |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2246 |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2247 if (statvfs(path, &statvfsb)) |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2248 return 1; /* error from statvfs, be conservative and say not wrtable */ |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2249 else |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2250 /* Otherwise, fsys is ro if bit is set. */ |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2251 return statvfsb.f_flag & ST_RDONLY; |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2252 } |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2253 #else |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2254 /* But on every other os, access has already done the right thing. */ |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2255 #define ro_fsys(path) 0 |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2256 #endif |
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2257 |
230 | 2258 /* Having this before file-symlink-p mysteriously caused it to be forgotten |
2259 on the RT/PC. */ | |
2260 DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, | |
2261 "Return t if file FILENAME can be written or created by you.") | |
2262 (filename) | |
2263 Lisp_Object filename; | |
2264 { | |
2265 Lisp_Object abspath, dir; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2266 Lisp_Object handler; |
230 | 2267 |
2268 CHECK_STRING (filename, 0); | |
2269 abspath = Fexpand_file_name (filename, Qnil); | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2270 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2271 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2272 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2273 handler = Ffind_file_name_handler (abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2274 if (!NILP (handler)) |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2275 return call2 (handler, Qfile_writable_p, abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2276 |
230 | 2277 if (access (XSTRING (abspath)->data, 0) >= 0) |
2741
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2278 return ((access (XSTRING (abspath)->data, 2) >= 0 |
3017
3afba65e22fa
* fileio.c (Ffile_writable_p): Pass XSTRING (foo)->data to
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
2279 && ! ro_fsys ((char *) XSTRING (abspath)->data)) |
2741
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2280 ? Qt : Qnil); |
230 | 2281 dir = Ffile_name_directory (abspath); |
2282 #ifdef VMS | |
485 | 2283 if (!NILP (dir)) |
230 | 2284 dir = Fdirectory_file_name (dir); |
2285 #endif /* VMS */ | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2286 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2287 if (!NILP (dir)) |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2288 dir = Fdirectory_file_name (dir); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2289 #endif /* MSDOS */ |
2741
1d72336294c6
* fileio.c (ro_fsys) [SOLARIS_BROKEN_ACCESS]: Check for the
Jim Blandy <jimb@redhat.com>
parents:
2650
diff
changeset
|
2290 return ((access (!NILP (dir) ? (char *) XSTRING (dir)->data : "", 2) >= 0 |
3017
3afba65e22fa
* fileio.c (Ffile_writable_p): Pass XSTRING (foo)->data to
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
2291 && ! ro_fsys ((char *) XSTRING (dir)->data)) |
230 | 2292 ? Qt : Qnil); |
2293 } | |
2294 | |
2295 DEFUN ("file-directory-p", Ffile_directory_p, Sfile_directory_p, 1, 1, 0, | |
2296 "Return t if file FILENAME is the name of a directory as a file.\n\ | |
2297 A directory name spec may be given instead; then the value is t\n\ | |
2298 if the directory so specified exists and really is a directory.") | |
2299 (filename) | |
2300 Lisp_Object filename; | |
2301 { | |
2302 register Lisp_Object abspath; | |
2303 struct stat st; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2304 Lisp_Object handler; |
230 | 2305 |
2306 abspath = expand_and_dir_to_file (filename, current_buffer->directory); | |
2307 | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2308 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2309 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2310 handler = Ffind_file_name_handler (abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2311 if (!NILP (handler)) |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2312 return call2 (handler, Qfile_directory_p, abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2313 |
230 | 2314 if (stat (XSTRING (abspath)->data, &st) < 0) |
2315 return Qnil; | |
2316 return (st.st_mode & S_IFMT) == S_IFDIR ? Qt : Qnil; | |
2317 } | |
2318 | |
536 | 2319 DEFUN ("file-accessible-directory-p", Ffile_accessible_directory_p, Sfile_accessible_directory_p, 1, 1, 0, |
2320 "Return t if file FILENAME is the name of a directory as a file,\n\ | |
2321 and files in that directory can be opened by you. In order to use a\n\ | |
2322 directory as a buffer's current directory, this predicate must return true.\n\ | |
2323 A directory name spec may be given instead; then the value is t\n\ | |
2324 if the directory so specified exists and really is a readable and\n\ | |
2325 searchable directory.") | |
2326 (filename) | |
2327 Lisp_Object filename; | |
2328 { | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2329 Lisp_Object handler; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2330 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2331 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2332 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2333 handler = Ffind_file_name_handler (filename); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2334 if (!NILP (handler)) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2335 return call2 (handler, Qfile_accessible_directory_p, filename); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2336 |
536 | 2337 if (NILP (Ffile_directory_p (filename)) |
2338 || NILP (Ffile_executable_p (filename))) | |
2339 return Qnil; | |
2340 else | |
2341 return Qt; | |
2342 } | |
2343 | |
230 | 2344 DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0, |
2345 "Return mode bits of FILE, as an integer.") | |
2346 (filename) | |
2347 Lisp_Object filename; | |
2348 { | |
2349 Lisp_Object abspath; | |
2350 struct stat st; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2351 Lisp_Object handler; |
230 | 2352 |
2353 abspath = expand_and_dir_to_file (filename, current_buffer->directory); | |
2354 | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2355 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2356 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2357 handler = Ffind_file_name_handler (abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2358 if (!NILP (handler)) |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2359 return call2 (handler, Qfile_modes, abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2360 |
230 | 2361 if (stat (XSTRING (abspath)->data, &st) < 0) |
2362 return Qnil; | |
2363 return make_number (st.st_mode & 07777); | |
2364 } | |
2365 | |
2366 DEFUN ("set-file-modes", Fset_file_modes, Sset_file_modes, 2, 2, 0, | |
2367 "Set mode bits of FILE to MODE (an integer).\n\ | |
2368 Only the 12 low bits of MODE are used.") | |
2369 (filename, mode) | |
2370 Lisp_Object filename, mode; | |
2371 { | |
2372 Lisp_Object abspath; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2373 Lisp_Object handler; |
230 | 2374 |
2375 abspath = Fexpand_file_name (filename, current_buffer->directory); | |
2376 CHECK_NUMBER (mode, 1); | |
2377 | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2378 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2379 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2380 handler = Ffind_file_name_handler (abspath); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2381 if (!NILP (handler)) |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2382 return call3 (handler, Qset_file_modes, abspath, mode); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2383 |
230 | 2384 #ifndef APOLLO |
2385 if (chmod (XSTRING (abspath)->data, XINT (mode)) < 0) | |
2386 report_file_error ("Doing chmod", Fcons (abspath, Qnil)); | |
2387 #else /* APOLLO */ | |
2388 if (!egetenv ("USE_DOMAIN_ACLS")) | |
2389 { | |
2390 struct stat st; | |
2391 struct timeval tvp[2]; | |
2392 | |
2393 /* chmod on apollo also change the file's modtime; need to save the | |
2394 modtime and then restore it. */ | |
2395 if (stat (XSTRING (abspath)->data, &st) < 0) | |
2396 { | |
2397 report_file_error ("Doing chmod", Fcons (abspath, Qnil)); | |
2398 return (Qnil); | |
2399 } | |
2400 | |
2401 if (chmod (XSTRING (abspath)->data, XINT (mode)) < 0) | |
2402 report_file_error ("Doing chmod", Fcons (abspath, Qnil)); | |
2403 | |
2404 /* reset the old accessed and modified times. */ | |
2405 tvp[0].tv_sec = st.st_atime + 1; /* +1 due to an Apollo roundoff bug */ | |
2406 tvp[0].tv_usec = 0; | |
2407 tvp[1].tv_sec = st.st_mtime + 1; /* +1 due to an Apollo roundoff bug */ | |
2408 tvp[1].tv_usec = 0; | |
2409 | |
2410 if (utimes (XSTRING (abspath)->data, tvp) < 0) | |
2411 report_file_error ("Doing utimes", Fcons (abspath, Qnil)); | |
2412 } | |
2413 #endif /* APOLLO */ | |
2414 | |
2415 return Qnil; | |
2416 } | |
2417 | |
1763
65e858c07a8b
(Fset_default_file_modes, Fdefault_file_modes): Renamed from .._mode.
Richard M. Stallman <rms@gnu.org>
parents:
1762
diff
changeset
|
2418 DEFUN ("set-default-file-modes", Fset_default_file_modes, Sset_default_file_modes, 1, 1, 0, |
1762
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2419 "Set the file permission bits for newly created files.\n\ |
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2420 The argument MODE should be an integer; only the low 9 bits are used.\n\ |
550 | 2421 This setting is inherited by subprocesses.") |
1762
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2422 (mode) |
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2423 Lisp_Object mode; |
550 | 2424 { |
1762
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2425 CHECK_NUMBER (mode, 0); |
550 | 2426 |
1762
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2427 umask ((~ XINT (mode)) & 0777); |
550 | 2428 |
2429 return Qnil; | |
2430 } | |
2431 | |
1763
65e858c07a8b
(Fset_default_file_modes, Fdefault_file_modes): Renamed from .._mode.
Richard M. Stallman <rms@gnu.org>
parents:
1762
diff
changeset
|
2432 DEFUN ("default-file-modes", Fdefault_file_modes, Sdefault_file_modes, 0, 0, 0, |
1762
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2433 "Return the default file protection for created files.\n\ |
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2434 The value is an integer.") |
550 | 2435 () |
2436 { | |
1762
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2437 int realmask; |
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2438 Lisp_Object value; |
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2439 |
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2440 realmask = umask (0); |
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2441 umask (realmask); |
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2442 |
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2443 XSET (value, Lisp_Int, (~ realmask) & 0777); |
d70878f22be4
(Fset_default_file_mode, Fdefault_file_mode):
Richard M. Stallman <rms@gnu.org>
parents:
1761
diff
changeset
|
2444 return value; |
550 | 2445 } |
2446 | |
689
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2447 #ifdef unix |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2448 |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2449 DEFUN ("unix-sync", Funix_sync, Sunix_sync, 0, 0, "", |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2450 "Tell Unix to finish all pending disk updates.") |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2451 () |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2452 { |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2453 sync (); |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2454 return Qnil; |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2455 } |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2456 |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2457 #endif /* unix */ |
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
2458 |
230 | 2459 DEFUN ("file-newer-than-file-p", Ffile_newer_than_file_p, Sfile_newer_than_file_p, 2, 2, 0, |
2460 "Return t if file FILE1 is newer than file FILE2.\n\ | |
2461 If FILE1 does not exist, the answer is nil;\n\ | |
2462 otherwise, if FILE2 does not exist, the answer is t.") | |
2463 (file1, file2) | |
2464 Lisp_Object file1, file2; | |
2465 { | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2466 Lisp_Object abspath1, abspath2; |
230 | 2467 struct stat st; |
2468 int mtime1; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2469 Lisp_Object handler; |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2470 struct gcpro gcpro1, gcpro2; |
230 | 2471 |
2472 CHECK_STRING (file1, 0); | |
2473 CHECK_STRING (file2, 0); | |
2474 | |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2475 abspath1 = Qnil; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2476 GCPRO2 (abspath1, file2); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2477 abspath1 = expand_and_dir_to_file (file1, current_buffer->directory); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2478 abspath2 = expand_and_dir_to_file (file2, current_buffer->directory); |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2479 UNGCPRO; |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2480 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2481 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2482 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2483 handler = Ffind_file_name_handler (abspath1); |
3705
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
2484 if (NILP (handler)) |
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
2485 handler = Ffind_file_name_handler (abspath2); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2486 if (!NILP (handler)) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2487 return call3 (handler, Qfile_newer_than_file_p, abspath1, abspath2); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2488 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2489 if (stat (XSTRING (abspath1)->data, &st) < 0) |
230 | 2490 return Qnil; |
2491 | |
2492 mtime1 = st.st_mtime; | |
2493 | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2494 if (stat (XSTRING (abspath2)->data, &st) < 0) |
230 | 2495 return Qt; |
2496 | |
2497 return (mtime1 > st.st_mtime) ? Qt : Qnil; | |
2498 } | |
2499 | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2500 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2501 Lisp_Object Qfind_buffer_file_type; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2502 #endif |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2503 |
230 | 2504 DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, |
3787
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2505 1, 4, 0, |
230 | 2506 "Insert contents of file FILENAME after point.\n\ |
3787
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2507 Returns list of absolute file name and length of data inserted.\n\ |
230 | 2508 If second argument VISIT is non-nil, the buffer's visited filename\n\ |
2509 and last save file modtime are set, and it is marked unmodified.\n\ | |
2510 If visiting and the file does not exist, visiting is completed\n\ | |
3787
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2511 before the error is signaled.\n\n\ |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2512 The optional third and fourth arguments BEG and END\n\ |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2513 specify what portion of the file to insert.\n\ |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2514 If VISIT is non-nil, BEG and END must be nil.") |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2515 (filename, visit, beg, end) |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2516 Lisp_Object filename, visit, beg, end; |
230 | 2517 { |
2518 struct stat st; | |
2519 register int fd; | |
2520 register int inserted = 0; | |
2521 register int how_much; | |
2522 int count = specpdl_ptr - specpdl; | |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2523 struct gcpro gcpro1, gcpro2; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2524 Lisp_Object handler, val, insval; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2525 Lisp_Object p; |
3787
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2526 int total; |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2527 |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2528 val = Qnil; |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2529 p = Qnil; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2530 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2531 GCPRO2 (filename, p); |
485 | 2532 if (!NILP (current_buffer->read_only)) |
230 | 2533 Fbarf_if_buffer_read_only(); |
2534 | |
2535 CHECK_STRING (filename, 0); | |
2536 filename = Fexpand_file_name (filename, Qnil); | |
2537 | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2538 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2539 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2540 handler = Ffind_file_name_handler (filename); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2541 if (!NILP (handler)) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2542 { |
3787
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2543 val = call5 (handler, Qinsert_file_contents, filename, visit, beg, end); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2544 goto handled; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2545 } |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2546 |
230 | 2547 fd = -1; |
2548 | |
2549 #ifndef APOLLO | |
2550 if (stat (XSTRING (filename)->data, &st) < 0 | |
410 | 2551 || (fd = open (XSTRING (filename)->data, 0)) < 0) |
230 | 2552 #else |
2553 if ((fd = open (XSTRING (filename)->data, 0)) < 0 | |
2554 || fstat (fd, &st) < 0) | |
2555 #endif /* not APOLLO */ | |
2556 { | |
2557 if (fd >= 0) close (fd); | |
485 | 2558 if (NILP (visit)) |
230 | 2559 report_file_error ("Opening input file", Fcons (filename, Qnil)); |
2560 st.st_mtime = -1; | |
2561 how_much = 0; | |
2562 goto notfound; | |
2563 } | |
2564 | |
2565 record_unwind_protect (close_file_unwind, make_number (fd)); | |
2566 | |
752 | 2567 #ifdef S_IFSOCK |
2568 /* This code will need to be changed in order to work on named | |
2569 pipes, and it's probably just not worth it. So we should at | |
2570 least signal an error. */ | |
2571 if ((st.st_mode & S_IFMT) == S_IFSOCK) | |
2572 Fsignal (Qfile_error, | |
2573 Fcons (build_string ("reading from named pipe"), | |
2574 Fcons (filename, Qnil))); | |
2575 #endif | |
2576 | |
230 | 2577 /* Supposedly happens on VMS. */ |
2578 if (st.st_size < 0) | |
2579 error ("File size is negative"); | |
752 | 2580 |
3787
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2581 if (!NILP (beg) || !NILP (end)) |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2582 if (!NILP (visit)) |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2583 error ("Attempt to visit less than an entire file"); |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2584 |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2585 if (!NILP (beg)) |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2586 CHECK_NUMBER (beg, 0); |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2587 else |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2588 XFASTINT (beg) = 0; |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2589 |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2590 if (!NILP (end)) |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2591 CHECK_NUMBER (end, 0); |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2592 else |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2593 { |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2594 XSETINT (end, st.st_size); |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2595 if (XINT (end) != st.st_size) |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2596 error ("maximum buffer size exceeded"); |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2597 } |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2598 |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2599 total = XINT (end) - XINT (beg); |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2600 |
230 | 2601 { |
2602 register Lisp_Object temp; | |
2603 | |
2604 /* Make sure point-max won't overflow after this insertion. */ | |
3787
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2605 XSET (temp, Lisp_Int, total); |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2606 if (total != XINT (temp)) |
230 | 2607 error ("maximum buffer size exceeded"); |
2608 } | |
2609 | |
4395
76b24be40a57
(Finsert_file_contents): Don't call prepare_to_modify_buffer
Richard M. Stallman <rms@gnu.org>
parents:
4270
diff
changeset
|
2610 if (NILP (visit) && total > 0) |
230 | 2611 prepare_to_modify_buffer (point, point); |
2612 | |
2613 move_gap (point); | |
3787
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2614 if (GAP_SIZE < total) |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2615 make_gap (total - GAP_SIZE); |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2616 |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2617 if (XINT (beg) != 0) |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2618 { |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2619 if (lseek (fd, XINT (beg), 0) < 0) |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2620 report_file_error ("Setting file position", Fcons (filename, Qnil)); |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2621 } |
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2622 |
230 | 2623 while (1) |
2624 { | |
3787
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2625 int try = min (total - inserted, 64 << 10); |
592
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
2626 int this; |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
2627 |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
2628 /* Allow quitting out of the actual I/O. */ |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
2629 immediate_quit = 1; |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
2630 QUIT; |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
2631 this = read (fd, &FETCH_CHAR (point + inserted - 1) + 1, try); |
e65af468dcc2
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
564
diff
changeset
|
2632 immediate_quit = 0; |
230 | 2633 |
2634 if (this <= 0) | |
2635 { | |
2636 how_much = this; | |
2637 break; | |
2638 } | |
2639 | |
2640 GPT += this; | |
2641 GAP_SIZE -= this; | |
2642 ZV += this; | |
2643 Z += this; | |
2644 inserted += this; | |
2645 } | |
2646 | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2647 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2648 /* Demacs 1.1.1 91/10/16 HIRANO Satoshi, MW July 1993 */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2649 /* Determine file type from name and remove LFs from CR-LFs if the file |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2650 is deemed to be a text file. */ |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2651 { |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2652 struct gcpro gcpro1; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2653 Lisp_Object code = Qnil; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2654 GCPRO1 (filename); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2655 code = call1 (Qfind_buffer_file_type, filename); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2656 UNGCPRO; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2657 if (XTYPE (code) == Lisp_Int) |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2658 XFASTINT (current_buffer->buffer_file_type) = XFASTINT (code); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2659 if (XFASTINT (current_buffer->buffer_file_type) == 0) |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2660 { |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2661 int reduced_size = |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2662 inserted - crlf_to_lf (inserted, &FETCH_CHAR (point - 1) + 1); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2663 ZV -= reduced_size; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2664 Z -= reduced_size; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2665 GPT -= reduced_size; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2666 GAP_SIZE += reduced_size; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2667 inserted -= reduced_size; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2668 } |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2669 } |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2670 #endif |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2671 |
230 | 2672 if (inserted > 0) |
1240
7365d006d0a0
(Finsert_file_contents): Do record_insert, then inc MODIFF.
Richard M. Stallman <rms@gnu.org>
parents:
1204
diff
changeset
|
2673 { |
7365d006d0a0
(Finsert_file_contents): Do record_insert, then inc MODIFF.
Richard M. Stallman <rms@gnu.org>
parents:
1204
diff
changeset
|
2674 record_insert (point, inserted); |
1299
b8337cdf2e8b
* fileio.c (Finsert_file_contents): Call offset_intervals() if
Joseph Arceneaux <jla@gnu.org>
parents:
1240
diff
changeset
|
2675 |
b8337cdf2e8b
* fileio.c (Finsert_file_contents): Call offset_intervals() if
Joseph Arceneaux <jla@gnu.org>
parents:
1240
diff
changeset
|
2676 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ |
b8337cdf2e8b
* fileio.c (Finsert_file_contents): Call offset_intervals() if
Joseph Arceneaux <jla@gnu.org>
parents:
1240
diff
changeset
|
2677 offset_intervals (current_buffer, point, inserted); |
1240
7365d006d0a0
(Finsert_file_contents): Do record_insert, then inc MODIFF.
Richard M. Stallman <rms@gnu.org>
parents:
1204
diff
changeset
|
2678 MODIFF++; |
7365d006d0a0
(Finsert_file_contents): Do record_insert, then inc MODIFF.
Richard M. Stallman <rms@gnu.org>
parents:
1204
diff
changeset
|
2679 } |
230 | 2680 |
2681 close (fd); | |
2682 | |
2683 /* Discard the unwind protect */ | |
2684 specpdl_ptr = specpdl + count; | |
2685 | |
2686 if (how_much < 0) | |
2687 error ("IO error reading %s: %s", | |
5517
8b2b6a296cda
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
5494
diff
changeset
|
2688 XSTRING (filename)->data, strerror (errno)); |
230 | 2689 |
2690 notfound: | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2691 handled: |
230 | 2692 |
485 | 2693 if (!NILP (visit)) |
230 | 2694 { |
2695 current_buffer->undo_list = Qnil; | |
2696 #ifdef APOLLO | |
2697 stat (XSTRING (filename)->data, &st); | |
2698 #endif | |
5390
d9c81d7079f3
(Finsert_file_contents): Don't run after change hook
Richard M. Stallman <rms@gnu.org>
parents:
5351
diff
changeset
|
2699 |
5395
e11486a64dab
(Finsert_file_contents): Avoid setting buffer-file-name field if ran a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5390
diff
changeset
|
2700 if (NILP (handler)) |
e11486a64dab
(Finsert_file_contents): Avoid setting buffer-file-name field if ran a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5390
diff
changeset
|
2701 { |
e11486a64dab
(Finsert_file_contents): Avoid setting buffer-file-name field if ran a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5390
diff
changeset
|
2702 current_buffer->modtime = st.st_mtime; |
e11486a64dab
(Finsert_file_contents): Avoid setting buffer-file-name field if ran a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5390
diff
changeset
|
2703 current_buffer->filename = filename; |
e11486a64dab
(Finsert_file_contents): Avoid setting buffer-file-name field if ran a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5390
diff
changeset
|
2704 } |
5390
d9c81d7079f3
(Finsert_file_contents): Don't run after change hook
Richard M. Stallman <rms@gnu.org>
parents:
5351
diff
changeset
|
2705 |
230 | 2706 current_buffer->save_modified = MODIFF; |
2707 current_buffer->auto_save_modified = MODIFF; | |
2708 XFASTINT (current_buffer->save_length) = Z - BEG; | |
2709 #ifdef CLASH_DETECTION | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2710 if (NILP (handler)) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2711 { |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2712 if (!NILP (current_buffer->filename)) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2713 unlock_file (current_buffer->filename); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2714 unlock_file (filename); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2715 } |
230 | 2716 #endif /* CLASH_DETECTION */ |
2717 /* If visiting nonexistent file, return nil. */ | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2718 if (current_buffer->modtime == -1) |
230 | 2719 report_file_error ("Opening input file", Fcons (filename, Qnil)); |
2720 } | |
2721 | |
5390
d9c81d7079f3
(Finsert_file_contents): Don't run after change hook
Richard M. Stallman <rms@gnu.org>
parents:
5351
diff
changeset
|
2722 if (inserted > 0 && NILP (visit) && total > 0) |
5129
d48d18e20316
(Finsert_file_contents): Don't call signal_after_change
Richard M. Stallman <rms@gnu.org>
parents:
4989
diff
changeset
|
2723 signal_after_change (point, 0, inserted); |
230 | 2724 |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2725 if (inserted > 0) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2726 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2727 p = Vafter_insert_file_functions; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2728 while (!NILP (p)) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2729 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2730 insval = call1 (Fcar (p), make_number (inserted)); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2731 if (!NILP (insval)) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2732 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2733 CHECK_NUMBER (insval, 0); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2734 inserted = XFASTINT (insval); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2735 } |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2736 QUIT; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2737 p = Fcdr (p); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2738 } |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2739 } |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2740 |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2741 if (!NILP (val)) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2742 RETURN_UNGCPRO (val); |
350 | 2743 RETURN_UNGCPRO (Fcons (filename, |
2744 Fcons (make_number (inserted), | |
2745 Qnil))); | |
230 | 2746 } |
3787
04b741620a50
* fileio.c (Finsert_file_contents): Two new args, BEG and END.
Jim Blandy <jimb@redhat.com>
parents:
3721
diff
changeset
|
2747 |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2748 static Lisp_Object build_annotations (); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2749 |
230 | 2750 DEFUN ("write-region", Fwrite_region, Swrite_region, 3, 5, |
2751 "r\nFWrite region to file: ", | |
2752 "Write current region into specified file.\n\ | |
2753 When called from a program, takes three arguments:\n\ | |
2754 START, END and FILENAME. START and END are buffer positions.\n\ | |
2755 Optional fourth argument APPEND if non-nil means\n\ | |
2756 append to existing file contents (if any).\n\ | |
2757 Optional fifth argument VISIT if t means\n\ | |
2758 set the last-save-file-modtime of buffer to this file's modtime\n\ | |
2759 and mark buffer not modified.\n\ | |
1377
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
2760 If VISIT is a string, it is a second file name;\n\ |
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
2761 the output goes to FILENAME, but the buffer is marked as visiting VISIT.\n\ |
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
2762 VISIT is also the file name to lock and unlock for clash detection.\n\ |
1761
b9ef55b0df4a
(Fwrite_region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
1679
diff
changeset
|
2763 If VISIT is neither t nor nil nor a string,\n\ |
b9ef55b0df4a
(Fwrite_region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
1679
diff
changeset
|
2764 that means do not print the \"Wrote file\" message.\n\ |
230 | 2765 Kludgy feature: if START is a string, then that string is written\n\ |
2766 to the file, instead of any buffer contents, and END is ignored.") | |
2767 (start, end, filename, append, visit) | |
2768 Lisp_Object start, end, filename, append, visit; | |
2769 { | |
2770 register int desc; | |
2771 int failure; | |
2772 int save_errno; | |
2773 unsigned char *fn; | |
2774 struct stat st; | |
4950
145c69e39666
(Fwrite_region): Fix minor bugs in POS arg to awrite.
Richard M. Stallman <rms@gnu.org>
parents:
4879
diff
changeset
|
2775 int tem; |
230 | 2776 int count = specpdl_ptr - specpdl; |
2777 #ifdef VMS | |
2778 unsigned char *fname = 0; /* If non-0, original filename (must rename) */ | |
2779 #endif /* VMS */ | |
848 | 2780 Lisp_Object handler; |
2407
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
2781 Lisp_Object visit_file; |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2782 Lisp_Object annotations; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2783 int visiting, quietly; |
1377
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
2784 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2785 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2786 int buffer_file_type |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2787 = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY; |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2788 #endif |
230 | 2789 |
5410
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2790 if (!NILP (start) && !STRINGP (start)) |
230 | 2791 validate_region (&start, &end); |
2792 | |
2407
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
2793 filename = Fexpand_file_name (filename, Qnil); |
5410
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2794 if (STRINGP (visit)) |
2435
b72453ad92ae
(Fwrite_region): Don't fail to set visit_file.
Richard M. Stallman <rms@gnu.org>
parents:
2407
diff
changeset
|
2795 visit_file = Fexpand_file_name (visit, Qnil); |
2407
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
2796 else |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
2797 visit_file = filename; |
1c590cd84ab3
(Fexpand_file_name): Default DEFALT at beginning,
Richard M. Stallman <rms@gnu.org>
parents:
2280
diff
changeset
|
2798 |
5410
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2799 visiting = (EQ (visit, Qt) || STRINGP (visit)); |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2800 quietly = !NILP (visit); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2801 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2802 annotations = Qnil; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2803 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2804 GCPRO4 (start, filename, annotations, visit_file); |
230 | 2805 |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2806 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2807 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
2808 handler = Ffind_file_name_handler (filename); |
848 | 2809 |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2810 if (!NILP (handler)) |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2811 { |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2812 Lisp_Object val; |
3705
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
2813 val = call6 (handler, Qwrite_region, start, end, |
309c27256ceb
(Fcopy_file): Pass all the args to the handler.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
2814 filename, append, visit); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2815 |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2816 if (visiting) |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2817 { |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2818 current_buffer->save_modified = MODIFF; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2819 XFASTINT (current_buffer->save_length) = Z - BEG; |
1377
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
2820 current_buffer->filename = visit_file; |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2821 } |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2822 UNGCPRO; |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2823 return val; |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2824 } |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
2825 |
5410
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2826 /* Special kludge to simplify auto-saving. */ |
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2827 if (NILP (start)) |
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2828 { |
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2829 XFASTINT (start) = BEG; |
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2830 XFASTINT (end) = Z; |
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2831 } |
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2832 |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2833 annotations = build_annotations (start, end); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2834 |
230 | 2835 #ifdef CLASH_DETECTION |
2836 if (!auto_saving) | |
1377
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
2837 lock_file (visit_file); |
230 | 2838 #endif /* CLASH_DETECTION */ |
2839 | |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2840 fn = XSTRING (filename)->data; |
230 | 2841 desc = -1; |
485 | 2842 if (!NILP (append)) |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2843 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2844 desc = open (fn, O_WRONLY | buffer_file_type); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2845 #else |
230 | 2846 desc = open (fn, O_WRONLY); |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2847 #endif |
230 | 2848 |
2849 if (desc < 0) | |
2850 #ifdef VMS | |
2851 if (auto_saving) /* Overwrite any previous version of autosave file */ | |
2852 { | |
2853 vms_truncate (fn); /* if fn exists, truncate to zero length */ | |
2854 desc = open (fn, O_RDWR); | |
2855 if (desc < 0) | |
5410
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2856 desc = creat_copy_attrs (STRINGP (current_buffer->filename) |
536 | 2857 ? XSTRING (current_buffer->filename)->data : 0, |
2858 fn); | |
230 | 2859 } |
2860 else /* Write to temporary name and rename if no errors */ | |
2861 { | |
2862 Lisp_Object temp_name; | |
2863 temp_name = Ffile_name_directory (filename); | |
2864 | |
485 | 2865 if (!NILP (temp_name)) |
230 | 2866 { |
2867 temp_name = Fmake_temp_name (concat2 (temp_name, | |
2868 build_string ("$$SAVE$$"))); | |
2869 fname = XSTRING (filename)->data; | |
2870 fn = XSTRING (temp_name)->data; | |
2871 desc = creat_copy_attrs (fname, fn); | |
2872 if (desc < 0) | |
2873 { | |
2874 /* If we can't open the temporary file, try creating a new | |
2875 version of the original file. VMS "creat" creates a | |
2876 new version rather than truncating an existing file. */ | |
2877 fn = fname; | |
2878 fname = 0; | |
2879 desc = creat (fn, 0666); | |
2880 #if 0 /* This can clobber an existing file and fail to replace it, | |
2881 if the user runs out of space. */ | |
2882 if (desc < 0) | |
2883 { | |
2884 /* We can't make a new version; | |
2885 try to truncate and rewrite existing version if any. */ | |
2886 vms_truncate (fn); | |
2887 desc = open (fn, O_RDWR); | |
2888 } | |
2889 #endif | |
2890 } | |
2891 } | |
2892 else | |
2893 desc = creat (fn, 0666); | |
2894 } | |
2895 #else /* not VMS */ | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2896 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2897 desc = open (fn, |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2898 O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type, |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2899 S_IREAD | S_IWRITE); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2900 #else /* not MSDOS */ |
230 | 2901 desc = creat (fn, auto_saving ? auto_save_mode_bits : 0666); |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
2902 #endif /* not MSDOS */ |
230 | 2903 #endif /* not VMS */ |
2904 | |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2905 UNGCPRO; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
2906 |
230 | 2907 if (desc < 0) |
2908 { | |
2909 #ifdef CLASH_DETECTION | |
2910 save_errno = errno; | |
1377
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
2911 if (!auto_saving) unlock_file (visit_file); |
230 | 2912 errno = save_errno; |
2913 #endif /* CLASH_DETECTION */ | |
2914 report_file_error ("Opening output file", Fcons (filename, Qnil)); | |
2915 } | |
2916 | |
2917 record_unwind_protect (close_file_unwind, make_number (desc)); | |
2918 | |
485 | 2919 if (!NILP (append)) |
230 | 2920 if (lseek (desc, 0, 2) < 0) |
2921 { | |
2922 #ifdef CLASH_DETECTION | |
1377
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
2923 if (!auto_saving) unlock_file (visit_file); |
230 | 2924 #endif /* CLASH_DETECTION */ |
2925 report_file_error ("Lseek error", Fcons (filename, Qnil)); | |
2926 } | |
2927 | |
2928 #ifdef VMS | |
2929 /* | |
2930 * Kludge Warning: The VMS C RTL likes to insert carriage returns | |
2931 * if we do writes that don't end with a carriage return. Furthermore | |
2932 * it cannot handle writes of more then 16K. The modified | |
2933 * version of "sys_write" in SYSDEP.C (see comment there) copes with | |
2934 * this EXCEPT for the last record (iff it doesn't end with a carriage | |
2935 * return). This implies that if your buffer doesn't end with a carriage | |
2936 * return, you get one free... tough. However it also means that if | |
2937 * we make two calls to sys_write (a la the following code) you can | |
2938 * get one at the gap as well. The easiest way to fix this (honest) | |
2939 * is to move the gap to the next newline (or the end of the buffer). | |
2940 * Thus this change. | |
2941 * | |
2942 * Yech! | |
2943 */ | |
2944 if (GPT > BEG && GPT_ADDR[-1] != '\n') | |
2945 move_gap (find_next_newline (GPT, 1)); | |
2946 #endif | |
2947 | |
2948 failure = 0; | |
2949 immediate_quit = 1; | |
2950 | |
5410
c96b98efb5b4
(Fwrite_region): Don't change START and END from nil
Richard M. Stallman <rms@gnu.org>
parents:
5395
diff
changeset
|
2951 if (STRINGP (start)) |
230 | 2952 { |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2953 failure = 0 > a_write (desc, XSTRING (start)->data, |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2954 XSTRING (start)->size, 0, &annotations); |
230 | 2955 save_errno = errno; |
2956 } | |
2957 else if (XINT (start) != XINT (end)) | |
2958 { | |
4950
145c69e39666
(Fwrite_region): Fix minor bugs in POS arg to awrite.
Richard M. Stallman <rms@gnu.org>
parents:
4879
diff
changeset
|
2959 int nwritten = 0; |
230 | 2960 if (XINT (start) < GPT) |
2961 { | |
2962 register int end1 = XINT (end); | |
2963 tem = XINT (start); | |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2964 failure = 0 > a_write (desc, &FETCH_CHAR (tem), |
4950
145c69e39666
(Fwrite_region): Fix minor bugs in POS arg to awrite.
Richard M. Stallman <rms@gnu.org>
parents:
4879
diff
changeset
|
2965 min (GPT, end1) - tem, tem, &annotations); |
145c69e39666
(Fwrite_region): Fix minor bugs in POS arg to awrite.
Richard M. Stallman <rms@gnu.org>
parents:
4879
diff
changeset
|
2966 nwritten += min (GPT, end1) - tem; |
230 | 2967 save_errno = errno; |
2968 } | |
2969 | |
2970 if (XINT (end) > GPT && !failure) | |
2971 { | |
2972 tem = XINT (start); | |
2973 tem = max (tem, GPT); | |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2974 failure = 0 > a_write (desc, &FETCH_CHAR (tem), XINT (end) - tem, |
4950
145c69e39666
(Fwrite_region): Fix minor bugs in POS arg to awrite.
Richard M. Stallman <rms@gnu.org>
parents:
4879
diff
changeset
|
2975 tem, &annotations); |
145c69e39666
(Fwrite_region): Fix minor bugs in POS arg to awrite.
Richard M. Stallman <rms@gnu.org>
parents:
4879
diff
changeset
|
2976 nwritten += XINT (end) - tem; |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2977 save_errno = errno; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2978 } |
4950
145c69e39666
(Fwrite_region): Fix minor bugs in POS arg to awrite.
Richard M. Stallman <rms@gnu.org>
parents:
4879
diff
changeset
|
2979 |
145c69e39666
(Fwrite_region): Fix minor bugs in POS arg to awrite.
Richard M. Stallman <rms@gnu.org>
parents:
4879
diff
changeset
|
2980 if (nwritten == 0) |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2981 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
2982 /* If file was empty, still need to write the annotations */ |
4950
145c69e39666
(Fwrite_region): Fix minor bugs in POS arg to awrite.
Richard M. Stallman <rms@gnu.org>
parents:
4879
diff
changeset
|
2983 failure = 0 > a_write (desc, "", 0, XINT (start), &annotations); |
230 | 2984 save_errno = errno; |
2985 } | |
2986 } | |
2987 | |
2988 immediate_quit = 0; | |
2989 | |
2280
bd56d208ed22
* fileio.c (HAVE_FSYNC): Define, if appropriate.
Jim Blandy <jimb@redhat.com>
parents:
2257
diff
changeset
|
2990 #ifdef HAVE_FSYNC |
230 | 2991 /* Note fsync appears to change the modtime on BSD4.2 (both vax and sun). |
2992 Disk full in NFS may be reported here. */ | |
3415
c37d05ce7e52
(Fwrite_region): Don't fsync if autosaving.
Richard M. Stallman <rms@gnu.org>
parents:
3410
diff
changeset
|
2993 /* mib says that closing the file will try to write as fast as NFS can do |
c37d05ce7e52
(Fwrite_region): Don't fsync if autosaving.
Richard M. Stallman <rms@gnu.org>
parents:
3410
diff
changeset
|
2994 it, and that means the fsync here is not crucial for autosave files. */ |
c37d05ce7e52
(Fwrite_region): Don't fsync if autosaving.
Richard M. Stallman <rms@gnu.org>
parents:
3410
diff
changeset
|
2995 if (!auto_saving && fsync (desc) < 0) |
230 | 2996 failure = 1, save_errno = errno; |
2997 #endif | |
2998 | |
2999 /* Spurious "file has changed on disk" warnings have been | |
3000 observed on Suns as well. | |
3001 It seems that `close' can change the modtime, under nfs. | |
3002 | |
3003 (This has supposedly been fixed in Sunos 4, | |
3004 but who knows about all the other machines with NFS?) */ | |
3005 #if 0 | |
3006 | |
3007 /* On VMS and APOLLO, must do the stat after the close | |
3008 since closing changes the modtime. */ | |
3009 #ifndef VMS | |
3010 #ifndef APOLLO | |
3011 /* Recall that #if defined does not work on VMS. */ | |
3012 #define FOO | |
3013 fstat (desc, &st); | |
3014 #endif | |
3015 #endif | |
3016 #endif | |
3017 | |
3018 /* NFS can report a write failure now. */ | |
3019 if (close (desc) < 0) | |
3020 failure = 1, save_errno = errno; | |
3021 | |
3022 #ifdef VMS | |
3023 /* If we wrote to a temporary name and had no errors, rename to real name. */ | |
3024 if (fname) | |
3025 { | |
3026 if (!failure) | |
3027 failure = (rename (fn, fname) != 0), save_errno = errno; | |
3028 fn = fname; | |
3029 } | |
3030 #endif /* VMS */ | |
3031 | |
3032 #ifndef FOO | |
3033 stat (fn, &st); | |
3034 #endif | |
3035 /* Discard the unwind protect */ | |
3036 specpdl_ptr = specpdl + count; | |
3037 | |
3038 #ifdef CLASH_DETECTION | |
3039 if (!auto_saving) | |
1377
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
3040 unlock_file (visit_file); |
230 | 3041 #endif /* CLASH_DETECTION */ |
3042 | |
3043 /* Do this before reporting IO error | |
3044 to avoid a "file has changed on disk" warning on | |
3045 next attempt to save. */ | |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3046 if (visiting) |
230 | 3047 current_buffer->modtime = st.st_mtime; |
3048 | |
3049 if (failure) | |
5517
8b2b6a296cda
Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents:
5494
diff
changeset
|
3050 error ("IO error writing %s: %s", fn, strerror (save_errno)); |
230 | 3051 |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3052 if (visiting) |
230 | 3053 { |
3054 current_buffer->save_modified = MODIFF; | |
3055 XFASTINT (current_buffer->save_length) = Z - BEG; | |
1377
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
3056 current_buffer->filename = visit_file; |
230 | 3057 } |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3058 else if (quietly) |
230 | 3059 return Qnil; |
3060 | |
3061 if (!auto_saving) | |
1377
dcec08a3bec4
(Fwrite_region): If VISIT is a file name,
Richard M. Stallman <rms@gnu.org>
parents:
1358
diff
changeset
|
3062 message ("Wrote %s", XSTRING (visit_file)->data); |
230 | 3063 |
3064 return Qnil; | |
3065 } | |
3066 | |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3067 Lisp_Object merge (); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3068 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3069 DEFUN ("car-less-than-car", Fcar_less_than_car, Scar_less_than_car, 2, 2, 0, |
4853
3ec2205d12b5
(Fcar_less_than_car): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
4841
diff
changeset
|
3070 "Return t if (car A) is numerically less than (car B).") |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3071 (a, b) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3072 Lisp_Object a, b; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3073 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3074 return Flss (Fcar (a), Fcar (b)); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3075 } |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3076 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3077 /* Build the complete list of annotations appropriate for writing out |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3078 the text between START and END, by calling all the functions in |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3079 write-region-annotate-functions and merging the lists they return. */ |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3080 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3081 static Lisp_Object |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3082 build_annotations (start, end) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3083 Lisp_Object start, end; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3084 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3085 Lisp_Object annotations; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3086 Lisp_Object p, res; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3087 struct gcpro gcpro1, gcpro2; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3088 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3089 annotations = Qnil; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3090 p = Vwrite_region_annotate_functions; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3091 GCPRO2 (annotations, p); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3092 while (!NILP (p)) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3093 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3094 res = call2 (Fcar (p), start, end); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3095 Flength (res); /* Check basic validity of return value */ |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3096 annotations = merge (annotations, res, Qcar_less_than_car); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3097 p = Fcdr (p); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3098 } |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3099 UNGCPRO; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3100 return annotations; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3101 } |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3102 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3103 /* Write to descriptor DESC the LEN characters starting at ADDR, |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3104 assuming they start at position POS in the buffer. |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3105 Intersperse with them the annotations from *ANNOT |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3106 (those which fall within the range of positions POS to POS + LEN), |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3107 each at its appropriate position. |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3108 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3109 Modify *ANNOT by discarding elements as we output them. |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3110 The return value is negative in case of system call failure. */ |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3111 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3112 int |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3113 a_write (desc, addr, len, pos, annot) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3114 int desc; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3115 register char *addr; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3116 register int len; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3117 int pos; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3118 Lisp_Object *annot; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3119 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3120 Lisp_Object tem; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3121 int nextpos; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3122 int lastpos = pos + len; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3123 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3124 while (1) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3125 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3126 tem = Fcar_safe (Fcar (*annot)); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3127 if (INTEGERP (tem) && XINT (tem) >= pos && XFASTINT (tem) <= lastpos) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3128 nextpos = XFASTINT (tem); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3129 else |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3130 return e_write (desc, addr, lastpos - pos); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3131 if (nextpos > pos) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3132 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3133 if (0 > e_write (desc, addr, nextpos - pos)) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3134 return -1; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3135 addr += nextpos - pos; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3136 pos = nextpos; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3137 } |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3138 tem = Fcdr (Fcar (*annot)); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3139 if (STRINGP (tem)) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3140 { |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3141 if (0 > e_write (desc, XSTRING (tem)->data, XSTRING (tem)->size)) |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3142 return -1; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3143 } |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3144 *annot = Fcdr (*annot); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3145 } |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3146 } |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3147 |
230 | 3148 int |
3149 e_write (desc, addr, len) | |
3150 int desc; | |
3151 register char *addr; | |
3152 register int len; | |
3153 { | |
3154 char buf[16 * 1024]; | |
3155 register char *p, *end; | |
3156 | |
3157 if (!EQ (current_buffer->selective_display, Qt)) | |
3158 return write (desc, addr, len) - len; | |
3159 else | |
3160 { | |
3161 p = buf; | |
3162 end = p + sizeof buf; | |
3163 while (len--) | |
3164 { | |
3165 if (p == end) | |
3166 { | |
3167 if (write (desc, buf, sizeof buf) != sizeof buf) | |
3168 return -1; | |
3169 p = buf; | |
3170 } | |
3171 *p = *addr++; | |
3172 if (*p++ == '\015') | |
3173 p[-1] = '\n'; | |
3174 } | |
3175 if (p != buf) | |
3176 if (write (desc, buf, p - buf) != p - buf) | |
3177 return -1; | |
3178 } | |
3179 return 0; | |
3180 } | |
3181 | |
3182 DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, | |
3183 Sverify_visited_file_modtime, 1, 1, 0, | |
3184 "Return t if last mod time of BUF's visited file matches what BUF records.\n\ | |
3185 This means that the file has not been changed since it was visited or saved.") | |
3186 (buf) | |
3187 Lisp_Object buf; | |
3188 { | |
3189 struct buffer *b; | |
3190 struct stat st; | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3191 Lisp_Object handler; |
230 | 3192 |
3193 CHECK_BUFFER (buf, 0); | |
3194 b = XBUFFER (buf); | |
3195 | |
3196 if (XTYPE (b->filename) != Lisp_String) return Qt; | |
3197 if (b->modtime == 0) return Qt; | |
3198 | |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3199 /* If the file name has special constructs in it, |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3200 call the corresponding file handler. */ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3201 handler = Ffind_file_name_handler (b->filename); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3202 if (!NILP (handler)) |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3203 return call2 (handler, Qverify_visited_file_modtime, buf); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3204 |
230 | 3205 if (stat (XSTRING (b->filename)->data, &st) < 0) |
3206 { | |
3207 /* If the file doesn't exist now and didn't exist before, | |
3208 we say that it isn't modified, provided the error is a tame one. */ | |
3209 if (errno == ENOENT || errno == EACCES || errno == ENOTDIR) | |
3210 st.st_mtime = -1; | |
3211 else | |
3212 st.st_mtime = 0; | |
3213 } | |
3214 if (st.st_mtime == b->modtime | |
3215 /* If both are positive, accept them if they are off by one second. */ | |
3216 || (st.st_mtime > 0 && b->modtime > 0 | |
3217 && (st.st_mtime == b->modtime + 1 | |
3218 || st.st_mtime == b->modtime - 1))) | |
3219 return Qt; | |
3220 return Qnil; | |
3221 } | |
3222 | |
3223 DEFUN ("clear-visited-file-modtime", Fclear_visited_file_modtime, | |
3224 Sclear_visited_file_modtime, 0, 0, 0, | |
3225 "Clear out records of last mod time of visited file.\n\ | |
3226 Next attempt to save will certainly not complain of a discrepancy.") | |
3227 () | |
3228 { | |
3229 current_buffer->modtime = 0; | |
3230 return Qnil; | |
3231 } | |
3232 | |
2257
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3233 DEFUN ("visited-file-modtime", Fvisited_file_modtime, |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3234 Svisited_file_modtime, 0, 0, 0, |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3235 "Return the current buffer's recorded visited file modification time.\n\ |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3236 The value is a list of the form (HIGH . LOW), like the time values\n\ |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3237 that `file-attributes' returns.") |
230 | 3238 () |
3239 { | |
2257
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3240 return long_to_cons (current_buffer->modtime); |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3241 } |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3242 |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3243 DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime, |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3244 Sset_visited_file_modtime, 0, 1, 0, |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3245 "Update buffer's recorded modification time from the visited file's time.\n\ |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3246 Useful if the buffer was not read from the file normally\n\ |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3247 or if the file itself has been changed for some known benign reason.\n\ |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3248 An argument specifies the modification time value to use\n\ |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3249 \(instead of that of the visited file), in the form of a list\n\ |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3250 \(HIGH . LOW) or (HIGH LOW).") |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3251 (time_list) |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3252 Lisp_Object time_list; |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3253 { |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3254 if (!NILP (time_list)) |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3255 current_buffer->modtime = cons_to_long (time_list); |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3256 else |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3257 { |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3258 register Lisp_Object filename; |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3259 struct stat st; |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3260 Lisp_Object handler; |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3261 |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3262 filename = Fexpand_file_name (current_buffer->filename, Qnil); |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3263 |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3264 /* If the file name has special constructs in it, |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3265 call the corresponding file handler. */ |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3266 handler = Ffind_file_name_handler (filename); |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3267 if (!NILP (handler)) |
3721
4550c56785d8
(Fset_visited_file_modtime): Don't give the handler
Richard M. Stallman <rms@gnu.org>
parents:
3705
diff
changeset
|
3268 /* The handler can find the file name the same way we did. */ |
3829
4130587b6ffc
* fileio.c (Fset_visited_file_modtime): We're only passing two
Jim Blandy <jimb@redhat.com>
parents:
3787
diff
changeset
|
3269 return call2 (handler, Qset_visited_file_modtime, Qnil); |
2257
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3270 else if (stat (XSTRING (filename)->data, &st) >= 0) |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3271 current_buffer->modtime = st.st_mtime; |
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3272 } |
230 | 3273 |
3274 return Qnil; | |
3275 } | |
3276 | |
3277 Lisp_Object | |
3278 auto_save_error () | |
3279 { | |
3280 unsigned char *name = XSTRING (current_buffer->name)->data; | |
3281 | |
3282 ring_bell (); | |
3283 message ("Autosaving...error for %s", name); | |
806 | 3284 Fsleep_for (make_number (1), Qnil); |
230 | 3285 message ("Autosaving...error!for %s", name); |
806 | 3286 Fsleep_for (make_number (1), Qnil); |
230 | 3287 message ("Autosaving...error for %s", name); |
806 | 3288 Fsleep_for (make_number (1), Qnil); |
230 | 3289 return Qnil; |
3290 } | |
3291 | |
3292 Lisp_Object | |
3293 auto_save_1 () | |
3294 { | |
3295 unsigned char *fn; | |
3296 struct stat st; | |
3297 | |
3298 /* Get visited file's mode to become the auto save file's mode. */ | |
3299 if (stat (XSTRING (current_buffer->filename)->data, &st) >= 0) | |
3300 /* But make sure we can overwrite it later! */ | |
3301 auto_save_mode_bits = st.st_mode | 0600; | |
3302 else | |
3303 auto_save_mode_bits = 0666; | |
3304 | |
3305 return | |
3306 Fwrite_region (Qnil, Qnil, | |
3307 current_buffer->auto_save_file_name, | |
3308 Qnil, Qlambda); | |
3309 } | |
3310 | |
3311 DEFUN ("do-auto-save", Fdo_auto_save, Sdo_auto_save, 0, 2, "", | |
3312 "Auto-save all buffers that need it.\n\ | |
3313 This is all buffers that have auto-saving enabled\n\ | |
3314 and are changed since last auto-saved.\n\ | |
3315 Auto-saving writes the buffer into a file\n\ | |
3316 so that your editing is not lost if the system crashes.\n\ | |
3317 This file is not the file you visited; that changes only when you save.\n\n\ | |
3318 Non-nil first argument means do not print any message if successful.\n\ | |
621 | 3319 Non-nil second argument means save only current buffer.") |
1775
f9ac4c0d8b72
* fileio.c (Fdo_auto_save): Add CURRENT_ONLY argument, as
Jim Blandy <jimb@redhat.com>
parents:
1763
diff
changeset
|
3320 (no_message, current_only) |
f9ac4c0d8b72
* fileio.c (Fdo_auto_save): Add CURRENT_ONLY argument, as
Jim Blandy <jimb@redhat.com>
parents:
1763
diff
changeset
|
3321 Lisp_Object no_message, current_only; |
230 | 3322 { |
3323 struct buffer *old = current_buffer, *b; | |
3324 Lisp_Object tail, buf; | |
3325 int auto_saved = 0; | |
3326 char *omessage = echo_area_glyphs; | |
1869
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3327 extern int minibuf_level; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3328 int do_handled_files; |
4270
3ce8e11f338b
(Fdo_auto_save): Temporarily clear Vquit_flag.
Richard M. Stallman <rms@gnu.org>
parents:
3963
diff
changeset
|
3329 Lisp_Object oquit; |
3ce8e11f338b
(Fdo_auto_save): Temporarily clear Vquit_flag.
Richard M. Stallman <rms@gnu.org>
parents:
3963
diff
changeset
|
3330 |
3ce8e11f338b
(Fdo_auto_save): Temporarily clear Vquit_flag.
Richard M. Stallman <rms@gnu.org>
parents:
3963
diff
changeset
|
3331 /* Ordinarily don't quit within this function, |
3ce8e11f338b
(Fdo_auto_save): Temporarily clear Vquit_flag.
Richard M. Stallman <rms@gnu.org>
parents:
3963
diff
changeset
|
3332 but don't make it impossible to quit (in case we get hung in I/O). */ |
3ce8e11f338b
(Fdo_auto_save): Temporarily clear Vquit_flag.
Richard M. Stallman <rms@gnu.org>
parents:
3963
diff
changeset
|
3333 oquit = Vquit_flag; |
3ce8e11f338b
(Fdo_auto_save): Temporarily clear Vquit_flag.
Richard M. Stallman <rms@gnu.org>
parents:
3963
diff
changeset
|
3334 Vquit_flag = Qnil; |
230 | 3335 |
3336 /* No GCPRO needed, because (when it matters) all Lisp_Object variables | |
3337 point to non-strings reached from Vbuffer_alist. */ | |
3338 | |
3339 auto_saving = 1; | |
3340 if (minibuf_level) | |
1775
f9ac4c0d8b72
* fileio.c (Fdo_auto_save): Add CURRENT_ONLY argument, as
Jim Blandy <jimb@redhat.com>
parents:
1763
diff
changeset
|
3341 no_message = Qt; |
230 | 3342 |
3343 /* Vrun_hooks is nil before emacs is dumped, and inc-vers.el will | |
3344 eventually call do-auto-save, so don't err here in that case. */ | |
485 | 3345 if (!NILP (Vrun_hooks)) |
230 | 3346 call1 (Vrun_hooks, intern ("auto-save-hook")); |
3347 | |
1869
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3348 /* First, save all files which don't have handlers. If Emacs is |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3349 crashing, the handlers may tweak what is causing Emacs to crash |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3350 in the first place, and it would be a shame if Emacs failed to |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3351 autosave perfectly ordinary files because it couldn't handle some |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3352 ange-ftp'd file. */ |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3353 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3354 for (tail = Vbuffer_alist; XGCTYPE (tail) == Lisp_Cons; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3355 tail = XCONS (tail)->cdr) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3356 { |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3357 buf = XCONS (XCONS (tail)->car)->cdr; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3358 b = XBUFFER (buf); |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3359 |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3360 if (!NILP (current_only) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3361 && b != current_buffer) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3362 continue; |
1775
f9ac4c0d8b72
* fileio.c (Fdo_auto_save): Add CURRENT_ONLY argument, as
Jim Blandy <jimb@redhat.com>
parents:
1763
diff
changeset
|
3363 |
1869
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3364 /* Check for auto save enabled |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3365 and file changed since last auto save |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3366 and file changed since last real save. */ |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3367 if (XTYPE (b->auto_save_file_name) == Lisp_String |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3368 && b->save_modified < BUF_MODIFF (b) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3369 && b->auto_save_modified < BUF_MODIFF (b) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3370 && (do_handled_files |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3371 || NILP (Ffind_file_name_handler (b->auto_save_file_name)))) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3372 { |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3373 if ((XFASTINT (b->save_length) * 10 |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3374 > (BUF_Z (b) - BUF_BEG (b)) * 13) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3375 /* A short file is likely to change a large fraction; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3376 spare the user annoying messages. */ |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3377 && XFASTINT (b->save_length) > 5000 |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3378 /* These messages are frequent and annoying for `*mail*'. */ |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3379 && !EQ (b->filename, Qnil) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3380 && NILP (no_message)) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3381 { |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3382 /* It has shrunk too much; turn off auto-saving here. */ |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3383 message ("Buffer %s has shrunk a lot; auto save turned off there", |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3384 XSTRING (b->name)->data); |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3385 /* User can reenable saving with M-x auto-save. */ |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3386 b->auto_save_file_name = Qnil; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3387 /* Prevent warning from repeating if user does so. */ |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3388 XFASTINT (b->save_length) = 0; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3389 Fsleep_for (make_number (1), Qnil); |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3390 continue; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3391 } |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3392 set_buffer_internal (b); |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3393 if (!auto_saved && NILP (no_message)) |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3394 message1 ("Auto-saving..."); |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3395 internal_condition_case (auto_save_1, Qt, auto_save_error); |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3396 auto_saved++; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3397 b->auto_save_modified = BUF_MODIFF (b); |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3398 XFASTINT (current_buffer->save_length) = Z - BEG; |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3399 set_buffer_internal (old); |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3400 } |
30eb06b22ae4
* fileio.c (Fdo_auto_save): If NO_MESSAGE is non-nil, don't tell
Jim Blandy <jimb@redhat.com>
parents:
1775
diff
changeset
|
3401 } |
230 | 3402 |
1059
430923239064
(Fdo_auto_save): Always call record_auto_save.
Richard M. Stallman <rms@gnu.org>
parents:
1044
diff
changeset
|
3403 /* Prevent another auto save till enough input events come in. */ |
430923239064
(Fdo_auto_save): Always call record_auto_save.
Richard M. Stallman <rms@gnu.org>
parents:
1044
diff
changeset
|
3404 record_auto_save (); |
230 | 3405 |
1775
f9ac4c0d8b72
* fileio.c (Fdo_auto_save): Add CURRENT_ONLY argument, as
Jim Blandy <jimb@redhat.com>
parents:
1763
diff
changeset
|
3406 if (auto_saved && NILP (no_message)) |
230 | 3407 message1 (omessage ? omessage : "Auto-saving...done"); |
3408 | |
4270
3ce8e11f338b
(Fdo_auto_save): Temporarily clear Vquit_flag.
Richard M. Stallman <rms@gnu.org>
parents:
3963
diff
changeset
|
3409 Vquit_flag = oquit; |
3ce8e11f338b
(Fdo_auto_save): Temporarily clear Vquit_flag.
Richard M. Stallman <rms@gnu.org>
parents:
3963
diff
changeset
|
3410 |
230 | 3411 auto_saving = 0; |
3412 return Qnil; | |
3413 } | |
3414 | |
3415 DEFUN ("set-buffer-auto-saved", Fset_buffer_auto_saved, | |
3416 Sset_buffer_auto_saved, 0, 0, 0, | |
3417 "Mark current buffer as auto-saved with its current text.\n\ | |
3418 No auto-save file will be written until the buffer changes again.") | |
3419 () | |
3420 { | |
3421 current_buffer->auto_save_modified = MODIFF; | |
3422 XFASTINT (current_buffer->save_length) = Z - BEG; | |
3423 return Qnil; | |
3424 } | |
3425 | |
3426 DEFUN ("recent-auto-save-p", Frecent_auto_save_p, Srecent_auto_save_p, | |
3427 0, 0, 0, | |
3428 "Return t if buffer has been auto-saved since last read in or saved.") | |
3429 () | |
3430 { | |
3431 return (current_buffer->save_modified < current_buffer->auto_save_modified) ? Qt : Qnil; | |
3432 } | |
3433 | |
3434 /* Reading and completing file names */ | |
3435 extern Lisp_Object Ffile_name_completion (), Ffile_name_all_completions (); | |
3436 | |
3437 DEFUN ("read-file-name-internal", Fread_file_name_internal, Sread_file_name_internal, | |
3438 3, 3, 0, | |
3439 "Internal subroutine for read-file-name. Do not call this.") | |
3440 (string, dir, action) | |
3441 Lisp_Object string, dir, action; | |
3442 /* action is nil for complete, t for return list of completions, | |
3443 lambda for verify final value */ | |
3444 { | |
3445 Lisp_Object name, specdir, realdir, val, orig_string; | |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3446 int changed; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3447 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3448 |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3449 realdir = dir; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3450 name = string; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3451 orig_string = Qnil; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3452 specdir = Qnil; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3453 changed = 0; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3454 /* No need to protect ACTION--we only compare it with t and nil. */ |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3455 GCPRO4 (string, realdir, name, specdir); |
230 | 3456 |
3457 if (XSTRING (string)->size == 0) | |
3458 { | |
3459 if (EQ (action, Qlambda)) | |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3460 { |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3461 UNGCPRO; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3462 return Qnil; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3463 } |
230 | 3464 } |
3465 else | |
3466 { | |
3467 orig_string = string; | |
3468 string = Fsubstitute_in_file_name (string); | |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3469 changed = NILP (Fstring_equal (string, orig_string)); |
230 | 3470 name = Ffile_name_nondirectory (string); |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3471 val = Ffile_name_directory (string); |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3472 if (! NILP (val)) |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3473 realdir = Fexpand_file_name (val, realdir); |
230 | 3474 } |
3475 | |
485 | 3476 if (NILP (action)) |
230 | 3477 { |
3478 specdir = Ffile_name_directory (string); | |
3479 val = Ffile_name_completion (name, realdir); | |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3480 UNGCPRO; |
230 | 3481 if (XTYPE (val) != Lisp_String) |
3482 { | |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3483 if (changed) |
230 | 3484 return string; |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3485 return val; |
230 | 3486 } |
3487 | |
485 | 3488 if (!NILP (specdir)) |
230 | 3489 val = concat2 (specdir, val); |
3490 #ifndef VMS | |
3491 { | |
3492 register unsigned char *old, *new; | |
3493 register int n; | |
3494 int osize, count; | |
3495 | |
3496 osize = XSTRING (val)->size; | |
3497 /* Quote "$" as "$$" to get it past substitute-in-file-name */ | |
3498 for (n = osize, count = 0, old = XSTRING (val)->data; n > 0; n--) | |
3499 if (*old++ == '$') count++; | |
3500 if (count > 0) | |
3501 { | |
3502 old = XSTRING (val)->data; | |
3503 val = Fmake_string (make_number (osize + count), make_number (0)); | |
3504 new = XSTRING (val)->data; | |
3505 for (n = osize; n > 0; n--) | |
3506 if (*old != '$') | |
3507 *new++ = *old++; | |
3508 else | |
3509 { | |
3510 *new++ = '$'; | |
3511 *new++ = '$'; | |
3512 old++; | |
3513 } | |
3514 } | |
3515 } | |
3516 #endif /* Not VMS */ | |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3517 return val; |
230 | 3518 } |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3519 UNGCPRO; |
230 | 3520 |
3521 if (EQ (action, Qt)) | |
3522 return Ffile_name_all_completions (name, realdir); | |
3523 /* Only other case actually used is ACTION = lambda */ | |
3524 #ifdef VMS | |
3525 /* Supposedly this helps commands such as `cd' that read directory names, | |
3526 but can someone explain how it helps them? -- RMS */ | |
3527 if (XSTRING (name)->size == 0) | |
3528 return Qt; | |
3529 #endif /* VMS */ | |
3530 return Ffile_exists_p (string); | |
3531 } | |
3532 | |
3533 DEFUN ("read-file-name", Fread_file_name, Sread_file_name, 1, 5, 0, | |
3534 "Read file name, prompting with PROMPT and completing in directory DIR.\n\ | |
3535 Value is not expanded---you must call `expand-file-name' yourself.\n\ | |
3536 Default name to DEFAULT if user enters a null string.\n\ | |
3537 (If DEFAULT is omitted, the visited file name is used.)\n\ | |
3538 Fourth arg MUSTMATCH non-nil means require existing file's name.\n\ | |
3539 Non-nil and non-t means also require confirmation after completion.\n\ | |
3540 Fifth arg INITIAL specifies text to start with.\n\ | |
3541 DIR defaults to current buffer's directory default.") | |
3542 (prompt, dir, defalt, mustmatch, initial) | |
3543 Lisp_Object prompt, dir, defalt, mustmatch, initial; | |
3544 { | |
866 | 3545 Lisp_Object val, insdef, insdef1, tem; |
230 | 3546 struct gcpro gcpro1, gcpro2; |
3547 register char *homedir; | |
3548 int count; | |
3549 | |
485 | 3550 if (NILP (dir)) |
230 | 3551 dir = current_buffer->directory; |
485 | 3552 if (NILP (defalt)) |
230 | 3553 defalt = current_buffer->filename; |
3554 | |
3555 /* If dir starts with user's homedir, change that to ~. */ | |
3556 homedir = (char *) egetenv ("HOME"); | |
3557 if (homedir != 0 | |
3558 && XTYPE (dir) == Lisp_String | |
3559 && !strncmp (homedir, XSTRING (dir)->data, strlen (homedir)) | |
3560 && XSTRING (dir)->data[strlen (homedir)] == '/') | |
3561 { | |
3562 dir = make_string (XSTRING (dir)->data + strlen (homedir) - 1, | |
3563 XSTRING (dir)->size - strlen (homedir) + 1); | |
3564 XSTRING (dir)->data[0] = '~'; | |
3565 } | |
3566 | |
3567 if (insert_default_directory) | |
3568 { | |
3569 insdef = dir; | |
866 | 3570 insdef1 = dir; |
485 | 3571 if (!NILP (initial)) |
230 | 3572 { |
863
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3573 Lisp_Object args[2], pos; |
230 | 3574 |
3575 args[0] = insdef; | |
3576 args[1] = initial; | |
3577 insdef = Fconcat (2, args); | |
964
ea0c91e13641
* fileio.c (Fread_filename): When calling Fcompleting_read,
Jim Blandy <jimb@redhat.com>
parents:
945
diff
changeset
|
3578 pos = make_number (XSTRING (dir)->size); |
866 | 3579 insdef1 = Fcons (insdef, pos); |
230 | 3580 } |
3581 } | |
3582 else | |
866 | 3583 insdef = Qnil, insdef1 = Qnil; |
230 | 3584 |
3585 #ifdef VMS | |
3586 count = specpdl_ptr - specpdl; | |
3587 specbind (intern ("completion-ignore-case"), Qt); | |
3588 #endif | |
3589 | |
3590 GCPRO2 (insdef, defalt); | |
3591 val = Fcompleting_read (prompt, intern ("read-file-name-internal"), | |
866 | 3592 dir, mustmatch, insdef1, |
863
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3593 Qfile_name_history); |
230 | 3594 |
3595 #ifdef VMS | |
3596 unbind_to (count, Qnil); | |
3597 #endif | |
3598 | |
3599 UNGCPRO; | |
485 | 3600 if (NILP (val)) |
230 | 3601 error ("No file name specified"); |
3602 tem = Fstring_equal (val, insdef); | |
485 | 3603 if (!NILP (tem) && !NILP (defalt)) |
230 | 3604 return defalt; |
3032
371058345c42
(Fread_file_name): If input is empty, do return the default
Richard M. Stallman <rms@gnu.org>
parents:
3017
diff
changeset
|
3605 if (XSTRING (val)->size == 0 && NILP (insdef)) |
5245
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
3606 { |
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
3607 if (!NILP (defalt)) |
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
3608 return defalt; |
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
3609 else |
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
3610 error ("No default file name"); |
4a9b93b0eac3
(Fmake_symbolic_link): Do expand FILENAME if starts with ~.
Richard M. Stallman <rms@gnu.org>
parents:
5129
diff
changeset
|
3611 } |
230 | 3612 return Fsubstitute_in_file_name (val); |
3613 } | |
3614 | |
3615 #if 0 /* Old version */ | |
3616 DEFUN ("read-file-name", Fread_file_name, Sread_file_name, 1, 5, 0, | |
3617 "Read file name, prompting with PROMPT and completing in directory DIR.\n\ | |
3618 Value is not expanded---you must call `expand-file-name' yourself.\n\ | |
3619 Default name to DEFAULT if user enters a null string.\n\ | |
3620 (If DEFAULT is omitted, the visited file name is used.)\n\ | |
3621 Fourth arg MUSTMATCH non-nil means require existing file's name.\n\ | |
3622 Non-nil and non-t means also require confirmation after completion.\n\ | |
3623 Fifth arg INITIAL specifies text to start with.\n\ | |
3624 DIR defaults to current buffer's directory default.") | |
3625 (prompt, dir, defalt, mustmatch, initial) | |
3626 Lisp_Object prompt, dir, defalt, mustmatch, initial; | |
3627 { | |
3628 Lisp_Object val, insdef, tem; | |
3629 struct gcpro gcpro1, gcpro2; | |
3630 register char *homedir; | |
3631 int count; | |
3632 | |
485 | 3633 if (NILP (dir)) |
230 | 3634 dir = current_buffer->directory; |
485 | 3635 if (NILP (defalt)) |
230 | 3636 defalt = current_buffer->filename; |
3637 | |
3638 /* If dir starts with user's homedir, change that to ~. */ | |
3639 homedir = (char *) egetenv ("HOME"); | |
3640 if (homedir != 0 | |
3641 && XTYPE (dir) == Lisp_String | |
3642 && !strncmp (homedir, XSTRING (dir)->data, strlen (homedir)) | |
3643 && XSTRING (dir)->data[strlen (homedir)] == '/') | |
3644 { | |
3645 dir = make_string (XSTRING (dir)->data + strlen (homedir) - 1, | |
3646 XSTRING (dir)->size - strlen (homedir) + 1); | |
3647 XSTRING (dir)->data[0] = '~'; | |
3648 } | |
3649 | |
485 | 3650 if (!NILP (initial)) |
230 | 3651 insdef = initial; |
3652 else if (insert_default_directory) | |
3653 insdef = dir; | |
3654 else | |
3655 insdef = build_string (""); | |
3656 | |
3657 #ifdef VMS | |
3658 count = specpdl_ptr - specpdl; | |
3659 specbind (intern ("completion-ignore-case"), Qt); | |
3660 #endif | |
3661 | |
3662 GCPRO2 (insdef, defalt); | |
3663 val = Fcompleting_read (prompt, intern ("read-file-name-internal"), | |
3664 dir, mustmatch, | |
863
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3665 insert_default_directory ? insdef : Qnil, |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3666 Qfile_name_history); |
230 | 3667 |
3668 #ifdef VMS | |
3669 unbind_to (count, Qnil); | |
3670 #endif | |
3671 | |
3672 UNGCPRO; | |
485 | 3673 if (NILP (val)) |
230 | 3674 error ("No file name specified"); |
3675 tem = Fstring_equal (val, insdef); | |
485 | 3676 if (!NILP (tem) && !NILP (defalt)) |
230 | 3677 return defalt; |
3678 return Fsubstitute_in_file_name (val); | |
3679 } | |
3680 #endif /* Old version */ | |
3681 | |
3682 syms_of_fileio () | |
3683 { | |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
3684 Qexpand_file_name = intern ("expand-file-name"); |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
3685 Qdirectory_file_name = intern ("directory-file-name"); |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
3686 Qfile_name_directory = intern ("file-name-directory"); |
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
3687 Qfile_name_nondirectory = intern ("file-name-nondirectory"); |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3688 Qunhandled_file_name_directory = intern ("unhandled-file-name-directory"); |
1105
80ad8d0704ba
(Ffile_name_directory, Ffile_name_nondirectory):
Richard M. Stallman <rms@gnu.org>
parents:
1071
diff
changeset
|
3689 Qfile_name_as_directory = intern ("file-name-as-directory"); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3690 Qcopy_file = intern ("copy-file"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3691 Qmake_directory = intern ("make-directory"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3692 Qdelete_directory = intern ("delete-directory"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3693 Qdelete_file = intern ("delete-file"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3694 Qrename_file = intern ("rename-file"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3695 Qadd_name_to_file = intern ("add-name-to-file"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3696 Qmake_symbolic_link = intern ("make-symbolic-link"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3697 Qfile_exists_p = intern ("file-exists-p"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3698 Qfile_executable_p = intern ("file-executable-p"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3699 Qfile_readable_p = intern ("file-readable-p"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3700 Qfile_symlink_p = intern ("file-symlink-p"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3701 Qfile_writable_p = intern ("file-writable-p"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3702 Qfile_directory_p = intern ("file-directory-p"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3703 Qfile_accessible_directory_p = intern ("file-accessible-directory-p"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3704 Qfile_modes = intern ("file-modes"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3705 Qset_file_modes = intern ("set-file-modes"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3706 Qfile_newer_than_file_p = intern ("file-newer-than-file-p"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3707 Qinsert_file_contents = intern ("insert-file-contents"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3708 Qwrite_region = intern ("write-region"); |
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3709 Qverify_visited_file_modtime = intern ("verify-visited-file-modtime"); |
3560
95021dcb923b
(syms_of_fileio): Set up Qset_visited_file_modtime.
Richard M. Stallman <rms@gnu.org>
parents:
3415
diff
changeset
|
3710 Qset_visited_file_modtime = intern ("set-visited-file-modtime"); |
843
8f6ea998ad0a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
806
diff
changeset
|
3711 |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3712 staticpro (&Qexpand_file_name); |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3713 staticpro (&Qdirectory_file_name); |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3714 staticpro (&Qfile_name_directory); |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3715 staticpro (&Qfile_name_nondirectory); |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3716 staticpro (&Qunhandled_file_name_directory); |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3717 staticpro (&Qfile_name_as_directory); |
863
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3718 staticpro (&Qcopy_file); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3719 staticpro (&Qmake_directory); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3720 staticpro (&Qdelete_directory); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3721 staticpro (&Qdelete_file); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3722 staticpro (&Qrename_file); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3723 staticpro (&Qadd_name_to_file); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3724 staticpro (&Qmake_symbolic_link); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3725 staticpro (&Qfile_exists_p); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3726 staticpro (&Qfile_executable_p); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3727 staticpro (&Qfile_readable_p); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3728 staticpro (&Qfile_symlink_p); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3729 staticpro (&Qfile_writable_p); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3730 staticpro (&Qfile_directory_p); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3731 staticpro (&Qfile_accessible_directory_p); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3732 staticpro (&Qfile_modes); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3733 staticpro (&Qset_file_modes); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3734 staticpro (&Qfile_newer_than_file_p); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3735 staticpro (&Qinsert_file_contents); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3736 staticpro (&Qwrite_region); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3737 staticpro (&Qverify_visited_file_modtime); |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3738 |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3739 Qfile_name_history = intern ("file-name-history"); |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3740 Fset (Qfile_name_history, Qnil); |
863
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3741 staticpro (&Qfile_name_history); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
853
diff
changeset
|
3742 |
230 | 3743 Qfile_error = intern ("file-error"); |
3744 staticpro (&Qfile_error); | |
3745 Qfile_already_exists = intern("file-already-exists"); | |
3746 staticpro (&Qfile_already_exists); | |
3747 | |
5494
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
3748 #ifdef MSDOS |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
3749 Qfind_buffer_file_type = intern ("find-buffer-file-type"); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
3750 staticpro (&Qfind_buffer_file_type); |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
3751 #endif |
1ea2b4351945
[MSDOS]: #include "msdos.h" and <sys/param.h> needed for
Richard M. Stallman <rms@gnu.org>
parents:
5410
diff
changeset
|
3752 |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3753 Qcar_less_than_car = intern ("car-less-than-car"); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3754 staticpro (&Qcar_less_than_car); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3755 |
230 | 3756 Fput (Qfile_error, Qerror_conditions, |
3757 Fcons (Qfile_error, Fcons (Qerror, Qnil))); | |
3758 Fput (Qfile_error, Qerror_message, | |
3759 build_string ("File error")); | |
3760 | |
3761 Fput (Qfile_already_exists, Qerror_conditions, | |
3762 Fcons (Qfile_already_exists, | |
3763 Fcons (Qfile_error, Fcons (Qerror, Qnil)))); | |
3764 Fput (Qfile_already_exists, Qerror_message, | |
3765 build_string ("File already exists")); | |
3766 | |
3767 DEFVAR_BOOL ("insert-default-directory", &insert_default_directory, | |
3768 "*Non-nil means when reading a filename start with default dir in minibuffer."); | |
3769 insert_default_directory = 1; | |
3770 | |
3771 DEFVAR_BOOL ("vms-stmlf-recfm", &vms_stmlf_recfm, | |
3772 "*Non-nil means write new files with record format `stmlf'.\n\ | |
3773 nil means use format `var'. This variable is meaningful only on VMS."); | |
3774 vms_stmlf_recfm = 0; | |
3775 | |
850
0bc61321ba50
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
848
diff
changeset
|
3776 DEFVAR_LISP ("file-name-handler-alist", &Vfile_name_handler_alist, |
0bc61321ba50
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
848
diff
changeset
|
3777 "*Alist of elements (REGEXP . HANDLER) for file names handled specially.\n\ |
0bc61321ba50
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
848
diff
changeset
|
3778 If a file name matches REGEXP, then all I/O on that file is done by calling\n\ |
0bc61321ba50
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
848
diff
changeset
|
3779 HANDLER.\n\ |
0bc61321ba50
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
848
diff
changeset
|
3780 \n\ |
0bc61321ba50
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
848
diff
changeset
|
3781 The first argument given to HANDLER is the name of the I/O primitive\n\ |
0bc61321ba50
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
848
diff
changeset
|
3782 to be handled; the remaining arguments are the arguments that were\n\ |
0bc61321ba50
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
848
diff
changeset
|
3783 passed to that primitive. For example, if you do\n\ |
0bc61321ba50
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
848
diff
changeset
|
3784 (file-exists-p FILENAME)\n\ |
0bc61321ba50
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
848
diff
changeset
|
3785 and FILENAME is handled by HANDLER, then HANDLER is called like this:\n\ |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3786 (funcall HANDLER 'file-exists-p FILENAME)\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3787 The function `find-file-name-handler' checks this list for a handler\n\ |
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3788 for its argument."); |
1178
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3789 Vfile_name_handler_alist = Qnil; |
fb4ec23ef80f
Don't include sys/dir.h.
Richard M. Stallman <rms@gnu.org>
parents:
1105
diff
changeset
|
3790 |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3791 DEFVAR_LISP ("after-insert-file-functions", &Vafter_insert_file_functions, |
4989
9fe45f58189f
(syms_of_fileio): Fix missing \n\'s.
Richard M. Stallman <rms@gnu.org>
parents:
4950
diff
changeset
|
3792 "A list of functions to be called at the end of `insert-file-contents'.\n\ |
9fe45f58189f
(syms_of_fileio): Fix missing \n\'s.
Richard M. Stallman <rms@gnu.org>
parents:
4950
diff
changeset
|
3793 Each is passed one argument, the number of bytes inserted. It should return\n\ |
9fe45f58189f
(syms_of_fileio): Fix missing \n\'s.
Richard M. Stallman <rms@gnu.org>
parents:
4950
diff
changeset
|
3794 the new byte count, and leave point the same. If `insert-file-contents' is\n\ |
9fe45f58189f
(syms_of_fileio): Fix missing \n\'s.
Richard M. Stallman <rms@gnu.org>
parents:
4950
diff
changeset
|
3795 intercepted by a handler from `file-name-handler-alist', that handler is\n\ |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3796 responsible for calling the after-insert-file-functions if appropriate."); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3797 Vafter_insert_file_functions = Qnil; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3798 |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3799 DEFVAR_LISP ("write-region-annotate-functions", &Vwrite_region_annotate_functions, |
4989
9fe45f58189f
(syms_of_fileio): Fix missing \n\'s.
Richard M. Stallman <rms@gnu.org>
parents:
4950
diff
changeset
|
3800 "A list of functions to be called at the start of `write-region'.\n\ |
9fe45f58189f
(syms_of_fileio): Fix missing \n\'s.
Richard M. Stallman <rms@gnu.org>
parents:
4950
diff
changeset
|
3801 Each is passed two arguments, START and END as for `write-region'. It should\n\ |
9fe45f58189f
(syms_of_fileio): Fix missing \n\'s.
Richard M. Stallman <rms@gnu.org>
parents:
4950
diff
changeset
|
3802 return a list of pairs (POSITION . STRING) of strings to be effectively\n\ |
9fe45f58189f
(syms_of_fileio): Fix missing \n\'s.
Richard M. Stallman <rms@gnu.org>
parents:
4950
diff
changeset
|
3803 inserted at the specified positions of the file being written (1 means to\n\ |
9fe45f58189f
(syms_of_fileio): Fix missing \n\'s.
Richard M. Stallman <rms@gnu.org>
parents:
4950
diff
changeset
|
3804 insert before the first byte written). The POSITIONs must be sorted into\n\ |
9fe45f58189f
(syms_of_fileio): Fix missing \n\'s.
Richard M. Stallman <rms@gnu.org>
parents:
4950
diff
changeset
|
3805 increasing order. If there are several functions in the list, the several\n\ |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3806 lists are merged destructively."); |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3807 Vwrite_region_annotate_functions = Qnil; |
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3808 |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3809 defsubr (&Sfind_file_name_handler); |
230 | 3810 defsubr (&Sfile_name_directory); |
3811 defsubr (&Sfile_name_nondirectory); | |
1679
cd48b2c1a7a4
Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents:
1589
diff
changeset
|
3812 defsubr (&Sunhandled_file_name_directory); |
230 | 3813 defsubr (&Sfile_name_as_directory); |
3814 defsubr (&Sdirectory_file_name); | |
3815 defsubr (&Smake_temp_name); | |
3816 defsubr (&Sexpand_file_name); | |
3817 defsubr (&Ssubstitute_in_file_name); | |
3818 defsubr (&Scopy_file); | |
1533
b86ef0432100
(Fmake_directory_internal): Renamed from Fmake_directory.
Richard M. Stallman <rms@gnu.org>
parents:
1377
diff
changeset
|
3819 defsubr (&Smake_directory_internal); |
686
bd3068742807
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
3820 defsubr (&Sdelete_directory); |
230 | 3821 defsubr (&Sdelete_file); |
3822 defsubr (&Srename_file); | |
3823 defsubr (&Sadd_name_to_file); | |
3824 #ifdef S_IFLNK | |
3825 defsubr (&Smake_symbolic_link); | |
3826 #endif /* S_IFLNK */ | |
3827 #ifdef VMS | |
3828 defsubr (&Sdefine_logical_name); | |
3829 #endif /* VMS */ | |
3830 #ifdef HPUX_NET | |
3831 defsubr (&Ssysnetunam); | |
3832 #endif /* HPUX_NET */ | |
3833 defsubr (&Sfile_name_absolute_p); | |
3834 defsubr (&Sfile_exists_p); | |
3835 defsubr (&Sfile_executable_p); | |
3836 defsubr (&Sfile_readable_p); | |
3837 defsubr (&Sfile_writable_p); | |
3838 defsubr (&Sfile_symlink_p); | |
3839 defsubr (&Sfile_directory_p); | |
536 | 3840 defsubr (&Sfile_accessible_directory_p); |
230 | 3841 defsubr (&Sfile_modes); |
3842 defsubr (&Sset_file_modes); | |
1763
65e858c07a8b
(Fset_default_file_modes, Fdefault_file_modes): Renamed from .._mode.
Richard M. Stallman <rms@gnu.org>
parents:
1762
diff
changeset
|
3843 defsubr (&Sset_default_file_modes); |
65e858c07a8b
(Fset_default_file_modes, Fdefault_file_modes): Renamed from .._mode.
Richard M. Stallman <rms@gnu.org>
parents:
1762
diff
changeset
|
3844 defsubr (&Sdefault_file_modes); |
230 | 3845 defsubr (&Sfile_newer_than_file_p); |
3846 defsubr (&Sinsert_file_contents); | |
3847 defsubr (&Swrite_region); | |
4841
8800a7377ceb
(Vafter_insert_file_functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
3848 defsubr (&Scar_less_than_car); |
230 | 3849 defsubr (&Sverify_visited_file_modtime); |
3850 defsubr (&Sclear_visited_file_modtime); | |
2257
668491072928
(Fvisited_file_modtime): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2236
diff
changeset
|
3851 defsubr (&Svisited_file_modtime); |
230 | 3852 defsubr (&Sset_visited_file_modtime); |
3853 defsubr (&Sdo_auto_save); | |
3854 defsubr (&Sset_buffer_auto_saved); | |
3855 defsubr (&Srecent_auto_save_p); | |
3856 | |
3857 defsubr (&Sread_file_name_internal); | |
3858 defsubr (&Sread_file_name); | |
689
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
3859 |
1204
567860ca77e0
* fileio.c (syms_of_fileio): Don't try to defsubr Sunix_sync
Jim Blandy <jimb@redhat.com>
parents:
1178
diff
changeset
|
3860 #ifdef unix |
689
45401d45581d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
3861 defsubr (&Sunix_sync); |
1204
567860ca77e0
* fileio.c (syms_of_fileio): Don't try to defsubr Sunix_sync
Jim Blandy <jimb@redhat.com>
parents:
1178
diff
changeset
|
3862 #endif |
230 | 3863 } |