source: trunk/minix/commands/elvis/move4.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

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