Mercurial > emacs
comparison src/fileio.c @ 21048:4d1d3581eeb4
(ENCODE_FILE): This macro is moved to coding.h.
(Vdefault_file_name_coding_system): New variable.
(syms_of_fileio): Defsubr it.
(Ffile_symlink_p): Use DECODE_FILE.
(Ffile_name_directory): Use size_byte member of XSTRING (filename).
(Ffile_name_as_directory): Likewise.
(Fdirectory_file_name): Likewise.
(Fsubstitute_in_file_name): Likewise.
(expand_and_dir_to_file): Likewise.
(Fdo_auto_save): Likewise.
(Fread_file_name): Likewise.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 03 Mar 1998 07:18:46 +0000 |
parents | 293eb7d1a966 |
children | d10664297ed2 |
comparison
equal
deleted
inserted
replaced
21047:55c278cd38f0 | 21048:4d1d3581eeb4 |
---|---|
150 #endif | 150 #endif |
151 | 151 |
152 #define min(a, b) ((a) < (b) ? (a) : (b)) | 152 #define min(a, b) ((a) < (b) ? (a) : (b)) |
153 #define max(a, b) ((a) > (b) ? (a) : (b)) | 153 #define max(a, b) ((a) > (b) ? (a) : (b)) |
154 | 154 |
155 /* Encode the file name NAME using the specified coding system | |
156 for file names, if any. */ | |
157 #define ENCODE_FILE(name) \ | |
158 (! NILP (Vfile_name_coding_system) \ | |
159 && XFASTINT (Vfile_name_coding_system) != 0 \ | |
160 ? Fencode_coding_string (name, Vfile_name_coding_system, Qt) \ | |
161 : name) | |
162 | |
163 /* Nonzero during writing of auto-save files */ | 155 /* Nonzero during writing of auto-save files */ |
164 int auto_saving; | 156 int auto_saving; |
165 | 157 |
166 /* Set by auto_save_1 to mode of original file so Fwrite_region will create | 158 /* Set by auto_save_1 to mode of original file so Fwrite_region will create |
167 a new file with the same mode as the original */ | 159 a new file with the same mode as the original */ |
168 int auto_save_mode_bits; | 160 int auto_save_mode_bits; |
169 | 161 |
170 /* Coding system for file names, or nil if none. */ | 162 /* Coding system for file names, or nil if none. */ |
171 Lisp_Object Vfile_name_coding_system; | 163 Lisp_Object Vfile_name_coding_system; |
164 | |
165 /* Coding system for file names used only when | |
166 Vfile_name_coding_system is nil. */ | |
167 Lisp_Object Vdefault_file_name_coding_system; | |
172 | 168 |
173 /* Alist of elements (REGEXP . HANDLER) for file names | 169 /* Alist of elements (REGEXP . HANDLER) for file names |
174 whose I/O is done with a special handler. */ | 170 whose I/O is done with a special handler. */ |
175 Lisp_Object Vfile_name_handler_alist; | 171 Lisp_Object Vfile_name_handler_alist; |
176 | 172 |
377 #endif | 373 #endif |
378 beg = XSTRING (filename)->data; | 374 beg = XSTRING (filename)->data; |
379 #ifdef DOS_NT | 375 #ifdef DOS_NT |
380 beg = strcpy (alloca (strlen (beg) + 1), beg); | 376 beg = strcpy (alloca (strlen (beg) + 1), beg); |
381 #endif | 377 #endif |
382 p = beg + XSTRING (filename)->size; | 378 p = beg + XSTRING (filename)->size_byte; |
383 | 379 |
384 while (p != beg && !IS_DIRECTORY_SEP (p[-1]) | 380 while (p != beg && !IS_DIRECTORY_SEP (p[-1]) |
385 #ifdef VMS | 381 #ifdef VMS |
386 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>' | 382 && p[-1] != ':' && p[-1] != ']' && p[-1] != '>' |
387 #endif /* VMS */ | 383 #endif /* VMS */ |
587 call the corresponding file handler. */ | 583 call the corresponding file handler. */ |
588 handler = Ffind_file_name_handler (file, Qfile_name_as_directory); | 584 handler = Ffind_file_name_handler (file, Qfile_name_as_directory); |
589 if (!NILP (handler)) | 585 if (!NILP (handler)) |
590 return call2 (handler, Qfile_name_as_directory, file); | 586 return call2 (handler, Qfile_name_as_directory, file); |
591 | 587 |
592 buf = (char *) alloca (XSTRING (file)->size + 10); | 588 buf = (char *) alloca (XSTRING (file)->size_byte + 10); |
593 return build_string (file_name_as_directory (buf, XSTRING (file)->data)); | 589 return build_string (file_name_as_directory (buf, XSTRING (file)->data)); |
594 } | 590 } |
595 | 591 |
596 /* | 592 /* |
597 * Convert from directory name to filename. | 593 * Convert from directory name to filename. |
782 | 778 |
783 #ifdef VMS | 779 #ifdef VMS |
784 /* 20 extra chars is insufficient for VMS, since we might perform a | 780 /* 20 extra chars is insufficient for VMS, since we might perform a |
785 logical name translation. an equivalence string can be up to 255 | 781 logical name translation. an equivalence string can be up to 255 |
786 chars long, so grab that much extra space... - sss */ | 782 chars long, so grab that much extra space... - sss */ |
787 buf = (char *) alloca (XSTRING (directory)->size + 20 + 255); | 783 buf = (char *) alloca (XSTRING (directory)->size_byte + 20 + 255); |
788 #else | 784 #else |
789 buf = (char *) alloca (XSTRING (directory)->size + 20); | 785 buf = (char *) alloca (XSTRING (directory)->size_byte + 20); |
790 #endif | 786 #endif |
791 directory_file_name (XSTRING (directory)->data, buf); | 787 directory_file_name (XSTRING (directory)->data, buf); |
792 return build_string (buf); | 788 return build_string (buf); |
793 } | 789 } |
794 | 790 |
1807 #ifdef DOS_NT | 1803 #ifdef DOS_NT |
1808 nm = strcpy (alloca (strlen (nm) + 1), nm); | 1804 nm = strcpy (alloca (strlen (nm) + 1), nm); |
1809 CORRECT_DIR_SEPS (nm); | 1805 CORRECT_DIR_SEPS (nm); |
1810 substituted = (strcmp (nm, XSTRING (filename)->data) != 0); | 1806 substituted = (strcmp (nm, XSTRING (filename)->data) != 0); |
1811 #endif | 1807 #endif |
1812 endp = nm + XSTRING (filename)->size; | 1808 endp = nm + XSTRING (filename)->size_byte; |
1813 | 1809 |
1814 /* If /~ or // appears, discard everything through first slash. */ | 1810 /* If /~ or // appears, discard everything through first slash. */ |
1815 | 1811 |
1816 for (p = nm; p != endp; p++) | 1812 for (p = nm; p != endp; p++) |
1817 { | 1813 { |
1900 if (!substituted) | 1896 if (!substituted) |
1901 return filename; | 1897 return filename; |
1902 | 1898 |
1903 /* If substitution required, recopy the string and do it */ | 1899 /* If substitution required, recopy the string and do it */ |
1904 /* Make space in stack frame for the new copy */ | 1900 /* Make space in stack frame for the new copy */ |
1905 xnm = (unsigned char *) alloca (XSTRING (filename)->size + total + 1); | 1901 xnm = (unsigned char *) alloca (XSTRING (filename)->size_byte + total + 1); |
1906 x = xnm; | 1902 x = xnm; |
1907 | 1903 |
1908 /* Copy the rest of the name through, replacing $ constructs with values */ | 1904 /* Copy the rest of the name through, replacing $ constructs with values */ |
1909 for (p = nm; *p;) | 1905 for (p = nm; *p;) |
1910 if (*p != '$') | 1906 if (*p != '$') |
2019 register Lisp_Object absname; | 2015 register Lisp_Object absname; |
2020 | 2016 |
2021 absname = Fexpand_file_name (filename, defdir); | 2017 absname = Fexpand_file_name (filename, defdir); |
2022 #ifdef VMS | 2018 #ifdef VMS |
2023 { | 2019 { |
2024 register int c = XSTRING (absname)->data[XSTRING (absname)->size - 1]; | 2020 register int c = XSTRING (absname)->data[XSTRING (absname)->size_byte - 1]; |
2025 if (c == ':' || c == ']' || c == '>') | 2021 if (c == ':' || c == ']' || c == '>') |
2026 absname = Fdirectory_file_name (absname); | 2022 absname = Fdirectory_file_name (absname); |
2027 } | 2023 } |
2028 #else | 2024 #else |
2029 /* Remove final slash, if any (unless this is the root dir). | 2025 /* Remove final slash, if any (unless this is the root dir). |
2030 stat behaves differently depending! */ | 2026 stat behaves differently depending! */ |
2031 if (XSTRING (absname)->size > 1 | 2027 if (XSTRING (absname)->size > 1 |
2032 && IS_DIRECTORY_SEP (XSTRING (absname)->data[XSTRING (absname)->size - 1]) | 2028 && IS_DIRECTORY_SEP (XSTRING (absname)->data[XSTRING (absname)->size_byte - 1]) |
2033 && !IS_DEVICE_SEP (XSTRING (absname)->data[XSTRING (absname)->size-2])) | 2029 && !IS_DEVICE_SEP (XSTRING (absname)->data[XSTRING (absname)->size_byte-2])) |
2034 /* We cannot take shortcuts; they might be wrong for magic file names. */ | 2030 /* We cannot take shortcuts; they might be wrong for magic file names. */ |
2035 absname = Fdirectory_file_name (absname); | 2031 absname = Fdirectory_file_name (absname); |
2036 #endif | 2032 #endif |
2037 return absname; | 2033 return absname; |
2038 } | 2034 } |
2879 xfree (buf); | 2875 xfree (buf); |
2880 return Qnil; | 2876 return Qnil; |
2881 } | 2877 } |
2882 val = make_string (buf, valsize); | 2878 val = make_string (buf, valsize); |
2883 xfree (buf); | 2879 xfree (buf); |
2884 return Fdecode_coding_string (val, Vfile_name_coding_system, Qt); | 2880 val = DECODE_FILE (val); |
2881 return val; | |
2885 #else /* not S_IFLNK */ | 2882 #else /* not S_IFLNK */ |
2886 return Qnil; | 2883 return Qnil; |
2887 #endif /* not S_IFLNK */ | 2884 #endif /* not S_IFLNK */ |
2888 } | 2885 } |
2889 | 2886 |
4788 && stream != NULL && do_handled_files == 0) | 4785 && stream != NULL && do_handled_files == 0) |
4789 { | 4786 { |
4790 if (!NILP (b->filename)) | 4787 if (!NILP (b->filename)) |
4791 { | 4788 { |
4792 fwrite (XSTRING (b->filename)->data, 1, | 4789 fwrite (XSTRING (b->filename)->data, 1, |
4793 XSTRING (b->filename)->size, stream); | 4790 XSTRING (b->filename)->size_byte, stream); |
4794 } | 4791 } |
4795 putc ('\n', stream); | 4792 putc ('\n', stream); |
4796 fwrite (XSTRING (b->auto_save_file_name)->data, 1, | 4793 fwrite (XSTRING (b->auto_save_file_name)->data, 1, |
4797 XSTRING (b->auto_save_file_name)->size, stream); | 4794 XSTRING (b->auto_save_file_name)->size_byte, stream); |
4798 putc ('\n', stream); | 4795 putc ('\n', stream); |
4799 } | 4796 } |
4800 | 4797 |
4801 if (!NILP (current_only) | 4798 if (!NILP (current_only) |
4802 && b != current_buffer) | 4799 && b != current_buffer) |
5067 && STRINGP (dir) | 5064 && STRINGP (dir) |
5068 && !strncmp (homedir, XSTRING (dir)->data, strlen (homedir)) | 5065 && !strncmp (homedir, XSTRING (dir)->data, strlen (homedir)) |
5069 && IS_DIRECTORY_SEP (XSTRING (dir)->data[strlen (homedir)])) | 5066 && IS_DIRECTORY_SEP (XSTRING (dir)->data[strlen (homedir)])) |
5070 { | 5067 { |
5071 dir = make_string (XSTRING (dir)->data + strlen (homedir) - 1, | 5068 dir = make_string (XSTRING (dir)->data + strlen (homedir) - 1, |
5072 XSTRING (dir)->size - strlen (homedir) + 1); | 5069 XSTRING (dir)->size_byte - strlen (homedir) + 1); |
5073 XSTRING (dir)->data[0] = '~'; | 5070 XSTRING (dir)->data[0] = '~'; |
5074 } | 5071 } |
5075 | 5072 |
5076 if (insert_default_directory && STRINGP (dir)) | 5073 if (insert_default_directory && STRINGP (dir)) |
5077 { | 5074 { |
5242 Qfind_buffer_file_type = intern ("find-buffer-file-type"); | 5239 Qfind_buffer_file_type = intern ("find-buffer-file-type"); |
5243 staticpro (&Qfind_buffer_file_type); | 5240 staticpro (&Qfind_buffer_file_type); |
5244 #endif /* DOS_NT */ | 5241 #endif /* DOS_NT */ |
5245 | 5242 |
5246 DEFVAR_LISP ("file-name-coding-system", &Vfile_name_coding_system, | 5243 DEFVAR_LISP ("file-name-coding-system", &Vfile_name_coding_system, |
5247 "*Coding system for encoding file names."); | 5244 "*Coding system for encoding file names.\n\ |
5245 If it is nil, default-file-name-coding-system (which see) is used."); | |
5248 Vfile_name_coding_system = Qnil; | 5246 Vfile_name_coding_system = Qnil; |
5247 | |
5248 DEFVAR_LISP ("default-file-name-coding-system", | |
5249 &Vdefault_file_name_coding_system, | |
5250 "Default coding system for encoding file names.\n\ | |
5251 This variable is used only when file-name-coding-system is nil.\n\ | |
5252 \n\ | |
5253 This variable is set/changed by the command set-language-environment.\n\ | |
5254 User should not set this variable manually,\n\ | |
5255 instead use file-name-coding-system to get a constant encoding\n\ | |
5256 of file names regardless of the current language environment."); | |
5257 Vdefault_file_name_coding_system = Qnil; | |
5249 | 5258 |
5250 DEFVAR_LISP ("auto-save-file-format", &Vauto_save_file_format, | 5259 DEFVAR_LISP ("auto-save-file-format", &Vauto_save_file_format, |
5251 "*Format in which to write auto-save files.\n\ | 5260 "*Format in which to write auto-save files.\n\ |
5252 Should be a list of symbols naming formats that are defined in `format-alist'.\n\ | 5261 Should be a list of symbols naming formats that are defined in `format-alist'.\n\ |
5253 If it is t, which is the default, auto-save files are written in the\n\ | 5262 If it is t, which is the default, auto-save files are written in the\n\ |