home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 05oslib / bios / putfld.c < prev    next >
Encoding:
Text File  |  1988-08-11  |  947 b   |  42 lines

  1. /*
  2.  *    putfld -- display a string in the prevailing
  3.  *    video attribute while compressing runs of a
  4.  *    single character, and pad the field to full width
  5.  *    with spaces if necessary
  6.  */
  7.  
  8. int
  9. putfld(s, w, pg)
  10. register char *s;    /* string to write */
  11. int w;            /* field width */
  12. int pg;            /* screen page for writes */
  13. {
  14.     int r, c, cols;
  15.     register int n;
  16.  
  17.     extern int putcur(int, int, int);
  18.     extern int readcur(int *, int *, int);
  19.     extern int writec(unsigned char, int, int);
  20.  
  21.     /* get starting (current) position */
  22.     readcur(&r, &c, pg);
  23.  
  24.     /* write the string */
  25.     for (n = 0; *s != '\0' && n < w; s += cols, n += cols) {
  26.         putcur(r, c + n, pg);
  27.         /* compress runs to a single call on writec() */
  28.         cols = 1;
  29.         while (*(s + cols) == *s && n + cols < w)
  30.             ++cols;
  31.         writec(*s, cols, pg);
  32.     }
  33.  
  34.     /* pad the field, if necessary */
  35.     if (n < w) {
  36.         putcur(r, c + n, pg);
  37.         writec(' ', w - n, pg);
  38.     }
  39.  
  40.     return (w - n);
  41. }
  42.