2 * Copyright (C) 1984-2017 Mark Nudelman
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
7 * For more information, see the README file.
14 extern IFILE curr_ifile;
16 extern int jump_sline;
20 * Each mark is identified by a lowercase or uppercase letter.
21 * The final one is lmark, for the "last mark"; addressed by the apostrophe.
23 #define NMARKS ((2*26)+1) /* a-z, A-Z, lastmark */
24 #define LASTMARK (NMARKS-1)
25 static struct mark marks[NMARKS];
28 * Initialize the mark table to show no marks are set.
35 for (i = 0; i < NMARKS; i++)
36 marks[i].m_scrpos.pos = NULL_POSITION;
40 * See if a mark letter is valid (between a and z).
46 if (c >= 'a' && c <= 'z')
47 return (&marks[c-'a']);
49 if (c >= 'A' && c <= 'Z')
50 return (&marks[c-'A'+26]);
52 error("Invalid mark letter", NULL_PARG);
57 * Get the mark structure identified by a character.
58 * The mark struct may come either from the mark table
59 * or may be constructed on the fly for certain characters like ^, $.
66 static struct mark sm;
72 * Beginning of the current file.
75 m->m_scrpos.pos = ch_zero();
77 m->m_ifile = curr_ifile;
81 * End of the current file.
85 error("Cannot seek to end of file", NULL_PARG);
89 m->m_scrpos.pos = ch_tell();
90 m->m_scrpos.ln = sc_height;
91 m->m_ifile = curr_ifile;
95 * Current position in the current file.
98 get_scrpos(&m->m_scrpos, TOP);
99 m->m_ifile = curr_ifile;
105 m = &marks[LASTMARK];
109 * Must be a user-defined mark.
114 if (m->m_scrpos.pos == NULL_POSITION)
116 error("Mark not set", NULL_PARG);
125 * Is a mark letter is invalid?
131 return (getmark(c) == NULL);
135 * Set a user-defined mark.
143 struct scrpos scrpos;
148 get_scrpos(&scrpos, where);
149 m->m_scrpos = scrpos;
150 m->m_ifile = curr_ifile;
154 * Clear a user-defined mark.
165 m->m_scrpos.pos = NULL_POSITION;
169 * Set lmark (the mark named by the apostrophe).
174 struct scrpos scrpos;
176 if (ch_getflags() & CH_HELPFILE)
178 get_scrpos(&scrpos, TOP);
179 if (scrpos.pos == NULL_POSITION)
181 marks[LASTMARK].m_scrpos = scrpos;
182 marks[LASTMARK].m_ifile = curr_ifile;
193 struct scrpos scrpos;
200 * If we're trying to go to the lastmark and
201 * it has not been set to anything yet,
202 * set it to the beginning of the current file.
204 if (m == &marks[LASTMARK] && m->m_scrpos.pos == NULL_POSITION)
206 m->m_ifile = curr_ifile;
207 m->m_scrpos.pos = ch_zero();
208 m->m_scrpos.ln = jump_sline;
212 * If we're using lmark, we must save the screen position now,
213 * because if we call edit_ifile() below, lmark will change.
214 * (We save the screen position even if we're not using lmark.)
216 scrpos = m->m_scrpos;
217 if (m->m_ifile != curr_ifile)
220 * Not in the current file; edit the correct file.
222 if (edit_ifile(m->m_ifile))
226 jump_loc(scrpos.pos, scrpos.ln);
230 * Return the position associated with a given mark letter.
232 * We don't return which screen line the position
233 * is associated with, but this doesn't matter much,
234 * because it's always the first non-blank line on the screen.
244 return (NULL_POSITION);
246 if (m->m_ifile != curr_ifile)
248 error("Mark not in current file", NULL_PARG);
249 return (NULL_POSITION);
251 return (m->m_scrpos.pos);
255 * Return the mark associated with a given position, if any.
263 /* Only lower case and upper case letters */
264 for (i = 0; i < 26*2; i++)
266 if (marks[i].m_ifile == curr_ifile && marks[i].m_scrpos.pos == pos)
268 if (i < 26) return 'a' + i;
276 * Clear the marks associated with a specified ifile.
284 for (i = 0; i < NMARKS; i++)
285 if (marks[i].m_ifile == ifile)
286 marks[i].m_scrpos.pos = NULL_POSITION;