This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
spitwad.c
123 lines (97 loc) · 2.56 KB
/
spitwad.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#define VERSION "1.1"
/*
=============================================================================
SPITWAD
by John Carmack
=============================================================================
*/
#include "cmdlib.h"
//================
//
// wad file types
//
//================
typedef struct
{
long filepos;
long size;
char name[8];
} lumpinfo_t;
typedef struct
{
char identification[4];
long numlumps;
long infotableofs;
} wadinfo_t;
/*
===============
=
= main
=
===============
*/
void main (int argc, char **argv)
{
char filename[128];
int handle;
wadinfo_t wad;
lumpinfo_t *lumps, *lump_p;
int i,j;
char name[9];
long datasize, wadsize, infosize;
char *lzss;
printf ("SPITWAD "VERSION" by John Carmack, copyright (c) 1992 Id Software\n");
if (CheckParm ("?") || (argc != 2 && argc != 4))
{
printf ("SPITWAD filename<.wad> [start end]\n");
exit (1);
}
strcpy (filename, argv[1]);
DefaultExtension (filename, ".wad");
handle = SafeOpenRead (filename);
wadsize = filelength(handle);
datasize = 0;
SafeRead (handle, &wad, sizeof(wad));
if (strncmp(wad.identification,"IWAD",4))
Error ("Wad file %s doesn't have IWAD id\n",filename);
wad.numlumps = LittleLong(wad.numlumps);
wad.infotableofs = LittleLong(wad.infotableofs);
infosize = wad.numlumps*sizeof(lumpinfo_t);
lumps = lump_p = SafeMalloc(infosize);
lseek (handle, wad.infotableofs, SEEK_SET);
SafeRead (handle, lumps, infosize);
infosize += sizeof(wadinfo_t);
printf ("\n");
printf ("WAD file : %s\n",filename);
printf ("numlumps : %lu\n",wad.numlumps);
printf ("infotableofs: %lu\n",wad.infotableofs);
printf ("\n");
printf ("lump name size filepos 0xsize 0xfpos\n");
printf ("---- -------- ------ -------- ------ ------\n");
name[8] = 0;
for (i=0 ; i<wad.numlumps ; i++, lump_p++)
{
datasize += LittleLong (lump_p->size);
strncpy (name,lump_p->name,8);
for (j=7 ; j>=0 ; j--)
if (!name[j])
name[j] = ' ';
else
break;
if (name[0] & 0x80)
{
lzss = "(lzss)";
name[0] &= 0x7f;
}
else lzss = 0;
printf ("%4i %s %6li %8li %6lx %6lx %s\n", i, name
, LittleLong(lump_p->size), LittleLong(lump_p->filepos)
, LittleLong(lump_p->size), LittleLong(lump_p->filepos),
lzss );
}
printf ("\n");
printf ("File size:%9li\n", wadsize);
printf ("Data size:%9li\n", datasize);
printf ("Info size:%9li\n", infosize);
printf ("Wasted :%9li\n", wadsize-(datasize+infosize));
}