home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / PRINT / DISPP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-28  |  3.8 KB  |  177 lines

  1. /***( disp.c )******************************************************************
  2. *                                                                              *
  3. *  Written: Brent Faulkner - June 15, 1989                                     *
  4. *  Updated: Brent Faulkner - June 15, 1989                                     *
  5. *                                                                              *
  6. ********************************************************************************
  7. *                                                                              *
  8. * Contents:     bdisp_p() - buffer a printf type format on the current page    *
  9. *                           and pad it with spaces                             *
  10. *              center_p() - buffer a 
  11. *                disp_p() - buffer a printf type format on the current page    *
  12. *               fdisp_p() - buffer a field on the current page                 *
  13. *                                                                              *
  14. *******************************************************************************/
  15. /* include files */
  16. #include <stdio.h>
  17. #include <bench.h>
  18. #include "prt.h"
  19.  
  20. /*
  21.  * Put a printf type format into the page buffer
  22.  * and pad it with spaces.
  23. */
  24. #ifdef ANSI
  25. int bdisp_p(int line, int col, int attr, int cnt, char *va_alist, ...)
  26. #else
  27. int bdisp_p(line, col, attr, cnt, va_alist)
  28. int line;
  29. int col;
  30. int attr;
  31. int cnt;
  32. va_dcl
  33. #endif
  34. {
  35.     va_list ap;
  36.     char *fmt;
  37.     int ret;
  38.  
  39. #ifdef ANSI
  40.     va_start(ap, va_alist);
  41.     fmt = va_alist;
  42. #else
  43.     va_start(ap);
  44.     fmt = va_arg(ap, char *);
  45. #endif
  46.  
  47.     vsprintf(vprtbuff, fmt, ap);
  48.     va_end(ap);
  49.  
  50.     ret = fdisp_p(line, col, attr, cnt, vprtbuff);
  51.     rephoriz_p(line, col + ret, P_NORMAL, cnt - ret, ' ');
  52.  
  53.     return(ret);
  54. }
  55.  
  56. /*
  57.  * Put a printf type string into the buffer centred in a given width
  58. */
  59. #ifdef ANSI
  60. int center_p(int line, int col, int attr, int width, char *va_alist, ...)
  61. #else
  62. int center_p(line, col, attr, width, va_alist)
  63. int line;
  64. int col;
  65. int attr;
  66. int width;
  67. va_dcl
  68. #endif
  69. {
  70.     va_list ap;
  71.     char *fmt;
  72.     int len;
  73.  
  74. #ifdef ANSI
  75.     va_start(ap, va_alist);
  76.     fmt = va_alist;
  77. #else
  78.     va_start(ap);
  79.     fmt = va_arg(ap, char *);
  80. #endif
  81.  
  82.     vsprintf(vprtbuff, fmt, ap);
  83.     va_end(ap);
  84.  
  85.     len = strlen(vprtbuff);
  86.  
  87.     col += (width - len) / 2;
  88.  
  89.     col += fdisp_p(line, col, attr, len, vprtbuff);
  90.  
  91.     return(width);
  92. }
  93.  
  94. /*
  95.  * Put a printf type format into the page buffer
  96. */
  97. #ifdef ANSI
  98. int disp_p(int line, int col, int attr, char *va_alist, ...)
  99. #else
  100. int disp_p(line, col, attr, va_alist)
  101. int line;
  102. int col;
  103. int attr;
  104. va_dcl
  105. #endif
  106. {
  107.     va_list ap;
  108.     char *fmt;
  109.  
  110. #ifdef ANSI
  111.     va_start(ap, va_alist);
  112.     fmt = va_alist;
  113. #else
  114.     va_start(ap);
  115.     fmt = va_arg(ap, char *);
  116. #endif
  117.  
  118.     vsprintf(vprtbuff, fmt, ap);
  119.     va_end(ap);
  120.  
  121.     for(fmt = vprtbuff; *fmt != '\0'; fmt++)
  122.         poke_p(line, col++, attr, *fmt);
  123.  
  124.     return((int)(fmt - vprtbuff));
  125. }
  126.  
  127. /*
  128.  * Put a string into the page buffer but stop at a '\0' or len characters
  129.  * Return number of characters output
  130. */
  131. int xdisp_p(line, col, attr, str)
  132. int line;
  133. int col;
  134. int attr;
  135. char *str;
  136. {
  137.     fdisp_p(line, col, attr, strlen(str), str);
  138. }
  139.  
  140. /*
  141.  * Put a string into the page buffer but stop at a '\0' or len characters
  142.  * Return number of characters output
  143. */
  144. int fdisp_p(line, col, attr, len, str)
  145. int line;
  146. int col;
  147. int attr;
  148. int len;
  149. char *str;
  150. {
  151.     int i;
  152.     char *ptr = str;
  153.  
  154.     for(i = 0; i < len && *str; i++)
  155.         poke_p(line, col + i, attr, *str++);
  156.  
  157.     return((int)(str - ptr));
  158. }
  159.  
  160. /*
  161.  * Put a string into the current page buffer and pad it to a given width
  162. */
  163. int ndisp_p(line, col, attr, cnt, str)
  164. int line;
  165. int col;
  166. int attr;
  167. int cnt;
  168. char *str;
  169. {
  170.     int ret;
  171.     
  172.     ret = fdisp_p(line, col, attr, cnt, str);
  173.     rephoriz_p(line, col + ret, attr, cnt - ret, ' ');
  174.  
  175.     return(cnt);
  176. }
  177.