Mercurial > hg > xemacs-beta
comparison src/dired.c @ 5495:1f0b15040456
Merge.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 01 May 2011 18:44:03 +0100 |
parents | 861f2601a38b 248176c74e6b |
children | 56144c8593a8 |
comparison
equal
deleted
inserted
replaced
5494:861f2601a38b | 5495:1f0b15040456 |
---|---|
1 /* Lisp functions for making directory listings. | 1 /* Lisp functions for making directory listings. |
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc. | 2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc. |
3 Copyright (C) 2001, 2002, 2010 Ben Wing. | 3 Copyright (C) 2001, 2002 Ben Wing. |
4 | 4 |
5 This file is part of XEmacs. | 5 This file is part of XEmacs. |
6 | 6 |
7 XEmacs is free software; you can redistribute it and/or modify it | 7 XEmacs is free software: you can redistribute it and/or modify it |
8 under the terms of the GNU General Public License as published by the | 8 under the terms of the GNU General Public License as published by the |
9 Free Software Foundation; either version 2, or (at your option) any | 9 Free Software Foundation, either version 3 of the License, or (at your |
10 later version. | 10 option) any later version. |
11 | 11 |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | 12 XEmacs is distributed in the hope that it will be useful, but WITHOUT |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 for more details. | 15 for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 17 You should have received a copy of the GNU General Public License |
18 along with XEmacs; see the file COPYING. If not, write to | 18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | 19 |
22 /* Synched up with: FSF 19.30. */ | 20 /* Synched up with: FSF 19.30. */ |
23 | 21 |
24 #include <config.h> | 22 #include <config.h> |
25 #include "lisp.h" | 23 #include "lisp.h" |
44 Lisp_Object Vcompletion_ignored_extensions; | 42 Lisp_Object Vcompletion_ignored_extensions; |
45 Lisp_Object Qdirectory_files; | 43 Lisp_Object Qdirectory_files; |
46 Lisp_Object Qfile_name_completion; | 44 Lisp_Object Qfile_name_completion; |
47 Lisp_Object Qfile_name_all_completions; | 45 Lisp_Object Qfile_name_all_completions; |
48 Lisp_Object Qfile_attributes; | 46 Lisp_Object Qfile_attributes; |
47 Lisp_Object Qfile_system_ignore_case_p; | |
49 | 48 |
50 static Lisp_Object | 49 static Lisp_Object |
51 close_directory_unwind (Lisp_Object unwind_obj) | 50 close_directory_unwind (Lisp_Object unwind_obj) |
52 { | 51 { |
53 DIR *d = (DIR *)get_opaque_ptr (unwind_obj); | 52 DIR *d = (DIR *)get_opaque_ptr (unwind_obj); |
178 } | 177 } |
179 } | 178 } |
180 unbind_to (speccount); /* This will close the dir */ | 179 unbind_to (speccount); /* This will close the dir */ |
181 | 180 |
182 if (NILP (nosort)) | 181 if (NILP (nosort)) |
183 list = Fsort (Fnreverse (list), Qstring_lessp); | 182 list = list_sort (Fnreverse (list), check_string_lessp_nokey, Qnil, Qnil); |
184 | 183 |
185 RETURN_UNGCPRO (list); | 184 RETURN_UNGCPRO (list); |
186 } | 185 } |
187 | 186 |
188 static Lisp_Object file_name_completion (Lisp_Object file, | 187 static Lisp_Object file_name_completion (Lisp_Object file, |
506 | 505 |
507 if (all_flag || NILP (bestmatch)) | 506 if (all_flag || NILP (bestmatch)) |
508 return bestmatch; | 507 return bestmatch; |
509 if (matchcount == 1 && bestmatchsize == file_name_length) | 508 if (matchcount == 1 && bestmatchsize == file_name_length) |
510 return Qt; | 509 return Qt; |
511 return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize)); | 510 return Fsubseq (bestmatch, Qzero, make_int (bestmatchsize)); |
512 } | 511 } |
513 | 512 |
514 | 513 |
515 static Lisp_Object user_name_completion (Lisp_Object user, | 514 static Lisp_Object user_name_completion (Lisp_Object user, |
516 int all_flag, | 515 int all_flag, |
770 | 769 |
771 if (all_flag || NILP (bestmatch)) | 770 if (all_flag || NILP (bestmatch)) |
772 return bestmatch; | 771 return bestmatch; |
773 if (matchcount == 1 && bestmatchsize == user_name_length) | 772 if (matchcount == 1 && bestmatchsize == user_name_length) |
774 return Qt; | 773 return Qt; |
775 return Fsubstring (bestmatch, Qzero, make_int (bestmatchsize)); | 774 return Fsubseq (bestmatch, Qzero, make_int (bestmatchsize)); |
776 } | 775 } |
777 | 776 |
778 | 777 |
779 Lisp_Object | 778 Lisp_Object |
780 make_directory_hash_table (const Ibyte *path) | 779 make_directory_hash_table (Lisp_Object path) |
781 { | 780 { |
782 DIR *d; | 781 DIR *d; |
783 if ((d = qxe_opendir (path))) | 782 if ((d = qxe_opendir (XSTRING_DATA (path)))) |
784 { | 783 { |
784 Lisp_Object hash_table_test = Qequal, hash = Qnil; | |
785 DIRENTRY *dp; | 785 DIRENTRY *dp; |
786 Lisp_Object hash = | 786 |
787 make_lisp_hash_table (20, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL); | 787 if (!UNBOUNDP (XSYMBOL_FUNCTION (Qfile_system_ignore_case_p)) |
788 && !NILP (call1 (Qfile_system_ignore_case_p, path))) | |
789 { | |
790 hash_table_test = Qequalp; | |
791 } | |
792 | |
793 hash = make_lisp_hash_table (20, HASH_TABLE_NON_WEAK, hash_table_test); | |
788 | 794 |
789 while ((dp = qxe_readdir (d))) | 795 while ((dp = qxe_readdir (d))) |
790 { | 796 { |
791 Bytecount len = NAMLEN (dp); | 797 Bytecount len = NAMLEN (dp); |
792 if (DIRENTRY_NONEMPTY (dp)) | 798 if (DIRENTRY_NONEMPTY (dp)) |
835 If file does not exist, returns nil. | 841 If file does not exist, returns nil. |
836 */ | 842 */ |
837 (filename)) | 843 (filename)) |
838 { | 844 { |
839 /* This function can GC. GC checked 1997.06.04. */ | 845 /* This function can GC. GC checked 1997.06.04. */ |
840 Lisp_Object values[12]; | |
841 Lisp_Object directory = Qnil; | 846 Lisp_Object directory = Qnil; |
842 struct stat s; | 847 struct stat s; |
843 char modes[10]; | 848 char modes[10]; |
844 Lisp_Object handler; | 849 Lisp_Object handler, mode, modestring = Qnil, size, gid; |
845 struct gcpro gcpro1, gcpro2; | 850 struct gcpro gcpro1, gcpro2, gcpro3; |
846 | 851 |
847 GCPRO2 (filename, directory); | 852 GCPRO3 (filename, directory, modestring); |
848 filename = Fexpand_file_name (filename, Qnil); | 853 filename = Fexpand_file_name (filename, Qnil); |
849 | 854 |
850 /* If the file name has special constructs in it, | 855 /* If the file name has special constructs in it, |
851 call the corresponding file handler. */ | 856 call the corresponding file handler. */ |
852 handler = Ffind_file_name_handler (filename, Qfile_attributes); | 857 handler = Ffind_file_name_handler (filename, Qfile_attributes); |
860 { | 865 { |
861 UNGCPRO; | 866 UNGCPRO; |
862 return Qnil; | 867 return Qnil; |
863 } | 868 } |
864 | 869 |
865 #ifdef BSD4_3 | 870 #ifdef BSD4_2 |
866 directory = Ffile_name_directory (filename); | 871 directory = Ffile_name_directory (filename); |
867 #endif | 872 #endif |
868 | 873 |
869 #if 0 /* #### shouldn't this apply to WIN32_NATIVE and maybe CYGWIN? */ | 874 #if 0 /* #### shouldn't this apply to WIN32_NATIVE and maybe CYGWIN? */ |
870 { | 875 { |
883 #endif | 888 #endif |
884 | 889 |
885 switch (s.st_mode & S_IFMT) | 890 switch (s.st_mode & S_IFMT) |
886 { | 891 { |
887 default: | 892 default: |
888 values[0] = Qnil; | 893 mode = Qnil; |
889 break; | 894 break; |
890 case S_IFDIR: | 895 case S_IFDIR: |
891 values[0] = Qt; | 896 mode = Qt; |
892 break; | 897 break; |
893 #ifdef S_IFLNK | 898 #ifdef S_IFLNK |
894 case S_IFLNK: | 899 case S_IFLNK: |
895 values[0] = Ffile_symlink_p (filename); | 900 mode = Ffile_symlink_p (filename); |
896 break; | 901 break; |
897 #endif | 902 #endif |
898 } | 903 } |
899 values[1] = make_int (s.st_nlink); | |
900 values[2] = make_int (s.st_uid); | |
901 values[3] = make_int (s.st_gid); | |
902 values[4] = make_time (s.st_atime); | |
903 values[5] = make_time (s.st_mtime); | |
904 values[6] = make_time (s.st_ctime); | |
905 | 904 |
906 #ifndef HAVE_BIGNUM | 905 #ifndef HAVE_BIGNUM |
907 values[7] = make_integer (NUMBER_FITS_IN_AN_EMACS_INT (s.st_size) ? | 906 size = make_integer (NUMBER_FITS_IN_AN_EMACS_INT (s.st_size) ? |
908 (EMACS_INT)s.st_size : -1); | 907 (EMACS_INT)s.st_size : -1); |
909 #else | 908 #else |
910 values[7] = make_integer (s.st_size); | 909 size = make_integer (s.st_size); |
911 #endif | 910 #endif |
912 | 911 |
913 filemodestring (&s, modes); | 912 filemodestring (&s, modes); |
914 values[8] = make_string ((Ibyte *) modes, 10); | 913 modestring = make_string ((Ibyte *) modes, 10); |
915 #ifdef BSD4_3 /* file gid will be dir gid */ | 914 |
915 #if defined (BSD4_2) || defined (BSD4_3) /* file gid will be dir gid */ | |
916 { | 916 { |
917 struct stat sdir; | 917 struct stat sdir; |
918 | 918 |
919 if (!NILP (directory) && qxe_stat (XSTRING_DATA (directory), &sdir) == 0) | 919 if (!NILP (directory) && qxe_stat (XSTRING_DATA (directory), &sdir) == 0) |
920 values[9] = (sdir.st_gid != s.st_gid) ? Qt : Qnil; | 920 gid = (sdir.st_gid != s.st_gid) ? Qt : Qnil; |
921 else /* if we can't tell, assume worst */ | 921 else /* if we can't tell, assume worst */ |
922 values[9] = Qt; | 922 gid = Qt; |
923 } | 923 } |
924 #else /* file gid will be egid */ | 924 #else /* file gid will be egid */ |
925 values[9] = (s.st_gid != getegid ()) ? Qt : Qnil; | 925 gid = (s.st_gid != getegid ()) ? Qt : Qnil; |
926 #endif /* BSD4_3 */ | 926 #endif /* BSD4_2 or BSD4_3 */ |
927 values[10] = make_int (s.st_ino); | 927 |
928 values[11] = make_int (s.st_dev); | 928 RETURN_UNGCPRO (listn (12, |
929 UNGCPRO; | 929 mode, |
930 return Flist (countof (values), values); | 930 make_int (s.st_nlink), |
931 make_int (s.st_uid), | |
932 make_int (s.st_gid), | |
933 make_time (s.st_atime), | |
934 make_time (s.st_mtime), | |
935 make_time (s.st_ctime), | |
936 size, | |
937 modestring, | |
938 gid, | |
939 make_int (s.st_ino), | |
940 make_int (s.st_dev))); | |
931 } | 941 } |
932 | 942 |
933 | 943 |
934 /************************************************************************/ | 944 /************************************************************************/ |
935 /* initialization */ | 945 /* initialization */ |
940 { | 950 { |
941 DEFSYMBOL (Qdirectory_files); | 951 DEFSYMBOL (Qdirectory_files); |
942 DEFSYMBOL (Qfile_name_completion); | 952 DEFSYMBOL (Qfile_name_completion); |
943 DEFSYMBOL (Qfile_name_all_completions); | 953 DEFSYMBOL (Qfile_name_all_completions); |
944 DEFSYMBOL (Qfile_attributes); | 954 DEFSYMBOL (Qfile_attributes); |
955 DEFSYMBOL (Qfile_system_ignore_case_p); | |
945 | 956 |
946 DEFSUBR (Fdirectory_files); | 957 DEFSUBR (Fdirectory_files); |
947 DEFSUBR (Ffile_name_completion); | 958 DEFSUBR (Ffile_name_completion); |
948 DEFSUBR (Ffile_name_all_completions); | 959 DEFSUBR (Ffile_name_all_completions); |
949 DEFSUBR (Fuser_name_completion); | 960 DEFSUBR (Fuser_name_completion); |