diff options
| author | Andreas Schwab | 1999-05-10 12:57:15 +0000 |
|---|---|---|
| committer | Andreas Schwab | 1999-05-10 12:57:15 +0000 |
| commit | 8d6d9fefe05cc27e039575f21dd36e7c5a961814 (patch) | |
| tree | 09cc842f53918de9c959c38753f6a59774ecb635 /src | |
| parent | daa3df262c9aa0c4e2601183f441479df418269b (diff) | |
| download | emacs-8d6d9fefe05cc27e039575f21dd36e7c5a961814.tar.gz emacs-8d6d9fefe05cc27e039575f21dd36e7c5a961814.zip | |
(Fread_file_name): Correct handling of dollars in file
names. Protect dollars in strings put on the file-name-history.
Substitute homedir by `~' also in default_filename.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/fileio.c b/src/fileio.c index 470146014a0..f5371e6ee38 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -5401,7 +5401,7 @@ DIR defaults to current buffer's directory default.") | |||
| 5401 | (prompt, dir, default_filename, mustmatch, initial) | 5401 | (prompt, dir, default_filename, mustmatch, initial) |
| 5402 | Lisp_Object prompt, dir, default_filename, mustmatch, initial; | 5402 | Lisp_Object prompt, dir, default_filename, mustmatch, initial; |
| 5403 | { | 5403 | { |
| 5404 | Lisp_Object val, insdef, insdef1, tem; | 5404 | Lisp_Object val, insdef, tem; |
| 5405 | struct gcpro gcpro1, gcpro2; | 5405 | struct gcpro gcpro1, gcpro2; |
| 5406 | register char *homedir; | 5406 | register char *homedir; |
| 5407 | int replace_in_history = 0; | 5407 | int replace_in_history = 0; |
| @@ -5433,6 +5433,19 @@ DIR defaults to current buffer's directory default.") | |||
| 5433 | STRING_BYTES (XSTRING (dir)) - strlen (homedir) + 1); | 5433 | STRING_BYTES (XSTRING (dir)) - strlen (homedir) + 1); |
| 5434 | XSTRING (dir)->data[0] = '~'; | 5434 | XSTRING (dir)->data[0] = '~'; |
| 5435 | } | 5435 | } |
| 5436 | /* Likewise for default_filename. */ | ||
| 5437 | if (homedir != 0 | ||
| 5438 | && STRINGP (default_filename) | ||
| 5439 | && !strncmp (homedir, XSTRING (default_filename)->data, strlen (homedir)) | ||
| 5440 | && IS_DIRECTORY_SEP (XSTRING (default_filename)->data[strlen (homedir)])) | ||
| 5441 | { | ||
| 5442 | default_filename | ||
| 5443 | = make_string (XSTRING (default_filename)->data + strlen (homedir) - 1, | ||
| 5444 | STRING_BYTES (XSTRING (default_filename)) - strlen (homedir) + 1); | ||
| 5445 | XSTRING (default_filename)->data[0] = '~'; | ||
| 5446 | } | ||
| 5447 | if (!NILP (default_filename)) | ||
| 5448 | default_filename = double_dollars (default_filename); | ||
| 5436 | 5449 | ||
| 5437 | if (insert_default_directory && STRINGP (dir)) | 5450 | if (insert_default_directory && STRINGP (dir)) |
| 5438 | { | 5451 | { |
| @@ -5445,18 +5458,15 @@ DIR defaults to current buffer's directory default.") | |||
| 5445 | args[1] = initial; | 5458 | args[1] = initial; |
| 5446 | insdef = Fconcat (2, args); | 5459 | insdef = Fconcat (2, args); |
| 5447 | pos = make_number (XSTRING (double_dollars (dir))->size); | 5460 | pos = make_number (XSTRING (double_dollars (dir))->size); |
| 5448 | insdef1 = Fcons (double_dollars (insdef), pos); | 5461 | insdef = Fcons (double_dollars (insdef), pos); |
| 5449 | } | 5462 | } |
| 5450 | else | 5463 | else |
| 5451 | insdef1 = double_dollars (insdef); | 5464 | insdef = double_dollars (insdef); |
| 5452 | } | 5465 | } |
| 5453 | else if (STRINGP (initial)) | 5466 | else if (STRINGP (initial)) |
| 5454 | { | 5467 | insdef = Fcons (double_dollars (initial), make_number (0)); |
| 5455 | insdef = initial; | ||
| 5456 | insdef1 = Fcons (double_dollars (insdef), make_number (0)); | ||
| 5457 | } | ||
| 5458 | else | 5468 | else |
| 5459 | insdef = Qnil, insdef1 = Qnil; | 5469 | insdef = Qnil; |
| 5460 | 5470 | ||
| 5461 | count = specpdl_ptr - specpdl; | 5471 | count = specpdl_ptr - specpdl; |
| 5462 | #ifdef VMS | 5472 | #ifdef VMS |
| @@ -5467,7 +5477,7 @@ DIR defaults to current buffer's directory default.") | |||
| 5467 | 5477 | ||
| 5468 | GCPRO2 (insdef, default_filename); | 5478 | GCPRO2 (insdef, default_filename); |
| 5469 | val = Fcompleting_read (prompt, intern ("read-file-name-internal"), | 5479 | val = Fcompleting_read (prompt, intern ("read-file-name-internal"), |
| 5470 | dir, mustmatch, insdef1, | 5480 | dir, mustmatch, insdef, |
| 5471 | Qfile_name_history, default_filename, Qnil); | 5481 | Qfile_name_history, default_filename, Qnil); |
| 5472 | 5482 | ||
| 5473 | tem = Fsymbol_value (Qfile_name_history); | 5483 | tem = Fsymbol_value (Qfile_name_history); |
| @@ -5494,7 +5504,7 @@ DIR defaults to current buffer's directory default.") | |||
| 5494 | if (NILP (val)) | 5504 | if (NILP (val)) |
| 5495 | error ("No file name specified"); | 5505 | error ("No file name specified"); |
| 5496 | 5506 | ||
| 5497 | tem = Fstring_equal (val, insdef); | 5507 | tem = Fstring_equal (val, CONSP (insdef) ? XCAR (insdef) : insdef); |
| 5498 | 5508 | ||
| 5499 | if (!NILP (tem) && !NILP (default_filename)) | 5509 | if (!NILP (tem) && !NILP (default_filename)) |
| 5500 | val = default_filename; | 5510 | val = default_filename; |
| @@ -5510,15 +5520,16 @@ DIR defaults to current buffer's directory default.") | |||
| 5510 | if (replace_in_history) | 5520 | if (replace_in_history) |
| 5511 | /* Replace what Fcompleting_read added to the history | 5521 | /* Replace what Fcompleting_read added to the history |
| 5512 | with what we will actually return. */ | 5522 | with what we will actually return. */ |
| 5513 | XCONS (Fsymbol_value (Qfile_name_history))->car = val; | 5523 | XCONS (Fsymbol_value (Qfile_name_history))->car = double_dollars (val); |
| 5514 | else if (add_to_history) | 5524 | else if (add_to_history) |
| 5515 | { | 5525 | { |
| 5516 | /* Add the value to the history--but not if it matches | 5526 | /* Add the value to the history--but not if it matches |
| 5517 | the last value already there. */ | 5527 | the last value already there. */ |
| 5528 | Lisp_Object val1 = double_dollars (val); | ||
| 5518 | tem = Fsymbol_value (Qfile_name_history); | 5529 | tem = Fsymbol_value (Qfile_name_history); |
| 5519 | if (! CONSP (tem) || NILP (Fequal (XCONS (tem)->car, val))) | 5530 | if (! CONSP (tem) || NILP (Fequal (XCONS (tem)->car, val1))) |
| 5520 | Fset (Qfile_name_history, | 5531 | Fset (Qfile_name_history, |
| 5521 | Fcons (val, tem)); | 5532 | Fcons (val1, tem)); |
| 5522 | } | 5533 | } |
| 5523 | return val; | 5534 | return val; |
| 5524 | } | 5535 | } |