move4.c

Go to the documentation of this file.
00001 /* move4.c */
00002 
00003 /* Author:
00004  *      Steve Kirkendall
00005  *      14407 SW Teal Blvd. #C
00006  *      Beaverton, OR 97005
00007  *      kirkenda@cs.pdx.edu
00008  */
00009 
00010 
00011 /* This file contains movement functions which are screen-relative */
00012 
00013 #include "config.h"
00014 #include "vi.h"
00015 
00016 /* This moves the cursor to a particular row on the screen */
00017 /*ARGSUSED*/
00018 MARK m_row(m, cnt, key)
00019         MARK    m;      /* the cursor position */
00020         long    cnt;    /* the row we'll move to */
00021         int     key;    /* the keystroke of this move - H/L/M */
00022 {
00023         DEFAULT(1);
00024 
00025         /* calculate destination line based on key */
00026         cnt--;
00027         switch (key)
00028         {
00029           case 'H':
00030                 cnt = topline + cnt;
00031                 break;
00032 
00033           case 'M':
00034                 cnt = topline + (LINES - 1) / 2;
00035                 break;
00036 
00037           case 'L':
00038                 cnt = botline - cnt;
00039                 break;
00040         }
00041 
00042         /* return the mark of the destination line */
00043         return MARK_AT_LINE(cnt);
00044 }
00045 
00046 
00047 /* This function repositions the current line to show on a given row */
00048 MARK m_z(m, cnt, key)
00049         MARK    m;      /* the cursor */
00050         long    cnt;    /* the line number we're repositioning */
00051         int     key;    /* key struck after the z */
00052 {
00053         long    newtop;
00054         int     i;
00055 
00056         /* Which line are we talking about? */
00057         if (cnt < 0 || cnt > nlines)
00058         {
00059                 return MARK_UNSET;
00060         }
00061         if (cnt)
00062         {
00063                 m = MARK_AT_LINE(cnt);
00064                 newtop = cnt;
00065         }
00066         else
00067         {
00068                 newtop = markline(m);
00069         }
00070 
00071         /* allow a "window size" number to be entered */
00072         for (i = 0; key >= '0' && key <= '9'; key = getkey(0))
00073         {
00074                 i = i * 10 + key - '0';
00075         }
00076 #ifndef CRUNCH
00077         if (i > 0 && i <= LINES - 1)
00078         {
00079                 *o_window = i;
00080                 wset = TRUE;
00081         }
00082 #else
00083         /* the number is ignored if -DCRUNCH */
00084 #endif
00085 
00086         /* figure out which line will have to be at the top of the screen */
00087         switch (key)
00088         {
00089           case '\n':
00090 #if OSK
00091           case '\l':
00092 #else
00093           case '\r':
00094 #endif
00095           case '+':
00096                 break;
00097 
00098           case '.':
00099           case 'z':
00100                 newtop -= LINES / 2;
00101                 break;
00102 
00103           case '-':
00104                 newtop -= LINES - 1;
00105                 break;
00106 
00107           default:
00108                 return MARK_UNSET;
00109         }
00110 
00111         /* make the new topline take effect */
00112         redraw(MARK_UNSET, FALSE);
00113         if (newtop >= 1)
00114         {
00115                 topline = newtop;
00116         }
00117         else
00118         {
00119                 topline = 1L;
00120         }
00121         redrawrange(0L, INFINITY, INFINITY);
00122 
00123         /* The cursor doesn't move */
00124         return m;
00125 }
00126 
00127 
00128 /* This function scrolls the screen.  It does this by calling redraw() with
00129  * an off-screen line as the argument.  It will move the cursor if necessary
00130  * so that the cursor is on the new screen.
00131  */
00132 /*ARGSUSED*/
00133 MARK m_scroll(m, cnt, key)
00134         MARK    m;      /* the cursor position */
00135         long    cnt;    /* for some keys: the number of lines to scroll */
00136         int     key;    /* keystroke that causes this movement */
00137 {
00138         MARK    tmp;    /* a temporary mark, used as arg to redraw() */
00139 
00140         /* adjust cnt, and maybe *o_scroll, depending of key */
00141         switch (key)
00142         {
00143           case ctrl('F'):
00144           case ctrl('B'):
00145                 DEFAULT(1);
00146                 redrawrange(0L, INFINITY, INFINITY); /* force complete redraw */
00147                 cnt = cnt * (LINES - 1) - 2; /* keeps two old lines on screen */
00148                 break;
00149 
00150           case ctrl('E'):
00151           case ctrl('Y'):
00152                 DEFAULT(1);
00153                 break;
00154 
00155           case ctrl('U'):
00156           case ctrl('D'):
00157                 if (cnt == 0) /* default */
00158                 {
00159                         cnt = *o_scroll;
00160                 }
00161                 else
00162                 {
00163                         if (cnt > LINES - 1)
00164                         {
00165                                 cnt = LINES - 1;
00166                         }
00167                         *o_scroll = cnt;
00168                 }
00169                 break;
00170         }
00171 
00172         /* scroll up or down, depending on key */
00173         switch (key)
00174         {
00175           case ctrl('B'):
00176           case ctrl('Y'):
00177           case ctrl('U'):
00178                 cnt = topline - cnt;
00179                 if (cnt < 1L)
00180                 {
00181                         cnt = 1L;
00182                         m = MARK_FIRST;
00183                 }
00184                 tmp = MARK_AT_LINE(cnt) + markidx(m);
00185                 redraw(tmp, FALSE);
00186                 if (markline(m) > botline)
00187                 {
00188                         m = MARK_AT_LINE(botline);
00189                 }
00190                 break;
00191 
00192           case ctrl('F'):
00193           case ctrl('E'):
00194           case ctrl('D'):
00195                 cnt = botline + cnt;
00196                 if (cnt > nlines)
00197                 {
00198                         cnt = nlines;
00199                         m = MARK_LAST;
00200                 }
00201                 tmp = MARK_AT_LINE(cnt) + markidx(m);
00202                 redraw(tmp, FALSE);
00203                 if (markline(m) < topline)
00204                 {
00205                         m = MARK_AT_LINE(topline);
00206                 }
00207                 break;
00208         }
00209 
00210         return m;
00211 }

Generated on Fri Apr 14 22:56:53 2006 for minix by  doxygen 1.4.6