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