void W_AddFile (char *filename)
{
wadinfo_t |
header; |
lumpinfo_t* |
lump_p; |
unsigned |
i; |
int |
handle; |
int |
length; |
int |
startlump; |
filelump_t* |
fileinfo; |
filelump_t |
singleinfo; |
int |
storehandle; |
//open the file and add to directory
//handle reload indicator.
if (filename[0] == ’~’)
{
filename++;
reloadname = filename; reloadlump = numlumps;
}
if ( (handle = open (filename,O_RDONLY | O_BINARY)) == -1)
{
printf (" couldn’t open %s\n",filename); return;
}
printf (" adding %s\n",filename); startlump = numlumps;
if (strcmpi (filename+strlen(filename)-3 , "wad" ) )
{
// single lump file fileinfo = &singleinfo; singleinfo.filepos = 0;
singleinfo.size = LONG(filelength(handle)); ExtractFileBase (filename, singleinfo.name); numlumps++;
}
else
{
// WAD file
read (handle, &header, sizeof(header));
if (strncmp(header.identification,"IWAD",4))
{
// Homebrew levels?
if (strncmp(header.identification,"PWAD",4))
{
I_Error ("Wad file %s doesn’t have IWAD " "or PWAD id\n", filename);
}
// ???modifiedgame = true;
}
header.numlumps = LONG(header.numlumps); header.infotableofs = LONG(header.infotableofs); length = header.numlumps*sizeof(filelump_t); fileinfo = alloca (length);
lseek (handle, header.infotableofs, SEEK_SET); read (handle, fileinfo, length);
numlumps += header.numlumps;
}