Mercurial > emacs
comparison src/fileio.c @ 41595:3a10e73aa1c1
(Ffind_file_name_handler): Give precedence to handlers
which match the end of the file-name.
(Fsubstitute_in_file_name): Don't signal an error if $ENVVAR
is not a valid env var, but leave it as is instead.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 26 Nov 2001 22:54:37 +0000 |
parents | 1d1183771c4f |
children | fccc74affd73 |
comparison
equal
deleted
inserted
replaced
41594:452efff38a6e | 41595:3a10e73aa1c1 |
---|---|
334 use the standard functions without calling themselves recursively. */) | 334 use the standard functions without calling themselves recursively. */) |
335 (filename, operation) | 335 (filename, operation) |
336 Lisp_Object filename, operation; | 336 Lisp_Object filename, operation; |
337 { | 337 { |
338 /* This function must not munge the match data. */ | 338 /* This function must not munge the match data. */ |
339 Lisp_Object chain, inhibited_handlers; | 339 Lisp_Object chain, inhibited_handlers, result = Qnil; |
340 int pos = -1; | |
340 | 341 |
341 CHECK_STRING (filename); | 342 CHECK_STRING (filename); |
342 | 343 |
343 if (EQ (operation, Vinhibit_file_name_operation)) | 344 if (EQ (operation, Vinhibit_file_name_operation)) |
344 inhibited_handlers = Vinhibit_file_name_handlers; | 345 inhibited_handlers = Vinhibit_file_name_handlers; |
351 Lisp_Object elt; | 352 Lisp_Object elt; |
352 elt = XCAR (chain); | 353 elt = XCAR (chain); |
353 if (CONSP (elt)) | 354 if (CONSP (elt)) |
354 { | 355 { |
355 Lisp_Object string; | 356 Lisp_Object string; |
357 int match_pos; | |
356 string = XCAR (elt); | 358 string = XCAR (elt); |
357 if (STRINGP (string) && fast_string_match (string, filename) >= 0) | 359 if (STRINGP (string) |
360 && (match_pos = fast_string_match (string, filename)) > pos) | |
358 { | 361 { |
359 Lisp_Object handler, tem; | 362 Lisp_Object handler, tem; |
360 | 363 |
361 handler = XCDR (elt); | 364 handler = XCDR (elt); |
362 tem = Fmemq (handler, inhibited_handlers); | 365 tem = Fmemq (handler, inhibited_handlers); |
363 if (NILP (tem)) | 366 if (NILP (tem)) |
364 return handler; | 367 { |
368 result = handler; | |
369 pos = match_pos; | |
370 } | |
365 } | 371 } |
366 } | 372 } |
367 | 373 |
368 QUIT; | 374 QUIT; |
369 } | 375 } |
370 return Qnil; | 376 return result; |
371 } | 377 } |
372 | 378 |
373 DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, | 379 DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, |
374 1, 1, 0, | 380 1, 1, 0, |
375 doc: /* Return the directory component in file name FILENAME. | 381 doc: /* Return the directory component in file name FILENAME. |
2099 strupr (target); /* $home == $HOME etc. */ | 2105 strupr (target); /* $home == $HOME etc. */ |
2100 #endif /* DOS_NT */ | 2106 #endif /* DOS_NT */ |
2101 | 2107 |
2102 /* Get variable value */ | 2108 /* Get variable value */ |
2103 o = (unsigned char *) egetenv (target); | 2109 o = (unsigned char *) egetenv (target); |
2104 if (!o) goto badvar; | 2110 if (o) |
2105 total += strlen (o); | 2111 { |
2106 substituted = 1; | 2112 total += strlen (o); |
2113 substituted = 1; | |
2114 } | |
2115 else if (*p == '}') | |
2116 goto badvar; | |
2107 } | 2117 } |
2108 | 2118 |
2109 if (!substituted) | 2119 if (!substituted) |
2110 return filename; | 2120 return filename; |
2111 | 2121 |
2151 #endif /* DOS_NT */ | 2161 #endif /* DOS_NT */ |
2152 | 2162 |
2153 /* Get variable value */ | 2163 /* Get variable value */ |
2154 o = (unsigned char *) egetenv (target); | 2164 o = (unsigned char *) egetenv (target); |
2155 if (!o) | 2165 if (!o) |
2156 goto badvar; | 2166 { |
2157 | 2167 *x++ = '$'; |
2158 if (STRING_MULTIBYTE (filename)) | 2168 strcpy (x, target); x+= strlen (target); |
2169 } | |
2170 else if (STRING_MULTIBYTE (filename)) | |
2159 { | 2171 { |
2160 /* If the original string is multibyte, | 2172 /* If the original string is multibyte, |
2161 convert what we substitute into multibyte. */ | 2173 convert what we substitute into multibyte. */ |
2162 while (*o) | 2174 while (*o) |
2163 { | 2175 { |