home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / d / elvis / Source / c / move4 < prev    next >
Encoding:
Text File  |  1989-12-31  |  3.2 KB  |  195 lines

  1. /* move4.c */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    16820 SW Tallac Way
  6.  *    Beaverton, OR 97006
  7.  *    kirkenda@jove.cs.pdx.edu, or ...uunet!tektronix!psueea!jove!kirkenda
  8.  */
  9.  
  10.  
  11. /* This file contains movement functions which are screen-relative */
  12.  
  13. #include "vi.h"
  14.  
  15. /* This moves the cursor to a particular row on the screen */
  16. MARK moverow(m, cnt, key)
  17.     MARK    m;    /* the cursor position */
  18.     long    cnt;    /* the row we'll move to */
  19.     int    key;    /* the keystroke of this move - H/L/M */
  20. {
  21.     DEFAULT(1);
  22.  
  23.     /* ignore off-screen counts */
  24.     if (cnt > LINES - 1)
  25.     {
  26.         return MARK_UNSET;
  27.     }
  28.  
  29.     /* calculate destination line based on key */
  30.     cnt--;
  31.     switch (key)
  32.     {
  33.       case 'H':
  34.         cnt = topline + cnt;
  35.         break;
  36.  
  37.       case 'M':
  38.         cnt = topline + (LINES - 1) / 2;
  39.         break;
  40.  
  41.       case 'L':
  42.         cnt = botline - cnt;
  43.         break;
  44.     }
  45.  
  46.     /* return the mark of the destination line */
  47.     return MARK_AT_LINE(cnt);
  48. }
  49.  
  50.  
  51. /* This function repositions the current line to show on a given row */
  52. MARK movez(m, cnt, key)
  53.     MARK    m;    /* the cursor */
  54.     long    cnt;    /* the line number we're repositioning */
  55.     int    key;    /* key struck after the z */
  56. {
  57.     long    newtop;
  58.  
  59.     /* Which line are we talking about? */
  60.     if (cnt < 0 || cnt > nlines)
  61.     {
  62.         return MARK_UNSET;
  63.     }
  64.     if (cnt)
  65.     {
  66.         m = MARK_AT_LINE(cnt);
  67.         newtop = cnt;
  68.     }
  69.     else
  70.     {
  71.         newtop = markline(m);
  72.     }
  73.  
  74.     /* figure out which line will have to be at the top of the screen */
  75.     switch (key)
  76.     {
  77.       case '\n':
  78.       case '\r':
  79.       case '+':
  80.         break;
  81.  
  82.       case '.':
  83.       case 'z':
  84.         newtop -= LINES / 2;
  85.         break;
  86.  
  87.       case '-':
  88.         newtop -= LINES - 1;
  89.         break;
  90.  
  91.       default:
  92.         return MARK_UNSET;
  93.     }
  94.  
  95.     /* make the new topline take effect */
  96.     if (newtop >= 1)
  97.     {
  98.         topline = newtop;
  99.     }
  100.     else
  101.     {
  102.         topline = 1L;
  103.     }
  104.     mustredraw = TRUE;
  105.  
  106.     /* The cursor doesn't move */
  107.     return m;
  108. }
  109.  
  110.  
  111. /* This function scrolls the screen.  It does this by calling redraw() with
  112.  * an off-screen line as the argument.  It will move the cursor if necessary
  113.  * so that the cursor is on the new screen.
  114.  */
  115. MARK movescroll(m, cnt, key)
  116.     MARK    m;    /* the cursor position */
  117.     long    cnt;    /* for some keys: the number of lines to scroll */
  118.     int    key;    /* keystroke that causes this movement */
  119. {
  120.     MARK    tmp;    /* a temporary mark, used as arg to redraw() */
  121.  
  122.     /* adjust cnt, and maybe *o_scroll, depending of key */
  123.     switch (key)
  124.     {
  125.       case ctrl('F'):
  126.       case ctrl('B'):
  127.         mustredraw = TRUE;
  128.         cnt = LINES - 2; /* keeps one old line on screen */
  129.         break;
  130.  
  131.       case ctrl('E'):
  132.       case ctrl('Y'):
  133.         DEFAULT(1);
  134.         if (cnt > LINES - 1)
  135.         {
  136.             cnt = LINES - 1;
  137.         }
  138.         break;
  139.  
  140.       case ctrl('U'):
  141.       case ctrl('D'):
  142.         if (cnt == 0) /* default */
  143.         {
  144.             cnt = *o_scroll;
  145.         }
  146.         else
  147.         {
  148.             if (cnt > LINES - 1)
  149.             {
  150.                 cnt = LINES - 1;
  151.             }
  152.             *o_scroll = cnt;
  153.         }
  154.         break;
  155.     }
  156.  
  157.     /* scroll up or down, depending on key */
  158.     switch (key)
  159.     {
  160.       case ctrl('B'):
  161.       case ctrl('Y'):
  162.       case ctrl('U'):
  163.         cnt = topline - cnt;
  164.         if (cnt < 1L)
  165.         {
  166.             cnt = 1L;
  167.         }
  168.         tmp = MARK_AT_LINE(cnt) + markidx(m);
  169.         redraw(tmp, FALSE);
  170.         if (markline(m) > botline)
  171.         {
  172.             m = MARK_AT_LINE(botline);
  173.         }
  174.         break;
  175.  
  176.       case ctrl('F'):
  177.       case ctrl('E'):
  178.       case ctrl('D'):
  179.         cnt = botline + cnt;
  180.         if (cnt > nlines)
  181.         {
  182.             cnt = nlines;
  183.         }
  184.         tmp = MARK_AT_LINE(cnt) + markidx(m);
  185.         redraw(tmp, FALSE);
  186.         if (markline(m) < topline)
  187.         {
  188.             m = MARK_AT_LINE(topline);
  189.         }
  190.         break;
  191.     }
  192.  
  193.     return m;
  194. }
  195.