source: trunk/minix/commands/elvis/move3.c@ 12

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

Minix 3.1.2a

File size: 2.6 KB
Line 
1/* move3.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 that perform character searches */
12
13#include "config.h"
14#include "vi.h"
15
16#ifndef NO_CHARSEARCH
17static MARK (*prevfwdfn)(); /* function to search in same direction */
18static MARK (*prevrevfn)(); /* function to search in opposite direction */
19static char prev_key; /* sought cvhar from previous [fFtT] */
20
21MARK m__ch(m, cnt, cmd)
22 MARK m; /* current position */
23 long cnt;
24 char cmd; /* command: either ',' or ';' */
25{
26 MARK (*tmp)();
27
28 if (!prevfwdfn)
29 {
30 msg("No previous f, F, t, or T command");
31 return MARK_UNSET;
32 }
33
34 if (cmd == ',')
35 {
36 m = (*prevrevfn)(m, cnt, prev_key);
37
38 /* Oops! we didn't want to change the prev*fn vars! */
39 tmp = prevfwdfn;
40 prevfwdfn = prevrevfn;
41 prevrevfn = tmp;
42
43 return m;
44 }
45 else
46 {
47 return (*prevfwdfn)(m, cnt, prev_key);
48 }
49}
50
51/* move forward within this line to next occurrence of key */
52MARK m_fch(m, cnt, key)
53 MARK m; /* where to search from */
54 long cnt;
55 char key; /* what to search for */
56{
57 REG char *text;
58
59 DEFAULT(1);
60
61 prevfwdfn = m_fch;
62 prevrevfn = m_Fch;
63 prev_key = key;
64
65 pfetch(markline(m));
66 text = ptext + markidx(m);
67 while (cnt-- > 0)
68 {
69 do
70 {
71 m++;
72 text++;
73 } while (*text && *text != key);
74 }
75 if (!*text)
76 {
77 return MARK_UNSET;
78 }
79 return m;
80}
81
82/* move backward within this line to previous occurrence of key */
83MARK m_Fch(m, cnt, key)
84 MARK m; /* where to search from */
85 long cnt;
86 char key; /* what to search for */
87{
88 REG char *text;
89
90 DEFAULT(1);
91
92 prevfwdfn = m_Fch;
93 prevrevfn = m_fch;
94 prev_key = key;
95
96 pfetch(markline(m));
97 text = ptext + markidx(m);
98 while (cnt-- > 0)
99 {
100 do
101 {
102 m--;
103 text--;
104 } while (text >= ptext && *text != key);
105 }
106 if (text < ptext)
107 {
108 return MARK_UNSET;
109 }
110 return m;
111}
112
113/* move forward within this line almost to next occurrence of key */
114MARK m_tch(m, cnt, key)
115 MARK m; /* where to search from */
116 long cnt;
117 char key; /* what to search for */
118{
119 /* skip the adjacent char */
120 pfetch(markline(m));
121 if (plen <= markidx(m))
122 {
123 return MARK_UNSET;
124 }
125 m++;
126
127 m = m_fch(m, cnt, key);
128 if (m == MARK_UNSET)
129 {
130 return MARK_UNSET;
131 }
132
133 prevfwdfn = m_tch;
134 prevrevfn = m_Tch;
135
136 return m - 1;
137}
138
139/* move backward within this line almost to previous occurrence of key */
140MARK m_Tch(m, cnt, key)
141 MARK m; /* where to search from */
142 long cnt;
143 char key; /* what to search for */
144{
145 /* skip the adjacent char */
146 if (markidx(m) == 0)
147 {
148 return MARK_UNSET;
149 }
150 m--;
151
152 m = m_Fch(m, cnt, key);
153 if (m == MARK_UNSET)
154 {
155 return MARK_UNSET;
156 }
157
158 prevfwdfn = m_Tch;
159 prevrevfn = m_tch;
160
161 return m + 1;
162}
163#endif
Note: See TracBrowser for help on using the repository browser.