src/archiver_wad.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 25 Aug 2010 01:28:28 -0400
changeset 1115 bc7257f4f8da
parent 1113 2136d64bd1ad
child 1118 2e09fc635fdd
permissions -rw-r--r--
Removed __PHYSFS_platformGetLastModTime().
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * WAD support routines for PhysicsFS.
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * This driver handles DOOM engine archives ("wads"). 
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 * This format (but not this driver) was designed by id Software for use
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  with the DOOM engine.
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 * The specs of the format are from the unofficial doom specs v1.666
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 * found here: http://www.gamers.org/dhs/helpdocs/dmsp1666.html
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
 * The format of the archive: (from the specs)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
 *
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
 *  A WAD file has three parts:
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
 *  (1) a twelve-byte header
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
 *  (2) one or more "lumps"
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
 *  (3) a directory or "info table" that contains the names, offsets, and
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
 *      sizes of all the lumps in the WAD
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
 *
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
 *  The header consists of three four-byte parts:
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
 *    (a) an ASCII string which must be either "IWAD" or "PWAD"
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
 *    (b) a 4-byte (long) integer which is the number of lumps in the wad
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
 *    (c) a long integer which is the file offset to the start of
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
 *    the directory
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
 *
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
 *  The directory has one 16-byte entry for every lump. Each entry consists
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
 *  of three parts:
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
 *
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
 *    (a) a long integer, the file offset to the start of the lump
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
 *    (b) a long integer, the size of the lump in bytes
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
 *    (c) an 8-byte ASCII string, the name of the lump, padded with zeros.
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
 *        For example, the "DEMO1" entry in hexadecimal would be
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
 *        (44 45 4D 4F 31 00 00 00)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
 * 
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
 * Note that there is no way to tell if an opened WAD archive is a
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
 *  IWAD or PWAD with this archiver.
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
 * I couldn't think of a way to provide that information, without being too
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
 *  hacky.
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
 * I don't think it's really that important though.
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
 *
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
 *
809
116b8fe30371 Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
    39
 * Please see the file LICENSE.txt in the source's root directory.
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
 *
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
 * This file written by Travis Wells, based on the GRP archiver by
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
 *  Ryan C. Gordon.
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
 */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
#if (defined PHYSFS_SUPPORTS_WAD)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
#include <stdio.h>
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
#include <stdlib.h>
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
#include <string.h>
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
#include "physfs.h"
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
#define __PHYSICSFS_INTERNAL__
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
#include "physfs_internal.h"
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
typedef struct
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
{
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
    57
    char name[18];
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    PHYSFS_uint32 startPos;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    PHYSFS_uint32 size;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
} WADentry;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
typedef struct
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
{
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    char *filename;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    PHYSFS_uint32 entryCount;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    PHYSFS_uint32 entryOffset;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
    WADentry *entries;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
} WADinfo;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
typedef struct
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
{
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
    void *handle;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
    WADentry *entry;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
    PHYSFS_uint32 curPos;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
} WADfileinfo;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
    78
static void WAD_dirClose(dvoid *opaque)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
{
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
    80
    WADinfo *info = ((WADinfo *) opaque);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
    81
    allocator.Free(info->filename);
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
    82
    allocator.Free(info->entries);
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
    83
    allocator.Free(info);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
} /* WAD_dirClose */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    87
static PHYSFS_sint64 WAD_read(fvoid *opaque, void *buffer, PHYSFS_uint64 len)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
{
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
    89
    WADfileinfo *finfo = (WADfileinfo *) opaque;
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    90
    const WADentry *entry = finfo->entry;
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    91
    const PHYSFS_uint64 bytesLeft = (PHYSFS_uint64)(entry->size-finfo->curPos);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    PHYSFS_sint64 rc;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    94
    if (bytesLeft < len)
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    95
        len = bytesLeft;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    97
    rc = __PHYSFS_platformRead(finfo->handle, buffer, len);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    if (rc > 0)
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    99
        finfo->curPos += (PHYSFS_uint32) rc;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   101
    return rc;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
} /* WAD_read */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   105
static PHYSFS_sint64 WAD_write(fvoid *f, const void *buf, PHYSFS_uint64 len)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
{
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
    BAIL_MACRO(ERR_NOT_SUPPORTED, -1);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
} /* WAD_write */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   111
static int WAD_eof(fvoid *opaque)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
{
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   113
    WADfileinfo *finfo = (WADfileinfo *) opaque;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
    WADentry *entry = finfo->entry;
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   115
    return (finfo->curPos >= entry->size);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
} /* WAD_eof */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   119
static PHYSFS_sint64 WAD_tell(fvoid *opaque)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
{
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   121
    return ((WADfileinfo *) opaque)->curPos;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
} /* WAD_tell */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   125
static int WAD_seek(fvoid *opaque, PHYSFS_uint64 offset)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
{
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   127
    WADfileinfo *finfo = (WADfileinfo *) opaque;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    WADentry *entry = finfo->entry;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    int rc;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    rc = __PHYSFS_platformSeek(finfo->handle, entry->startPos + offset);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    if (rc)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
        finfo->curPos = (PHYSFS_uint32) offset;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   137
    return rc;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
} /* WAD_seek */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   141
static PHYSFS_sint64 WAD_fileLength(fvoid *opaque)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
{
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   143
    WADfileinfo *finfo = (WADfileinfo *) opaque;
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   144
    return ((PHYSFS_sint64) finfo->entry->size);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
} /* WAD_fileLength */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   148
static int WAD_fileClose(fvoid *opaque)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
{
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   150
    WADfileinfo *finfo = (WADfileinfo *) opaque;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
    BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   152
    allocator.Free(finfo);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   153
    return 1;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
} /* WAD_fileClose */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   157
static inline int readAll(void *fh, void *buf, const PHYSFS_uint64 len)
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   158
{
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   159
    return (__PHYSFS_platformRead(fh, buf, len) == len);
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   160
} /* readAll */
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   161
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   162
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
static int wad_open(const char *filename, int forWriting,
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
                    void **fh, PHYSFS_uint32 *count,PHYSFS_uint32 *offset)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
{
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
    PHYSFS_uint8 buf[4];
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
    *fh = NULL;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
    BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
    *fh = __PHYSFS_platformOpenRead(filename);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
    BAIL_IF_MACRO(*fh == NULL, NULL, 0);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   174
    if (!readAll(*fh, buf, 4))
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
        goto openWad_failed;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    if (memcmp(buf, "IWAD", 4) != 0 && memcmp(buf, "PWAD", 4) != 0)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    {
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
        __PHYSFS_setError(ERR_UNSUPPORTED_ARCHIVE);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
        goto openWad_failed;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
    } /* if */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   183
    if (!readAll(*fh, count, sizeof (PHYSFS_uint32)))
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
        goto openWad_failed;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
    *count = PHYSFS_swapULE32(*count);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   188
    if (!readAll(*fh, offset, sizeof (PHYSFS_uint32)))
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
        goto openWad_failed;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
    *offset = PHYSFS_swapULE32(*offset);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   193
    return 1;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
openWad_failed:
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
    if (*fh != NULL)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
        __PHYSFS_platformClose(*fh);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    *count = -1;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
    *fh = NULL;
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   201
    return 0;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
} /* wad_open */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
static int wad_entry_cmp(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
{
928
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   207
    if (one != two)
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   208
    {
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   209
        const WADentry *a = (const WADentry *) _a;
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   210
        return strcmp(a[one].name, a[two].name);
928
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   211
    } /* if */
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   212
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   213
    return 0;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
} /* wad_entry_cmp */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
static void wad_entry_swap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
{
928
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   219
    if (one != two)
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   220
    {
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   221
        WADentry tmp;
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   222
        WADentry *first = &(((WADentry *) _a)[one]);
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   223
        WADentry *second = &(((WADentry *) _a)[two]);
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   224
        memcpy(&tmp, first, sizeof (WADentry));
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   225
        memcpy(first, second, sizeof (WADentry));
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   226
        memcpy(second, &tmp, sizeof (WADentry));
0e37b8163248 Various archiver swap and compare functions now check if they are
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   227
    } /* if */
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
} /* wad_entry_swap */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
static int wad_load_entries(const char *name, int forWriting, WADinfo *info)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
{
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    void *fh = NULL;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
    PHYSFS_uint32 fileCount;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
    PHYSFS_uint32 directoryOffset;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    WADentry *entry;
622
c8e67ca63ad6 Patches to get this building on Mac Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 610
diff changeset
   237
    char lastDirectory[9];
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   238
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   239
    lastDirectory[8] = 0; /* Make sure lastDirectory stays null-terminated. */
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
    BAIL_IF_MACRO(!wad_open(name, forWriting, &fh, &fileCount,&directoryOffset), NULL, 0);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
    info->entryCount = fileCount;
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   243
    info->entries = (WADentry *) allocator.Malloc(sizeof(WADentry)*fileCount);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
    if (info->entries == NULL)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
    {
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
        __PHYSFS_platformClose(fh);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
        BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
    } /* if */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
    __PHYSFS_platformSeek(fh,directoryOffset);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
    for (entry = info->entries; fileCount > 0; fileCount--, entry++)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
    {
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   254
        if ( (!readAll(fh, &entry->startPos, sizeof (PHYSFS_uint32))) ||
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   255
             (!readAll(fh, &entry->size, sizeof (PHYSFS_uint32))) ||
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   256
             (!readAll(fh, &entry->name, 8)) )
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
        {
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
            __PHYSFS_platformClose(fh);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   259
            return 0;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
        } /* if */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
        entry->name[8] = '\0'; /* name might not be null-terminated in file. */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
        entry->size = PHYSFS_swapULE32(entry->size);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
        entry->startPos = PHYSFS_swapULE32(entry->startPos);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
    } /* for */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
    __PHYSFS_platformClose(fh);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
    __PHYSFS_sort(info->entries, info->entryCount,
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
                  wad_entry_cmp, wad_entry_swap);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   271
    return 1;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
} /* wad_load_entries */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   275
static void *WAD_openArchive(const char *name, int forWriting)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
{
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   277
    WADinfo *info = (WADinfo *) allocator.Malloc(sizeof (WADinfo));
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   279
    BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
    memset(info, '\0', sizeof (WADinfo));
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   282
    info->filename = (char *) allocator.Malloc(strlen(name) + 1);
678
73a2641375a0 Cleaned up some minor bloat with my new evil GOTO_*_MACRO macros.
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   283
    GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, WAD_openArchive_failed);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
    if (!wad_load_entries(name, forWriting, info))
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
        goto WAD_openArchive_failed;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
    strcpy(info->filename, name);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   289
    return info;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
WAD_openArchive_failed:
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   292
    if (info != NULL)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
    {
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   294
        if (info->filename != NULL)
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   295
            allocator.Free(info->filename);
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   296
        if (info->entries != NULL)
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   297
            allocator.Free(info->entries);
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   298
        allocator.Free(info);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
    } /* if */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   301
    return NULL;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
} /* WAD_openArchive */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 650
diff changeset
   305
static void WAD_enumerateFiles(dvoid *opaque, const char *dname,
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 694
diff changeset
   306
                               int omitSymLinks, PHYSFS_EnumFilesCallback cb,
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 694
diff changeset
   307
                               const char *origdir, void *callbackdata)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
{
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   309
    WADinfo *info = ((WADinfo *) opaque);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
    WADentry *entry = info->entries;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
    PHYSFS_uint32 max = info->entryCount;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
    PHYSFS_uint32 i;
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 650
diff changeset
   313
    const char *name;
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   314
    char *sep;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 650
diff changeset
   316
    if (*dname == '\0')  /* root directory enumeration? */
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   317
    {
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   318
        for (i = 0; i < max; i++, entry++)
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   319
        {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 650
diff changeset
   320
            name = entry->name;
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 650
diff changeset
   321
            if (strchr(name, '/') == NULL)
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 694
diff changeset
   322
                cb(callbackdata, origdir, name);
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   323
        } /* for */
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   324
    } /* if */
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   325
    else
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   326
    {
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   327
        for (i = 0; i < max; i++, entry++)
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   328
        {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 650
diff changeset
   329
            name = entry->name;
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 650
diff changeset
   330
            sep = strchr(name, '/');
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   331
            if (sep != NULL)
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   332
            {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 650
diff changeset
   333
                if (strncmp(dname, name, (sep - name)) == 0)
759
e4f83afe8969 Patched archivers/wad.c to compile again.
Ryan C. Gordon <icculus@icculus.org>
parents: 754
diff changeset
   334
                    cb(callbackdata, origdir, sep + 1);
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   335
            } /* if */
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   336
        } /* for */
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   337
    } /* else */
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
} /* WAD_enumerateFiles */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   341
static WADentry *wad_find_entry(const WADinfo *info, const char *name)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
{
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
    WADentry *a = info->entries;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
    PHYSFS_sint32 lo = 0;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
    PHYSFS_sint32 hi = (PHYSFS_sint32) (info->entryCount - 1);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
    PHYSFS_sint32 middle;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
    int rc;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
    while (lo <= hi)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
    {
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
        middle = lo + ((hi - lo) / 2);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
        rc = strcmp(name, a[middle].name);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
        if (rc == 0)  /* found it! */
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   354
            return &a[middle];
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
        else if (rc > 0)
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
            lo = middle + 1;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
        else
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
            hi = middle - 1;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
    } /* while */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
    BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
} /* wad_find_entry */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   365
static int WAD_exists(dvoid *opaque, const char *name)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
{
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   367
    return (wad_find_entry((WADinfo *) opaque, name) != NULL);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
} /* WAD_exists */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   371
static int WAD_isDirectory(dvoid *opaque, const char *name, int *fileExists)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
{
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   373
    WADentry *entry = wad_find_entry(((WADinfo *) opaque), name);
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   374
    if (entry != NULL)
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   375
    {
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   376
        char *n;
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   377
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   378
        *fileExists = 1;
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   379
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   380
        /* Can't be a directory if it's a subdirectory. */
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   381
        if (strchr(entry->name, '/') != NULL)
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   382
            return 0;
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   383
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   384
        /* Check if it matches "MAP??" or "E?M?" ... */
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   385
        n = entry->name;
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   386
        if ((n[0] == 'E' && n[2] == 'M') ||
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   387
            (n[0] == 'M' && n[1] == 'A' && n[2] == 'P' && n[6] == 0))
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   388
        {
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   389
            return 1;
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   390
        } /* if */
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   391
        return 0;
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   392
    } /* if */
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   393
    else
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   394
    {
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   395
        *fileExists = 0;
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   396
        return 0;
610
1d8057a5d08e Says Travis Wells:
Ryan C. Gordon <icculus@icculus.org>
parents: 609
diff changeset
   397
    } /* else */
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
} /* WAD_isDirectory */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   401
static int WAD_isSymLink(dvoid *opaque, const char *name, int *fileExists)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
{
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   403
    *fileExists = WAD_exists(opaque, name);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   404
    return 0;  /* never symlinks in a wad. */
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
} /* WAD_isSymLink */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   408
static fvoid *WAD_openRead(dvoid *opaque, const char *fnm, int *fileExists)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
{
648
5c993684b8f2 Cleaned up archiver interface to not deal with DirHandles anymore,
Ryan C. Gordon <icculus@icculus.org>
parents: 622
diff changeset
   410
    WADinfo *info = ((WADinfo *) opaque);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
    WADfileinfo *finfo;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
    WADentry *entry;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
    entry = wad_find_entry(info, fnm);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
    *fileExists = (entry != NULL);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
    BAIL_IF_MACRO(entry == NULL, NULL, NULL);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   418
    finfo = (WADfileinfo *) allocator.Malloc(sizeof (WADfileinfo));
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   419
    BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
    finfo->handle = __PHYSFS_platformOpenRead(info->filename);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
    if ( (finfo->handle == NULL) ||
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
         (!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
    {
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   425
        allocator.Free(finfo);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   426
        return NULL;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
    } /* if */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
    finfo->curPos = 0;
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
    finfo->entry = entry;
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   431
    return finfo;
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
} /* WAD_openRead */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   435
static fvoid *WAD_openWrite(dvoid *opaque, const char *name)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
{
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
    BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
} /* WAD_openWrite */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   441
static fvoid *WAD_openAppend(dvoid *opaque, const char *name)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
{
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
    BAIL_MACRO(ERR_NOT_SUPPORTED, NULL);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
} /* WAD_openAppend */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   447
static int WAD_remove(dvoid *opaque, const char *name)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
{
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
    BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
} /* WAD_remove */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
650
298b8bb26775 Did the same thing to FileHandles than I did to DirHandles, but this
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   453
static int WAD_mkdir(dvoid *opaque, const char *name)
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
{
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
    BAIL_MACRO(ERR_NOT_SUPPORTED, 0);
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
} /* WAD_mkdir */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
658
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   458
1108
b63e39d5be04 Fixed details of PHYSFS_Archiver's stat method.
Ryan C. Gordon <icculus@icculus.org>
parents: 1106
diff changeset
   459
static int WAD_stat(dvoid *opaque, const char *filename, int *exists,
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   460
                    PHYSFS_Stat *stat)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   461
{
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   462
    const WADinfo *info = (const WADinfo *) opaque;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   463
    const WADentry *entry = wad_find_entry(info, filename);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   464
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   465
    *exists = (entry != 0);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   466
    if (!entry)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   467
        return 0;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   468
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   469
    stat->filesize = entry->size;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   470
    stat->filetype = PHYSFS_FILETYPE_REGULAR;
1115
bc7257f4f8da Removed __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
   471
    stat->accesstime = -1;
bc7257f4f8da Removed __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
   472
    stat->modtime = -1;
bc7257f4f8da Removed __PHYSFS_platformGetLastModTime().
Ryan C. Gordon <icculus@icculus.org>
parents: 1113
diff changeset
   473
    stat->createtime = -1;
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   474
    stat->readonly = 1; /* WADs are always readonly */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   475
1106
94c3669d0311 Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1098
diff changeset
   476
    return 1;
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   477
} /* WAD_stat */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   478
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   479
658
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   480
const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_WAD =
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   481
{
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   482
    "WAD",
694
80bc8858b4ab Added translation for WAD file type.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   483
    WAD_ARCHIVE_DESCRIPTION,
658
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   484
    "Travis Wells <traviswells@mchsi.com>",
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   485
    "http://www.3dmm2.com/doom/",
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   486
};
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   487
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   488
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   489
const PHYSFS_Archiver __PHYSFS_Archiver_WAD =
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   490
{
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   491
    &__PHYSFS_ArchiveInfo_WAD,
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   492
    WAD_openArchive,        /* openArchive() method    */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   493
    WAD_enumerateFiles,     /* enumerateFiles() method */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   494
    WAD_exists,             /* exists() method         */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   495
    WAD_isDirectory,        /* isDirectory() method    */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   496
    WAD_isSymLink,          /* isSymLink() method      */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   497
    WAD_openRead,           /* openRead() method       */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   498
    WAD_openWrite,          /* openWrite() method      */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   499
    WAD_openAppend,         /* openAppend() method     */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   500
    WAD_remove,             /* remove() method         */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   501
    WAD_mkdir,              /* mkdir() method          */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   502
    WAD_dirClose,           /* dirClose() method       */
1109
c69df75dbcc3 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1108
diff changeset
   503
    WAD_stat,               /* stat() method           */
658
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   504
    WAD_read,               /* read() method           */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   505
    WAD_write,              /* write() method          */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   506
    WAD_eof,                /* eof() method            */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   507
    WAD_tell,               /* tell() method           */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   508
    WAD_seek,               /* seek() method           */
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   509
    WAD_fileLength,         /* fileLength() method     */
1109
c69df75dbcc3 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1108
diff changeset
   510
    WAD_fileClose           /* fileClose() method      */
658
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   511
};
1981818c6170 Removed all the forward declaration cruft from the archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   512
609
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
#endif  /* defined PHYSFS_SUPPORTS_WAD */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
/* end of wad.c ... */
3a91332776e0 Added Doom WAD support.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516