Re: pathname with tilde and wildcard characters

Richard M Kreuter via Sbcl-help <[email protected]>
Newsgroups gmane.lisp.steel-bank.general
Message-ID <[email protected]>
Peter Münster <[email protected]> wrote:

> On Thu, Jun 06 2024, Peter Münster wrote:
> 
> > I just have to choose! ;)
> 
> Ah, perhaps not! I’ve just discovered "enough-namestring":
> 
> (enough-namestring (parse-native-namestring my-file-name))
> 
> This seems to work. What do you think, is this robust?

Hi Peter,

It's a little unclear to me what you're trying to accomplish.

When you're typing things into an SBCL REPL, you can escape wildcard
characters with a backslash on Unix (circumflex on Windows). As folks
have mentioned you could enter this:

  (open "~/tmp/test-\\?\\?-file")

OTOH, if you're trying to write a program that combines inputs with the
notion of "beneath my home directory", then how you do it depends on the
format of the input.

For example, if your inputs come from a "catalog" file you previously
wrote using SBCL's namestring syntax, then you might process each input
in the catalog with

  (loop for input = <read an input or NIL>
        while input
	do
     (with-open-file (file (merge-pathnames
                            input (user-homedir-pathname)))
       ...))

(Exactly how you read the input depends on your catalog format. Maybe
it's READ-LINE, maybe it's some custom parser, etc.)

By contrast, if the catalog was prepared by some non-Lisp program, the
contents should be presumed not to be in Lisp namestring syntax, but
"native namestring" syntax, i.e., verbatim format. In that case, to
process the files, you could write

  (loop for input = <read an input or NIL>
        while input
	do
     (let ((parse (sb-ext:parse-native-namestring 
                   input nil (user-homedir-pathname))))
       (with-open-file (file (merge-pathnames
                              parse (user-homedir-pathname)))
       ...)))

So it's the same basic program either way, but you must call a function
to request "native namestring" interpretation of the input.

The underlying idea here is that there are 2 different formats in play:
native namestring syntax, which is the format the OS uses; and Lisp
namestring syntax, which is a format that can express a few more
concepts than an underlying OS can (such as wildcards on Unix). The
formats are slightly different, and should be handled
carefully. Conflict is fairly rare, however, because filenames
containing wildcards, backslashes, etc. aren't common. All the same,
it's technically a mistake to combine strings unless you're sure they're
in the same format (or, perhaps, that unusual filenames will never
appear).

I hope that demystifies things a bit.

Regards,
Richard


_______________________________________________
Sbcl-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-help
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.