diff options
| author | Stefan Monnier | 2002-04-30 00:59:49 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2002-04-30 00:59:49 +0000 |
| commit | 86d008122bd0e2de52393a2b975edf53019d6fef (patch) | |
| tree | f1ad7f8bf5f596b270bb2940801809fe58e2e084 /src/lread.c | |
| parent | cae578a808bee476ebb2a9efac863d7d6c51f595 (diff) | |
| download | emacs-86d008122bd0e2de52393a2b975edf53019d6fef.tar.gz emacs-86d008122bd0e2de52393a2b975edf53019d6fef.zip | |
(openp): Change arg exec_only to predicate.
(build_load_history): Use XCAR/XCDR.
(Flocate_file_internal): New fun.
(syms_of_lread): Defsubr it.
(Fload): Update call to openp.
Diffstat (limited to 'src/lread.c')
| -rw-r--r-- | src/lread.c | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/src/lread.c b/src/lread.c index 86b79fbad30..fd04d57507c 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -694,7 +694,7 @@ Return t if file exists. */) | |||
| 694 | : Fappend (2, (tmp[0] = Vload_suffixes, | 694 | : Fappend (2, (tmp[0] = Vload_suffixes, |
| 695 | tmp[1] = default_suffixes, | 695 | tmp[1] = default_suffixes, |
| 696 | tmp))), | 696 | tmp))), |
| 697 | &found, 0); | 697 | &found, Qnil); |
| 698 | UNGCPRO; | 698 | UNGCPRO; |
| 699 | } | 699 | } |
| 700 | 700 | ||
| @@ -942,6 +942,24 @@ complete_filename_p (pathname) | |||
| 942 | ); | 942 | ); |
| 943 | } | 943 | } |
| 944 | 944 | ||
| 945 | DEFUN ("locate-file-internal", Flocate_file_internal, Slocate_file_internal, 2, 4, 0, | ||
| 946 | doc: /* Search for FILENAME through PATH. | ||
| 947 | If SUFFIXES is non-nil, it should be a list of suffixes to append to | ||
| 948 | file name when searching. | ||
| 949 | If non-nil, PREDICATE is used instead of `file-readable-p'. | ||
| 950 | PREDICATE can also be an integer to pass to the access(2) function, | ||
| 951 | in which case file-name-handlers are ignored. */) | ||
| 952 | (filename, path, suffixes, predicate) | ||
| 953 | Lisp_Object filename, path, suffixes, predicate; | ||
| 954 | { | ||
| 955 | Lisp_Object file; | ||
| 956 | int fd = openp (path, filename, suffixes, &file, predicate); | ||
| 957 | if (NILP (predicate) && fd > 0) | ||
| 958 | close (fd); | ||
| 959 | return file; | ||
| 960 | } | ||
| 961 | |||
| 962 | |||
| 945 | /* Search for a file whose name is STR, looking in directories | 963 | /* Search for a file whose name is STR, looking in directories |
| 946 | in the Lisp list PATH, and trying suffixes from SUFFIX. | 964 | in the Lisp list PATH, and trying suffixes from SUFFIX. |
| 947 | On success, returns a file descriptor. On failure, returns -1. | 965 | On success, returns a file descriptor. On failure, returns -1. |
| @@ -949,24 +967,25 @@ complete_filename_p (pathname) | |||
| 949 | SUFFIXES is a list of strings containing possible suffixes. | 967 | SUFFIXES is a list of strings containing possible suffixes. |
| 950 | The empty suffix is automatically added iff the list is empty. | 968 | The empty suffix is automatically added iff the list is empty. |
| 951 | 969 | ||
| 952 | EXEC_ONLY nonzero means don't open the files, | 970 | PREDICATE non-nil means don't open the files, |
| 953 | just look for one that is executable. In this case, | 971 | just look for one that satisfies the predicate. In this case, |
| 954 | returns 1 on success. | 972 | returns 1 on success. The predicate can be a lisp function or |
| 973 | an integer to pass to `access' (in which case file-name-handlers | ||
| 974 | are ignored). | ||
| 955 | 975 | ||
| 956 | If STOREPTR is nonzero, it points to a slot where the name of | 976 | If STOREPTR is nonzero, it points to a slot where the name of |
| 957 | the file actually found should be stored as a Lisp string. | 977 | the file actually found should be stored as a Lisp string. |
| 958 | nil is stored there on failure. | 978 | nil is stored there on failure. |
| 959 | 979 | ||
| 960 | If the file we find is remote, return -2 | 980 | If the file we find is remote, return -2 |
| 961 | but store the found remote file name in *STOREPTR. | 981 | but store the found remote file name in *STOREPTR. */ |
| 962 | We do not check for remote files if EXEC_ONLY is nonzero. */ | ||
| 963 | 982 | ||
| 964 | int | 983 | int |
| 965 | openp (path, str, suffixes, storeptr, exec_only) | 984 | openp (path, str, suffixes, storeptr, predicate) |
| 966 | Lisp_Object path, str; | 985 | Lisp_Object path, str; |
| 967 | Lisp_Object suffixes; | 986 | Lisp_Object suffixes; |
| 968 | Lisp_Object *storeptr; | 987 | Lisp_Object *storeptr; |
| 969 | int exec_only; | 988 | Lisp_Object predicate; |
| 970 | { | 989 | { |
| 971 | register int fd; | 990 | register int fd; |
| 972 | int fn_size = 100; | 991 | int fn_size = 100; |
| @@ -1054,9 +1073,12 @@ openp (path, str, suffixes, storeptr, exec_only) | |||
| 1054 | (load "/bar.el") where the file is actually "/bar.el.gz". */ | 1073 | (load "/bar.el") where the file is actually "/bar.el.gz". */ |
| 1055 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); | 1074 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); |
| 1056 | string = build_string (fn); | 1075 | string = build_string (fn); |
| 1057 | if (!NILP (handler) && !exec_only) | 1076 | if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate)) |
| 1058 | { | 1077 | { |
| 1059 | exists = !NILP (Ffile_readable_p (string)); | 1078 | if (NILP (predicate)) |
| 1079 | exists = !NILP (Ffile_readable_p (string)); | ||
| 1080 | else | ||
| 1081 | exists = !NILP (call1 (predicate, string)); | ||
| 1060 | if (exists && !NILP (Ffile_directory_p (string))) | 1082 | if (exists && !NILP (Ffile_directory_p (string))) |
| 1061 | exists = 0; | 1083 | exists = 0; |
| 1062 | 1084 | ||
| @@ -1080,8 +1102,8 @@ openp (path, str, suffixes, storeptr, exec_only) | |||
| 1080 | if (exists) | 1102 | if (exists) |
| 1081 | { | 1103 | { |
| 1082 | /* Check that we can access or open it. */ | 1104 | /* Check that we can access or open it. */ |
| 1083 | if (exec_only) | 1105 | if (NATNUMP (predicate)) |
| 1084 | fd = (access (pfn, X_OK) == 0) ? 1 : -1; | 1106 | fd = (access (pfn, XFASTINT (predicate)) == 0) ? 1 : -1; |
| 1085 | else | 1107 | else |
| 1086 | fd = emacs_open (pfn, O_RDONLY, 0); | 1108 | fd = emacs_open (pfn, O_RDONLY, 0); |
| 1087 | 1109 | ||
| @@ -1123,9 +1145,9 @@ build_load_history (stream, source) | |||
| 1123 | tail = Vload_history; | 1145 | tail = Vload_history; |
| 1124 | prev = Qnil; | 1146 | prev = Qnil; |
| 1125 | foundit = 0; | 1147 | foundit = 0; |
| 1126 | while (!NILP (tail)) | 1148 | while (CONSP (tail)) |
| 1127 | { | 1149 | { |
| 1128 | tem = Fcar (tail); | 1150 | tem = XCAR (tail); |
| 1129 | 1151 | ||
| 1130 | /* Find the feature's previous assoc list... */ | 1152 | /* Find the feature's previous assoc list... */ |
| 1131 | if (!NILP (Fequal (source, Fcar (tem)))) | 1153 | if (!NILP (Fequal (source, Fcar (tem)))) |
| @@ -1134,11 +1156,11 @@ build_load_history (stream, source) | |||
| 1134 | 1156 | ||
| 1135 | /* If we're loading, remove it. */ | 1157 | /* If we're loading, remove it. */ |
| 1136 | if (loading) | 1158 | if (loading) |
| 1137 | { | 1159 | { |
| 1138 | if (NILP (prev)) | 1160 | if (NILP (prev)) |
| 1139 | Vload_history = Fcdr (tail); | 1161 | Vload_history = XCDR (tail); |
| 1140 | else | 1162 | else |
| 1141 | Fsetcdr (prev, Fcdr (tail)); | 1163 | Fsetcdr (prev, XCDR (tail)); |
| 1142 | } | 1164 | } |
| 1143 | 1165 | ||
| 1144 | /* Otherwise, cons on new symbols that are not already members. */ | 1166 | /* Otherwise, cons on new symbols that are not already members. */ |
| @@ -1148,20 +1170,20 @@ build_load_history (stream, source) | |||
| 1148 | 1170 | ||
| 1149 | while (CONSP (tem2)) | 1171 | while (CONSP (tem2)) |
| 1150 | { | 1172 | { |
| 1151 | newelt = Fcar (tem2); | 1173 | newelt = XCAR (tem2); |
| 1152 | 1174 | ||
| 1153 | if (NILP (Fmemq (newelt, tem))) | 1175 | if (NILP (Fmemq (newelt, tem))) |
| 1154 | Fsetcar (tail, Fcons (Fcar (tem), | 1176 | Fsetcar (tail, Fcons (XCAR (tem), |
| 1155 | Fcons (newelt, Fcdr (tem)))); | 1177 | Fcons (newelt, XCDR (tem)))); |
| 1156 | 1178 | ||
| 1157 | tem2 = Fcdr (tem2); | 1179 | tem2 = XCDR (tem2); |
| 1158 | QUIT; | 1180 | QUIT; |
| 1159 | } | 1181 | } |
| 1160 | } | 1182 | } |
| 1161 | } | 1183 | } |
| 1162 | else | 1184 | else |
| 1163 | prev = tail; | 1185 | prev = tail; |
| 1164 | tail = Fcdr (tail); | 1186 | tail = XCDR (tail); |
| 1165 | QUIT; | 1187 | QUIT; |
| 1166 | } | 1188 | } |
| 1167 | 1189 | ||
| @@ -3594,6 +3616,7 @@ syms_of_lread () | |||
| 3594 | defsubr (&Sread_event); | 3616 | defsubr (&Sread_event); |
| 3595 | defsubr (&Sget_file_char); | 3617 | defsubr (&Sget_file_char); |
| 3596 | defsubr (&Smapatoms); | 3618 | defsubr (&Smapatoms); |
| 3619 | defsubr (&Slocate_file_internal); | ||
| 3597 | 3620 | ||
| 3598 | DEFVAR_LISP ("obarray", &Vobarray, | 3621 | DEFVAR_LISP ("obarray", &Vobarray, |
| 3599 | doc: /* Symbol table for use by `intern' and `read'. | 3622 | doc: /* Symbol table for use by `intern' and `read'. |