Glargh! glob() is really useful!!! Make sure your library has it!!!
(according to the man page, it is in POSIX.2)
BeOS doesn’t have it.
Oh dear. Well here I took some 10 minutes to write one, share and enjoy.
Bells and whistles such as [^]{} are left as an exercise to the reader.
int match(char *str, char *pat)
{
char *p = NULL, *q;
for(; {
switch(pat) {
case '’:
p = ++pat;
q = str;
break;
default:
if(*pat != *str) {
if(p) {
pat = p;
str = ++q;
break;
} else
return 0;
}
/* fallthrough */
case '?':
if(!*str)
return !*pat;
pat++;
str++;
}
}
}
- DOS/Windows has been supporting / in path since well… too long to remember!
It’s just the UI and the DOS tools that don’t want / (there’re lame, they treat
/ like a - in Un*x tools)
- MacOS should have an opendir() that do all the works, if it doesn’t it’s lame
too (wait for MacOS X,
a real multitasking os at least, MacOS X = Linux '91 !!!)
Herve PARISSI
"You assume too much" (The Menace Phantom)> ----- Original Message -----
From: max@quendi.de (Max Horn)
To:
Sent: Wednesday, June 28, 2000 10:20 PM
Subject: Re: [SDL] Re: platform independent directory access
At 12:39 Uhr -0700 28.06.2000, Sam Hart wrote:
On Wed, 28 Jun 2000, Max Horn wrote:
Ok, but what about MacOS and BeOS? What do people who want their
programs
to be portable to those OS’s have to do???
-bill!
I dunno if this helps you, but exult includes a func that translates
a unix path to Win/MacOS path. Afterwards, you can just use std c lib.
I can provide you with the code, if ya want.
That would be nice. I am presently working on something that /should/
handle Win/MacOS files… but I haven’t a system to test them on… so it
would be nice to have one that works.
I’m familiar w/ exult, all I personally would need is the file it’s
contained in an /maybe/ the line number… though I’m sure there would be
others on the list that would be interrested in more
it’s in utils.cc, function Switch_slash() (line 51). Make sure to get
the latest CVS, I checked it in yesterday.
You call Switch_slash() a bit similiar to strcpy. Example:
FILE* fopen_portable( const char * fname, const char * mode )
{
char name[512];
Switch_slash(name, fname);
return fopen( name, mode );
}
Of course, make sure the C lib doesn’t already convert path
delimeters on its own
Also, Switch_slash() is not perfect. It doesn’t handle absolute
pathes (which would be very complicated, considering that DOS/Win,
Unix and MacOS handle this all completly different).
bye,
max
Max “The Black Fingolfin” Horn
<mailto:max at quendi.de>
http://www.quendi.de - please use my guestbook!
- MacOS should have an opendir() that do all the works
[obvious trolls cut out]
The MacOS file system differs from a normal Unix fs in many respects,
but an opendir()/readdir() should not be hard to write. MacOS X uses
a Mac fs (HFS+) and kernel tricks for the BSD layer to see it as a
Unixy fs. For instance, ‘:’ and ‘/’ are swapped, since they are the
directory separators. A similar approach could be taken.
Emulating stat() would also be necessary for completeness.