From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Hrvoje Niksic Newsgroups: gmane.emacs.devel Subject: Re: locate-file in Emacs Date: Wed, 17 Apr 2002 11:47:14 +0200 Sender: emacs-devel-admin@gnu.org Message-ID: References: <200204170928.g3H9SVb27019@rum.cs.yale.edu> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1019036897 30699 127.0.0.1 (17 Apr 2002 09:48:17 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 17 Apr 2002 09:48:17 +0000 (UTC) Cc: emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 16xm2z-0007z2-00 for ; Wed, 17 Apr 2002 11:48:17 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 16xmLc-00066L-00 for ; Wed, 17 Apr 2002 12:07:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16xm2u-0006CR-00; Wed, 17 Apr 2002 05:48:12 -0400 Original-Received: from dragon.arsdigita.de ([212.84.246.66] helo=florida.arsdigita.de) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16xm21-0006A7-00 for ; Wed, 17 Apr 2002 05:47:17 -0400 Original-Received: from hniksic by florida.arsdigita.de with local (Exim 3.35 #1 (Debian)) id 16xm1y-00025o-00; Wed, 17 Apr 2002 11:47:14 +0200 Original-To: "Stefan Monnier" X-Attribution: Hrvoje X-Face: &{dT~)Pu6V<0y?>3p$;@vh\`C7xB~A0T-J%Og)J,@-1%q6Q+, gs<-9M#&`I8cJp2b1{vPE|~+JE+gx;a7%BG{}nY^ehK1"q#rG O,Rn1A_Cy%t]V=Brv7h ("Stefan Monnier"'s message of "Wed, 17 Apr 2002 05:28:31 -0400") Original-Lines: 67 User-Agent: Gnus/5.090006 (Oort Gnus v0.06) XEmacs/21.4 (Common Lisp, i686-pc-linux) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:2695 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:2695 "Stefan Monnier" writes: >> Several years ago I talked to Richard Stallman about incorporating the >> `locate-file' function in Emacs. `locate-file' is a very useful >> XEmacs function that searches for a file in a path. > > I like it. Thanks. > This is obviously very convenient. It should ideally be implemented > on top of the `openp' function, such as the quick-hack > implementation below. It ignores a part of the interface -- the MODE argument in this case. My version may not be as optimized, but at least it implements all of the interface. You might want to start by including (and advertising) it, and replacing it with an optimized version if it gets used. PREDICATE might make sense, but I don't remember needing it in practice. Plus, it'd change the interface and hence undermine the whole point of sharing the function. Note that MODE is actually quite easy to implement -- just add a MODE option to openp(), and have it call access() instead of open() when MODE is provided. Before doing anything else, decode MODE from Lisp to C with code like this (written by me, thus copyright-safe): static int decode_mode_1 (Lisp_Object mode) { if (EQ (mode, Qexists)) return F_OK; else if (EQ (mode, Qexecutable)) return X_OK; else if (EQ (mode, Qwritable)) return W_OK; else if (EQ (mode, Qreadable)) return R_OK; else if (INTP (mode)) { check_int_range (XINT (mode), 0, 7); return XINT (mode); } else signal_simple_error ("Invalid value", mode); return 0; /* unreached */ } static int decode_mode (Lisp_Object mode) { if (NILP (mode)) return R_OK; else if (CONSP (mode)) { Lisp_Object tail; int mask = 0; EXTERNAL_LIST_LOOP (tail, mode) mask |= decode_mode_1 (XCAR (tail)); return mask; } else return decode_mode_1 (mode); } Such decoded mode is a valid second argument to access.