2 * Copyright (C) 1984-2007 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 about less, or for information on how to
8 * contact the author, 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
= NULL_POSITION
;
48 * See if a mark letter is valid (between a and z).
54 if (c
>= 'a' && c
<= 'z')
55 return (&marks
[c
-'a']);
57 if (c
>= 'A' && c
<= 'Z')
58 return (&marks
[c
-'A'+26]);
60 error("Invalid mark letter", NULL_PARG
);
65 * Get the mark structure identified by a character.
66 * The mark struct may come either from the mark table
67 * or may be constructed on the fly for certain characters like ^, $.
73 register struct mark
*m
;
74 static struct mark sm
;
80 * Beginning of the current file.
83 m
->m_scrpos
.pos
= ch_zero();
85 m
->m_ifile
= curr_ifile
;
89 * End of the current file.
93 error("Cannot seek to end of file", NULL_PARG
);
97 m
->m_scrpos
.pos
= ch_tell();
98 m
->m_scrpos
.ln
= sc_height
-1;
99 m
->m_ifile
= curr_ifile
;
103 * Current position in the current file.
106 get_scrpos(&m
->m_scrpos
);
107 m
->m_ifile
= curr_ifile
;
113 m
= &marks
[LASTMARK
];
117 * Must be a user-defined mark.
122 if (m
->m_scrpos
.pos
== NULL_POSITION
)
124 error("Mark not set", NULL_PARG
);
133 * Is a mark letter is invalid?
139 return (getmark(c
) == NULL
);
143 * Set a user-defined mark.
149 register struct mark
*m
;
150 struct scrpos scrpos
;
156 m
->m_scrpos
= scrpos
;
157 m
->m_ifile
= curr_ifile
;
161 * Set lmark (the mark named by the apostrophe).
166 struct scrpos scrpos
;
168 if (ch_getflags() & CH_HELPFILE
)
171 if (scrpos
.pos
== NULL_POSITION
)
173 marks
[LASTMARK
].m_scrpos
= scrpos
;
174 marks
[LASTMARK
].m_ifile
= curr_ifile
;
184 register struct mark
*m
;
185 struct scrpos scrpos
;
192 * If we're trying to go to the lastmark and
193 * it has not been set to anything yet,
194 * set it to the beginning of the current file.
196 if (m
== &marks
[LASTMARK
] && m
->m_scrpos
.pos
== NULL_POSITION
)
198 m
->m_ifile
= curr_ifile
;
199 m
->m_scrpos
.pos
= ch_zero();
200 m
->m_scrpos
.ln
= jump_sline
;
204 * If we're using lmark, we must save the screen position now,
205 * because if we call edit_ifile() below, lmark will change.
206 * (We save the screen position even if we're not using lmark.)
208 scrpos
= m
->m_scrpos
;
209 if (m
->m_ifile
!= curr_ifile
)
212 * Not in the current file; edit the correct file.
214 if (edit_ifile(m
->m_ifile
))
218 jump_loc(scrpos
.pos
, scrpos
.ln
);
222 * Return the position associated with a given mark letter.
224 * We don't return which screen line the position
225 * is associated with, but this doesn't matter much,
226 * because it's always the first non-blank line on the screen.
232 register struct mark
*m
;
236 return (NULL_POSITION
);
238 if (m
->m_ifile
!= curr_ifile
)
240 error("Mark not in current file", NULL_PARG
);
241 return (NULL_POSITION
);
243 return (m
->m_scrpos
.pos
);
247 * Clear the marks associated with a specified ifile.
255 for (i
= 0; i
< NMARKS
; i
++)
256 if (marks
[i
].m_ifile
== ifile
)
257 marks
[i
].m_scrpos
.pos
= NULL_POSITION
;