1 /* $NetBSD: mark.c,v 1.3 2013/09/04 19:44:21 tron Exp $ */
4 * Copyright (C) 1984-2012 Mark Nudelman
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.
15 extern IFILE curr_ifile
;
17 extern int jump_sline
;
20 * A mark is an ifile (input file) plus a position within the file.
24 struct scrpos m_scrpos
;
29 * Each mark is identified by a lowercase or uppercase letter.
30 * The final one is lmark, for the "last mark"; addressed by the apostrophe.
32 #define NMARKS ((2*26)+1) /* a-z, A-Z, lastmark */
33 #define LASTMARK (NMARKS-1)
34 static struct mark marks
[NMARKS
];
37 * Initialize the mark table to show no marks are set.
44 for (i
= 0; i
< NMARKS
; i
++)
45 marks
[i
].m_scrpos
.pos
= NULL_POSITION
;
49 * See if a mark letter is valid (between a and z).
55 if (c
>= 'a' && c
<= 'z')
56 return (&marks
[c
-'a']);
58 if (c
>= 'A' && c
<= 'Z')
59 return (&marks
[c
-'A'+26]);
61 error("Invalid mark letter", NULL_PARG
);
66 * Get the mark structure identified by a character.
67 * The mark struct may come either from the mark table
68 * or may be constructed on the fly for certain characters like ^, $.
74 register struct mark
*m
;
75 static struct mark sm
;
81 * Beginning of the current file.
84 m
->m_scrpos
.pos
= ch_zero();
86 m
->m_ifile
= curr_ifile
;
90 * End of the current file.
94 error("Cannot seek to end of file", NULL_PARG
);
98 m
->m_scrpos
.pos
= ch_tell();
99 m
->m_scrpos
.ln
= sc_height
-1;
100 m
->m_ifile
= curr_ifile
;
104 * Current position in the current file.
107 get_scrpos(&m
->m_scrpos
);
108 m
->m_ifile
= curr_ifile
;
114 m
= &marks
[LASTMARK
];
118 * Must be a user-defined mark.
123 if (m
->m_scrpos
.pos
== NULL_POSITION
)
125 error("Mark not set", NULL_PARG
);
134 * Is a mark letter is invalid?
140 return (getmark(c
) == NULL
);
144 * Set a user-defined mark.
150 register struct mark
*m
;
151 struct scrpos scrpos
;
157 m
->m_scrpos
= scrpos
;
158 m
->m_ifile
= curr_ifile
;
162 * Set lmark (the mark named by the apostrophe).
167 struct scrpos scrpos
;
169 if (ch_getflags() & CH_HELPFILE
)
172 if (scrpos
.pos
== NULL_POSITION
)
174 marks
[LASTMARK
].m_scrpos
= scrpos
;
175 marks
[LASTMARK
].m_ifile
= curr_ifile
;
185 register struct mark
*m
;
186 struct scrpos scrpos
;
193 * If we're trying to go to the lastmark and
194 * it has not been set to anything yet,
195 * set it to the beginning of the current file.
197 if (m
== &marks
[LASTMARK
] && m
->m_scrpos
.pos
== NULL_POSITION
)
199 m
->m_ifile
= curr_ifile
;
200 m
->m_scrpos
.pos
= ch_zero();
201 m
->m_scrpos
.ln
= jump_sline
;
205 * If we're using lmark, we must save the screen position now,
206 * because if we call edit_ifile() below, lmark will change.
207 * (We save the screen position even if we're not using lmark.)
209 scrpos
= m
->m_scrpos
;
210 if (m
->m_ifile
!= curr_ifile
)
213 * Not in the current file; edit the correct file.
215 if (edit_ifile(m
->m_ifile
))
219 jump_loc(scrpos
.pos
, scrpos
.ln
);
223 * Return the position associated with a given mark letter.
225 * We don't return which screen line the position
226 * is associated with, but this doesn't matter much,
227 * because it's always the first non-blank line on the screen.
233 register struct mark
*m
;
237 return (NULL_POSITION
);
239 if (m
->m_ifile
!= curr_ifile
)
241 error("Mark not in current file", NULL_PARG
);
242 return (NULL_POSITION
);
244 return (m
->m_scrpos
.pos
);
248 * Clear the marks associated with a specified ifile.
256 for (i
= 0; i
< NMARKS
; i
++)
257 if (marks
[i
].m_ifile
== ifile
)
258 marks
[i
].m_scrpos
.pos
= NULL_POSITION
;