components/prboom/w_wad.c
//
// W_AddFile
// All files are optional, but at least one file must be
//  found (PWAD, if all required lumps are present).
// Files with a .wad extension are wadlink files
//  with multiple lumps.
// Other files are single lumps with the base filename
//  for the lump name.
//
// Reload hack removed by Lee Killough
// CPhipps - source is an enum
//
// proff - changed using pointer to wadfile_info_t
W_AddFile
All files are optional, but at least one file must be
found (PWAD, if all required lumps are present).
Files with a .wad extension are wadlink files
with multiple lumps.
Other files are single lumps with the base filename
for the lump name.

Reload hack removed by Lee Killough
CPhipps - source is an enum

changed using pointer to wadfile_info_t
W_AddFile All files are optional but at least one file must be found ( PWAD if all required lumps are present ) . Files with a . wad extension are wadlink files with multiple lumps . Other files are single lumps with the base filename for the lump name . Reload hack removed by Lee Killough CPhipps - source is an enum changed using pointer to wadfile_info_t
static void W_AddFile(wadfile_info_t *wadfile) 
{
  wadinfo_t   header;
  lumpinfo_t* lump_p;
  unsigned    i;
  int         length;
  int         startlump;
  filelump_t  *fileinfo, *fileinfo2free=NULL; 
  filelump_t  singleinfo;
  wadfile->handle = I_Open(wadfile->name,O_RDONLY | O_BINARY);
#ifdef HAVE_NET
  if (wadfile->handle == -1 && D_NetGetWad(wadfile->name)) 
    wadfile->handle = I_Open(wadfile->name,O_RDONLY | O_BINARY);
#endif
  if (wadfile->handle == -1) 
    {
      if (  strlen(wadfile->name)<=4 ||      
	         (strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".lmp" ) &&
	          strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".gwa" ) )
         )
	I_Error("W_AddFile: couldn't open %s",wadfile->name);
      return;
    }
  lprintf (LO_INFO," adding %s\n",wadfile->name);
  startlump = numlumps;
  if (  strlen(wadfile->name)<=4 || 
	      (
          strcasecmp(wadfile->name+strlen(wadfile->name)-4,".wad") && 
	        strcasecmp(wadfile->name+strlen(wadfile->name)-4,".gwa")
        )
     )
    {
      fileinfo = &singleinfo;
      singleinfo.filepos = 0;
      singleinfo.size = LONG(I_Filelength(wadfile->handle));
      ExtractFileBase(wadfile->name, singleinfo.name);
      numlumps++;
    }
  else
    {
      I_Read(wadfile->handle, &header, sizeof(header));
      if (strncmp(header.identification,"IWAD",4) &&
          strncmp(header.identification,"PWAD",4))
        I_Error("W_AddFile: Wad file %s doesn't have IWAD or PWAD id", wadfile->name);
      header.numlumps = LONG(header.numlumps);
      header.infotableofs = LONG(header.infotableofs);
      length = header.numlumps*sizeof(filelump_t);
      fileinfo2free = fileinfo = malloc(length);    
      I_Lseek(wadfile->handle, header.infotableofs, SEEK_SET);
      I_Read(wadfile->handle, fileinfo, length);
      numlumps += header.numlumps;
    }
    lumpinfo = realloc(lumpinfo, numlumps*sizeof(lumpinfo_t));
    lump_p = &lumpinfo[startlump];
    for (i=startlump ; (int)i<numlumps ; i++,lump_p++, fileinfo++)
      {
        lump_p->wadfile = wadfile;                    
        lump_p->position = LONG(fileinfo->filepos);
        lump_p->size = LONG(fileinfo->size);
        lump_p->li_namespace = ns_global;               4/17/98
        strncpy (lump_p->name, fileinfo->name, 8);
	lump_p->source = wadfile->src;                    
      }
    free(fileinfo2free);      
}
static void W_AddFile ( wadfile_info_t * wadfile ) { wadinfo_t header ; lumpinfo_t * lump_p ; unsigned i ; int length ; int startlump ; filelump_t * fileinfo , * fileinfo2free = NULL ; filelump_t singleinfo ; wadfile -> handle = I_Open ( wadfile -> name , O_RDONLY | O_BINARY ) ; #ifdef HAVE_NET if ( wadfile -> handle == -1 && D_NetGetWad ( wadfile -> name ) ) wadfile -> handle = I_Open ( wadfile -> name , O_RDONLY | O_BINARY ) ; #endif if ( wadfile -> handle == -1 ) { if ( strlen ( wadfile -> name ) <= 4 || ( strcasecmp ( wadfile -> name + strlen ( wadfile -> name ) - 4 , " " ) && strcasecmp ( wadfile -> name + strlen ( wadfile -> name ) - 4 , " " ) ) ) I_Error ( " " , wadfile -> name ) ; return ; } lprintf ( LO_INFO , " \n " , wadfile -> name ) ; startlump = numlumps ; if ( strlen ( wadfile -> name ) <= 4 || ( strcasecmp ( wadfile -> name + strlen ( wadfile -> name ) - 4 , " " ) && strcasecmp ( wadfile -> name + strlen ( wadfile -> name ) - 4 , " " ) ) ) { fileinfo = & singleinfo ; singleinfo . filepos = 0 ; singleinfo . size = LONG ( I_Filelength ( wadfile -> handle ) ) ; ExtractFileBase ( wadfile -> name , singleinfo . name ) ; numlumps ++ ; } else { I_Read ( wadfile -> handle , & header , sizeof ( header ) ) ; if ( strncmp ( header . identification , " " , 4 ) && strncmp ( header . identification , " " , 4 ) ) I_Error ( " " , wadfile -> name ) ; header . numlumps = LONG ( header . numlumps ) ; header . infotableofs = LONG ( header . infotableofs ) ; length = header . numlumps * sizeof ( filelump_t ) ; fileinfo2free = fileinfo = malloc ( length ) ; I_Lseek ( wadfile -> handle , header . infotableofs , SEEK_SET ) ; I_Read ( wadfile -> handle , fileinfo , length ) ; numlumps += header . numlumps ; } lumpinfo = realloc ( lumpinfo , numlumps * sizeof ( lumpinfo_t ) ) ; lump_p = & lumpinfo [ startlump ] ; for ( i = startlump ; ( int ) i < numlumps ; i ++ , lump_p ++ , fileinfo ++ ) { lump_p -> wadfile = wadfile ; lump_p -> position = LONG ( fileinfo -> filepos ) ; lump_p -> size = LONG ( fileinfo -> size ) ; lump_p -> li_namespace = ns_global ; strncpy ( lump_p -> name , fileinfo -> name , 8 ) ; lump_p -> source = wadfile -> src ; } free ( fileinfo2free ) ; }
W_AddFile
All files are optional, but at least one file must be
found (PWAD, if all required lumps are present).
W_AddFile All files are optional but at least one file must be found ( PWAD if all required lumps are present ) .
// killough 1/31/98: static, const //killough // open the file and add to directory // CPhipps // add error check -- killough //jff 8/3/98 use logical output routine // single lump file // WAD file // killough // Fill in lumpinfo //  killough 4/25/98 // killough 4/17/98 // Ty 08/29/98 // killough