home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 100-199 / ff197.lzh / Stevie / updateNs.c < prev    next >
C/C++ Source or Header  |  1989-03-28  |  7KB  |  296 lines

  1. /*
  2.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  3.  *
  4.  * Code Contributions By : Tim Thompson           twitch!tjt
  5.  *                         Tony Andrews           onecom!wldrdg!tony 
  6.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  7.  */
  8.  
  9. #include "stevie.h"
  10.  
  11. /*
  12.  * updateNextscreen() 
  13.  *
  14.  * Based on the current value of Topchar, transfer a screenfull of stuff from
  15.  * Filemem to Nextscreen, and update Botchar. 
  16.  */
  17.  
  18. void
  19. updateNextscreen(type)
  20.     int             type;
  21. {
  22.     register char  *ptr;
  23.     register char   c;
  24.     register int    row;
  25.     register int    col;
  26.     register char  *screenp;
  27.     register char  *endscreen;
  28.     register char  *nextrow;
  29.     LPtr            start;
  30.     LINE           *memp;
  31.     LINE           *save;    /* save pos. in case line won't fit */
  32.     char            extra[16];
  33.     char           *p_extra;
  34.     int             n_extra;
  35.     bool_t          done;    /* if TRUE, we hit the end of the file */
  36.     bool_t          didline;    /* if TRUE, we finished the last line */
  37.     int             srow;    /* starting row of the current line */
  38.     int             lno;    /* number of the line we're doing */
  39.     int             coff;    /* column offset */
  40.     int             idx;
  41.     int             i;
  42.     int             j;
  43.     char            lines;
  44.  
  45.     if (NumLineSizes == 0)
  46.     type = NOT_VALID;
  47.  
  48.     MustRedrawLine = FALSE;
  49.     MustRedrawScreen = TRUE;
  50.  
  51.     idx = 0;
  52.     row = 0;
  53.     start.linep = Topchar->linep;
  54.     screenp = Nextscreen;
  55.  
  56.     /* The number of rows shown is Rows-1. */
  57.     /* The last line is the status/command line. */
  58.     endscreen = Nextscreen + (Rows - 1) * Columns;
  59.  
  60.     if ((type == VALID) || (type == VALID_TO_CURSCHAR)) {
  61.     j = -1;
  62.     for (i = 0; i < NumLineSizes; i++) {
  63.         if (LinePointers[i] == Topchar->linep) {
  64.         j = i;
  65.         break;
  66.         }
  67.         row += LineSizes[i];
  68.     }
  69.     if (j == -1) {
  70.         /* Are we off the top of the screen by one line ? */
  71.         if (Topchar->linep->next == LinePointers[0]) {
  72.         i = plines(Topchar);
  73.         if (i < (Rows - 1)) {
  74.             screenp = endscreen - (i * Columns);
  75.         
  76.             while (screenp > Nextscreen)
  77.                 *(--endscreen) = *(--screenp);
  78.  
  79.             endscreen = Nextscreen + (i * Columns);
  80.  
  81.             for(idx = NumLineSizes;  idx > 0;  idx--) {
  82.             LinePointers[idx] = LinePointers[idx - 1];
  83.             LineSizes[idx] = LineSizes[idx - 1];
  84.             }
  85.             LineSizes[idx] = i;
  86.         }
  87.         }
  88.         row = 0;
  89.     } else if (j == 0 && type == VALID) {
  90.         return;
  91.     } else {
  92.         nextrow = Nextscreen + row * Columns;
  93.         row = 0;
  94.         for (;;) {
  95.         LineSizes[idx] = LineSizes[j];
  96.         LinePointers[idx] = LinePointers[j];
  97.  
  98.         if (type == VALID_TO_CURSCHAR) {
  99.             if (LinePointers[idx]->next == Curschar->linep) {
  100.             break;
  101.             }
  102.         }
  103.         j++;
  104.         if (j >= NumLineSizes)
  105.             break;
  106.  
  107.         row += LineSizes[idx];
  108.         idx++;
  109.         }
  110.         start.linep = LinePointers[idx];
  111.  
  112.         endscreen = nextrow + row * Columns;
  113.         while (nextrow < endscreen)
  114.         *screenp++ = *nextrow++;
  115.             endscreen = Nextscreen + (Rows - 1) * Columns;
  116.     }
  117.     }
  118.  
  119.     srow = row;
  120.     save = memp = start.linep;
  121.  
  122.     coff = P(P_NU) ? 8 : 0;
  123.  
  124.     if (P(P_NU))
  125.     lno = cntllines(Filemem, &start);
  126.  
  127.     done = didline = FALSE;
  128.     col = 0;
  129.     lines = 1;
  130.  
  131.     LinePointers[idx] = memp;
  132.  
  133.     p_extra = NULL;
  134.     n_extra = 0;
  135.     if (P(P_NU)) {
  136.     strcpy(extra, mkline(lno++));
  137.     p_extra = extra;
  138.     n_extra = 8;
  139.     }
  140.     ptr = memp->s;
  141.  
  142.     /*
  143.      * We go one past the end of the screen so we can find out if the last
  144.      * line fit on the screen or not. 
  145.      */
  146.     while (screenp <= endscreen) {
  147.  
  148.     /* Get the next character to put on the screen. */
  149.  
  150.     /*
  151.      * The 'extra' array contains the extra stuff that is inserted to
  152.      * represent special characters (tabs, and other non-printable stuff. 
  153.      */
  154.  
  155.     if (n_extra > 0) {
  156.         c = *p_extra++;
  157.         n_extra--;
  158.     } else {
  159.         c = *ptr++;
  160.         if (c < 32 || c > 127) {
  161.             if (c == NUL) {
  162.             srow = ++row;
  163.             /*
  164.              * Save this position in case the next line won't fit on the
  165.              * screen completely. 
  166.              */
  167.             save = memp;
  168.             if (memp->next != Fileend->linep) {
  169.                 memp = memp->next;
  170.                 ptr = memp->s;
  171.             } else {
  172.                 done = TRUE;
  173.             }
  174.             if (P(P_LS)) {
  175.                 *screenp++ = '$';
  176.                 if (screenp > endscreen)
  177.                 break;
  178.                 col++;
  179.                 if (col >= Columns) {
  180.                 row++;
  181.                 lines++;
  182.                 }
  183.             }
  184.  
  185.             LineSizes[idx++] = lines;
  186.             lines = 1;
  187.             LinePointers[idx] = memp;
  188.             if (P(P_NU)) {
  189.                 strcpy(extra, mkline(lno++));
  190.                 p_extra = extra;
  191.                 n_extra = 8;
  192.             }
  193.             /* blank out the rest of this row */
  194.             nextrow = Nextscreen + (row * Columns);
  195.             while (screenp < nextrow)
  196.                 *screenp++ = ' ';
  197.  
  198.             if (done)
  199.                 break;
  200.  
  201.             if (screenp == endscreen) {
  202.             didline = TRUE;
  203.             break;
  204.             } else if (screenp > endscreen) {
  205.             idx--;
  206.             break;
  207.             }
  208.  
  209.             col = 0;
  210.             continue;
  211.             } else if (c == TAB) {
  212.                 if (!P(P_LS)) {
  213.                 strcpy(extra, "               ");
  214.                 p_extra = extra;
  215.                 /* tab amount depends on current column */
  216.                 n_extra = ((P(P_TS) - 1) - (col - coff) % P(P_TS));
  217.                 c = ' ';
  218.             }
  219.         } else if ((n_extra = chars[c].ch_size - 1) > 0) {
  220.             p_extra = chars[c].ch_str;
  221.             c = *p_extra++;
  222.             }
  223.         }
  224.     }
  225.  
  226.     if (col >= Columns) {
  227.         lines++;
  228.         row++;
  229.         col = 0;
  230.     }
  231.     /* store the character in Nextscreen */
  232.     *screenp++ = c;
  233.     col++;
  234.     }
  235.  
  236.     /* Do we have to do off the top of the screen processing ? */
  237.     if (endscreen != (Nextscreen + (Rows - 1) * Columns)) {
  238.         endscreen = Nextscreen + (Rows - 1) * Columns;
  239.  
  240.     row = 0;
  241.     for(idx = 0; idx <= NumLineSizes && row < (Rows - 1);  idx++)
  242.         row += LineSizes[idx];
  243.  
  244.     if (row < (Rows - 1)) {
  245.         screenp = Nextscreen + (row * Columns);
  246.         done = TRUE;
  247.     } else if (row > (Rows - 1)) {    /* Need to blank out the last line */
  248.         idx--;
  249.         save = LinePointers[idx];
  250.         srow = row - LineSizes[idx];
  251.         didline = FALSE;
  252.     } else {
  253.         memp = LinePointers[idx];
  254.         screenp = Nextscreen + (row * Columns);
  255.         didline = TRUE;
  256.     }
  257.     }
  258.  
  259.     /*
  260.      * If we didn't hit the end of the file, and we didn't finish the last
  261.      * line we were working on, then the line didn't fit. 
  262.      */
  263.     if (!done && !didline) {
  264.     /*
  265.      * Clear the rest of the screen and mark the unused lines. 
  266.      */
  267.     screenp = Nextscreen + (srow * Columns);
  268.     while (screenp < endscreen)
  269.         *screenp++ = ' ';
  270.  
  271.     for (; srow < (Rows - 1); srow++)
  272.         Nextscreen[srow * Columns] = '@';
  273.  
  274.     Botchar->linep = save;
  275.     } else {
  276.     /* make sure the rest of the screen is blank */
  277.     while (screenp < endscreen)
  278.         *screenp++ = ' ';
  279.  
  280.     /* put '~'s on rows that aren't part of the file. */
  281.     if (col != 0)
  282.         row++;
  283.     while (row < Rows) {
  284.         Nextscreen[row * Columns] = '~';
  285.         row++;
  286.     }
  287.  
  288.     if (done)        /* we hit the end of the file */
  289.         *Botchar = *Fileend;
  290.     else
  291.         Botchar->linep = memp;    /* FIX - prev? */
  292.     }
  293.  
  294.     NumLineSizes = idx;
  295. }
  296.