home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / UNGETC.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.2 KB  |  78 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - ungetc.cas
  3.  *
  4.  * function(s)
  5.  *        ungetc - pushes a character back into input stream
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <stdio.h>
  19. #include <asmrules.h>
  20.  
  21. #undef  ungetc                /* remove macro version */
  22.  
  23. /*---------------------------------------------------------------------*
  24.  
  25. Name            ungetc - pushes a character back into input stream
  26.  
  27. Usage           #include <stdio.h>
  28.                 int ungetc(int c, FILE *stream);
  29.  
  30. Prototype in    stdio.h
  31.  
  32. Description     pushes the character c back onto the named input stream.
  33.                 This character will be returned on the next call to getc
  34.                 or fread for that stream.  One character may be pushed
  35.                 back in all situations.  A second call to ungetc without
  36.                 a call to getc will force the previous character to be
  37.                 forgotten.  fseek erases all memory of a pushed-back
  38.                 character.
  39.  
  40. Return value    returns the character c if it is successful.  A value of
  41.                 EOF indicates an error.
  42.  
  43. *---------------------------------------------------------------------*/
  44. asm _TEXT       segment public 'CODE'
  45. asm             public __Nungetc
  46. asm __Nungetc   label near
  47.  
  48. #if LPROG
  49. asm             pop     ax
  50. asm             push    cs
  51. asm             push    ax
  52. #endif
  53. asm             ends
  54.  
  55. int _FARFUNC ungetc( int c, FILE *fp )
  56.   {
  57.   if( c != EOF )
  58.     {
  59.     if( fp->level < 0 )  return( EOF );    /* file is not in input mode */
  60.  
  61.     fp->flags &= ~_F_EOF;                  /* clear EOF flag */
  62.  
  63.     if( ++(fp->level) > 1 )                /* store in file buffer */
  64.       {
  65.       return( (unsigned char)(*--(fp->curp) = c) );
  66.       }
  67.     else                                   /* buf was empty, use hold   */
  68.       {
  69.       fp->curp = &fp->hold;
  70.       return( (unsigned char)(fp->hold = c) );
  71.       }
  72.     }
  73.   else
  74.     {
  75.     return( c );
  76.     }
  77.   }
  78.