home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
D!Zone (Collector's Edition)
/
D_ZONE_CD.ISO
/
programs
/
editors
/
dmijum
/
wadfile.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-12-06
|
43KB
|
1,094 lines
/*
* WADFILE.C
*
* Version 1.0.0
*
* Abstract:
* This module contains all the WADFILE processing routines for the
* WadLib library.
*
* History:
* 1.0.0 (March 31, 1994)
*
* Author:
* Michael McMahon
*
****************************************************************************
* Wadfile Function Directory
*---------------------------------------------------------------------------
*Index: Name : Description
*---------------------------------------------------------------------------
* #1 : WadfileAddLump : Add a lump to a Wadfile being created.
* #2 : WadfileClose : Close file, flush cache, update WAD directory
* #3 : WadfileCopyEntry : Copies a lump from one Wadfile to another.
* #4 : WadfileCopyMap : Copies a map from one Wadfile to another.
* #5 : WadfileCreate : Create WAD file and initialize Wadfile struct.
* #6 : WadfileGetDirInfo : Read directory info into Wadfile structure.
* #7 : WadfileGetNextDirInfo : Move to next directory entry and read it in.
* #8 : WadfileGetPrevDirInfo : Move to last directory entry and read it in.
* #9 : WadfileInitialize : One-time call, set up memory allocators.
* #10 : WadfileLumpClose : Close lump inside WAD file, free its memory.
* #11 : WadfileLumpCopy : Copy lump file from one Wadfile to another.
* #12 : WadfileLumpOpen : Open lump at current directory position.
* #13 : WadfileOpen : Open a WAD file and initialize Wadfile struct.
* #14 : WadfileSeek : Find first dir entry with a search string.
* #15 : WadfileSeekMap : Find map given episode and map. ExMy
****************************************************************************
*
* WADLIB SOFTWARE LICENSE AGREEMENT
*
* 1. GRANT OF LICENSE. Michael McMahon and his affiliations (collectively
* the "AUTHOR") grant you (either an individual or an entity) the
* non-exclusive, royalty-free right to use this library source code,
* documentation, and sample code (collectively, the "SOFTWARE") for
* any lawful purpose subject to the terms of this license. By using the
* SOFTWARE you are agreeing to be bound to all the terms of this license.
*
* 2. COPYRIGHT. The SOFTWARE is Copyright (c) 1994, Michael McMahon,
* PO Box 14807, San Luis Nabisco, CA 93406-4807 USA. All Rights Reserved
* Worldwide. You may not use, modify, or distribute the SOFTWARE except
* as otherwise provided herein.
*
* 3. DECLARATION OF PUBLIC DOMAIN DISTRIBUTION AND USE. The distribution
* and use of the SOFTWARE is hereby designated PUBLIC DOMAIN by the
* the AUTHOR. You may not sell, rent, or lease this SOFTWARE. The
* SOFTWARE may be reproduced verbatim in part or in full by any
* reproduction means for any lawful purpose, and may also be subject to
* the following agreement.
*
* 4. AGREEMENT FOR USE OF SOFTWARE. The AUTHOR grants you a non-exclusive,
* royalty-free right to incorporate the SOFTWARE into any production for
* any legal purpose as long as you agree
* (a) to indemnify, hold harmless, and defend the AUTHOR from and against
* any claims or lawsuits, including attorneys' fees, that arise or
* result from the use or distribution of your software production; and
* (b) no matter how much the SOFTWARE is modified, the AUTHOR owns the
* copyright and this original, unmodified copyright notice remains
* intact in the source code; and,
* (c) the AUTHOR is not held responsible for fixing bugs or making
* enhancements or changes to the SOFTWARE for any reason; and,
* (d) the SOFTWARE is not redistributed if it is modified in any way; and,
* (e) otherwise comply with the terms of this agreement; and,
* (f) the AUTHOR is forgiven for making so many demands.
*
* THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. THE
* AUTHOR FURTHER DISCLAIMS ALL IMPLIED WARRANTIES, INCLUDING WITHOUT
* LIMITATION ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR OF FITNESS
* FOR A PARTICULAR PURPOSE. THE ENTIRE RISK ARISING OUT OF THE USE
* OR PERFORMANCE OF THE SOFTWARE REMAINS WITH YOU.
*
* The author can be reached at:
* Michael McMahon
* P.O. Box 14807
* San Luis Nabisco, CA 93406-4807 USA
* Internet: mmcmahon@oboe.calpoly.edu
* [Bug reports, suggestions, success stories, etc. are welcome; tech
* support, and other unnecessary two-way mail, is not]
*/
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <mem.h>
#include "general.h"
#include "wadfile.h"
/* Private wadfile variables */
static int wadfileInitialized=FALSE; /* Module doesn't work unless TRUE */
static WadfileMalloc wadfileMalloc; /* User's allocate memory routine */
static WadfileFree wadfileFree; /* User's free memory routine */
static int wadfileNumAllocations; /* Keeps track of the malloc's */
/*------------------------- Private routines ------------------------------*/
/**[ Internal 1 of 2 ]****************************************************
* *
* wf_malloc *
* *
* Desc: *
* This calls the user's memory allocation routine and updates *
* the 'wadfileNumAllocations' variable. *
* *
* Def: *
* static void * wf_malloc(unsigned long size); *
* *
* Parm: *
* size Number of bytes to allocate. *
* *
* Retn: *
* Pointer to allocated memory, or NULL if not enough memory. *
* *
* Notes: *
* This is the gateway for the WADFILE routines to access the user's *
* memory allocation routine. Don't call 'wadfileMalloc()' directly. *
* *
*************************************************************************/
static void * wf_malloc(unsigned long size)
{
void * result;
/* Sanity check */
assert(wadfileMalloc != NULL);
/* Allocate memory and bump wadfileNumAllocations if successful */
result = wadfileMalloc(size);
if (result != NULL)
wadfileNumAllocations++;
return result;
}
/**[ Internal 2 of 2 ]****************************************************
* *
* wf_free *
* *
* Desc: *
* This calls the user's memory de-allocation routine and updates *
* the 'wadfileNumAllocations' variable. *
* *
* Def: *
* static void wf_free(void * ptr); *
* *
* Parm: *
* ptr Valid memory pointer that was allocated with wf_malloc. *
* *
* Retn: *
* None *
* *
* Notes: *
* This is the gateway for the WADFILE routines to access the user's *
* memory deallocation routine. Don't call 'wadfileFree()' directly. *
* *
*************************************************************************/
static void wf_free(void * ptr)
{
/* Sanity