2 * Copyright (C) 1984-2015 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;
19 * Each mark is identified by a lowercase or uppercase letter.
20 * The final one is lmark, for the "last mark"; addressed by the apostrophe.
22 #define NMARKS ((2*26)+1) /* a-z, A-Z, lastmark */
23 #define LASTMARK (NMARKS-1)
24 static struct mark marks[NMARKS];
27 * Initialize the mark table to show no marks are set.
34 for (i = 0; i < NMARKS; i++)
35 marks[i].m_scrpos.pos = NULL_POSITION;
39 * See if a mark letter is valid (between a and z).
45 if (c >= 'a' && c <= 'z')
46 return (&marks[c-'a']);
48 if (c >= 'A' && c <= 'Z')
49 return (&marks[c-'A'+26]);
51 error("Invalid mark letter", NULL_PARG);
56 * Get the mark structure identified by a character.
57 * The mark struct may come either from the mark table
58 * or may be constructed on the fly for certain characters like ^, $.
64 register struct mark *m;
65 static struct mark sm;
71 * Beginning of the current file.
74 m->m_scrpos.pos = ch_zero();
76 m->m_ifile = curr_ifile;
80 * End of the current file.
84 error("Cannot seek to end of file", NULL_PARG);
88 m->m_scrpos.pos = ch_tell();
89 m->m_scrpos.ln = sc_height-1;
90 m->m_ifile = curr_ifile;
94 * Current position in the current file.
97 get_scrpos(&m->m_scrpos);
98 m->m_ifile = curr_ifile;
104 m = &marks[LASTMARK];
108 * Must be a user-defined mark.
113 if (m->m_scrpos.pos == NULL_POSITION)
115 error("Mark not set", NULL_PARG);
124 * Is a mark letter is invalid?
130 return (getmark(c) == NULL);
134 * Set a user-defined mark.
140 register struct mark *m;
141 struct scrpos scrpos;
147 m->m_scrpos = scrpos;
148 m->m_ifile = curr_ifile;
152 * Set lmark (the mark named by the apostrophe).
157 struct scrpos scrpos;
159 if (ch_getflags() & CH_HELPFILE)
162 if (scrpos.pos == NULL_POSITION)
164 marks[LASTMARK].m_scrpos = scrpos;
165 marks[LASTMARK].m_ifile = curr_ifile;
175 register struct mark *m;
176 struct scrpos scrpos;
183 * If we're trying to go to the lastmark and
184 * it has not been set to anything yet,
185 * set it to the beginning of the current file.
187 if (m == &marks[LASTMARK] && m->m_scrpos.pos == NULL_POSITION)
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)
203 * Not in the current file; edit the correct file.
205 if (edit_ifile(m->m_ifile))
209 jump_loc(scrpos.pos, scrpos.ln);
213 * Return the position associated with a given mark letter.
215 * We don't return which screen line the position
216 * is associated with, but this doesn't matter much,
217 * because it's always the first non-blank line on the screen.
223 register struct mark *m;
227 return (NULL_POSITION);
229 if (m->m_ifile != curr_ifile)
231 error("Mark not in current file", NULL_PARG);
232 return (NULL_POSITION);
234 return (m->m_scrpos.pos);
238 * Clear the marks associated with a specified ifile.
246 for (i = 0; i < NMARKS; i++)
247 if (marks[i].m_ifile == ifile)
248 marks[i].m_scrpos.pos = NULL_POSITION;