mirror of
https://github.com/freedoom/freedoom.git
synced 2025-08-31 20:16:55 -04:00
Set endianess for all struct.(un)pack calls
Fixes build on big endian
This commit is contained in:
parent
66d52a4b27
commit
0dffa0776d
7 changed files with 21 additions and 21 deletions
|
@ -31,8 +31,8 @@ def main():
|
|||
# three lumps needed - see bootstrap/README.txt
|
||||
lumps = [
|
||||
(b"PLAYPAL", read()),
|
||||
(b"TEXTURE1", struct.pack("i", 0)), # empty texture1
|
||||
(b"PNAMES", struct.pack("i8s", 1, b"")),
|
||||
(b"TEXTURE1", struct.pack("<i", 0)), # empty texture1
|
||||
(b"PNAMES", struct.pack("<i8s", 1, b"")),
|
||||
] # single pname
|
||||
|
||||
# calculate wad directory (lump offsets etc.)
|
||||
|
@ -43,7 +43,7 @@ def main():
|
|||
pos += len(data)
|
||||
|
||||
# write wad header
|
||||
write(struct.pack("4sii", b"IWAD", len(waddir), pos))
|
||||
write(struct.pack("<4sii", b"IWAD", len(waddir), pos))
|
||||
|
||||
# write lump contents
|
||||
for name, data in lumps:
|
||||
|
@ -51,7 +51,7 @@ def main():
|
|||
|
||||
# write wad directory
|
||||
for i in waddir:
|
||||
write(struct.pack("ii8s", *i))
|
||||
write(struct.pack("<ii8s", *i))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -49,7 +49,7 @@ def read_palette(filename):
|
|||
for i in range(256):
|
||||
data = f.read(3)
|
||||
|
||||
color = struct.unpack("BBB", data)
|
||||
color = struct.unpack("<BBB", data)
|
||||
colors.append(color)
|
||||
|
||||
return colors
|
||||
|
@ -159,7 +159,7 @@ def solid_color_list(color):
|
|||
def output_colormap(colormap):
|
||||
"""Output the given palette to stdout."""
|
||||
for c in colormap:
|
||||
x = struct.pack("B", c)
|
||||
x = struct.pack("<B", c)
|
||||
os.write(sys.stdout.fileno(), x)
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class BitReader:
|
|||
"Reached end of decompress stream "
|
||||
+ "(%i bytes)" % len(self.data)
|
||||
)
|
||||
result, = struct.unpack("B", self.data[self.index : self.index + 1])
|
||||
result, = struct.unpack("<B", self.data[self.index : self.index + 1])
|
||||
self.index += 1
|
||||
return result
|
||||
|
||||
|
@ -155,7 +155,7 @@ def decompress(data, data_len):
|
|||
|
||||
# print "len: %i" % len(result)
|
||||
|
||||
return struct.pack("%iB" % len(result), *result)
|
||||
return struct.pack("<%iB" % len(result), *result)
|
||||
|
||||
|
||||
FIELDS = [
|
||||
|
@ -187,13 +187,13 @@ def decode_type_9(data):
|
|||
|
||||
for i in range(len(FIELDS)):
|
||||
instr_data[FIELDS[i]], = struct.unpack(
|
||||
"B", decompressed_data[i : i + 1]
|
||||
"<B", decompressed_data[i : i + 1]
|
||||
)
|
||||
|
||||
# Decode instrument name
|
||||
|
||||
ps = decompressed_data[14:]
|
||||
instr_name, = struct.unpack("%ip" % len(ps), ps)
|
||||
instr_name, = struct.unpack("<%ip" % len(ps), ps)
|
||||
instr_data["name"] = instr_name.decode("ascii")
|
||||
|
||||
return instr_data
|
||||
|
|
|
@ -97,14 +97,14 @@ def encode_instrument_names(instruments):
|
|||
|
||||
for instrument in instruments:
|
||||
instr_name = instrument.voice1["name"].encode("ascii")
|
||||
result.append(struct.pack("32s", instr_name))
|
||||
result.append(struct.pack("<32s", instr_name))
|
||||
|
||||
return b"".join(result)
|
||||
|
||||
|
||||
def write(filename, instruments):
|
||||
header = struct.pack(
|
||||
"%is" % len(GENMIDI_HEADER), GENMIDI_HEADER.encode("ascii")
|
||||
"<%is" % len(GENMIDI_HEADER), GENMIDI_HEADER.encode("ascii")
|
||||
)
|
||||
|
||||
with open(filename, "wb") as f:
|
||||
|
|
|
@ -28,7 +28,7 @@ def read(filename):
|
|||
with open(filename, "rb") as f:
|
||||
data = f.read()
|
||||
|
||||
header, name = struct.unpack("4s32s", data[0:36])
|
||||
header, name = struct.unpack("<4s32s", data[0:36])
|
||||
header = header.decode("ascii")
|
||||
|
||||
if header != HEADER_VALUE:
|
||||
|
@ -38,20 +38,20 @@ def read(filename):
|
|||
result = {"name": name.decode("ascii").rstrip("\0").rstrip()}
|
||||
|
||||
for i in range(len(FIELDS)):
|
||||
result[FIELDS[i]], = struct.unpack("B", instr_data[i : i + 1])
|
||||
result[FIELDS[i]], = struct.unpack("<B", instr_data[i : i + 1])
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def write(filename, data):
|
||||
with open(filename, "wb") as f:
|
||||
f.write(struct.pack("4s", HEADER_VALUE.encode("ascii")))
|
||||
f.write(struct.pack("32s", data["name"].encode("ascii")))
|
||||
f.write(struct.pack("<4s", HEADER_VALUE.encode("ascii")))
|
||||
f.write(struct.pack("<32s", data["name"].encode("ascii")))
|
||||
|
||||
for field in FIELDS:
|
||||
f.write(struct.pack("B", data[field]))
|
||||
f.write(struct.pack("<B", data[field]))
|
||||
for x in range(16 - len(FIELDS)):
|
||||
f.write(struct.pack("B", 0))
|
||||
f.write(struct.pack("<B", 0))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -83,7 +83,7 @@ def read_palette(filename):
|
|||
|
||||
for i in range(256):
|
||||
data = f.read(3)
|
||||
color = struct.unpack("BBB", data)
|
||||
color = struct.unpack("<BBB", data)
|
||||
|
||||
colors.append(color)
|
||||
|
||||
|
@ -164,7 +164,7 @@ def output_palette(pal):
|
|||
for color in palette:
|
||||
color = tuple(map(clamp_pixval, color))
|
||||
|
||||
encoded = struct.pack("BBB", *color)
|
||||
encoded = struct.pack("<BBB", *color)
|
||||
os.write(sys.stdout.fileno(), encoded)
|
||||
|
||||
|
||||
|
|
|
@ -274,7 +274,7 @@ def write_pnames_lump(pnames, filename):
|
|||
with open(filename, "wb") as out:
|
||||
out.write(struct.pack("<l", len(pnames)))
|
||||
for pname in pnames:
|
||||
out.write(struct.pack("8s", pname.encode("ascii")))
|
||||
out.write(struct.pack("<8s", pname.encode("ascii")))
|
||||
|
||||
|
||||
def usage():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue