David,
Looks like a lot of progress. I don't have time just now to look
very closely.
> I seem to have got over the listing directories problem, i.e. I can get
> a listing of files in a directory, however I was wondering if there is a
> way of getting a directory name (like sys_fname_name(dirname))
If you have a full file name, then sys_fname_path returns the directory,
e.g.
sys_fname_path('/usr/X11R6/lib/libXm.so') =>
** /usr/X11R6/lib/
If you want it without the final '/' (why?) you can do
allbutlast(1, sys_fname_path('/usr/X11R6/lib/libXm.so')) =>
** /usr/X11R6/lib
> problem is that when I want to check the name of a fully qualified path
> that ends with a slash, like ~/work/java/todo/ I get nothing back.
sys_fname_path('~/work/java/todo/') =>
If you want to check whether a string ends with the character `/`
do
if last(string) == `/` then
last('/goo/faz/drum/') =>
** 47
> I can
> scan the string and strip the slash at the end, but was wondering if
> there was a more elegant way of doing this...
allbutlast and allbutfirst are often useful.
By the way if you want to get a list of matching a pattern in a
string one of the easiest ways is to use pipein, making it run
the unix 'ls' command as an argument to 'sh' and return the
resulting strings a line at a time. See HELP pipein, pipeutils
define list_files(pattern) -> list;
lvars
dev =
pipein('/bin/sh',
['/bin/sh' '-c' % '/bin/ls ' <> pattern%], false),
len;
;;; make a list of the results by reading the strings from
;;; the device dev one at a time:
[%
until (sysread(dev, sysstring, sysstringlen) ->> len) == 0 do
substring(1, len, sysstring)
enduntil
%] -> list;
enddefine;
list_files('/usr/X11R6/lib/libXm.so*') ==>
** [/usr/X11R6/lib/libXm.so
/usr/X11R6/lib/libXm.so.1
/usr/X11R6/lib/libXm.so.1.0.2
/usr/X11R6/lib/libXm.so.3
/usr/X11R6/lib/libXm.so.3.0.1
]
Alternatively you could create a string repeater using partial
application, i.e. creating the device dev, and then returning
a procedure that is partially applied to it, which returns
one string whenever it is invoked, until the device produces
no more, and then returns termin.
An example of a procedure that uses partial application to return a
repeater procedure is LIB * LINE_REPEATER
Aaron
|