<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>linux, allegro, and directories</title>
		<link>http://www.allegro.cc/forums/view/246330</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 27 Feb 2003 14:11:54 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>

Ok,</p><p>it would appear that linux has a problem with finding files based on a path.</p><p>ok heres the part of code that matters
</p><div class="source-code snippet"><div class="inner"><pre>  spell <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span><span class="s">"spell.dat"</span><span class="k2">)</span><span class="k2">;</span>
  <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>spell<span class="k2">)</span>
   <span class="k2">{</span>
      file_select<span class="k2">(</span><span class="s">"load spell.dat"</span>, filename, <span class="s">"dat"</span><span class="k2">)</span><span class="k2">;</span>
      spell <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span>filename<span class="k2">)</span><span class="k2">;</span>
      <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>spell<span class="k2">)</span><span class="k2">{</span>no_dat<span class="k3">=</span><span class="n">0</span><span class="k2">;</span><span class="k2">}</span><span class="k1">else</span><span class="k2">{</span>no_dat<span class="k3">=</span><span class="n">1</span><span class="k2">;</span><span class="k2">}</span>
   <span class="k2">}</span>
  <span class="k2">}</span>
</pre></div></div><p>

And when the program runs, the spell.dat is in the same folder as the exe and it dosen&#039;t find it and I enter the if(!spell) statement, loading spell from the file_select at runtime it is able load spell.dat </p><p>So whats the prob??<br /><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /><br /> Thankss
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (superstar4410)</author>
		<pubDate>Thu, 27 Feb 2003 02:26:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 27 Feb 2003 02:28:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Check the path parameter. That&#039;s not a path you pass here. Try &quot;./&quot; instead.<br />Also use file_select_ex().<br />Make sure that you pass bothe upper and lower case extension &quot;dat;DAT&quot; just to make sure.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Thu, 27 Feb 2003 02:38:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>yea i&#039;m in the directory and I&#039;m clicking on it
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (superstar4410)</author>
		<pubDate>Thu, 27 Feb 2003 02:54:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>yea i&#039;m in the directory and I&#039;m clicking on it</p></div></div><p>

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&#039;s probably good to get used to those too).</p><p>Amd make absolutely sure the case of the filename is the same in either case - Linux is case sensitive.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 27 Feb 2003 03:00:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Ok I found the direct problem, <br />maybe its how the path is set</p><p>I did some debugging and I found out that<br />its putting<br />/home/superstar4410</p><p>at the beginning of ever &quot;  &quot;<br />so with spell = load_datafile(&quot;spell.dat&quot;)<br />its trying to load /home/superstar4410/spell.dat and thats not the correct path</p><p>so how can I fix this</p><p>Thanks</p><p>[EDIT]:o:o:o:o:o:o</p><p>Yea you were right, it works from the konsole fine, but from the folder it tries to add /home/superstar4410 before the path
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (superstar4410)</author>
		<pubDate>Thu, 27 Feb 2003 03:03:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>use allgros functions to get the path of the executable.<br />Then use that path to prefix your file paths.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (spellcaster)</author>
		<pubDate>Thu, 27 Feb 2003 03:08:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>not to be lazy but, <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /></p><p>could you give me a code example
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (superstar4410)</author>
		<pubDate>Thu, 27 Feb 2003 03:26:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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&#039;t care from what directory it is started, as spellcaster suggested.</p><p>You could probably do (untested!) <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_92.html" target="_blank">chdir</a><span class="k2">(</span>get_filename_path<span class="k2">(</span>argv<span class="k2">[</span><span class="n">0</span><span class="k2">]</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span> from main, though that isn&#039;t exactly nice.<br />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&#039;s value).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 27 Feb 2003 03:39:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>whats the acutally function name<br />it dosen&#039;t recognize get_filename_path
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (superstar4410)</author>
		<pubDate>Thu, 27 Feb 2003 05:50:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think the function you really need is <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_386.html" target="_blank">getcwd</a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></span> which returns the current working directory.. argv[0] is the application name and does not always contain the path.</p><p>Oooh it&#039;s not ANSI/POSIX compliant... but I know it works in Windows/DOS/Linux... what do they exactly mean by that anyway.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Steve Terry)</author>
		<pubDate>Thu, 27 Feb 2003 10:26:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Have a look at the Allegro docs, there&#039;s a function like that somewhere that does effectively that. Come to think of it, you shouldn&#039;t pass it argv[0], but the result of get_executable_name().</p><p>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&#039;t be too hard - you&#039;re using make anyway, right <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 27 Feb 2003 14:11:54 +0000</pubDate>
	</item>
</rss>
