Use standard C file functions for WAD code
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 15
This commit is contained in:
parent
02c50cf818
commit
cce6e26442
1 changed files with 40 additions and 42 deletions
82
src/w_wad.c
82
src/w_wad.c
|
|
@ -1,7 +1,7 @@
|
|||
// Emacs style mode select -*- C++ -*-
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Id: w_wad.c 8 2005-07-23 16:44:57Z fraggle $
|
||||
// $Id: w_wad.c 15 2005-07-23 18:50:34Z fraggle $
|
||||
//
|
||||
// Copyright(C) 1993-1996 Id Software, Inc.
|
||||
// Copyright(C) 2005 Simon Howard
|
||||
|
|
@ -22,6 +22,9 @@
|
|||
// 02111-1307, USA.
|
||||
//
|
||||
// $Log$
|
||||
// Revision 1.3 2005/07/23 18:50:34 fraggle
|
||||
// Use standard C file functions for WAD code
|
||||
//
|
||||
// Revision 1.2 2005/07/23 16:44:57 fraggle
|
||||
// Update copyright to GNU GPL
|
||||
//
|
||||
|
|
@ -36,29 +39,17 @@
|
|||
|
||||
|
||||
static const char
|
||||
rcsid[] = "$Id: w_wad.c 8 2005-07-23 16:44:57Z fraggle $";
|
||||
rcsid[] = "$Id: w_wad.c 15 2005-07-23 18:50:34Z fraggle $";
|
||||
|
||||
|
||||
#ifdef NORMALUNIX
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <alloca.h>
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "m_swap.h"
|
||||
#include "i_system.h"
|
||||
#include "z_zone.h"
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "w_wad.h"
|
||||
#endif
|
||||
#include "w_wad.h"
|
||||
|
||||
|
||||
|
|
@ -84,14 +75,21 @@ void strupr (char* s)
|
|||
while (*s) { *s = toupper(*s); s++; }
|
||||
}
|
||||
|
||||
int filelength (int handle)
|
||||
int filelength (FILE *handle)
|
||||
{
|
||||
struct stat fileinfo;
|
||||
long savedpos;
|
||||
long length;
|
||||
// save the current position in the file
|
||||
savedpos = ftell(handle);
|
||||
|
||||
if (fstat (handle,&fileinfo) == -1)
|
||||
I_Error ("Error fstating");
|
||||
// jump to the end and find the length
|
||||
fseek(handle, 0, SEEK_END);
|
||||
length = ftell(handle);
|
||||
|
||||
return fileinfo.st_size;
|
||||
// go back to the old location
|
||||
fseek(handle, savedpos, SEEK_SET);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -156,12 +154,12 @@ void W_AddFile (char *filename)
|
|||
wadinfo_t header;
|
||||
lumpinfo_t* lump_p;
|
||||
unsigned i;
|
||||
int handle;
|
||||
FILE *handle;
|
||||
int length;
|
||||
int startlump;
|
||||
filelump_t* fileinfo;
|
||||
filelump_t singleinfo;
|
||||
int storehandle;
|
||||
FILE *storehandle;
|
||||
|
||||
// open the file and add to directory
|
||||
|
||||
|
|
@ -173,7 +171,7 @@ void W_AddFile (char *filename)
|
|||
reloadlump = numlumps;
|
||||
}
|
||||
|
||||
if ( (handle = open (filename,O_RDONLY | O_BINARY)) == -1)
|
||||
if ( (handle = fopen(filename,"rb")) == NULL)
|
||||
{
|
||||
printf (" couldn't open %s\n",filename);
|
||||
return;
|
||||
|
|
@ -194,7 +192,7 @@ void W_AddFile (char *filename)
|
|||
else
|
||||
{
|
||||
// WAD file
|
||||
read (handle, &header, sizeof(header));
|
||||
fread (&header, sizeof(header), 1, handle);
|
||||
if (strncmp(header.identification,"IWAD",4))
|
||||
{
|
||||
// Homebrew levels?
|
||||
|
|
@ -210,8 +208,8 @@ void W_AddFile (char *filename)
|
|||
header.infotableofs = LONG(header.infotableofs);
|
||||
length = header.numlumps*sizeof(filelump_t);
|
||||
fileinfo = alloca (length);
|
||||
lseek (handle, header.infotableofs, SEEK_SET);
|
||||
read (handle, fileinfo, length);
|
||||
fseek(handle, header.infotableofs, SEEK_SET);
|
||||
fread(fileinfo, length, 1, handle);
|
||||
numlumps += header.numlumps;
|
||||
}
|
||||
|
||||
|
|
@ -224,7 +222,7 @@ void W_AddFile (char *filename)
|
|||
|
||||
lump_p = &lumpinfo[startlump];
|
||||
|
||||
storehandle = reloadname ? -1 : handle;
|
||||
storehandle = reloadname ? NULL : handle;
|
||||
|
||||
for (i=startlump ; i<numlumps ; i++,lump_p++, fileinfo++)
|
||||
{
|
||||
|
|
@ -235,7 +233,7 @@ void W_AddFile (char *filename)
|
|||
}
|
||||
|
||||
if (reloadname)
|
||||
close (handle);
|
||||
fclose (handle);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -252,23 +250,23 @@ void W_Reload (void)
|
|||
int lumpcount;
|
||||
lumpinfo_t* lump_p;
|
||||
unsigned i;
|
||||
int handle;
|
||||
FILE *handle;
|
||||
int length;
|
||||
filelump_t* fileinfo;
|
||||
|
||||
if (!reloadname)
|
||||
return;
|
||||
|
||||
if ( (handle = open (reloadname,O_RDONLY | O_BINARY)) == -1)
|
||||
if ( (handle = fopen(reloadname,"rb")) == NULL)
|
||||
I_Error ("W_Reload: couldn't open %s",reloadname);
|
||||
|
||||
read (handle, &header, sizeof(header));
|
||||
fread(&header, sizeof(header), 1, handle);
|
||||
lumpcount = LONG(header.numlumps);
|
||||
header.infotableofs = LONG(header.infotableofs);
|
||||
length = lumpcount*sizeof(filelump_t);
|
||||
fileinfo = alloca (length);
|
||||
lseek (handle, header.infotableofs, SEEK_SET);
|
||||
read (handle, fileinfo, length);
|
||||
fseek(handle, header.infotableofs, SEEK_SET);
|
||||
fread(fileinfo, length, 1, handle);
|
||||
|
||||
// Fill in lumpinfo
|
||||
lump_p = &lumpinfo[reloadlump];
|
||||
|
|
@ -284,7 +282,7 @@ void W_Reload (void)
|
|||
lump_p->size = LONG(fileinfo->size);
|
||||
}
|
||||
|
||||
close (handle);
|
||||
fclose(handle);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -448,7 +446,7 @@ W_ReadLump
|
|||
{
|
||||
int c;
|
||||
lumpinfo_t* l;
|
||||
int handle;
|
||||
FILE *handle;
|
||||
|
||||
if (lump >= numlumps)
|
||||
I_Error ("W_ReadLump: %i >= numlumps",lump);
|
||||
|
|
@ -457,24 +455,24 @@ W_ReadLump
|
|||
|
||||
// ??? I_BeginRead ();
|
||||
|
||||
if (l->handle == -1)
|
||||
if (l->handle == NULL)
|
||||
{
|
||||
// reloadable file, so use open / read / close
|
||||
if ( (handle = open (reloadname,O_RDONLY | O_BINARY)) == -1)
|
||||
if ( (handle = fopen(reloadname,"rb")) == NULL)
|
||||
I_Error ("W_ReadLump: couldn't open %s",reloadname);
|
||||
}
|
||||
else
|
||||
handle = l->handle;
|
||||
|
||||
lseek (handle, l->position, SEEK_SET);
|
||||
c = read (handle, dest, l->size);
|
||||
fseek(handle, l->position, SEEK_SET);
|
||||
c = fread (dest, 1, l->size, handle);
|
||||
|
||||
if (c < l->size)
|
||||
I_Error ("W_ReadLump: only read %i of %i on lump %i",
|
||||
c,l->size,lump);
|
||||
|
||||
if (l->handle == -1)
|
||||
close (handle);
|
||||
if (l->handle == NULL)
|
||||
fclose (handle);
|
||||
|
||||
// ??? I_EndRead ();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue