2 * Copyright (C) 1984-2012 Mark Nudelman
3 * Modified for use with illumos by Garrett D'Amore.
4 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
14 extern IFILE curr_ifile
;
16 extern int jump_sline
;
19 * A mark is an ifile (input file) plus a position within the file.
23 struct scrpos m_scrpos
;
28 * Each mark is identified by a lowercase or uppercase letter.
29 * The final one is lmark, for the "last mark"; addressed by the apostrophe.
31 #define NMARKS ((2*26)+1) /* a-z, A-Z, lastmark */
32 #define LASTMARK (NMARKS-1)
33 static struct mark marks
[NMARKS
];
36 * Initialize the mark table to show no marks are set.
43 for (i
= 0; i
< NMARKS
; i
++)
44 marks
[i
].m_scrpos
.pos
= -1;
48 * See if a mark letter is valid (between a and z).
53 if (c
>= 'a' && c
<= 'z')
54 return (&marks
[c
-'a']);
56 if (c
>= 'A' && c
<= 'Z')
57 return (&marks
[c
-'A'+26]);
59 error("Invalid mark letter", NULL
);
64 * Get the mark structure identified by a character.
65 * The mark struct may come either from the mark table
66 * or may be constructed on the fly for certain characters like ^, $.
72 static struct mark sm
;
77 * Beginning of the current file.
80 m
->m_scrpos
.pos
= ch_zero();
82 m
->m_ifile
= curr_ifile
;
86 * End of the current file.
89 error("Cannot seek to end of file", NULL
);
93 m
->m_scrpos
.pos
= ch_tell();
94 m
->m_scrpos
.ln
= sc_height
-1;
95 m
->m_ifile
= curr_ifile
;
99 * Current position in the current file.
102 get_scrpos(&m
->m_scrpos
);
103 m
->m_ifile
= curr_ifile
;
109 m
= &marks
[LASTMARK
];
113 * Must be a user-defined mark.
118 if (m
->m_scrpos
.pos
== -1) {
119 error("Mark not set", NULL
);
128 * Is a mark letter is invalid?
133 return (getmark(c
) == NULL
);
137 * Set a user-defined mark.
143 struct scrpos scrpos
;
149 m
->m_scrpos
= scrpos
;
150 m
->m_ifile
= curr_ifile
;
154 * Set lmark (the mark named by the apostrophe).
159 struct scrpos scrpos
;
161 if (ch_getflags() & CH_HELPFILE
)
164 if (scrpos
.pos
== -1)
166 marks
[LASTMARK
].m_scrpos
= scrpos
;
167 marks
[LASTMARK
].m_ifile
= curr_ifile
;
177 struct scrpos scrpos
;
184 * If we're trying to go to the lastmark and
185 * it has not been set to anything yet,
186 * set it to the beginning of the current file.
188 if (m
== &marks
[LASTMARK
] && m
->m_scrpos
.pos
== -1) {
189 m
->m_ifile
= curr_ifile
;
190 m
->m_scrpos
.pos
= ch_zero();
191 m
->m_scrpos
.ln
= jump_sline
;
195 * If we're using lmark, we must save the screen position now,
196 * because if we call edit_ifile() below, lmark will change.
197 * (We save the screen position even if we're not using lmark.)
199 scrpos
= m
->m_scrpos
;
200 if (m
->m_ifile
!= curr_ifile
) {
202 * Not in the current file; edit the correct file.
204 if (edit_ifile(m
->m_ifile
))
208 jump_loc(scrpos
.pos
, scrpos
.ln
);
212 * Return the position associated with a given mark letter.
214 * We don't return which screen line the position
215 * is associated with, but this doesn't matter much,
216 * because it's always the first non-blank line on the screen.
227 if (m
->m_ifile
!= curr_ifile
) {
228 error("Mark not in current file", NULL
);
231 return (m
->m_scrpos
.pos
);
235 * Clear the marks associated with a specified ifile.
242 for (i
= 0; i
< NMARKS
; i
++)
243 if (marks
[i
].m_ifile
== ifile
)
244 marks
[i
].m_scrpos
.pos
= -1;