home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / CPRINTF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  3.5 KB  |  138 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - cprintf.c
  3.  *
  4.  * function(s)
  5.  *      __cputn - character output function
  6.  *      cprintf - sends formatted output to the console
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*[]------------------------------------------------------------[]*/
  10. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #include <conio.h>
  20.  
  21. extern unsigned _wscroll;
  22.  
  23. #include <stdarg.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <dos.h>
  27. #include <_printf.h>
  28. #include <_video.h>
  29. #define BELL        '\a'
  30. #define BACKSPACE    '\b'
  31. #define LINEFEED    '\n'
  32. #define CR        '\r'
  33.  
  34.  
  35. /*---------------------------------------------------------------------*
  36.  
  37. Name        __cputn - character output function
  38.  
  39. Description    prints a string of n chars on the screen
  40.  
  41. Return value    returns last character printed
  42.  
  43. Note        template must match putnF typedef from _printf.h
  44.  
  45. *------------------------------------------------------------------------*/
  46. #pragma argsused
  47. unsigned pascal near __cputn(const void *s, unsigned n, void *dontCare)
  48. {
  49.     int col, row;
  50.     unsigned char c = 0;
  51.     unsigned int videochar;
  52.  
  53.     col = _wherex();
  54.     row = _wherey();
  55.  
  56.   while (n--) {
  57.     switch (c = *(((char*)s)++)) {
  58.     case BELL :
  59.       _AH = V_WR_TTY;
  60.       _AL = BELL;
  61.       _VideoInt();
  62.       break;
  63.     case BACKSPACE :
  64.       if (col > _video.windowx1)
  65.     col--;
  66.       break;
  67.     case CR :
  68.       col = _video.windowx1;
  69.       break;
  70.     case LINEFEED :
  71.       ++row;
  72.       break;
  73.     default :
  74.       if (!_video.graphicsmode && directvideo) {
  75.     _AH = _video.attribute;
  76.     _AL = c;
  77.     videochar = _AX;
  78.     __vram(__vptr(col+1,row+1), &videochar, 1);
  79.       }
  80.       else {
  81.     _DL = col;
  82.     _DH = row;
  83.     _AH = V_SET_CURSOR_POS;
  84.     _BH = 0;
  85.     _VideoInt();
  86.     _BL = _video.attribute;
  87.     _AL = c;
  88.     _AH = V_WR_CHAR_ATTR;
  89.     _BH = 0;
  90.     _CX = 1;
  91.     _VideoInt();
  92.       }
  93.       col++;
  94.       break;
  95.     } /* end switch */
  96.  
  97.     if (col > _video.windowx2) {    /* line wrap? */
  98.       col = _video.windowx1;
  99.       row += _wscroll;
  100.     }
  101.     if (row > _video.windowy2) { /* screen wrap? */
  102.     __scroll(UP, _video.windowx1, _video.windowy1,
  103.     _video.windowx2, _video.windowy2, 1);
  104.     row--;
  105.     }
  106.   } /* end while */
  107.  
  108.   _DL = col;
  109.   _DH = row;
  110.   _AH = V_SET_CURSOR_POS;
  111.   _BH = 0;
  112.   _VideoInt();
  113.   return c;
  114. } /* cputn */
  115.  
  116.  
  117. /*---------------------------------------------------------------------*
  118.  
  119. Name        cprintf - sends formatted output to the console
  120.  
  121. Usage        int cprintf(char *format [,argument, ...]);
  122.  
  123. Prototype in    conio.h
  124.  
  125. Description    member of the printf family.  cprintf send its output
  126.         directly to the console.  It does not translate linefeed
  127.         characters into CR/LF combinations.
  128.  
  129. Return value    success : the number of bytes output.
  130.         error : EOF
  131.  
  132. *------------------------------------------------------------------------*/
  133. int    cdecl cprintf(const char *fmt, ...)
  134. {
  135.   return  __vprinter (__cputn, 0, fmt, (void _ss *) _va_ptr);
  136. }
  137.  
  138.