Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » linux, allegro, and directories

This thread is locked; no one can reply to it. rss feed Print
linux, allegro, and directories
superstar4410
Member #926
January 2001
avatar

Ok,

it would appear that linux has a problem with finding files based on a path.

ok heres the part of code that matters

  spell = load_datafile("spell.dat");
  if(!spell)
   {
      file_select("load spell.dat", filename, "dat");
      spell = load_datafile(filename);
      if(!spell){no_dat=0;}else{no_dat=1;}
   }
  }

And when the program runs, the spell.dat is in the same folder as the exe and it dosen't find it and I enter the if(!spell) statement, loading spell from the file_select at runtime it is able load spell.dat

So whats the prob??
???
Thankss

Don't take yourself too seriously, but do take your responsibilities very seriously.

Thomas Fjellstrom
Member #476
June 2000
avatar

are you in the directory that the program is in when you run it? Are you running it from a console? Or just clicking on the program?

--
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

spellcaster
Member #1,493
September 2001
avatar

Check the path parameter. That's not a path you pass here. Try "./" instead.
Also use file_select_ex().
Make sure that you pass bothe upper and lower case extension "dat;DAT" just to make sure.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

superstar4410
Member #926
January 2001
avatar

yea i'm in the directory and I'm clicking on it

Don't take yourself too seriously, but do take your responsibilities very seriously.

Evert
Member #794
November 2000
avatar

Quote:

yea i'm in the directory and I'm clicking on it

Right, so your filemanager is in that directory. Try running the program from the command-line (many things work naturally from a terminal in Linux, so it's probably good to get used to those too).

Amd make absolutely sure the case of the filename is the same in either case - Linux is case sensitive.

superstar4410
Member #926
January 2001
avatar

Ok I found the direct problem,
maybe its how the path is set

I did some debugging and I found out that
its putting
/home/superstar4410

at the beginning of ever " "
so with spell = load_datafile("spell.dat")
its trying to load /home/superstar4410/spell.dat and thats not the correct path

so how can I fix this

Thanks

[EDIT]:o:o:o:o:o:o

Yea you were right, it works from the konsole fine, but from the folder it tries to add /home/superstar4410 before the path

Don't take yourself too seriously, but do take your responsibilities very seriously.

spellcaster
Member #1,493
September 2001
avatar

use allgros functions to get the path of the executable.
Then use that path to prefix your file paths.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

superstar4410
Member #926
January 2001
avatar

not to be lazy but, ::)

could you give me a code example

Don't take yourself too seriously, but do take your responsibilities very seriously.

Evert
Member #794
November 2000
avatar

The file manager (apparently) starts the program with the working directory set to your home directory. You should probably make the program so that it doesn't care from what directory it is started, as spellcaster suggested.

You could probably do (untested!) chdir(get_filename_path(argv[0])); from main, though that isn't exactly nice.
The other option would be to store the path information in the game config file and read it when the game starts (put configfiles in the directory pointed to by $HOME; use the C function getenv to get it's value).

superstar4410
Member #926
January 2001
avatar

whats the acutally function name
it dosen't recognize get_filename_path

Don't take yourself too seriously, but do take your responsibilities very seriously.

Steve Terry
Member #1,989
March 2002
avatar

I think the function you really need is getcwd(); which returns the current working directory.. argv[0] is the application name and does not always contain the path.

Oooh it's not ANSI/POSIX compliant... but I know it works in Windows/DOS/Linux... what do they exactly mean by that anyway.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Evert
Member #794
November 2000
avatar

Have a look at the Allegro docs, there's a function like that somewhere that does effectively that. Come to think of it, you shouldn't pass it argv[0], but the result of get_executable_name().

As Steve Terry said though, the result is unreliable. You should really make your game so that it will work from any directory. The config file solution I mentioned above is probably your best bet for now, otherwise just stick with running from a terminal (shouldn't be too hard - you're using make anyway, right ;))

Go to: