home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff256.lzh / Stevie / format_l.c < prev    next >
C/C++ Source or Header  |  1989-10-19  |  1KB  |  84 lines

  1. /*
  2.  * format_line() 
  3.  *
  4.  * Return a pointer to a string buffer containing a formated screen line.
  5.  *
  6.  * By G. R. (Fred) Walter    watmath!grwalter 
  7.  */
  8.  
  9. #include "stevie.h"
  10.  
  11. char           *tab_expand = "                ";
  12.  
  13. char           *
  14. format_line(ptr, len)
  15.     register char  *ptr;
  16.     int            *len;
  17. {
  18.     register char  *dest;
  19.     register char   c;
  20.     register int    col;
  21.     char           *p_extra;
  22.     int             n_extra;
  23.     int             coff;    /* column offset */
  24.  
  25.     dest = IObuff;
  26.     col = 0;
  27.  
  28.     coff = P(P_NU) ? 8 : 0;
  29.  
  30.     n_extra = 0;
  31.     p_extra = NULL;
  32.  
  33.     for (;;) {
  34.     if (n_extra > 0) {
  35.         c = *p_extra++;
  36.         n_extra--;
  37.     } else {
  38.         c = *ptr++;
  39.         while (c >= 32 && c < 127) {
  40.         *dest++ = c;
  41.         col++;
  42.         if (col >= IOSIZE)
  43.             goto DONE_FORMAT_LINE;
  44.         c = *ptr++;
  45.         }
  46.         if (!P(P_LS)) {
  47.         if (c == TAB) {
  48.             /* tab amount depends on current column */
  49.             p_extra = tab_expand;
  50.             n_extra = (P(P_TS) - 1) - (col - coff) % P(P_TS);
  51.             c = ' ';
  52.             goto I_HATE_GOTOS;
  53.         } else if (c == NUL) {
  54.             break;
  55.         }
  56.         } else if (c == NUL) {
  57.         *dest++ = '$';
  58.         col++;
  59.         break;
  60.         }
  61.         if ((n_extra = chars[c].ch_size - 1) > 0) {
  62.         p_extra = chars[c].ch_str;
  63.         c = *p_extra++;
  64.         }
  65.     }
  66. I_HATE_GOTOS:
  67.     *dest++ = c;
  68.     col++;
  69.     if (col >= IOSIZE)
  70.         break;
  71.     }
  72. DONE_FORMAT_LINE:
  73.     if (col >= IOSIZE) {
  74.     dest--;
  75.     col--;
  76.     }
  77.     *dest = NUL;
  78.  
  79.     if (len != NULL)
  80.     *len = col + coff;
  81.  
  82.     return (IObuff);
  83. }
  84.