home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / UNGETC.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.5 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. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18. #pragma inline
  19. #include <stdio.h>
  20. #include <asmrules.h>
  21.  
  22. #undef    ungetc                /* remove macro version */
  23.  
  24. /*---------------------------------------------------------------------*
  25.  
  26. Name        ungetc - pushes a character back into input stream
  27.  
  28. Usage        #include <stdio.h>
  29.         int ungetc(int c, FILE *stream);
  30.  
  31. Prototype in    stdio.h
  32.  
  33. Description    pushes the character c back onto the named input stream.
  34.         This character will be returned on the next call to getc
  35.         or fread for that stream.  One character may be pushed
  36.         back in all situations.  A second call to ungetc without
  37.         a call to getc will force the previous character to be
  38.         forgotten.  fseek erases all memory of a pushed-back
  39.         character.
  40.  
  41. Return value    returns the character c if it is successful.  A value of
  42.         EOF indicates an error.
  43.  
  44. *---------------------------------------------------------------------*/
  45. asm _TEXT    segment byte public 'CODE'
  46. asm         public __Nungetc
  47. asm __Nungetc    label near
  48. #if LPROG
  49. asm        pop    ax
  50. asm        push    cs
  51. asm        push    ax
  52. #endif
  53. asm        ends
  54.  
  55. int 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.