<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>editting a file</title>
		<link>http://www.allegro.cc/forums/view/605966</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 08 Jan 2011 22:48:40 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>hi,</p><p>Got a quetion about files. Say I open a file in binary mode and I it&#39;s an array of structs.</p><p>If I wanted to delete the last struct so that file is smaller, how would I go about it ?</p><p>My struct is F_REP so the whole file is</p><p>sizeof(int) + sizeof(F_REP) * n /*** EIDT ****/ the int is the value of n</p><p>The only way I can think of is create a temporary array, write all the structs to it then open the file in write mode so the current contents are discarded.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 05 Jan 2011 05:21:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>stdio includes the <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_368.html" target="_blank">ftruncate</a></span> function.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>4.4BSD, SVr4 (these function calls first appeared in BSD 4.2). POSIX 1003.1-1996 has ftruncate. POSIX 1003.1-2001 also has truncate, as an XSI extension.</p></div></div><p>

It lets you reduce the size of a file.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 05 Jan 2011 05:48:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Thanks Thomas.</p><p>How do I get the handle for the file ?</p><p>I&#39;ve looked in K&amp;R. It says there&#39;s an fd member in the FILE struct but I tried it and got a compiler error.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 05 Jan 2011 06:18:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think there&#39;s a portable way to do this.  Except for reading the file and writing it out again like you suggested yourself.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Wed, 05 Jan 2011 06:32:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Alrighty. Thanks Torhu, I&#39;ll try that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 05 Jan 2011 06:35:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605966/897212#target">William Labbett</a> said:</div><div class="quote"><p>How do I get the handle for the file ?</p></div></div><p><a href="http://linux.die.net/man/3/fileno">fileno</a> <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 05 Jan 2011 06:42:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Excellent - got it working. Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 05 Jan 2011 06:47:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Note that this is not portable:
</p><div class="source-code snippet"><div class="inner"><pre>MY_STRUCT foo<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_fwrite"><span class="a">al_fwrite</span></a><span class="k2">(</span>fp, <span class="k3">&amp;</span>foo, <span class="k1">sizeof</span><span class="k2">(</span>MY_STRUCT<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
Different architectures could have different sizes of integers, etc. So while you can write and read back on the same machine, if you go from 32-bit to 64-bit or PPC to Intel, it might break.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 05 Jan 2011 08:39:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I suppose the same applies to fwrite and fread.</p><p>Does that mean it might be an idea to check sizeof(int) et al at the beginning of the prog so as to abort if the architecture isn&#39;t suitable ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 05 Jan 2011 09:07:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, just write known sized integers to the file, in a known endian format.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 05 Jan 2011 09:11:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you are using Allegro, it has things like <span class="source-code"><a href="http://www.allegro.cc/manual/al_fwrite32le"><span class="a">al_fwrite32le</span></a><span class="k2">(</span><span class="k2">)</span></span> to help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 05 Jan 2011 09:15:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
So maybe I should switch to using ALLEGRO_FILE ? Hhhhmmmm. Just as I was getting to the end of coding my editor. Guess I&#39;ll have to go that extra mile.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 05 Jan 2011 09:23:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, and you should save each field independently:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> n<span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>i<span class="k2">)</span>
<span class="k2">{</span>
  <a href="http://www.allegro.cc/manual/al_fwrite32le"><span class="a">al_fwrite32le</span></a><span class="k2">(</span>fp, foo<span class="k2">[</span>i<span class="k2">]</span><span class="k3">-</span><span class="k3">&gt;</span>int1<span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/al_fwrite32le"><span class="a">al_fwrite32le</span></a><span class="k2">(</span>fp, foo<span class="k2">[</span>i<span class="k2">]</span><span class="k3">-</span><span class="k3">&gt;</span>int2<span class="k2">)</span><span class="k2">;</span>
<span class="c">// etc...</span>
<span class="k2">}</span>
</pre></div></div><p>
Then when you read, do it in the same order, using the read function.</p><p>Another advantage of this is that you can change your struct easily without invalidating all of your saved files. (Because your loader could check a version number stored in the file and adjust itself accordingly.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 05 Jan 2011 10:19:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Okay. Thanks <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>BTW, do I need that single integer at the beginning of the file which stores the number of structures in the file or can get that buy getting the size of file somehow and dividing it by the size of the structure ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 05 Jan 2011 11:57:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You could either have a number at the beginning or you could check for <span class="source-code"><a href="http://www.allegro.cc/manual/al_feof"><span class="a">al_feof</span></a><span class="k2">(</span><span class="k2">)</span></span> and stop when you reach it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 05 Jan 2011 12:04:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>

The idea of the program being able to cope with different versions of the file sounds worth pursuing (I had that problem as this is the second version of the program I&#39;m writing).</p><p>I suppose I&#39;d read the file differently for different versions.</p><p>Then I&#39;d store a variable in a config file which determines which version of the file to save. That way I could load older versions, and convert them to the up-to-date version.</p><p>Does that sound sensible ?</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605966/897254#target">Matthew Leverton</a> said:</div><div class="quote"><p>
You could either have a number at the beginning or you could check for al_feof() and stop when you reach it.
</p></div></div><p>

Would I still be able to get the number of structures in the file that way ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 05 Jan 2011 12:16:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605966/897255#target">William Labbett</a> said:</div><div class="quote"><p> Would I still be able to get the number of structures in the file that way ?
</p></div></div><p>If you needed to know up front (to create the memory), then it would be simplest to store the size as an integer at the beginning.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Then I&#39;d store a variable in a config file which determines which version of the file to save.
</p></div></div><p>You really don&#39;t have to keep any details on what version to save. The program could always save the latest version. So the writing code could be simple.</p><p>However, the reading code may need to do something slightly different depending on which version it is reading. But normally it looks something like:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>version <span class="k3">&gt;</span> <span class="n">10</span><span class="k2">)</span> <span class="k2">{</span>
  foo-&gt;x <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fread32le"><span class="a">al_fread32le</span></a><span class="k2">(</span>fp<span class="k2">)</span><span class="k2">;</span>
  foo-&gt;y <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fread32le"><span class="a">al_fread32le</span></a><span class="k2">(</span>fp<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
<span class="k1">else</span> <span class="k2">{</span>
  foo-&gt;x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
  foo-&gt;y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 05 Jan 2011 12:24:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
 Right. Thanks for all of that. It should keep me busy for a good while.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 05 Jan 2011 12:33:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How frequently do you plan to add/remove data from the file?</p><p>If infrequent, keep up what you&#39;re doing.  If you think, however, that reading/<u>re</u>writing will be a major portion of it, you could also weigh the computational hit of writing a kind of byte index at the beginning of your file.</p><div class="source-code"><div class="toolbar"><span class="name">custom_record</span><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>  <span class="n">3</span>  <span class="c">// 3 records follow</span>
<span class="number">  2</span>  <span class="n">5</span>  <span class="c">// offset of 1st record</span>
<span class="number">  3</span>  <span class="n">9</span>  <span class="c">// offset of 2nd record</span>
<span class="number">  4</span>  <span class="n">11</span> <span class="c">// offset of 3rd record</span>
<span class="number">  5</span>  data1a
<span class="number">  6</span>  data1b
<span class="number">  7</span>  data1c
<span class="number">  8</span>  data1d
<span class="number">  9</span>  data2a
<span class="number"> 10</span>  data2b
<span class="number"> 11</span>  data3a
<span class="number"> 12</span>  data3b
<span class="number"> 13</span>  data3c
<span class="number"> 14</span>  data3d
<span class="number"> 15</span>  data3e
</div></div><p>

Then you could jump immediately to the data you need.  This is a lot more complex, and if you don&#39;t do it right, you&#39;ll corrupt the entire file (&quot;FAT table? I don&#39;t need this; let&#39;s erase it and see what... hey, what the..?&quot;), so proceed carefully if you do want to do this.</p><p>Advantages: Faster sinital seek time to get to the record you want<br />Disadvantages: Remove a record in the middle, and you&#39;ve essentially got to load the entire glossary, modify it (correctly) after the record is removed, write that back out to the file on save (where you MAY have to shift ALL of your elements up several bytes if you remove 1+ indices).  But reads would be faster...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Wed, 05 Jan 2011 12:59:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
 I know I&#39;ll be reading writing and rewriting a lot but I think I&#39;ll be okay without the byte index since all the structures are the same size so I just need to al_fseek to start of the struct when reading/writing it.</p><p> Does that sound okay ?</p><p>/*** EDIT *****/</p><p>I&#39;ve got another query hopefully someone can help with :</p><p>I was thinking that since I&#39;m only going to be using my file editor on my machine it won&#39;t matter if the size of types is different on another, so I thought maybe I didn&#39;t need to change the code.</p><p>Then I thought, what about when the game runs on another machine ? </p><p>My struct looks like this :</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">struct</span> F_REP
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  
<span class="number">  4</span>   <span class="k1">char</span> png_filename<span class="k2">[</span> MAX_LENGTH_FOR_FRD_STRING <span class="k2">]</span><span class="k2">;</span>
<span class="number">  5</span>   
<span class="number">  6</span>   <span class="k1">int</span> type<span class="k2">;</span>
<span class="number">  7</span>   
<span class="number">  8</span>   <span class="k1">int</span> squares_wide_on_map<span class="k2">;</span>
<span class="number">  9</span>   <span class="k1">int</span> squares_high_on_map<span class="k2">;</span>
<span class="number"> 10</span>
<span class="number"> 11</span>   <span class="k1">int</span> x_offset<span class="k2">;</span>             <span class="c">/* the x offset from the top left square indicating where the feature is positioned */</span>
<span class="number"> 12</span>   <span class="k1">int</span> y_offset<span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>   
<span class="number"> 15</span> 
<span class="number"> 16</span>   <span class="k1">int</span> num_layers_or_frames<span class="k2">;</span>
<span class="number"> 17</span>
<span class="number"> 18</span>   <span class="k1">int</span> ticks_per_frame<span class="k2">;</span>
<span class="number"> 19</span>
<span class="number"> 20</span>   <span class="k1">int</span> line_in_animation_specs_file<span class="k2">;</span>
<span class="number"> 21</span>   
<span class="number"> 22</span>   <span class="k1">int</span> altitude<span class="k2">;</span>
<span class="number"> 23</span>
<span class="number"> 24</span>
<span class="number"> 25</span>   <span class="k1">int</span> feature_has_shadow<span class="k2">;</span>
<span class="number"> 26</span>
<span class="number"> 27</span>   <span class="k1">int</span> shadow_x_offset<span class="k2">;</span>
<span class="number"> 28</span>   <span class="k1">int</span> shadow_y_offset<span class="k2">;</span>
<span class="number"> 29</span>   
<span class="number"> 30</span>   <span class="k1">int</span> feature_has_collision_map<span class="k2">;</span>
<span class="number"> 31</span>
<span class="number"> 32</span>   <span class="k1">int</span> c_x_offset<span class="k2">;</span>
<span class="number"> 33</span>   <span class="k1">int</span> c_y_offset<span class="k2">;</span>
<span class="number"> 34</span>   
<span class="number"> 35</span>   <span class="k1">int</span> has_mask<span class="k2">;</span>
<span class="number"> 36</span>
<span class="number"> 37</span>
<span class="number"> 38</span>
<span class="number"> 39</span>
<span class="number"> 40</span><span class="k2">}</span><span class="k2">;</span>
</div></div><p>


Could this potentially cause problems when</p><p>I do </p><p>fread( *array_of_F_REP, sizeof(F_REP), num_reps, file);</p><p>?</p><p>So what I&#39;m really asking is Do I really need to rewrite the code ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 05 Jan 2011 18:58:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The <span class="source-code"><span class="k1">int</span></span> data type varies in size from compiler and architecture to compiler and architecture. That means that <span class="source-code"><span class="k1">sizeof</span><span class="k2">(</span>F_REP<span class="k2">)</span></span> will also vary. If the files are written on a machine where <span class="source-code"><span class="k1">int</span></span> is 4 bytes, but read on a machine where <span class="source-code"><span class="k1">int</span></span> is 8 bytes, then you&#39;ll read incorrectly and the data will all be wrong. Additionally, from architecture to architecture, the byte order of data types varies. On some machines, bytes appear as you would expect: <span class="source-code">ABCD</span>. On others, the bytes are reversed, <span class="source-code">DCBA</span>. Again, if you write on one and read on another then the data will be wrong.</p><p>This is the same problem seen with network programming. If you write a networked program that you want to be able to speak to any computer of any architecture then you need to define a protocol to communicate multi-byte data with. The common convention is to send multi-byte values as Big Endian (most significant byte first), which translates to the last byte first. This is referred to as <i>network byte order</i> and is a good way to store data in the file system as well. The sender/writer needs to convert multi-byte data from host byte order (whichever byte order the machine uses) to network byte order. The receiver/reader needs to convert from network byte order to host byte order. There are a set of functions in Berkeley Sockets and WinSock to do this. Presumably, that is exactly what Allegro&#39;s functions do as well (I imagine that they are just wrappers over the network library calls).</p><p>Note that if the files are only ever created and read on the same machine (never shared between machines) then you don&#39;t technically need to care about storage format because the format won&#39;t change for a given machine (unless you change something about the machine, like the compiler or operating system architecture).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Wed, 05 Jan 2011 20:21:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605966/897261#target">William Labbett</a> said:</div><div class="quote"><p> So what I&#39;m really asking is Do I really need to rewrite the code ?
</p></div></div><p>Yes, you do. (Or at least, it would be easier to do that than to manage different data files for 32-bit and 64-bit.)</p><p>It should be pretty simple, since you mostly have integer data. Just use the functions I already mentioned. You can use <span class="source-code"><a href="http://www.allegro.cc/manual/al_fwrite"><span class="a">al_fwrite</span></a></span> to write out png_filename.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 05 Jan 2011 23:31:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605966/897282#target">bamccaig</a> said:</div><div class="quote"><p>
Note that if the files are only ever created and read on the same machine (never shared between machines) then you don&#39;t technically need to care about storage format because the format won&#39;t change for a given machine (unless you change something about the machine, like the compiler or operating system architecture).
</p></div></div><p>
Actually it&#39;s a compiler only think, not OS. So distributing an executable wouldn&#39;t be any problem since it will do the same on any computer able to run it. The problem comes when you distribute the source code and people compile it with different compilers (or compiler version) and/or for different architectures.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Thu, 06 Jan 2011 00:12:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 06 Jan 2011 00:15:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605966/897297#target">Oscar Giner</a> said:</div><div class="quote"><p> Actually it&#39;s a compiler only think, not OS.
</p></div></div><p>Correct ... and if you have any plans on ever distributing your program, you might as well just do it properly from the beginning. It&#39;s not <i>that</i> much more work, and it saves problems of having incompatible data files in the future. And as already mentioned, saving the entire struct as-is makes it more difficult to change the struct.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Thu, 06 Jan 2011 00:54:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for the help guys.</p><p>Just wondering what I should do instead of using ftruncate now. I guess I&#39;ll have to rewrite the whole file when I want to change it&#39;s size ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 06 Jan 2011 02:54:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">void</span> save<span class="k2">(</span><span class="k1">struct</span> F_REP<span class="k3">*</span> f_rep, <a href="http://www.allegro.cc/manual/PACKFILE"><span class="a">PACKFILE</span></a><span class="k3">*</span> pf<span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>F_REP <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="s">"f_rep was passed in as a NULL pointer!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>pf    <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="s">"pf was passed in as a NULL pointer!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span>
<span class="number">  6</span>  <span class="c">/**&lt; first, write the # of actually-used bytes in this string */</span>
<span class="number">  7</span>  <a href="http://www.allegro.cc/manual/pack_iputl"><span class="a">pack_iputl</span></a><span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_764.html" target="_blank">strlen</a><span class="k2">(</span>f_rep-&gt;png_filename<span class="k2">)</span>, pf<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span>  <a href="http://www.allegro.cc/manual/pack_iputl"><span class="a">pack_iputl</span></a><span class="k2">(</span>f_rep-&gt;type, pf<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>  <a href="http://www.allegro.cc/manual/pack_iputl"><span class="a">pack_iputl</span></a><span class="k2">(</span>f_rep-&gt;squares_wide_on_map, pf<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>  ...
<span class="number"> 12</span>  <a href="http://www.allegro.cc/manual/pack_iputl"><span class="a">pack_iputl</span></a><span class="k2">(</span>f_rep-&gt;has_mask, pf<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span><span class="k2">}</span>
<span class="number"> 14</span>
<span class="number"> 15</span>
<span class="number"> 16</span><span class="k1">void</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_642.html" target="_blank">read</a><span class="k2">(</span><span class="k1">struct</span> F_REP<span class="k3">*</span> f_rep, <a href="http://www.allegro.cc/manual/PACKFILE"><span class="a">PACKFILE</span></a><span class="k3">*</span> pf<span class="k2">)</span>
<span class="number"> 17</span><span class="k2">{</span>
<span class="number"> 18</span>  <span class="k1">size_t</span> len_filename <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 19</span>
<span class="number"> 20</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>F_REP <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="s">"f_rep was passed in as a NULL pointer!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_48.html" target="_blank">assert</a><span class="k2">(</span>pf    <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="s">"pf was passed in as a NULL pointer!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>
<span class="number"> 23</span>  <span class="c">/**&lt; first, read in the number of bytes in the string */</span>
<span class="number"> 24</span>  len_filename <span class="k3">=</span> <a href="http://www.allegro.cc/manual/pack_igetl"><span class="a">pack_igetl</span></a><span class="k2">(</span>pf<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>  <a href="http://www.allegro.cc/manual/pack_fread"><span class="a">pack_fread</span></a><span class="k2">(</span><span class="k3">&amp;</span>f_rep-&gt;png_filename, len_filename, pf<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>  <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/pack_feof"><span class="a">pack_feof</span></a><span class="k2">(</span>pf<span class="k2">)</span><span class="k2">)</span>
<span class="number"> 27</span>    exit_with_error<span class="k2">(</span><span class="s">"EOF reached after reading in `png_filename'!\n"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 28</span>
<span class="number"> 29</span>  f_rep-&gt;type <span class="k3">=</span> <a href="http://www.allegro.cc/manual/pack_igetl"><span class="a">pack_igetl</span></a><span class="k2">(</span>pf<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 30</span>  f_rep-&gt;squares_wide_on_map <span class="k3">=</span> <a href="http://www.allegro.cc/manual/pack_igetl"><span class="a">pack_igetl</span></a><span class="k2">(</span>pf<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 31</span>  ...
<span class="number"> 32</span>  f_rep-&gt;has_mask <span class="k3">=</span>  <span class="k3">=</span> <a href="http://www.allegro.cc/manual/pack_igetl"><span class="a">pack_igetl</span></a><span class="k2">(</span>pf<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 33</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Sat, 08 Jan 2011 22:48:40 +0000</pubDate>
	</item>
</rss>
