2 * Copyright (C) 1984-2012 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.
13 extern IFILE curr_ifile;
15 extern int jump_sline;
18 * A mark is an ifile (input file) plus a position within the file.
22 struct scrpos m_scrpos;
27 * Each mark is identified by a lowercase or uppercase letter.
28 * The final one is lmark, for the "last mark"; addressed by the apostrophe.
30 #define NMARKS ((2*26)+1) /* a-z, A-Z, lastmark */
31 #define LASTMARK (NMARKS-1)
32 static struct mark marks[NMARKS];
35 * Initialize the mark table to show no marks are set.
42 for (i = 0; i < NMARKS; i++)
43 marks[i].m_scrpos.pos = NULL_POSITION;
47 * 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_PARG);
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 register struct mark *m;
73 static struct mark sm;
79 * Beginning of the current file.
82 m->m_scrpos.pos = ch_zero();
84 m->m_ifile = curr_ifile;
88 * End of the current file.
92 error("Cannot seek to end of file", NULL_PARG);
96 m->m_scrpos.pos = ch_tell();
97 m->m_scrpos.ln = sc_height-1;
98 m->m_ifile = curr_ifile;
102 * Current position in the current file.
105 get_scrpos(&m->m_scrpos);
106 m->m_ifile = curr_ifile;
112 m = &marks[LASTMARK];
116 * Must be a user-defined mark.
121 if (m->m_scrpos.pos == NULL_POSITION)
123 error("Mark not set", NULL_PARG);
132 * Is a mark letter is invalid?
138 return (getmark(c) == NULL);
142 * Set a user-defined mark.
148 register struct mark *m;
149 struct scrpos scrpos;
155 m->m_scrpos = scrpos;
156 m->m_ifile = curr_ifile;
160 * Set lmark (the mark named by the apostrophe).
165 struct scrpos scrpos;
167 if (ch_getflags() & CH_HELPFILE)
170 if (scrpos.pos == NULL_POSITION)
172 marks[LASTMARK].m_scrpos = scrpos;
173 marks[LASTMARK].m_ifile = curr_ifile;
183 register struct mark *m;
184 struct scrpos scrpos;
191 * If we're trying to go to the lastmark and
192 * it has not been set to anything yet,
193 * set it to the beginning of the current file.
195 if (m == &marks[LASTMARK] && m->m_scrpos.pos == NULL_POSITION)
197 m->m_ifile = curr_ifile;
198 m->m_scrpos.pos = ch_zero();
199 m->m_scrpos.ln = jump_sline;
203 * If we're using lmark, we must save the screen position now,
204 * because if we call edit_ifile() below, lmark will change.
205 * (We save the screen position even if we're not using lmark.)
207 scrpos = m->m_scrpos;
208 if (m->m_ifile != curr_ifile)
211 * Not in the current file; edit the correct file.
213 if (edit_ifile(m->m_ifile))
217 jump_loc(scrpos.pos, scrpos.ln);
221 * Return the position associated with a given mark letter.
223 * We don't return which screen line the position
224 * is associated with, but this doesn't matter much,
225 * because it's always the first non-blank line on the screen.
231 register struct mark *m;
235 return (NULL_POSITION);
237 if (m->m_ifile != curr_ifile)
239 error("Mark not in current file", NULL_PARG);
240 return (NULL_POSITION);
242 return (m->m_scrpos.pos);
246 * Clear the marks associated with a specified ifile.
254 for (i = 0; i < NMARKS; i++)
255 if (marks[i].m_ifile == ifile)
256 marks[i].m_scrpos.pos = NULL_POSITION;