home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / PROCWRKB.ZIP / BENCH1.ZIP / WIN / MIP / WDISP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-16  |  4.4 KB  |  222 lines

  1. /* ==( mip/wdisp.c )== */
  2. /* ----------------------------------------------- */
  3. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  4. /* Modification to this source is not supported    */
  5. /* by Vestronix Inc.                               */
  6. /*            All Rights Reserved                  */
  7. /* ----------------------------------------------- */
  8. /* Written   Geo  26-Aug-88                        */
  9. /* Modified  Geo  18-Jul-90  See comments below    */
  10. /* ----------------------------------------------- */
  11. /* %W%  (%H% %T%) */
  12.  
  13. /*
  14.  *  Modifications
  15.  *
  16.  *  18-Jul-90  Geo - Overhauled
  17.  *   4-Jan-89  Geo - Added xdisp_w, fast no vararg'd disp_w
  18.  *  25-Oct-89  Geo - 1.32 Merge
  19. */
  20.  
  21. /*
  22.  * Display functions
  23.  * usually vararg'd
  24. */
  25.  
  26. # include <stdio.h>
  27. # include <bench.h>
  28.  
  29. extern char *sysbase; /* wbase.c */
  30.  
  31. /*
  32.  * Global Vararg display buffer
  33.  * Note when this is used - xdisp must be called to display
  34.  * as it in turn does not use this buffer
  35. */
  36. char vdispbuff[W_PHY_WIDTH+1];
  37.  
  38. /*
  39.  * Varags disp_w - allows printf expressions to be used into the window
  40.  * return the number of characters output
  41. */
  42. # ifdef UNIX
  43. int disp_w(row, col, attr, va_alist)
  44. int row, col, attr;
  45. va_dcl
  46. # else
  47. int CDECL disp_w(int row, int col, int attr, char *va_alist, ...)
  48. # endif
  49. {
  50.     va_list ap;
  51.     register char *fmt;
  52.  
  53. # ifdef UNIX
  54.     va_start(ap);
  55.     fmt = va_arg(ap, char *);
  56. # else
  57.     va_start(ap, va_alist);
  58.     fmt = va_alist;
  59. # endif
  60.  
  61. # ifdef WDEBUG
  62.     if (fmt == vdispbuff)
  63.         fprintf(stderr, "\r\ndisp_w(): called with target vdispbuffer\r\n");
  64. # endif
  65.  
  66.     vsprintf(vdispbuff, fmt, ap);
  67.     va_end(ap);
  68.  
  69.     /* Add to our Screen Output buffer */
  70.     for (fmt = vdispbuff; *fmt != '\0'; fmt++)
  71.     {
  72. # ifndef WDEBUG
  73.         if (fmt != vdispbuff)
  74.             ADDPOKE(attr, *fmt);
  75.         else
  76. # endif
  77.             poke_w(row, col++, attr, *fmt);
  78.     }
  79.  
  80.     /* Watcom C 70 required this cast ! - Geo */
  81.     return((int)(fmt - (char *)vdispbuff));
  82. }
  83.  
  84.  
  85. /*
  86.  * Display string but stop either at a '\0' or len characters
  87.  * Return number of characters output
  88. */
  89. int fdisp_w(row, col, attr, len, str)
  90. int row, col, attr, len;
  91. char *str;
  92. {
  93. register char *ptr = str;
  94. int i = 0;
  95.  
  96.     /* Geo -> get rid of i (use --len) */
  97.     for ( ; i < len && *ptr; i++, ptr++)
  98.     {
  99. # ifndef WDEBUG
  100.         /* First set up sysbase */
  101.         if (ptr != str)
  102.             ADDPOKE(attr, *ptr);
  103.         else
  104. # endif
  105.             poke_w(row, col++, attr, *ptr);
  106.  
  107.     }
  108.     return((int)(ptr - str));
  109. }
  110.  
  111. /*
  112.  * Display '\0' terminated string
  113.  * Return number of characters output
  114. */
  115. int xdisp_w(row, col, attr, str)
  116. int row, col, attr;
  117. char *str;
  118. {
  119. register char *ptr = str;
  120.  
  121.     for ( ; *ptr; ptr++)
  122.     {
  123. # ifndef WDEBUG
  124.         /* First set up sysbase */
  125.         if (ptr != str)
  126.             ADDPOKE(attr, *ptr);
  127.         else
  128. # endif
  129.             poke_w(row, col++, attr, *ptr);
  130.     }
  131.     return((int)(ptr - str));
  132. }
  133.  
  134. /*
  135.  * Display string and set rest of string to normal spaces
  136.  * Returns number of chars output from the string
  137.  * Requires a '\0' terminated string
  138. */
  139. # ifdef UNIX
  140. int bdisp_w(row, col, attr, cnt, va_alist)
  141. int row, col, attr, cnt;
  142. va_dcl
  143. # else
  144. int CDECL bdisp_w(int row, int col, int attr, int cnt, char *va_alist, ...)
  145. # endif
  146. {
  147.     va_list ap;
  148.     char *fmt;
  149.     int ret;
  150.  
  151. # ifdef UNIX
  152.     va_start(ap);
  153.     fmt = va_arg(ap, char *);
  154. # else
  155.     va_start(ap, va_alist);
  156.     fmt = va_alist;
  157. # endif
  158.  
  159. # ifdef WDEBUG
  160.     if (fmt == vdispbuff)
  161.         fprintf(stderr, "\r\nbdisp_w(): called with target vdispbuffer\r\n");
  162. # endif
  163.  
  164.     vsprintf(vdispbuff, fmt, ap);
  165.     va_end(ap);
  166.  
  167.     /* Add to our Screen Output buffer */
  168.     ret = fdisp_w(row, col, attr, cnt, vdispbuff);
  169.     rephoriz_w(row, col + ret, NORMAL, cnt - ret, ' ');
  170.  
  171.     return(ret);
  172. }
  173.  
  174. /*
  175.  * Display string and pad to cnt characters
  176.  * Will always output cnt characters
  177. */
  178. int ndisp_w(row, col, attr, cnt, str)
  179. int row, col, attr, cnt;
  180. char *str;
  181. {
  182. int ret;
  183.  
  184.     ret = fdisp_w(row, col, attr, cnt, str);
  185.     rephoriz_w(row, col + ret, attr, cnt - ret, ' ');
  186.  
  187.     return(cnt);
  188. }
  189.  
  190. /*
  191.  * Centres a text string within a given width
  192. */
  193. # ifdef UNIX
  194. int center_w(row, col, attr, width, va_alist)
  195. int row, col, attr, width;
  196. va_dcl
  197. # else
  198. int CDECL center_w(int row, int col, int attr, int width, char *va_alist, ...)
  199. # endif
  200. {
  201.     va_list ap;
  202.     char *fmt;
  203.  
  204. # ifdef UNIX
  205.     va_start(ap);
  206.     fmt = va_arg(ap, char *);
  207. # else
  208.     va_start(ap, va_alist);
  209.     fmt = va_alist;
  210. # endif
  211.  
  212.     vsprintf(vdispbuff, fmt, ap);
  213.     va_end(ap);
  214.  
  215.     col += (width - strlen(vdispbuff)) >> 1;
  216.  
  217.     xdisp_w(row, col, attr, vdispbuff);
  218.  
  219.     return(width);
  220. }
  221.  
  222.