forked from bloovis/microemacs.mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathring.c
More file actions
105 lines (88 loc) · 2.38 KB
/
ring.c
File metadata and controls
105 lines (88 loc) · 2.38 KB
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
/*
Copyright (C) 2008 Mark Alexander
This file is part of MicroEMACS, a small text editor.
MicroEMACS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Name: MicroEMACS
* Mark ring utilities
* By: Mark Alexander
* marka@pobox.com
*
* The functions in this file manipulate mark rings.
* The ring is a stack in which overflow is handled
* by recycling the oldest entries.
*
* There are functions for clearing a ring, pushing
* a mark on a ring, and popping a mark off the ring.
*
*/
#include "def.h"
static POS nullpos = { NULL, 0 };
/*
* Fetch the most recent mark from the ring, move it to the end of
* the ring, and return it to the caller. If the ring is empty,
* return a mark with a null line pointer.
*/
POS
popmark (void)
{
POS top;
int i, count;
MARKRING *ring = &curwp->w_ring;
/* Check for empty ring. */
count = ring->m_count;
if (count == 0)
return nullpos;
/* Rotate the ring. */
top = ring->m_ring[0];
for (i = 0; i < count - 1; i++)
ring->m_ring[i] = ring->m_ring[i + 1];
ring->m_ring[count - 1] = top;
/* Return old top stack item. */
return top;
}
/*
* Push a mark onto the current window's mark ring.
* If the ring is full, reuse the oldest mark.
*/
void
pushmark (POS pos)
{
int i, count;
MARKRING *ring = &curwp->w_ring;
if (pos.p == NULL)
return;
/* Check for full ring. */
if (ring->m_count < RINGSIZE)
ring->m_count++;
count = ring->m_count;
/* Make room on the ring for a new item. */
for (i = count - 1; i > 0; i--)
ring->m_ring[i] = ring->m_ring[i - 1];
/* Push the mark. */
ring->m_ring[0] = pos;
}
/*
* Clear a mark ring.
*/
void
clearmarks (MARKRING *ring)
{
int i;
for (i = 0; i < RINGSIZE; i++)
{
ring->m_ring[i].p = NULL;
ring->m_ring[i].o = 0;
}
ring->m_count = 0;
}