components/prboom/d_deh.c
// ====================================================================
// ProcessDehFile
// Purpose: Read and process a DEH or BEX file
// Args:    filename    -- name of the DEH/BEX file
//          outfilename -- output file (DEHOUT.TXT), appended to here
// Returns: void
//
// killough 10/98:
// substantially modified to allow input from wad lumps instead of .deh files.
ProcessDehFile
Purpose: Read and process a DEH or BEX file
Args:    filename    -- name of the DEH/BEX file
outfilename -- output file (DEHOUT.TXT), appended to here
Returns: void

killough 10/98:
substantially modified to allow input from wad lumps instead of .deh files.
ProcessDehFile Purpose : Read and process a DEH or BEX file Args : filename -- name of the DEH / BEX file outfilename -- output file ( DEHOUT . TXT ) appended to here Returns : void killough 10 / 98 : substantially modified to allow input from wad lumps instead of . deh files .
void ProcessDehFile(const char *filename, const char *outfilename, int lumpnum)
{
  static FILE *fileout;       
  DEHFILE infile, *filein = &infile;    
  char inbuffer[DEH_BUFFERMAX];  
  if (outfilename && *outfilename && !fileout)
    {
      static boolean firstfile = true; 
      if (!strcmp(outfilename, "-"))
        fileout = stdout;
      else
        if (0) 
          {
            lprintf(LO_WARN, "Could not open -dehout file %s\n... using stdout.\n",
                   outfilename);
            fileout = stdout;
          }
      firstfile = false;
    }
  : allow DEH files to come from wad lumps
  if (filename)
    {
		if(0) 
        {
          lprintf(LO_WARN, "-deh file %s not found\n",filename);
          return;  
        }
      infile.lump = NULL;
    }
  else  
    {
      infile.size = W_LumpLength(lumpnum);
      infile.inp = infile.lump = W_CacheLumpNum(lumpnum);
      filename = "(WAD)";
    }
  lprintf(LO_INFO, "Loading DEH file %s\n",filename);
  if (fileout) fprintf(fileout,"\nLoading DEH file %s\n\n",filename);
  while (dehfgets(inbuffer,sizeof(inbuffer),filein))
    {
      unsigned i;
      lfstrip(inbuffer);
      if (fileout) fprintf(fileout,"Line='%s'\n",inbuffer);
      if (!*inbuffer || *inbuffer == '#' || *inbuffer == ' ')
        continue; 
      : INCLUDE code rewritten to allow arbitrary nesting,
      if (!strnicmp(inbuffer,"INCLUDE",7)) 
        {
          : moved to here
          char *nextfile;
          boolean oldnotext = includenotext;       
          : exclude if inside wads (only to discourage
          if (infile.lump)
            {
              if (fileout)
                fprintf(fileout,
                        "No files may be included from wads: %s\n",inbuffer);
              continue;
            }
          if (!strnicmp(nextfile = ptr_lstrip(inbuffer+7),"NOTEXT",6))
            includenotext = true, nextfile = ptr_lstrip(nextfile+6);
          if (fileout)
            fprintf(fileout,"Branching to include file %s...\n", nextfile);
          :
          ProcessDehFile(nextfile,NULL,0); 
          includenotext = oldnotext;
          if (fileout) fprintf(fileout,"...continuing with %s\n",filename);
          continue;
        }
      for (i=0; i<DEH_BLOCKMAX; i++)
        if (!strncasecmp(inbuffer,deh_blocks[i].key,strlen(deh_blocks[i].key)))
          { 
            if (fileout)
              fprintf(fileout,"Processing function [%d] for %s\n",
                      i, deh_blocks[i].key);
            deh_blocks[i].fptr(filein,fileout,inbuffer);  
            break;  
          }
    }
  if (infile.lump)
    W_UnlockLumpNum(lumpnum);                 
  else
    fclose(infile.f);                         
  if (outfilename)   : only at top recursion level
    {
      if (fileout != stdout)
        fclose(fileout);
      fileout = NULL;
    }
}
void ProcessDehFile ( const char * filename , const char * outfilename , int lumpnum ) { static FILE * fileout ; DEHFILE infile , * filein = & infile ; char inbuffer [ DEH_BUFFERMAX ] ; if ( outfilename && * outfilename && ! fileout ) { static boolean firstfile = true ; if ( ! strcmp ( outfilename , " " ) ) fileout = stdout ; else if ( 0 ) { lprintf ( LO_WARN , " \n \n " , outfilename ) ; fileout = stdout ; } firstfile = false ; } if ( filename ) { if ( 0 ) { lprintf ( LO_WARN , " \n " , filename ) ; return ; } infile . lump = NULL ; } else { infile . size = W_LumpLength ( lumpnum ) ; infile . inp = infile . lump = W_CacheLumpNum ( lumpnum ) ; filename = " " ; } lprintf ( LO_INFO , " \n " , filename ) ; if ( fileout ) fprintf ( fileout , " \n \n \n " , filename ) ; while ( dehfgets ( inbuffer , sizeof ( inbuffer ) , filein ) ) { unsigned i ; lfstrip ( inbuffer ) ; if ( fileout ) fprintf ( fileout , " \n " , inbuffer ) ; if ( ! * inbuffer || * inbuffer == ' ' || * inbuffer == ' ' ) continue ; if ( ! strnicmp ( inbuffer , " " , 7 ) ) { char * nextfile ; boolean oldnotext = includenotext ; if ( infile . lump ) { if ( fileout ) fprintf ( fileout , " \n " , inbuffer ) ; continue ; } if ( ! strnicmp ( nextfile = ptr_lstrip ( inbuffer + 7 ) , " " , 6 ) ) includenotext = true , nextfile = ptr_lstrip ( nextfile + 6 ) ; if ( fileout ) fprintf ( fileout , " \n " , nextfile ) ; ProcessDehFile ( nextfile , NULL , 0 ) ; includenotext = oldnotext ; if ( fileout ) fprintf ( fileout , " \n " , filename ) ; continue ; } for ( i = 0 ; i < DEH_BLOCKMAX ; i ++ ) if ( ! strncasecmp ( inbuffer , deh_blocks [ i ] . key , strlen ( deh_blocks [ i ] . key ) ) ) { if ( fileout ) fprintf ( fileout , " \n " , i , deh_blocks [ i ] . key ) ; deh_blocks [ i ] . fptr ( filein , fileout , inbuffer ) ; break ; } } if ( infile . lump ) W_UnlockLumpNum ( lumpnum ) ; else fclose ( infile . f ) ; if ( outfilename ) { if ( fileout != stdout ) fclose ( fileout ) ; fileout = NULL ; } }
ProcessDehFile
Purpose: Read and process a DEH or BEX file
Args:    filename    -- name of the DEH/BEX file
outfilename -- output file (DEHOUT.TXT), appended to here
Returns: void
ProcessDehFile Purpose : Read and process a DEH or BEX file Args : filename -- name of the DEH / BEX file outfilename -- output file ( DEHOUT . TXT ) appended to here Returns : void
// In case -dehout was used // killough 10/98 // Place to put the primary infostring // Open output file if we're writing output // to allow append to output log //        if (!(fileout=fopen(outfilename, firstfile ? "wt" : "at"))) // killough 10/98: allow DEH files to come from wad lumps //if (!(infile.f = fopen(filename,"rt"))) // should be checked up front anyway // DEH file comes from lump indicated by third argument // move deh_codeptr initialisation to D_BuildBEXTables // loop until end of file /* Blank line or comment line */ // -- If DEH_BLOCKMAX is set right, the processing is independently // -- handled based on data in the deh_blocks[] structure array // killough 10/98: INCLUDE code rewritten to allow arbitrary nesting, // and to greatly simplify code, fix memory leaks, other bugs // include a file // preserve state while including a file // killough 10/98: moved to here // killough 10/98 // killough 10/98: exclude if inside wads (only to discourage // the practice, since the code could otherwise handle it) // check for no-text directive, used when including a DEH // file but using the BEX format to handle strings // killough 10/98: // Second argument must be NULL to prevent closing fileout too soon // do the included file // matches one // call function // we got one, that's enough for this block // Mark purgable // Close real file // killough 10/98: only at top recursion level