Mercurial > hg > xemacs-beta
comparison src/editfns.c @ 440:8de8e3f6228a r21-2-28
Import from CVS: tag r21-2-28
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:33:38 +0200 |
parents | 9d177e8d4150 |
children | abe6d1db359e |
comparison
equal
deleted
inserted
replaced
439:357dd071b03c | 440:8de8e3f6228a |
---|---|
94 #endif | 94 #endif |
95 | 95 |
96 if ((p = getenv ("NAME"))) | 96 if ((p = getenv ("NAME"))) |
97 /* I don't think it's the right thing to do the ampersand | 97 /* I don't think it's the right thing to do the ampersand |
98 modification on NAME. Not that it matters anymore... -hniksic */ | 98 modification on NAME. Not that it matters anymore... -hniksic */ |
99 Vuser_full_name = build_ext_string (p, FORMAT_OS); | 99 Vuser_full_name = build_ext_string (p, Qnative); |
100 else | 100 else |
101 Vuser_full_name = Fuser_full_name (Qnil); | 101 Vuser_full_name = Fuser_full_name (Qnil); |
102 } | 102 } |
103 | 103 |
104 DEFUN ("char-to-string", Fchar_to_string, 1, 1, 0, /* | 104 DEFUN ("char-to-string", Fchar_to_string, 1, 1, 0, /* |
129 Convert arg STRING to a character, the first character of that string. | 129 Convert arg STRING to a character, the first character of that string. |
130 An empty string will return the constant `nil'. | 130 An empty string will return the constant `nil'. |
131 */ | 131 */ |
132 (str)) | 132 (str)) |
133 { | 133 { |
134 struct Lisp_String *p; | 134 Lisp_String *p; |
135 CHECK_STRING (str); | 135 CHECK_STRING (str); |
136 | 136 |
137 p = XSTRING (str); | 137 p = XSTRING (str); |
138 if (string_length (p) != 0) | 138 if (string_length (p) != 0) |
139 return make_char (string_char (p, 0)); | 139 return make_char (string_char (p, 0)); |
623 tmpdir = getenv ("TMPDIR"); | 623 tmpdir = getenv ("TMPDIR"); |
624 if (!tmpdir) | 624 if (!tmpdir) |
625 tmpdir = "/tmp"; | 625 tmpdir = "/tmp"; |
626 #endif | 626 #endif |
627 | 627 |
628 return build_ext_string (tmpdir, FORMAT_FILENAME); | 628 return build_ext_string (tmpdir, Qfile_name); |
629 } | 629 } |
630 | 630 |
631 DEFUN ("user-login-name", Fuser_login_name, 0, 1, 0, /* | 631 DEFUN ("user-login-name", Fuser_login_name, 0, 1, 0, /* |
632 Return the name under which the user logged in, as a string. | 632 Return the name under which the user logged in, as a string. |
633 This is based on the effective uid, not the real uid. | 633 This is based on the effective uid, not the real uid. |
766 { | 766 { |
767 CONST char *user_name_ext; | 767 CONST char *user_name_ext; |
768 | 768 |
769 /* Fuck me. getpwnam() can call select() and (under IRIX at least) | 769 /* Fuck me. getpwnam() can call select() and (under IRIX at least) |
770 things get wedged if a SIGIO arrives during this time. */ | 770 things get wedged if a SIGIO arrives during this time. */ |
771 GET_C_STRING_OS_DATA_ALLOCA (user_name, user_name_ext); | 771 TO_EXTERNAL_FORMAT (LISP_STRING, user_name, |
772 C_STRING_ALLOCA, user_name_ext, | |
773 Qnative); | |
772 slow_down_interrupts (); | 774 slow_down_interrupts (); |
773 pw = (struct passwd *) getpwnam (user_name_ext); | 775 pw = (struct passwd *) getpwnam (user_name_ext); |
774 speed_up_interrupts (); | 776 speed_up_interrupts (); |
775 } | 777 } |
776 | 778 |
784 q = strchr (p, ','); | 786 q = strchr (p, ','); |
785 #endif | 787 #endif |
786 tem = ((!NILP (user) && !pw) | 788 tem = ((!NILP (user) && !pw) |
787 ? Qnil | 789 ? Qnil |
788 : make_ext_string ((Extbyte *) p, (q ? q - p : strlen (p)), | 790 : make_ext_string ((Extbyte *) p, (q ? q - p : strlen (p)), |
789 FORMAT_OS)); | 791 Qnative)); |
790 | 792 |
791 #ifdef AMPERSAND_FULL_NAME | 793 #ifdef AMPERSAND_FULL_NAME |
792 if (!NILP (tem)) | 794 if (!NILP (tem)) |
793 { | 795 { |
794 p = (char *) XSTRING_DATA (tem); | 796 p = (char *) XSTRING_DATA (tem); |
809 #endif /* AMPERSAND_FULL_NAME */ | 811 #endif /* AMPERSAND_FULL_NAME */ |
810 | 812 |
811 return tem; | 813 return tem; |
812 } | 814 } |
813 | 815 |
814 static char *cached_home_directory; | 816 static Extbyte *cached_home_directory; |
815 | 817 |
816 void | 818 void |
817 uncache_home_directory (void) | 819 uncache_home_directory (void) |
818 { | 820 { |
819 cached_home_directory = NULL; /* in some cases, this may cause the leaking | 821 cached_home_directory = NULL; /* in some cases, this may cause the leaking |
820 of a few bytes */ | 822 of a few bytes */ |
821 } | 823 } |
822 | 824 |
823 /* Returns the home directory, in external format */ | 825 /* Returns the home directory, in external format */ |
824 char * | 826 Extbyte * |
825 get_home_directory (void) | 827 get_home_directory (void) |
826 { | 828 { |
827 int output_home_warning = 0; | 829 int output_home_warning = 0; |
828 | 830 |
829 if (cached_home_directory == NULL) | 831 if (cached_home_directory == NULL) |
830 { | 832 { |
831 if ((cached_home_directory = getenv("HOME")) == NULL) | 833 if ((cached_home_directory = (Extbyte *) getenv("HOME")) == NULL) |
832 { | 834 { |
833 #if defined(WINDOWSNT) && !defined(__CYGWIN32__) | 835 #if defined(WINDOWSNT) && !defined(__CYGWIN32__) |
834 char *homedrive, *homepath; | 836 char *homedrive, *homepath; |
835 | 837 |
836 if ((homedrive = getenv("HOMEDRIVE")) != NULL && | 838 if ((homedrive = getenv("HOMEDRIVE")) != NULL && |
837 (homepath = getenv("HOMEPATH")) != NULL) | 839 (homepath = getenv("HOMEPATH")) != NULL) |
838 { | 840 { |
839 cached_home_directory = | 841 cached_home_directory = |
840 (char *) xmalloc(strlen(homedrive) + strlen(homepath) + 1); | 842 (Extbyte *) xmalloc (strlen (homedrive) + |
841 sprintf(cached_home_directory, "%s%s", homedrive, homepath); | 843 strlen (homepath) + 1); |
844 sprintf((char *) cached_home_directory, "%s%s", | |
845 homedrive, | |
846 homepath); | |
842 } | 847 } |
843 else | 848 else |
844 { | 849 { |
845 # if 1 | 850 # if 1 |
846 /* | 851 /* |
859 } | 864 } |
860 # else | 865 # else |
861 /* | 866 /* |
862 * This is NT Emacs behavior | 867 * This is NT Emacs behavior |
863 */ | 868 */ |
864 cached_home_directory = "C:\\"; | 869 cached_home_directory = (Extbyte *) "C:\\"; |
865 output_home_warning = 1; | 870 output_home_warning = 1; |
866 # endif | 871 # endif |
867 } | 872 } |
868 #else /* !WINDOWSNT */ | 873 #else /* !WINDOWSNT */ |
869 /* | 874 /* |
870 * Unix, typically. | 875 * Unix, typically. |
871 * Using "/" isn't quite right, but what should we do? | 876 * Using "/" isn't quite right, but what should we do? |
872 * We probably should try to extract pw_dir from /etc/passwd, | 877 * We probably should try to extract pw_dir from /etc/passwd, |
873 * before falling back to this. | 878 * before falling back to this. |
874 */ | 879 */ |
875 cached_home_directory = "/"; | 880 cached_home_directory = (Extbyte *) "/"; |
876 output_home_warning = 1; | 881 output_home_warning = 1; |
877 #endif /* !WINDOWSNT */ | 882 #endif /* !WINDOWSNT */ |
878 } | 883 } |
879 if (initialized && output_home_warning) | 884 if (initialized && output_home_warning) |
880 { | 885 { |
893 DEFUN ("user-home-directory", Fuser_home_directory, 0, 0, 0, /* | 898 DEFUN ("user-home-directory", Fuser_home_directory, 0, 0, 0, /* |
894 Return the user's home directory, as a string. | 899 Return the user's home directory, as a string. |
895 */ | 900 */ |
896 ()) | 901 ()) |
897 { | 902 { |
898 char *path = get_home_directory (); | 903 Extbyte *path = get_home_directory (); |
899 | 904 |
900 return path == NULL ? Qnil : | 905 return path == NULL ? Qnil : |
901 Fexpand_file_name (Fsubstitute_in_file_name | 906 Fexpand_file_name (Fsubstitute_in_file_name |
902 (build_ext_string (path, FORMAT_FILENAME)), | 907 (build_ext_string ((char *) path, Qfile_name)), |
903 Qnil); | 908 Qnil); |
904 } | 909 } |
905 | 910 |
906 DEFUN ("system-name", Fsystem_name, 0, 0, 0, /* | 911 DEFUN ("system-name", Fsystem_name, 0, 0, 0, /* |
907 Return the name of the machine you are running on, as a string. | 912 Return the name of the machine you are running on, as a string. |
1069 *buf = 1; | 1074 *buf = 1; |
1070 if (emacs_strftime (buf, size, | 1075 if (emacs_strftime (buf, size, |
1071 (CONST char *) XSTRING_DATA (format_string), | 1076 (CONST char *) XSTRING_DATA (format_string), |
1072 localtime (&value)) | 1077 localtime (&value)) |
1073 || !*buf) | 1078 || !*buf) |
1074 return build_ext_string (buf, FORMAT_BINARY); | 1079 return build_ext_string (buf, Qbinary); |
1075 /* If buffer was too small, make it bigger. */ | 1080 /* If buffer was too small, make it bigger. */ |
1076 size *= 2; | 1081 size *= 2; |
1077 } | 1082 } |
1078 } | 1083 } |
1079 | 1084 |
1223 tem = (char *) ctime (&value); | 1228 tem = (char *) ctime (&value); |
1224 | 1229 |
1225 strncpy (buf, tem, 24); | 1230 strncpy (buf, tem, 24); |
1226 buf[24] = 0; | 1231 buf[24] = 0; |
1227 | 1232 |
1228 return build_ext_string (buf, FORMAT_BINARY); | 1233 return build_ext_string (buf, Qbinary); |
1229 } | 1234 } |
1230 | 1235 |
1231 #define TM_YEAR_ORIGIN 1900 | 1236 #define TM_YEAR_ORIGIN 1900 |
1232 | 1237 |
1233 /* Yield A - B, measured in seconds. */ | 1238 /* Yield A - B, measured in seconds. */ |
1817 | 1822 |
1818 get_buffer_range_char (buf, start, end, &pos, &stop, 0); | 1823 get_buffer_range_char (buf, start, end, &pos, &stop, 0); |
1819 mc_count = begin_multiple_change (buf, pos, stop); | 1824 mc_count = begin_multiple_change (buf, pos, stop); |
1820 if (STRINGP (table)) | 1825 if (STRINGP (table)) |
1821 { | 1826 { |
1822 struct Lisp_String *stable = XSTRING (table); | 1827 Lisp_String *stable = XSTRING (table); |
1823 Charcount size = string_char_length (stable); | 1828 Charcount size = string_char_length (stable); |
1824 #ifdef MULE | 1829 #ifdef MULE |
1825 /* Under Mule, string_char(n) is O(n), so for large tables or | 1830 /* Under Mule, string_char(n) is O(n), so for large tables or |
1826 large regions it makes sense to create an array of Emchars. */ | 1831 large regions it makes sense to create an array of Emchars. */ |
1827 if (size * (stop - pos) > 65536) | 1832 if (size * (stop - pos) > 65536) |
1897 } | 1902 } |
1898 else if (CHAR_TABLEP (table) | 1903 else if (CHAR_TABLEP (table) |
1899 && (XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_GENERIC | 1904 && (XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_GENERIC |
1900 || XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_CHAR)) | 1905 || XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_CHAR)) |
1901 { | 1906 { |
1902 struct Lisp_Char_Table *ctable = XCHAR_TABLE (table); | 1907 Lisp_Char_Table *ctable = XCHAR_TABLE (table); |
1903 | 1908 |
1904 for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++) | 1909 for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++) |
1905 { | 1910 { |
1906 Lisp_Object replacement = get_char_table (oc, ctable); | 1911 Lisp_Object replacement = get_char_table (oc, ctable); |
1907 retry2: | 1912 retry2: |