annotate src/wadfile.cc @ 58:d554e443475d

Un-inline some member functions for easier debugging. Other smaller cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 26 Sep 2011 07:00:55 +0300
parents dd94096a7fcd
children 4ef9dfbd82b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
2 * wadfile.cc - Wad_file class
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
3 * AYM 2001-09-18
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 */
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 /*
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 This file is part of Yadex.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 Yadex incorporates code from DEU 5.21 that was put in the public domain in
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 1994 by Raphaël Quinet and Brendon Wyber.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 The rest of Yadex is Copyright © 1997-2003 André Majorel and others.and others.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 This program is free software; you can redistribute it and/or modify it under
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 the terms of the GNU General Public License as published by the Free Software
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 Foundation; either version 2 of the License, or (at your option) any later
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 version.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 This program is distributed in the hope that it will be useful, but WITHOUT
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 You should have received a copy of the GNU General Public License along with
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 Place, Suite 330, Boston, MA 02111-1307, USA.
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 */
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 #include "yadex.h"
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 #include "wadfile.h"
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
35 * Wad_file::~Wad_file - dtor
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
37 Wad_file::~Wad_file()
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 {
58
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
39 FreeMemory(directory);
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
40 directory = NULL;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
41 FreeMemory(filename);
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
42 filename = NULL; // Catch bugs
54
dd94096a7fcd Cleanups, use NULL instead of 0.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
43 if (fp != NULL)
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
44 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
45 fclose(fp);
54
dd94096a7fcd Cleanups, use NULL instead of 0.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
46 fp = NULL; // Catch bugs
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
47 }
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
52 * Wad_file::where - return file(offset) string
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 *
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
54 * Return pointer to a per-Wad_file buffer.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
56 const char *Wad_file::where() const
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
58 const unsigned long offset = ftell(fp);
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
59 const size_t offset_len = +3;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
60 const size_t name_len_max = sizeof where_ - 1 - offset_len;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
62 if (name_len_max >= strlen(filename))
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
63 sprintf(where_, "%s(%lXh)", filename, offset);
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
64 else
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
65 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
66 const char *ellipsis = "...";
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
67 const size_t total = name_len_max - strlen(ellipsis);
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
68 const size_t left = total / 2;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
69 const size_t right = total - left;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
70 sprintf(where_, "%*s%s%*s(%lXh)",
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
71 left, filename, ellipsis, right, filename + total, offset);
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
72 }
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
74 return where_;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 }
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 /*
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
79 * Wad_file::read_vbytes - read bytes from a wad file
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 *
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
81 * Read up to <count> bytes and store them into buffer
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
82 * <buf>. <count> is _not_ limited to size_t. If an I/O
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
83 * error occurs, set the error flag. EOF is not considered
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
84 * an error.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 *
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
86 * Return the number of bytes read.
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 */
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
88 long Wad_file::read_vbytes(void *buf, long count) const
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 {
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
90 long bytes_read_total;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
91 size_t bytes_read;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
92 size_t bytes_to_read;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
94 bytes_read_total = 0;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
95 bytes_to_read = 0x8000;
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
96 while (count > 0)
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
97 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
98 if (count <= 0x8000)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
99 bytes_to_read = (size_t) count;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
100 bytes_read = fread(buf, 1, bytes_to_read, fp);
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
101 bytes_read_total += bytes_read;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
102 if (bytes_read != bytes_to_read)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
103 break;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
104 buf = (char *) buf + bytes_read;
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
105 count -= bytes_read;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
106 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
107 if (ferror(fp))
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
108 {
33
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
109 if (!error_)
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
110 err("%s: read error", where());
a68786b9c74b Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
111 error_ = true;
25
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
112 }
8eaf72e2041b Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
113 return bytes_read_total;
0
241c93442be0 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 }
58
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
115
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
116 /*
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
117 * Wad_file::error - tell whether any errors occurred
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
118 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
119 * Reset the error indicator and call clearerr() on the
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
120 * underlying stdio stream. Thus calling Wad_file::error()
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
121 * again immediately after always returns false. Calling
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
122 * this function is the only way to clear the error flag of
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
123 * a Wad_file.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
124 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
125 * So short that it's a good candidate for inlining.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
126 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
127 * Return true if an error occurred, false otherwise.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
128 */
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
129 bool Wad_file::error() const
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
130 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
131 if (!error_)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
132 return false;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
133
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
134 clearerr(fp);
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
135 error_ = false;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
136 return true;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
137 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
138
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
139
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
140 /*
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
141 * Wad_file::seek - move the file pointer
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
142 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
143 * If an error occurs, set the error flag.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
144 */
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
145 void Wad_file::seek(long offset) const
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
146 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
147 if (fseek(fp, offset, 0) != 0)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
148 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
149 if (!error_)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
150 err("%s: can't seek to %lXh", filename, offset);
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
151 error_ = true;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
152 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
153 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
154
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
155
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
156 /*
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
157 * Wad_file::read_u8 - read a byte
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
158 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
159 * If an error occurs, set the error flag and the return
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
160 * value is undefined.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
161 */
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
162 u8 Wad_file::read_u8() const
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
163 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
164 u8 v = u8(getc(fp));
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
165
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
166 if (feof(fp) || ferror(fp))
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
167 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
168 if (!error_)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
169 err("%s: read error", where());
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
170 error_ = true;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
171 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
172 return v;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
173 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
174
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
175
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
176 /*
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
177 * Wad_file::read_u8 - read a byte
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
178 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
179 * If an error occurs, set the error flag and the contents
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
180 * of buf is undefined.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
181 */
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
182 void Wad_file::read_u8(u8 & buf) const
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
183 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
184 buf = getc(fp);
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
185
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
186 if (feof(fp) || ferror(fp))
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
187 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
188 if (!error_)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
189 err("%s: read error", where());
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
190 error_ = true;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
191 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
192 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
193
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
194
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
195 /*
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
196 * Wad_file::read_i16 - read a little-endian 16-bit signed integer
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
197 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
198 * If an error occurs, set the error flag and the return
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
199 * value is undefined.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
200 */
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
201 i16 Wad_file::read_i16() const
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
202 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
203 const size_t nbytes = 2;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
204 u8 buf[nbytes];
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
205
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
206 if (fread(buf, 1, nbytes, fp) != nbytes)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
207 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
208 if (!error_)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
209 err("%s: read error", where());
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
210 error_ = true;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
211 return EOF; // Whatever
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
212 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
213 return buf[0] | buf[1] << 8;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
214 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
215
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
216
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
217 /*
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
218 * Wad_file::read_i16 - read a little-endian 16-bit signed integer
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
219 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
220 * The value read is stored in *buf. If an error occurs,
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
221 * set the error flag and the contents of *buf is undefined.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
222 */
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
223 void Wad_file::read_i16(i16 * buf) const
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
224 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
225 *buf = getc(fp) | (getc(fp) << 8);
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
226
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
227 if (feof(fp) || ferror(fp))
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
228 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
229 if (!error_)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
230 err("%s: read error", where());
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
231 error_ = true;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
232 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
233 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
234
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
235
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
236 /*
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
237 * Wad_file::read_i32 - read little-endian 32-bit signed integers
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
238 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
239 * Read <count> little-endian 32-bit signed integers from
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
240 * wad file <wadfile> into *buf. If an error occurs, set
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
241 * error_ and the contents of *buf is undefined.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
242 */
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
243 void Wad_file::read_i32(i32 * buf, long count) const
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
244 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
245 while (count-- > 0)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
246 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
247 *buf++ = getc(fp)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
248 | (getc(fp) << 8)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
249 | ((i32) getc(fp) << 16) | ((i32) getc(fp) << 24);
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
250 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
251
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
252 if (feof(fp) || ferror(fp))
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
253 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
254 if (!error_)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
255 err("%s: read error", where());
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
256 error_ = true;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
257 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
258 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
259
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
260
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
261 /*
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
262 * Wad_file::read_bytes - read bytes from a wad file
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
263 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
264 * Read <count> bytes and store them into buffer <buf>.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
265 * <count> is _not_ limited to size_t. If an I/O error
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
266 * occurs or EOF is reached before the requested number of
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
267 * bytes is read, set the error flag.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
268 */
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
269 void Wad_file::read_bytes(void *buf, long count) const
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
270 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
271 long bytes_read;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
272
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
273 bytes_read = read_vbytes(buf, count);
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
274 if (bytes_read != count)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
275 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
276 if (!error_)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
277 err("%s: read error", where());
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
278 error_ = true;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
279 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
280 }
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
281
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
282
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
283 /*
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
284 * Wad_file::what - what a wad contains
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
285 *
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
286 * Written for the sake of the "w" command. Return the
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
287 * name of the first lump in the wad, which gives an idea
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
288 * of what it contains. The string is *not* NUL-terminated.
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
289 */
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
290 const char *Wad_file::what() const
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
291 {
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
292 if (directory == 0)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
293 return "(nodir)";
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
294 if (dirsize < 1)
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
295 return "(empty)";
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
296 return directory[0].name;
d554e443475d Un-inline some member functions for easier debugging. Other smaller cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
297 }