]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/miscellany/less-177/mark.c
4 extern IFILE curr_ifile
;
9 * A mark is an ifile (input file) plus a position within the file.
13 struct scrpos m_scrpos
;
18 * Each mark is identified by a lowercase or uppercase letter.
20 #define NMARKS (2*26) /* a-z, A-Z */
21 static struct mark marks
[NMARKS
];
24 * Special mark for the "last mark"; addressed by the apostrophe.
26 static struct mark lmark
;
29 * Initialize the mark table to show no marks are set.
36 for (i
= 0; i
< NMARKS
; i
++)
37 marks
[i
].m_scrpos
.pos
= NULL_POSITION
;
38 lmark
.m_scrpos
.pos
= NULL_POSITION
;
42 * See if a mark letter is valid (between a and z).
48 if (c
>= 'a' && c
<= 'z')
49 return (&marks
[c
-'a']);
51 if (c
>= 'A' && c
<= 'Z')
52 return (&marks
[c
-'A'+26]);
54 error("Invalid mark letter", NULL_PARG
);
59 * Get the mark structure identified by a character.
60 * The mark struct may come either from the mark table
61 * or may be constructed on the fly for certain characters like ^, $.
67 register struct mark
*m
;
68 static struct mark sm
;
74 * Beginning of the current file.
77 m
->m_scrpos
.pos
= ch_zero();
79 m
->m_ifile
= curr_ifile
;
83 * End of the current file.
87 error("Cannot seek to end of file", NULL_PARG
);
91 m
->m_scrpos
.pos
= ch_tell();
92 m
->m_scrpos
.ln
= sc_height
-1;
93 m
->m_ifile
= curr_ifile
;
97 * Current position in the current file.
100 m
->m_scrpos
.pos
= ch_tell();
102 m
->m_ifile
= curr_ifile
;
112 * Must be a user-defined mark.
117 if (m
->m_scrpos
.pos
== NULL_POSITION
)
119 error("Mark not set", NULL_PARG
);
128 * Is a mark letter is invalid?
134 return (getmark(c
) == NULL
);
138 * Set a user-defined mark.
144 register struct mark
*m
;
145 struct scrpos scrpos
;
151 m
->m_scrpos
= scrpos
;
152 m
->m_ifile
= curr_ifile
;
156 * Set lmark (the mark named by the apostrophe).
161 struct scrpos scrpos
;
164 if (scrpos
.pos
== NULL_POSITION
)
166 lmark
.m_scrpos
= scrpos
;
167 lmark
.m_ifile
= curr_ifile
;
177 register struct mark
*m
;
178 struct scrpos scrpos
;
185 * If we're trying to go to the lastmark and
186 * it has not been set to anything yet,
187 * set it to the beginning of the current file.
189 if (m
== &lmark
&& m
->m_scrpos
.pos
== NULL_POSITION
)
191 m
->m_ifile
= curr_ifile
;
192 m
->m_scrpos
.pos
= ch_zero();
193 m
->m_scrpos
.ln
= jump_sline
;
197 * If we're using lmark, we must save the screen position now,
198 * because if we call edit() below, lmark will change.
199 * (We save the screen position even if we're not using lmark.)
201 scrpos
= m
->m_scrpos
;
202 if (m
->m_ifile
!= curr_ifile
)
205 * Not in the current file; edit the correct file.
207 if (edit(get_filename(m
->m_ifile
), 0))
211 jump_loc(scrpos
.pos
, scrpos
.ln
);
215 * Return the position associated with a given mark letter.
217 * We don't return which screen line the position
218 * is associated with, but this doesn't matter much,
219 * because it's always the first non-blank line on the screen.
225 register struct mark
*m
;
229 return (NULL_POSITION
);
231 if (m
->m_ifile
!= curr_ifile
)
233 error("Mark not in current file", NULL_PARG
);
234 return (NULL_POSITION
);
236 return (m
->m_scrpos
.pos
);