Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » A5 Make Path Absolute

Credits go to Edgar Reynaldo, Matthew Leverton, and Thomas Fjellstrom for helping out!
This thread is locked; no one can reply to it. rss feed Print
A5 Make Path Absolute
James Bunting
Member #30
April 2000
avatar

In Allegro 5, al_make_path_canonical does not seem to convert relative paths to absolute, whereas Allegro 4's canonicalize_filename did (as I recall).

I concede that the newer approach makes perfect sense as a relative path is arguably more simple but don't worry about all that.

Anyway, I could missing something simple so...

Does Allegro 5 have a simple "1 liner" method to make a path absolute, or do I have to code my way around it by getting the CWD manually and appending the path?

al_make_path_absolute_where_possible()?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Matthew Leverton
Supreme Loser
January 1999
avatar

First create a path for the current working directory:

char *tmp = al_get_current_directory();
ALLEGRO_PATH *cwd = al_create_path_for_directory(tmp);
al_free(tmp);

Then whenever you want an absolute path:

al_rebase_path(cwd, path);

So it's a one liner if you first create a global path object for the current working directory. (Be sure to free it later.)

Here ya go :

Leaks memory due to the call to al_get_current_directory().

Thomas Fjellstrom
Member #476
June 2000
avatar

Hm, I thought it existed, but it looks like it slipped my mind. All it would likely do is just append cwd and the path, which can be done easily enough.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Matthew Leverton
Supreme Loser
January 1999
avatar

Hm, I thought it existed, but it looks like it slipped my mind

It's kind of a specialty function that I'm not sure should exist in Allegro. That is, creating an absolute path from the current working directory is two discrete steps.

It might be nice to have something like: al_get_standard_path(ALLEGRO_CURRENT_PATH), but even that is just a convenience wrapper around the code I wrote above.

James Bunting
Member #30
April 2000
avatar

Thanks for the help people.

For the record I am working on porting a file picker dialog I originally wrote for AllegroGL under Allegro 4. I could not find a file dialog in 5 (apart from the native one which crashes in full screen and would require a mode switch anyway).

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

James Bunting
Member #30
April 2000
avatar

Sounds promising, I will look into that thanks.

Shot of work in progress picker here BTW
http://www.jbserver.com/temp/picker.jpg

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

RE: pic
Looks pretty good. I think the scrollbar handles should be shrunk to fit inside the scrollbar area though, just by a pixel though. They almost look oversized right now.

If you're feeling ambitious, you might want to implement a folder tree.

Go to: