From: Ken Tilton
Subject: Newby pathname question: wildcards
Date: 
Message-ID: <Nb2Ah.16$8y5.13@newsfe10.lga>
This works:

(directory (make-pathname
             :directory '(:absolute "0dev" "AlgebraOne" "skills")
             :name "Reverse Inequality*"
             :type "mov"))

But I wonder if that asterisk trick is portable (esp. to the Mac, but 
also just as a rule) and of course wonder if there is not some mechanism 
in the pathname standard that would let me do it with a keyword.

I see I could do :wild for the whole pathname, but I want to restrict 
the matches to those with a certain prefix. Looking at the CLHS and 
CLtL2, I think I am doomed to veering outside the standard.

My next question is OT: what would /you/ do if your well-out-of-warranty 
Dell Inspiron 5150 screen suddenly started doing the "do not attempt to 
adjust your television" thing, though an external monitor workds fine. 
It /looks/ like hardware and taking it apart and jiggling and banging 
things actually produced a legible image for 1.25 seconds... time for 
Windows Vista (on my new laptop)? or are these things salvageable? By 
CompUSA? Should I call someone I find on the Web and start buying parts 
at random?

ken


-- 
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
                                   -- Elwood P. Dowd

In this world, you must be oh so smart or oh so pleasant.
                                   -- Elwood's Mom

From: Richard M Kreuter
Subject: Re: Newby pathname question: wildcards
Date: 
Message-ID: <8764a79g1z.fsf@progn.net>
Ken Tilton <·········@gmail.com> writes:

> This works:
>
> (directory (make-pathname
>             :directory '(:absolute "0dev" "AlgebraOne" "skills")
>             :name "Reverse Inequality*"
>             :type "mov"))

Does it?  The MAKE-PATHNAME call returns a pathname for which
WILD-PATHNAME-P is false under SBCL and Allegro [*].

> But I wonder if that asterisk trick is portable (esp. to the Mac, but
> also just as a rule) and of course wonder if there is not some
> mechanism in the pathname standard that would let me do it with a
> keyword.

Nope.  The Hyperspec only standardizes :wild and :wild-inferiors for
wildcards.  Fancier patterns are permitted, but not specified.

> I see I could do :wild for the whole pathname, but I want to restrict
> the matches to those with a certain prefix. Looking at the CLHS and
> CLtL2, I think I am doomed to veering outside the standard.

The Hyperspec chapter on pathnames is almost completely useless as an
API reference (implementations are allowed to do or not do nearly
anything with pathnames).

In fact, all implementations I've tried do support fancy wildcards
like the above, though they differ in how you can get such pathnames.
ISTR finding that PARSE-NAMESTRING did what I wanted everywhere I
tried it.

Also, to be persnickety, you're supposed to supply a :case :common and
mess up the string arguments' case whenever calling MAKE-PATHNAME or
any of PATHNAME-{HOST,DEVICE,DIRECTORY,NAME,TYPE}, if you're concerned
about portability.

--
RmK


[*]

;SBCL uses the string arguments to MAKE-PATHNAME verbatim.
* (wild-pathname-p "*")
T
* (make-pathname :name "*")
#P"\\*"
* (wild-pathname-p *)
NIL

;Allegro seems to use the string argument to MAKE-PATHNAME verbatim,
; but it could just be that its WILD-PATHNAME-P is broken.  This
; example was generated using prompt.franz.com late 2006.
CL-USER(1): (wild-pathname-p "*")
T
CL-USER(2): (make-pathname :name "*")
#P"*"
CL-USER(3): (wild-pathname-p *)
NIL

;OpenMCL treats string arguments to MAKE-PATHNAME as namestrings.
? (wild-pathname-p "*")
0
? (make-pathname :name "*")
#P"*"
? (wild-pathname-p *)
0

;Clisp treats string arguments to MAKE-PATHNAME as namestrings.
[1]> (wild-pathname-p "*")
T
[2]> (make-pathname :name "*")
#P"*"
[3]> (wild-pathname-p *)
T

;ECL treats string arguments to MAKE-PATHNAME as namestrings.
> (wild-pathname-p "*")
T
> (make-pathname :name "*")
#P"*"
> (wild-pathname-p *)
T 
From: Ken Tilton
Subject: Re: Newby pathname question: wildcards
Date: 
Message-ID: <gQ6Ah.40$%N4.10@newsfe11.lga>
Richard M Kreuter wrote:
> Ken Tilton <·········@gmail.com> writes:
> 
> 
>>This works:
>>
>>(directory (make-pathname
>>            :directory '(:absolute "0dev" "AlgebraOne" "skills")
>>            :name "Reverse Inequality*"
>>            :type "mov"))
> 
> 
> Does it?  The MAKE-PATHNAME call returns a pathname for which
> WILD-PATHNAME-P is false under SBCL and Allegro [*].

Well, it works in the sense that directory on that pathname returned all 
the files I expected.

Nice discussion of pathnames, btw.

kt

-- 
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
                                   -- Elwood P. Dowd

In this world, you must be oh so smart or oh so pleasant.
                                   -- Elwood's Mom
From: Raymond Toy
Subject: Re: Newby pathname question: wildcards
Date: 
Message-ID: <sxd1wkuxae3.fsf@rtp.ericsson.se>
>>>>> "Richard" == Richard M Kreuter <Richard> writes:

    Richard> In fact, all implementations I've tried do support fancy wildcards
    Richard> like the above, though they differ in how you can get such pathnames.
    Richard> ISTR finding that PARSE-NAMESTRING did what I wanted everywhere I
    Richard> tried it.

Would that include gcl?  If so, could you tell me how you did it?

AFAICT gcl supports :wild, but not :wild-inferiors, and
:wild-inferiors is what I really wanted.  A peek at some of the code
indicates that gcl just does "ls -d" or something.

Ray
From: Richard M Kreuter
Subject: Re: Newby pathname question: wildcards
Date: 
Message-ID: <87y7n191kc.fsf@progn.net>
Raymond Toy <···········@ericsson.com> writes:

>>>>>> "Richard" == Richard M Kreuter <Richard> writes:
>
>     Richard> In fact, all implementations I've tried do support fancy wildcards
>     Richard> like the above, though they differ in how you can get such pathnames.
>     Richard> ISTR finding that PARSE-NAMESTRING did what I wanted everywhere I
>     Richard> tried it.
>
> Would that include gcl?

No, it doesn't.  Also, I meant to refer only to patterns like "a*b" in
a name, type, or single element of the directory.  Sorry about the
ambiguity.

> AFAICT gcl supports :wild, but not :wild-inferiors, and
> :wild-inferiors is what I really wanted.  A peek at some of the code
> indicates that gcl just does "ls -d" or something.

Crikey, it actually runs the command under the shell, and doesn't seem
to do any quoting or escaping.  It looks like gcl's DIRECTORY is all
kinds of broken and exploitable.

$ gclcvs
GCL (GNU Common Lisp)  2.7.0 CLtL1    Dec 11 2004 01:28:53
Source License: LGPL(gcl,gmp), GPL(unexec,bfd)
Binary License:  GPL due to GPL'ed components: (READLINE BFD UNEXEC)
Modifications of this banner must retain notice of a compatible license
Dedicated to the memory of W. Schelter

Use (help) to get some basic information on how to use GCL.

>(directory #P"/tmp/a b")
(#P"/home/kreuter/bad-query.sql"
 #P"/home/kreuter/bash-203"
 #P"/home/kreuter/bash-203.zip"
 #P"/home/kreuter/blastdb"
 #P"/home/kreuter/blast.out")
>(directory #P"; echo 'hi!' | tr 'a-z' 'A-Z' > /dev/tty;") 
HI!

(#P"/home/kreuter/")



--
RmK
From: Raymond Toy
Subject: Re: Newby pathname question: wildcards
Date: 
Message-ID: <sxdtzxouzau.fsf@rtp.ericsson.se>
>>>>> "Richard" == Richard M Kreuter <Richard> writes:

    Richard> Crikey, it actually runs the command under the shell, and doesn't seem
    Richard> to do any quoting or escaping.  It looks like gcl's DIRECTORY is all
    Richard> kinds of broken and exploitable.

    Richard> $ gclcvs
    Richard> GCL (GNU Common Lisp)  2.7.0 CLtL1    Dec 11 2004 01:28:53
    Richard> Source License: LGPL(gcl,gmp), GPL(unexec,bfd)
    Richard> Binary License:  GPL due to GPL'ed components: (READLINE BFD UNEXEC)
    Richard> Modifications of this banner must retain notice of a compatible license
    Richard> Dedicated to the memory of W. Schelter

    Richard> Use (help) to get some basic information on how to use GCL.

    >> (directory #P"/tmp/a b")
    Richard> (#P"/home/kreuter/bad-query.sql"
    Richard>  #P"/home/kreuter/bash-203"
    Richard>  #P"/home/kreuter/bash-203.zip"
    Richard>  #P"/home/kreuter/blastdb"
    Richard>  #P"/home/kreuter/blast.out")
    >> (directory #P"; echo 'hi!' | tr 'a-z' 'A-Z' > /dev/tty;") 
    Richard> HI!

Yow!  It never occurred to me to try anything like that!

Ray
From: rydis (Martin Rydstr|m) @CD.Chalmers.SE
Subject: Re: Newby pathname question: wildcards
Date: 
Message-ID: <w4clkj2jvna.fsf@rackham.cd.chalmers.se>
Ken Tilton <·········@gmail.com> writes:
> This works:

> (directory (make-pathname
>              :directory '(:absolute "0dev" "AlgebraOne" "skills")
>              :name "Reverse Inequality*"
>              :type "mov"))

> But I wonder if that asterisk trick is portable (esp. to the Mac, but
> also just as a rule) and of course wonder if there is not some
> mechanism in the pathname standard that would let me do it with a
> keyword.

> I see I could do :wild for the whole pathname, but I want to restrict
> the matches to those with a certain prefix. Looking at the CLHS and
> CLtL2, I think I am doomed to veering outside the standard.

It isn't portable, as others have said. Is this good enough?
---
(defun prefix-matches (prefix wild-path) 
  (remove-if-not (lambda (potential-match)
                   (= (length prefix)
                      (mismatch prefix (pathname-name potential-match))))
                 (directory wild-path)))

(prefix-matches "Reverse Inequality" 
                (make-pathname  
                 :directory '(:absolute "tmp" "Zot")
                 :name :wild :type "mov"))
---

Should be portable, as far as I can tell; you might prefer to mess
with *default-pathname-defaults* and possibly merge wild-path with
it, or something.

Regards,

',mr

-- 
rydis (Martin Rydstr�m) @CD.Chalmers.SE             http://www.rydis.se

[Emacs] is written in Lisp, which is the only computer language that is
beautiful.  -- Neal Stephenson, _In the Beginning was the Command Line_