Single way of File paths from Linux to Mac?

Is there a single way to use file paths that would automatically
translate over for the Mac without having to alter the code? I like
having the same code compile on all three platforms, but Mac throws in
that “:Data:file.bmp” requirement rather than “Data/file.bmp” that even
Windows can deal with. Suggestions?

Thanks,
Mike–
http://dotfile.net/ - Dedicated to Open Source Software

Is there a single way to use file paths that would automatically
translate over for the Mac without having to alter the code? I like
having the same code compile on all three platforms, but Mac throws in
that “:Data:file.bmp” requirement rather than “Data/file.bmp” that even
Windows can deal with. Suggestions?

http://icculus.org/physfs/

–ryan.

Nice. But no support for Mac. That is MacOS. Sorry if you thought Linux
on Mac…

Cheer,
Mike

Ryan C. Gordon wrote:>>Is there a single way to use file paths that would automatically

translate over for the Mac without having to alter the code? I like
having the same code compile on all three platforms, but Mac throws in
that “:Data:file.bmp” requirement rather than “Data/file.bmp” that even
Windows can deal with. Suggestions?

http://icculus.org/physfs/

–ryan.


http://dotfile.net/ - Dedicated to Open Source Software

Michael Vanecek wrote:

Is there a single way to use file paths that would automatically
translate over for the Mac without having to alter the code? I like
having the same code compile on all three platforms, but Mac throws in
that “:Data:file.bmp” requirement rather than “Data/file.bmp” that even
Windows can deal with. Suggestions?

Thanks,
Mike

I know very little of mac, but does not :Data denote an absolute path,
that should translate into /Data/file.bmp?

If so, in some header file that is included everywhere:

#if mac
#define DIRSEP “:”
#elif linux
#define DIRSEP “/”
#endif
… = fopen(“Data” DIRSEP “file.bmp”, “r”);

There are other ways.–
Michel Bardiaux
Peaktime Belgium S.A. Rue Margot, 37 B-1457 Nil St Vincent
Tel : +32 10 65.44.15 Fax : +32 10 65.44.10

I’ll give that a try. No, the first : actually denotes relative path.
Don’t ask my why, it’s weird. So :Data:file.bmp is the correct way. If
you did Data:file.bmp an error of Data not found would result because it
would be looking at root for Data - an absolute path example would be
"HD:project files:ogltest:Data:file.bmp" but I prefer to use relative.

Thanks,
Mike

Michel Bardiaux wrote:> Michael Vanecek wrote:

Is there a single way to use file paths that would automatically
translate over for the Mac without having to alter the code? I like
having the same code compile on all three platforms, but Mac throws in
that “:Data:file.bmp” requirement rather than “Data/file.bmp” that even
Windows can deal with. Suggestions?

Thanks,
Mike

I know very little of mac, but does not :Data denote an absolute path,
that should translate into /Data/file.bmp?

If so, in some header file that is included everywhere:

#if mac
#define DIRSEP “:”
#elif linux
#define DIRSEP “/”
#endif
… = fopen(“Data” DIRSEP “file.bmp”, “r”);

There are other ways.


http://dotfile.net/ - Dedicated to Open Source Software

Michael Vanecek wrote:

Is there a single way to use file paths that would automatically
translate over for the Mac without having to alter the code? I like
having the same code compile on all three platforms, but Mac throws in
that “:Data:file.bmp” requirement rather than “Data/file.bmp” that even
Windows can deal with. Suggestions?

SDL_RWFromFile() attempts to convert unix paths to mac paths on mac
hosts (at least it should work for relative paths)

This is planned to be cleaned up and put in a more regular framework for 1.3

Thanks again. I did:

#ifdef macintosh
#define DATADIR “:Data:”
#else
#define DATADIR “Data/”
#endif

and it works fine on Linux and Mac. Haven’t tested win32 yet, but I
don’t think that’ll be a problem. I can stick that in my .h file and
smoke it… :slight_smile:

Mike

Michel Bardiaux wrote:> Michael Vanecek wrote:

Is there a single way to use file paths that would automatically
translate over for the Mac without having to alter the code? I like
having the same code compile on all three platforms, but Mac throws in
that “:Data:file.bmp” requirement rather than “Data/file.bmp” that even
Windows can deal with. Suggestions?

Thanks,
Mike

I know very little of mac, but does not :Data denote an absolute path,
that should translate into /Data/file.bmp?

If so, in some header file that is included everywhere:

#if mac
#define DIRSEP “:”
#elif linux
#define DIRSEP “/”
#endif
… = fopen(“Data” DIRSEP “file.bmp”, “r”);

There are other ways.


http://dotfile.net/ - Dedicated to Open Source Software

[ CC:ing this to sdl-list — more people may be interested ]

Michael Vanecek wrote:

It’s hard to tell whether this parses the source
file, or the path string though… It looks like it wants to parse the
file, but I’m compiling that file - what’s to parse when I run it? If
it’s just a way to filter file-names before passing to another function
like SDL_LoadImage(), then it’d certainly be applicable… Actually,
since it’s a really small thing, I may just write something myself…

You may indeed write your own translator (it’s easy), or steal
unix_to_mac() in SDL_rwops.c if your code is GPL or LGPL. Or you could
just use SDL_RWFromFile(), which basically works like fopen().
SDL_image is able to read images from RWops as well so for image
loading you need nothing more