// // 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 static void W_AddFile(wadfile_info_t *wadfile) // killough 1/31/98: static, const { wadinfo_t header; lumpinfo_t* lump_p; unsigned i; int length; int startlump; filelump_t *fileinfo, *fileinfo2free=NULL; //killough filelump_t singleinfo; // open the file and add to directory wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY); #ifdef HAVE_NET if (wadfile->handle == -1 && D_NetGetWad(wadfile->name)) // CPhipps wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY); #endif if (wadfile->handle == -1) { if ( strlen(wadfile->name)<=4 || // add error check -- killough (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; } //jff 8/3/98 use logical output routine 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") ) ) { // single lump file fileinfo = &singleinfo; singleinfo.filepos = 0; singleinfo.size = LONG(I_Filelength(wadfile->handle)); ExtractFileBase(wadfile->name, singleinfo.name); numlumps++; } else { // WAD file 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); // killough lseek(wadfile->handle, header.infotableofs, SEEK_SET); I_Read(wadfile->handle, fileinfo, length); numlumps += header.numlumps; } // Fill in lumpinfo 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; // killough 4/25/98 lump_p->position = LONG(fileinfo->filepos); lump_p->size = LONG(fileinfo->size); lump_p->li_namespace = ns_global; // killough 4/17/98 strncpy (lump_p->name, fileinfo->name, 8); lump_p->source = wadfile->src; // Ty 08/29/98 } free(fileinfo2free); // killough }
// // 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 static void W_AddFile(wadfile_info_t *wadfile) // killough 1/31/98: static, const { wadinfo_t header; lumpinfo_t* lump_p; unsigned i; int length; int startlump; filelump_t *fileinfo, *fileinfo2free=NULL; //killough filelump_t singleinfo; // open the file and add to directory //e6y #ifdef ALL_IN_ONE unsigned char *handle; dboolean predefined_lump = (wadfile->src == source_pre); if(predefined_lump) handle = GetAllInOneLumpHandle(); else { #endif //ROBO: Precache wadfile->handle = fopen(wadfile->name, "rb"); #ifdef HAVE_NET if (wadfile->handle == 0 && D_NetGetWad(wadfile->name)) // CPhipps wadfile->handle = fopen(wadfile->name, "rb"); #endif if (wadfile->handle == 0 && strlen(wadfile->name) > 4 && wadfile->src == source_pwad && !strcasecmp(wadfile->name + strlen(wadfile->name) - 4 , ".wad") && D_TryGetWad(wadfile->name)) { wadfile->handle = fopen(wadfile->name, "rb"); } if (wadfile->handle == 0) { if ( strlen(wadfile->name)<=4 || // add error check -- killough (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; } { struct stat statbuf; stat(wadfile->name, &statbuf); wadfile->length = statbuf.st_size; wadfile->data = malloc(statbuf.st_size); fread(wadfile->data, statbuf.st_size, 1, wadfile->handle); } //e6y #ifdef ALL_IN_ONE } #endif //jff 8/3/98 use logical output routine 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") ) ) { // single lump file fileinfo = &singleinfo; singleinfo.filepos = 0; singleinfo.size = wadfile->length; //LittleLong(I_Filelength(wadfile->handle)); ExtractFileBase(wadfile->name, singleinfo.name); numlumps++; } else { // WAD file //e6y #ifdef ALL_IN_ONE if(predefined_lump) memcpy(&header, handle, sizeof(header)); else #endif memcpy(&header, wadfile->data, sizeof(header)); // 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 = LittleLong(header.numlumps); header.infotableofs = LittleLong(header.infotableofs); length = header.numlumps*sizeof(filelump_t); fileinfo2free = fileinfo = malloc(length); // killough //e6y #ifdef ALL_IN_ONE if(predefined_lump) memcpy(fileinfo, handle + header.infotableofs, length); else #endif // lseek(wadfile->handle, header.infotableofs, SEEK_SET), // I_Read(wadfile->handle, fileinfo, length); memcpy(fileinfo, &wadfile->data[header.infotableofs], length); numlumps += header.numlumps; } // Fill in lumpinfo lumpinfo = realloc(lumpinfo, numlumps*sizeof(lumpinfo_t)); lump_p = &lumpinfo[startlump]; for (i=startlump ; (int)i<numlumps ; i++,lump_p++, fileinfo++) { lump_p->flags = 0; //e6y lump_p->wadfile = wadfile; // killough 4/25/98 lump_p->position = LittleLong(fileinfo->filepos); lump_p->size = LittleLong(fileinfo->size); if (wadfile->src == source_lmp) { // Modifications to place command-line-added demo lumps // into a separate "ns_demos" namespace so that they cannot // conflict with other lump names lump_p->li_namespace = ns_demos; } else { lump_p->li_namespace = ns_global; // killough 4/17/98 } strncpy (lump_p->name, fileinfo->name, 8); lump_p->source = wadfile->src; // Ty 08/29/98 } free(fileinfo2free); // killough }
// // 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 static void W_AddFile(wadfile_info_t *wadfile) // killough 1/31/98: static, const { wadinfo_t header; lumpinfo_t* lump_p; unsigned i; int length; int startlump; filelump_t *fileinfo, *fileinfo2free=NULL; //killough filelump_t singleinfo; int flags = 0; // open the file and add to directory wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY); #ifdef HAVE_NET if (wadfile->handle == -1 && D_NetGetWad(wadfile->name)) // CPhipps wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY); #endif if (wadfile->handle == -1 && strlen(wadfile->name) > 4 && wadfile->src == source_pwad && !strcasecmp(wadfile->name + strlen(wadfile->name) - 4 , ".wad") && D_TryGetWad(wadfile->name)) { wadfile->handle = open(wadfile->name, O_RDONLY | O_BINARY); } if (wadfile->handle == -1) { if ( strlen(wadfile->name)<=4 || // add error check -- killough (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; } //jff 8/3/98 use logical output routine lprintf (LO_INFO," adding %s\n",wadfile->name); startlump = numlumps; // mark lumps from internal resource if (wadfile->src == source_auto_load) { int len = strlen(PACKAGE_TARNAME ".wad"); int len_file = strlen(wadfile->name); if (len_file >= len) { if (!strcasecmp(wadfile->name + len_file - len, PACKAGE_TARNAME ".wad")) { flags = LUMP_PRBOOM; } } } if ( strlen(wadfile->name)<=4 || ( strcasecmp(wadfile->name+strlen(wadfile->name)-4,".wad") && strcasecmp(wadfile->name+strlen(wadfile->name)-4,".gwa") ) ) { // single lump file fileinfo = &singleinfo; singleinfo.filepos = 0; singleinfo.size = LittleLong(I_Filelength(wadfile->handle)); ExtractFileBase(wadfile->name, singleinfo.name); numlumps++; } else { // WAD file 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 = LittleLong(header.numlumps); header.infotableofs = LittleLong(header.infotableofs); length = header.numlumps*sizeof(filelump_t); fileinfo2free = fileinfo = malloc(length); // killough lseek(wadfile->handle, header.infotableofs, SEEK_SET), I_Read(wadfile->handle, fileinfo, length); numlumps += header.numlumps; } // Fill in lumpinfo lumpinfo = realloc(lumpinfo, numlumps*sizeof(lumpinfo_t)); lump_p = &lumpinfo[startlump]; for (i=startlump ; (int)i<numlumps ; i++,lump_p++, fileinfo++) { lump_p->flags = flags; lump_p->wadfile = wadfile; // killough 4/25/98 lump_p->position = LittleLong(fileinfo->filepos); lump_p->size = LittleLong(fileinfo->size); if (wadfile->src == source_lmp) { // Modifications to place command-line-added demo lumps // into a separate "ns_demos" namespace so that they cannot // conflict with other lump names lump_p->li_namespace = ns_demos; } else { lump_p->li_namespace = ns_global; // killough 4/17/98 } strncpy (lump_p->name, fileinfo->name, 8); lump_p->source = wadfile->src; // Ty 08/29/98 // IWAD file used as recource PWAD must not override TEXTURE1 or PNAMES if (wadfile->src != source_iwad && !strncmp(header.identification,"IWAD",4) && (!strnicmp(fileinfo->name,"TEXTURE1",8) || !strnicmp(fileinfo->name,"PNAMES",6))) { strncpy (lump_p->name, "-IGNORE-", 8); } } free(fileinfo2free); // killough }