-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMARK.C
144 lines (126 loc) · 2.82 KB
/
MARK.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* Copyright (c) 1990,1991,1992 Chris and John Downey */
#ifndef lint
static char *sccsid = "@(#)mark.c 2.1 (Chris & John Downey) 7/29/92";
#endif
/***
* program name:
xvi
* function:
PD version of UNIX "vi" editor, with extensions.
* module name:
mark.c
* module function:
Routines to maintain and manipulate marks.
* history:
STEVIE - ST Editor for VI Enthusiasts, Version 3.10
Originally by Tim Thompson (twitch!tjt)
Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
Heavily modified by Chris & John Downey
***/
#include "xvi.h"
#ifdef MEGAMAX
overlay "mark"
#endif
/*
* A new buffer - initialise it so there are no marks.
*/
void
init_marks(buffer)
Buffer *buffer;
{
Mark *mlist = buffer->b_mlist;
int i;
for (i = 0; i < NMARKS; i++)
mlist[i].m_name = '\0';
buffer->b_pcvalid = FALSE;
}
/*
* setmark(c) - set mark 'c' at current cursor position in given buffer.
*
* Returns TRUE on success, FALSE if no room for mark or bad name given.
*/
bool_t
setmark(c, buffer, pos)
int c;
Buffer *buffer;
Posn *pos;
{
Mark *mlist = buffer->b_mlist;
int i;
if (!is_alpha((unsigned char) c))
return(FALSE);
/*
* If there is already a mark of this name, then just use the
* existing mark entry.
*/
for (i = 0; i < NMARKS; i++) {
if (mlist[i].m_name == (unsigned char) c) {
mlist[i].m_pos = *pos;
return(TRUE);
}
}
/*
* There wasn't a mark of the given name, so find a free slot
*/
for (i = 0; i < NMARKS; i++) {
if (mlist[i].m_name == '\0') { /* got a free one */
mlist[i].m_name = c;
mlist[i].m_pos = *pos;
return(TRUE);
}
}
return(FALSE);
}
/*
* setpcmark() - set the previous context mark to the current position
*/
void
setpcmark(window)
Xviwin *window;
{
window->w_buffer->b_pcmark.m_pos = *(window->w_cursor);
window->w_buffer->b_pcvalid = TRUE;
}
/*
* getmark(c) - find mark for char 'c' in given buffer
*
* Return pointer to Position or NULL if no such mark.
*/
Posn *
getmark(c, buffer)
int c;
Buffer *buffer;
{
Mark *mlist = buffer->b_mlist;
int i;
if (c == '\'' || c == '`') { /* previous context mark */
return(buffer->b_pcvalid ? &(buffer->b_pcmark.m_pos) : NULL);
}
for (i = 0; i < NMARKS; i++) {
if (mlist[i].m_name == (unsigned char) c)
return(&(mlist[i].m_pos));
}
return(NULL);
}
/*
* clrmark(line) - clear any marks for 'line'
*
* Used any time a line is deleted so we don't have marks pointing to
* non-existent lines.
*/
void
clrmark(line, buffer)
Line *line;
Buffer *buffer;
{
Mark *mlist = buffer->b_mlist;
int i;
for (i = 0; i < NMARKS; i++) {
if (mlist[i].m_pos.p_line == line) {
mlist[i].m_name = '\0';
}
}
if (buffer->b_pcvalid && (buffer->b_pcmark.m_pos.p_line == line)) {
buffer->b_pcvalid = FALSE;
}
}