components/prboom/d_deh.c
// ====================================================================
// deh_procText
// Purpose: Handle DEH Text block
// Notes:   We look things up in the current information and if found
//          we replace it.  At the same time we write the new and
//          improved BEX syntax to the log file for future use.
// Args:    fpin  -- input file stream
//          fpout -- output file stream (DEHOUT.TXT)
//          line  -- current line in file to process
// Returns: void
//
deh_procText
Purpose: Handle DEH Text block
Notes:   We look things up in the current information and if found
we replace it.  At the same time we write the new and
improved BEX syntax to the log file for future use.
deh_procText Purpose : Handle DEH Text block Notes : We look things up in the current information and if found we replace it . At the same time we write the new and improved BEX syntax to the log file for future use .
static void deh_procText(DEHFILE *fpin, FILE* fpout, char *line)
{
  char key[DEH_MAXKEYLEN];
  char inbuffer[DEH_BUFFERMAX*2];  
  int i; 
  int fromlen, tolen;  
  int usedlen;  
  boolean found = FALSE;  
  char* line2 = NULL;   
  if (includenotext) 
    {
      if (fpout) fprintf(fpout,
                         "Skipped text block because of notext directive\n");
      strcpy(inbuffer,line);
      while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
        dehfgets(inbuffer, sizeof(inbuffer), fpin);  
      return; 
    }
  sscanf(line,"%s %i %i",key,&fromlen,&tolen);
  if (fpout) fprintf(fpout,
                     "Processing Text (key=%s, from=%d, to=%d)\n",
                     key, fromlen, tolen);
  {
    int c, totlen = 0;
    while (totlen < fromlen + tolen && (c = dehfgetc(fpin)) != EOF)
      if (c != '\r')
	inbuffer[totlen++] = c;
    inbuffer[totlen]='\0';
  }
  if (fromlen==4 && tolen==4)
    {
      i=0;
      while (sprnames[i])  
        {                                                      
          if (!strnicmp(sprnames[i],inbuffer,fromlen))         
            {
              if (fpout) fprintf(fpout,
                                 "Changing name of sprite at index %d from %s to %*s\n",
                                 i,sprnames[i],tolen,&inbuffer[fromlen]);
        {
    char *s;
    sprnames[i] = s = strdup(sprnames[i]);
    strncpy(s,&inbuffer[fromlen],tolen);
        }
              found = TRUE;
              break;  
            }
          ++i;  
        }
    }
  else
    if (fromlen < 7 && tolen < 7)  
      {
        usedlen = (fromlen < tolen) ? fromlen : tolen;
        if (fromlen != tolen)
          if (fpout) fprintf(fpout,
                             "Warning: Mismatched lengths from=%d, to=%d, used %d\n",
                             fromlen, tolen, usedlen);
        for (i=1; i<NUMSFX; i++)
          {
            if (strlen(S_sfx[i].name) != (size_t)fromlen) continue;
            if (!strnicmp(S_sfx[i].name,inbuffer,fromlen))
              {
                if (fpout) fprintf(fpout,
                                   "Changing name of sfx from %s to %*s\n",
                                   S_sfx[i].name,usedlen,&inbuffer[fromlen]);
                S_sfx[i].name = strdup(&inbuffer[fromlen]);
                found = TRUE;
                break;  
              }
          }
        if (!found)  
          {
            for (i=1; i<NUMMUSIC; i++)
              {
                if (strlen(S_music[i].name) != (size_t)fromlen) continue;
                if (!strnicmp(S_music[i].name,inbuffer,fromlen))
                  {
                    if (fpout) fprintf(fpout,
                                       "Changing name of music from %s to %*s\n",
                                       S_music[i].name,usedlen,&inbuffer[fromlen]);
                    S_music[i].name = strdup(&inbuffer[fromlen]);
                    found = TRUE;
                    break;  
                  }
              }
          }  
      }
  if (!found) 
    {
      if (fpout) fprintf(fpout,"Checking text area through strings for '%.12s%s' from=%d to=%d\n",inbuffer, (strlen(inbuffer) > 12) ? "..." : "",fromlen,tolen);
      if ((size_t)fromlen <= strlen(inbuffer))
        {
          line2 = strdup(&inbuffer[fromlen]);
          inbuffer[fromlen] = '\0';
        }
      deh_procStringSub(NULL, inbuffer, line2, fpout);
    }
  free(line2); 
  return;
}
static void deh_procText ( DEHFILE * fpin , FILE * fpout , char * line ) { char key [ DEH_MAXKEYLEN ] ; char inbuffer [ DEH_BUFFERMAX * 2 ] ; int i ; int fromlen , tolen ; int usedlen ; boolean found = FALSE ; char * line2 = NULL ; if ( includenotext ) { if ( fpout ) fprintf ( fpout , " \n " ) ; strcpy ( inbuffer , line ) ; while ( ! dehfeof ( fpin ) && * inbuffer && ( * inbuffer != ' ' ) ) dehfgets ( inbuffer , sizeof ( inbuffer ) , fpin ) ; return ; } sscanf ( line , " " , key , & fromlen , & tolen ) ; if ( fpout ) fprintf ( fpout , " \n " , key , fromlen , tolen ) ; { int c , totlen = 0 ; while ( totlen < fromlen + tolen && ( c = dehfgetc ( fpin ) ) != EOF ) if ( c != ' \r ' ) inbuffer [ totlen ++ ] = c ; inbuffer [ totlen ] = ' \0 ' ; } if ( fromlen == 4 && tolen == 4 ) { i = 0 ; while ( sprnames [ i ] ) { if ( ! strnicmp ( sprnames [ i ] , inbuffer , fromlen ) ) { if ( fpout ) fprintf ( fpout , " \n " , i , sprnames [ i ] , tolen , & inbuffer [ fromlen ] ) ; { char * s ; sprnames [ i ] = s = strdup ( sprnames [ i ] ) ; strncpy ( s , & inbuffer [ fromlen ] , tolen ) ; } found = TRUE ; break ; } ++ i ; } } else if ( fromlen < 7 && tolen < 7 ) { usedlen = ( fromlen < tolen ) ? fromlen : tolen ; if ( fromlen != tolen ) if ( fpout ) fprintf ( fpout , " \n " , fromlen , tolen , usedlen ) ; for ( i = 1 ; i < NUMSFX ; i ++ ) { if ( strlen ( S_sfx [ i ] . name ) != ( size_t ) fromlen ) continue ; if ( ! strnicmp ( S_sfx [ i ] . name , inbuffer , fromlen ) ) { if ( fpout ) fprintf ( fpout , " \n " , S_sfx [ i ] . name , usedlen , & inbuffer [ fromlen ] ) ; S_sfx [ i ] . name = strdup ( & inbuffer [ fromlen ] ) ; found = TRUE ; break ; } } if ( ! found ) { for ( i = 1 ; i < NUMMUSIC ; i ++ ) { if ( strlen ( S_music [ i ] . name ) != ( size_t ) fromlen ) continue ; if ( ! strnicmp ( S_music [ i ] . name , inbuffer , fromlen ) ) { if ( fpout ) fprintf ( fpout , " \n " , S_music [ i ] . name , usedlen , & inbuffer [ fromlen ] ) ; S_music [ i ] . name = strdup ( & inbuffer [ fromlen ] ) ; found = TRUE ; break ; } } } } if ( ! found ) { if ( fpout ) fprintf ( fpout , " \n " , inbuffer , ( strlen ( inbuffer ) > 12 ) ? " " : " " , fromlen , tolen ) ; if ( ( size_t ) fromlen <= strlen ( inbuffer ) ) { line2 = strdup ( & inbuffer [ fromlen ] ) ; inbuffer [ fromlen ] = ' \0 ' ; } deh_procStringSub ( NULL , inbuffer , line2 , fpout ) ; } free ( line2 ) ; return ; }
deh_procText
Purpose: Handle DEH Text block
Notes:   We look things up in the current information and if found
we replace it.
deh_procText Purpose : Handle DEH Text block Notes : We look things up in the current information and if found we replace it .
// can't use line -- double size buffer too. // loop variable // as specified on the text block line // shorter of fromlen and tolen if not matched // to allow early exit once found // duplicate line for rerouting // Ty 04/11/98 - Included file may have NOTEXT skip flag set // flag to skip included deh-style text // skip block // Ty 05/17/98 - don't care if this fails // ************** Early return // killough 8/98: allow hex numbers in input: // killough 10/98: fix incorrect usage of feof // if the from and to are 4, this may be a sprite rename.  Check it // against the array and process it as such if it matches.  Remember // that the original names are (and should remain) uppercase. // Future: this will be from a separate [SPRITES] block. // null terminated list in info.c //jff 3/19/98 //check pointer //not first char // Ty 03/18/98 - not using strdup because length is fixed // killough 10/98: but it's an array of pointers, so we must // use strdup unless we redeclare sprnames and change all else // CPhipps - fix constness problem // only one will match--quit early // next array element // lengths of music and sfx are 6 or shorter // Try sound effects entries - see sounds.c // avoid short prefix erroneous match // only one matches, quit early // not yet // Try music name entries - see sounds.c // avoid short prefix erroneous match // only one matches, quit early // end !found test // Nothing we want to handle here--see if strings can deal with it. // may be NULL, ignored by free()