comparison src/fileio.c @ 20621:ee017970042d

(Fdo_auto_save): Save and restore multibyteness of minibuffer. (Fwrite_region): Use message_with_string. (auto_save_error, Fdo_auto_save): Likewise. (Ffile_name_directory): Maybe use make_unibyte_string. (Ffile_name_nondirectory): Likewise. (Fsubstitute_in_file_name): Convert substituted envvars to multibyte if necessary. Otherwise use make_unibyte_string. (Finsert_file_contents): Use make_unibyte_string. (double_dollars): Use make_uninit_multibyte_string.
author Richard M. Stallman <rms@gnu.org>
date Fri, 09 Jan 1998 23:12:05 +0000
parents c9095cd30412
children 0de9f45a1db6
comparison
equal deleted inserted replaced
20620:a3cb242e8349 20621:ee017970042d
407 p = beg + strlen (beg); 407 p = beg + strlen (beg);
408 } 408 }
409 } 409 }
410 CORRECT_DIR_SEPS (beg); 410 CORRECT_DIR_SEPS (beg);
411 #endif /* DOS_NT */ 411 #endif /* DOS_NT */
412 return make_string (beg, p - beg); 412
413 } 413 if (STRING_MULTIBYTE (filename))
414 414 return make_string (beg, p - beg);
415 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, Sfile_name_nondirectory, 415 return make_unibyte_string (beg, p - beg);
416 1, 1, 0, 416 }
417
418 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory,
419 Sfile_name_nondirectory, 1, 1, 0,
417 "Return file name FILENAME sans its directory.\n\ 420 "Return file name FILENAME sans its directory.\n\
418 For example, in a Unix-syntax file name,\n\ 421 For example, in a Unix-syntax file name,\n\
419 this is everything after the last slash,\n\ 422 this is everything after the last slash,\n\
420 or the entire name if it contains no slash.") 423 or the entire name if it contains no slash.")
421 (filename) 424 (filename)
441 #endif /* VMS */ 444 #endif /* VMS */
442 #ifdef DOS_NT 445 #ifdef DOS_NT
443 /* only recognise drive specifier at beginning */ 446 /* only recognise drive specifier at beginning */
444 && !(p[-1] == ':' && p == beg + 2) 447 && !(p[-1] == ':' && p == beg + 2)
445 #endif 448 #endif
446 ) p--; 449 )
447 450 p--;
448 return make_string (p, end - p); 451
449 } 452 if (STRING_MULTIBYTE (filename))
450 453 return make_string (p, end - p);
451 DEFUN ("unhandled-file-name-directory", Funhandled_file_name_directory, Sunhandled_file_name_directory, 1, 1, 0, 454 return make_unibyte_string (p, end - p);
455 }
456
457 DEFUN ("unhandled-file-name-directory", Funhandled_file_name_directory,
458 Sunhandled_file_name_directory, 1, 1, 0,
452 "Return a directly usable directory name somehow associated with FILENAME.\n\ 459 "Return a directly usable directory name somehow associated with FILENAME.\n\
453 A `directly usable' directory name is one that may be used without the\n\ 460 A `directly usable' directory name is one that may be used without the\n\
454 intervention of any file handler.\n\ 461 intervention of any file handler.\n\
455 If FILENAME is a directly usable file itself, return\n\ 462 If FILENAME is a directly usable file itself, return\n\
456 \(file-name-directory FILENAME).\n\ 463 \(file-name-directory FILENAME).\n\
1930 /* Get variable value */ 1937 /* Get variable value */
1931 o = (unsigned char *) egetenv (target); 1938 o = (unsigned char *) egetenv (target);
1932 if (!o) 1939 if (!o)
1933 goto badvar; 1940 goto badvar;
1934 1941
1935 strcpy (x, o); 1942 if (STRING_MULTIBYTE (filename))
1936 x += strlen (o); 1943 {
1944 /* If the original string is multibyte,
1945 convert what we substitute into multibyte. */
1946 unsigned char workbuf[4], *str;
1947 int len;
1948 extern int nonascii_insert_offset;
1949
1950 while (*o)
1951 {
1952 int c = *o++;
1953 if (c >= 0200)
1954 {
1955 c += nonascii_insert_offset;
1956 len = CHAR_STRING (c, workbuf, str);
1957 bcopy (str, x, len);
1958 x += len;
1959 }
1960 else
1961 *x++ = c;
1962 }
1963 }
1964 else
1965 {
1966 strcpy (x, o);
1967 x += strlen (o);
1968 }
1937 } 1969 }
1938 1970
1939 *x = 0; 1971 *x = 0;
1940 1972
1941 /* If /~ or // appears, discard everything through first slash. */ 1973 /* If /~ or // appears, discard everything through first slash. */
1954 else if (IS_DRIVE (p[0]) && p[1] == ':' 1986 else if (IS_DRIVE (p[0]) && p[1] == ':'
1955 && p > nm && IS_DIRECTORY_SEP (p[-1])) 1987 && p > nm && IS_DIRECTORY_SEP (p[-1]))
1956 xnm = p; 1988 xnm = p;
1957 #endif 1989 #endif
1958 1990
1959 return make_string (xnm, x - xnm); 1991 if (STRING_MULTIBYTE (filename))
1992 return make_string (xnm, x - xnm);
1993 return make_unibyte_string (xnm, x - xnm);
1960 1994
1961 badsubst: 1995 badsubst:
1962 error ("Bad format environment-variable substitution"); 1996 error ("Bad format environment-variable substitution");
1963 missingclose: 1997 missingclose:
1964 error ("Missing \"}\" in environment-variable substitution"); 1998 error ("Missing \"}\" in environment-variable substitution");
3258 if (nread < 0) 3292 if (nread < 0)
3259 error ("IO error reading %s: %s", 3293 error ("IO error reading %s: %s",
3260 XSTRING (orig_filename)->data, strerror (errno)); 3294 XSTRING (orig_filename)->data, strerror (errno));
3261 else if (nread > 0) 3295 else if (nread > 0)
3262 { 3296 {
3263 val = call1 (Vset_auto_coding_function, 3297 Lisp_Object tem;
3264 make_string (read_buf, nread)); 3298 /* Always make this a unibyte string
3299 because we have not yet decoded it. */
3300 tem = make_unibyte_string (read_buf, nread);
3301 val = call1 (Vset_auto_coding_function, tem);
3265 /* Rewind the file for the actual read done later. */ 3302 /* Rewind the file for the actual read done later. */
3266 if (lseek (fd, 0, 0) < 0) 3303 if (lseek (fd, 0, 0) < 0)
3267 report_file_error ("Setting file position", 3304 report_file_error ("Setting file position",
3268 Fcons (orig_filename, Qnil)); 3305 Fcons (orig_filename, Qnil));
3269 } 3306 }
4329 } 4366 }
4330 else if (quietly) 4367 else if (quietly)
4331 return Qnil; 4368 return Qnil;
4332 4369
4333 if (!auto_saving) 4370 if (!auto_saving)
4334 message ("Wrote %s", XSTRING (visit_file)->data); 4371 message_with_string ("Wrote %s", visit_file, 1);
4335 4372
4336 return Qnil; 4373 return Qnil;
4337 } 4374 }
4338 4375
4339 Lisp_Object merge (); 4376 Lisp_Object merge ();
4622 4659
4623 Lisp_Object 4660 Lisp_Object
4624 auto_save_error () 4661 auto_save_error ()
4625 { 4662 {
4626 ring_bell (); 4663 ring_bell ();
4627 message ("Autosaving...error for %s", XSTRING (current_buffer->name)->data); 4664 message_with_string ("Autosaving...error for %s", current_buffer->name, 1);
4628 Fsleep_for (make_number (1), Qnil); 4665 Fsleep_for (make_number (1), Qnil);
4629 message ("Autosaving...error!for %s", XSTRING (current_buffer->name)->data); 4666 message_with_string ("Autosaving...error for %s", current_buffer->name, 0);
4630 Fsleep_for (make_number (1), Qnil); 4667 Fsleep_for (make_number (1), Qnil);
4631 message ("Autosaving...error for %s", XSTRING (current_buffer->name)->data); 4668 message_with_string ("Autosaving...error for %s", current_buffer->name, 0);
4632 Fsleep_for (make_number (1), Qnil); 4669 Fsleep_for (make_number (1), Qnil);
4633 return Qnil; 4670 return Qnil;
4634 } 4671 }
4635 4672
4636 Lisp_Object 4673 Lisp_Object
4687 struct buffer *old = current_buffer, *b; 4724 struct buffer *old = current_buffer, *b;
4688 Lisp_Object tail, buf; 4725 Lisp_Object tail, buf;
4689 int auto_saved = 0; 4726 int auto_saved = 0;
4690 char *omessage = echo_area_glyphs; 4727 char *omessage = echo_area_glyphs;
4691 int omessage_length = echo_area_glyphs_length; 4728 int omessage_length = echo_area_glyphs_length;
4729 int oldmultibyte = message_enable_multibyte;
4692 int do_handled_files; 4730 int do_handled_files;
4693 Lisp_Object oquit; 4731 Lisp_Object oquit;
4694 FILE *stream; 4732 FILE *stream;
4695 Lisp_Object lispstream; 4733 Lisp_Object lispstream;
4696 int count = specpdl_ptr - specpdl; 4734 int count = specpdl_ptr - specpdl;
4806 && !EQ (b->filename, Qnil) 4844 && !EQ (b->filename, Qnil)
4807 && NILP (no_message)) 4845 && NILP (no_message))
4808 { 4846 {
4809 /* It has shrunk too much; turn off auto-saving here. */ 4847 /* It has shrunk too much; turn off auto-saving here. */
4810 minibuffer_auto_raise = orig_minibuffer_auto_raise; 4848 minibuffer_auto_raise = orig_minibuffer_auto_raise;
4811 message ("Buffer %s has shrunk a lot; auto save turned off there", 4849 message_with_string ("Buffer %s has shrunk a lot; auto save turned off there",
4812 XSTRING (b->name)->data); 4850 b->name, 1);
4813 minibuffer_auto_raise = 0; 4851 minibuffer_auto_raise = 0;
4814 /* Turn off auto-saving until there's a real save, 4852 /* Turn off auto-saving until there's a real save,
4815 and prevent any more warnings. */ 4853 and prevent any more warnings. */
4816 XSETINT (b->save_length, -1); 4854 XSETINT (b->save_length, -1);
4817 Fsleep_for (make_number (1), Qnil); 4855 Fsleep_for (make_number (1), Qnil);
4841 if (auto_saved && NILP (no_message)) 4879 if (auto_saved && NILP (no_message))
4842 { 4880 {
4843 if (omessage) 4881 if (omessage)
4844 { 4882 {
4845 sit_for (1, 0, 0, 0, 0); 4883 sit_for (1, 0, 0, 0, 0);
4846 message2 (omessage, omessage_length); 4884 message2 (omessage, omessage_length, oldmultibyte);
4847 } 4885 }
4848 else 4886 else
4849 message1 ("Auto-saving...done"); 4887 message1 ("Auto-saving...done");
4850 } 4888 }
4851 4889
4895 { 4933 {
4896 register unsigned char *old, *new; 4934 register unsigned char *old, *new;
4897 register int n; 4935 register int n;
4898 int osize, count; 4936 int osize, count;
4899 4937
4900 osize = XSTRING (val)->size; 4938 osize = XSTRING (val)->size_byte;
4901 /* Quote "$" as "$$" to get it past substitute-in-file-name */ 4939
4940 /* Count the number of $ characters. */
4902 for (n = osize, count = 0, old = XSTRING (val)->data; n > 0; n--) 4941 for (n = osize, count = 0, old = XSTRING (val)->data; n > 0; n--)
4903 if (*old++ == '$') count++; 4942 if (*old++ == '$') count++;
4904 if (count > 0) 4943 if (count > 0)
4905 { 4944 {
4906 old = XSTRING (val)->data; 4945 old = XSTRING (val)->data;
4907 val = Fmake_string (make_number (osize + count), make_number (0)); 4946 val = make_uninit_multibyte_string (XSTRING (val)->size + count,
4947 osize + count);
4908 new = XSTRING (val)->data; 4948 new = XSTRING (val)->data;
4909 for (n = osize; n > 0; n--) 4949 for (n = osize; n > 0; n--)
4910 if (*old != '$') 4950 if (*old != '$')
4911 *new++ = *old++; 4951 *new++ = *old++;
4912 else 4952 else