components/prboom/d_deh.c
// killough 10/98: emulate IO whether input really comes from a file or not
killough 10/98: emulate IO whether input really comes from a file or not
killough 10 / 98 : emulate IO whether input really comes from a file or not
static char *dehfgets(char *buf, size_t n, DEHFILE *fp)
{
  if (!fp->lump)                                     
    return (fgets)(buf, n, fp->f);                   
  if (!n || !*fp->inp || fp->size<=0)                
    return NULL;
  if (n==1)
    fp->size--, *buf = *fp->inp++;
  else
    {                                                
      char *p = buf;
      while (n>1 && *fp->inp && fp->size &&
             (n--, fp->size--, *p++ = *fp->inp++) != '\n')
        ;
      *p = 0;
    }
  return buf;                                        
}
static char * dehfgets ( char * buf , size_t n , DEHFILE * fp ) { if ( ! fp -> lump ) return ( fgets ) ( buf , n , fp -> f ) ; if ( ! n || ! * fp -> inp || fp -> size <= 0 ) return NULL ; if ( n == 1 ) fp -> size -- , * buf = * fp -> inp ++ ; else { char * p = buf ; while ( n > 1 && * fp -> inp && fp -> size && ( n -- , fp -> size -- , * p ++ = * fp -> inp ++ ) != ' \n ' ) ; * p = 0 ; } return buf ; }
killough 10/98: emulate IO whether input really comes from a file or not
killough 10 / 98 : emulate IO whether input really comes from a file or not
// If this is a real file, // return regular fgets // If no more characters // copy buffer // Return buffer pointer