Newsgroups: comp.lang.lisp.x
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!ix.netcom.com!netcom.com!mayer
From: mayer@netcom.com (Niels P. Mayer)
Subject: Re: filename from path?
Message-ID: <mayerD47tsM.2B2@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
References: <PSHANNON.95Feb15173958@iapetus.cv.nrao.edu>
Date: Sat, 18 Feb 1995 21:45:58 GMT
Lines: 76
Sender: mayer@netcom2.netcom.com

In article <PSHANNON.95Feb15173958@iapetus.cv.nrao.edu>, pshannon@iapetus.cv.nrao.edu (Paul Shannon) writes:
> I have written a simple function in common lisp which returns
> a filename from a (possibly long) path:
> 
>     (shortname "/home/pshannon/work/winterp/data")  --> "data"
> 
> I need to do the same thing in xlisp.
> 
> My lisp sensibilities are probably not what they should be...I
> wrote this thing using common lisp's "find" and aref.  I
> kept on thinking this function would be built in.
> 
> In any case, find doesn't seem to be in xlisp.  Can anyone give
> me advice about the best way to write this function in xlisp?

Such functionality exists in WINTERP 2.0's "library" -- see
winterp/examples/lib-utils/unixstuf.lsp or access it via WWW as
http://www.eit.com/software/winterp/examples/lib-utils/unixstuf.lsp .

I don't claim these are the best-written functions on earth, but they work
for me. I guess others might have used reverse/position-if/subseq...

(defun file:get-path (filepath-str)
  (do
   ((i (1- (length filepath-str)) (1- i))
    )
   ((or (< i 0) (char= (char filepath-str i) #\/))
    (if (< i 0)
        filepath-str
      (subseq filepath-str 0 i))
    )
   )
  )

(defun file:remove-path (filepath-str)
  (do
   ((i (1- (length filepath-str)) (1- i))
    )
   ((or (< i 0) (char= (char filepath-str i) #\/))
    (if (< i 0)
        filepath-str
      (subseq filepath-str (1+ i)))
    )
   )
  )


(defun file:remove-extension (filepath-str)
  (do
   ((i (1- (length filepath-str)) (1- i))
    )
   ((or (< i 0) (char= (char filepath-str i) #\.))
    (if (< i 0)
        filepath-str
      (subseq filepath-str 0 i))
    )
   )
  )

(defun file:get-extension (filepath-str)
  (do
   ((i (1- (length filepath-str)) (1- i))
    )
   ((or (< i 0) (char= (char filepath-str i) #\.))
    (if (< i 0)
        NIL
      (subseq filepath-str i nil))
    )
   )
  )

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
==     Niels Mayer -- http://cyborganic.com/~niels -- mayer@netcom.com     ==
==    "When your hammer is C++, everything begins to look like a thumb."   ==
==                      -- Steve Haflich, smh@Franz.COM.                   ==
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
