xref: /freebsd/contrib/less/input.c (revision a15691bf119a9d4b1ec5a237d2f7eda79cbf01ce)
1a5f0fb15SPaul Saab /*
2*a15691bfSXin LI  * Copyright (C) 1984-2015  Mark Nudelman
3a5f0fb15SPaul Saab  *
4a5f0fb15SPaul Saab  * You may distribute under the terms of either the GNU General Public
5a5f0fb15SPaul Saab  * License or the Less License, as specified in the README file.
6a5f0fb15SPaul Saab  *
796e55cc7SXin LI  * For more information, see the README file.
8a5f0fb15SPaul Saab  */
9a5f0fb15SPaul Saab 
10a5f0fb15SPaul Saab 
11a5f0fb15SPaul Saab /*
12a5f0fb15SPaul Saab  * High level routines dealing with getting lines of input
13a5f0fb15SPaul Saab  * from the file being viewed.
14a5f0fb15SPaul Saab  *
15a5f0fb15SPaul Saab  * When we speak of "lines" here, we mean PRINTABLE lines;
16a5f0fb15SPaul Saab  * lines processed with respect to the screen width.
17a5f0fb15SPaul Saab  * We use the term "raw line" to refer to lines simply
18a5f0fb15SPaul Saab  * delimited by newlines; not processed with respect to screen width.
19a5f0fb15SPaul Saab  */
20a5f0fb15SPaul Saab 
21a5f0fb15SPaul Saab #include "less.h"
22a5f0fb15SPaul Saab 
23a5f0fb15SPaul Saab extern int squeeze;
24a5f0fb15SPaul Saab extern int chopline;
258ed69c6fSPaul Saab extern int hshift;
26a5f0fb15SPaul Saab extern int quit_if_one_screen;
27a5f0fb15SPaul Saab extern int sigs;
28a5f0fb15SPaul Saab extern int ignore_eoi;
296dcb072bSXin LI extern int status_col;
30a5f0fb15SPaul Saab extern POSITION start_attnpos;
31a5f0fb15SPaul Saab extern POSITION end_attnpos;
32a5f0fb15SPaul Saab #if HILITE_SEARCH
33a5f0fb15SPaul Saab extern int hilite_search;
34a5f0fb15SPaul Saab extern int size_linebuf;
35a5f0fb15SPaul Saab #endif
36a5f0fb15SPaul Saab 
37a5f0fb15SPaul Saab /*
38a5f0fb15SPaul Saab  * Get the next line.
39a5f0fb15SPaul Saab  * A "current" position is passed and a "new" position is returned.
40a5f0fb15SPaul Saab  * The current position is the position of the first character of
41a5f0fb15SPaul Saab  * a line.  The new position is the position of the first character
42a5f0fb15SPaul Saab  * of the NEXT line.  The line obtained is the line starting at curr_pos.
43a5f0fb15SPaul Saab  */
44a5f0fb15SPaul Saab 	public POSITION
45a5f0fb15SPaul Saab forw_line(curr_pos)
46a5f0fb15SPaul Saab 	POSITION curr_pos;
47a5f0fb15SPaul Saab {
486dcb072bSXin LI 	POSITION base_pos;
49a5f0fb15SPaul Saab 	POSITION new_pos;
50a5f0fb15SPaul Saab 	register int c;
51a5f0fb15SPaul Saab 	int blankline;
52a5f0fb15SPaul Saab 	int endline;
536dcb072bSXin LI 	int backchars;
54a5f0fb15SPaul Saab 
557374caaaSXin LI get_forw_line:
56a5f0fb15SPaul Saab 	if (curr_pos == NULL_POSITION)
57a5f0fb15SPaul Saab 	{
58a5f0fb15SPaul Saab 		null_line();
59a5f0fb15SPaul Saab 		return (NULL_POSITION);
60a5f0fb15SPaul Saab 	}
61a5f0fb15SPaul Saab #if HILITE_SEARCH
627374caaaSXin LI 	if (hilite_search == OPT_ONPLUS || is_filtering() || status_col)
63*a15691bfSXin LI 	{
64a5f0fb15SPaul Saab 		/*
65a5f0fb15SPaul Saab 		 * If we are ignoring EOI (command F), only prepare
66a5f0fb15SPaul Saab 		 * one line ahead, to avoid getting stuck waiting for
67a5f0fb15SPaul Saab 		 * slow data without displaying the data we already have.
68a5f0fb15SPaul Saab 		 * If we're not ignoring EOI, we *could* do the same, but
69a5f0fb15SPaul Saab 		 * for efficiency we prepare several lines ahead at once.
70a5f0fb15SPaul Saab 		 */
71a5f0fb15SPaul Saab 		prep_hilite(curr_pos, curr_pos + 3*size_linebuf,
72a5f0fb15SPaul Saab 				ignore_eoi ? 1 : -1);
73*a15691bfSXin LI 		curr_pos = next_unfiltered(curr_pos);
74*a15691bfSXin LI 	}
75a5f0fb15SPaul Saab #endif
76a5f0fb15SPaul Saab 	if (ch_seek(curr_pos))
77a5f0fb15SPaul Saab 	{
78a5f0fb15SPaul Saab 		null_line();
79a5f0fb15SPaul Saab 		return (NULL_POSITION);
80a5f0fb15SPaul Saab 	}
81a5f0fb15SPaul Saab 
827374caaaSXin LI 	/*
837374caaaSXin LI 	 * Step back to the beginning of the line.
847374caaaSXin LI 	 */
856dcb072bSXin LI 	base_pos = curr_pos;
866dcb072bSXin LI 	for (;;)
876dcb072bSXin LI 	{
886dcb072bSXin LI 		if (ABORT_SIGS())
896dcb072bSXin LI 		{
906dcb072bSXin LI 			null_line();
916dcb072bSXin LI 			return (NULL_POSITION);
926dcb072bSXin LI 		}
936dcb072bSXin LI 		c = ch_back_get();
946dcb072bSXin LI 		if (c == EOI)
956dcb072bSXin LI 			break;
966dcb072bSXin LI 		if (c == '\n')
976dcb072bSXin LI 		{
986dcb072bSXin LI 			(void) ch_forw_get();
996dcb072bSXin LI 			break;
1006dcb072bSXin LI 		}
1016dcb072bSXin LI 		--base_pos;
1026dcb072bSXin LI 	}
1036dcb072bSXin LI 
1047374caaaSXin LI 	/*
1057374caaaSXin LI 	 * Read forward again to the position we should start at.
1067374caaaSXin LI 	 */
107a5f0fb15SPaul Saab  	prewind();
1086dcb072bSXin LI 	plinenum(base_pos);
1096dcb072bSXin LI 	(void) ch_seek(base_pos);
1107374caaaSXin LI 	new_pos = base_pos;
1117374caaaSXin LI 	while (new_pos < curr_pos)
1126dcb072bSXin LI 	{
1136dcb072bSXin LI 		if (ABORT_SIGS())
1146dcb072bSXin LI 		{
1156dcb072bSXin LI 			null_line();
1166dcb072bSXin LI 			return (NULL_POSITION);
1176dcb072bSXin LI 		}
1186dcb072bSXin LI 		c = ch_forw_get();
1197374caaaSXin LI 		backchars = pappend(c, new_pos);
1207374caaaSXin LI 		new_pos++;
1216dcb072bSXin LI 		if (backchars > 0)
1226dcb072bSXin LI 		{
1236dcb072bSXin LI 			pshift_all();
1247374caaaSXin LI 			new_pos -= backchars;
1256dcb072bSXin LI 			while (--backchars >= 0)
1266dcb072bSXin LI 				(void) ch_back_get();
1276dcb072bSXin LI 		}
1286dcb072bSXin LI 	}
1296dcb072bSXin LI 	(void) pflushmbc();
1306dcb072bSXin LI 	pshift_all();
131a5f0fb15SPaul Saab 
1327374caaaSXin LI 	/*
1337374caaaSXin LI 	 * Read the first character to display.
1347374caaaSXin LI 	 */
135a5f0fb15SPaul Saab 	c = ch_forw_get();
136a5f0fb15SPaul Saab 	if (c == EOI)
137a5f0fb15SPaul Saab 	{
138a5f0fb15SPaul Saab 		null_line();
139a5f0fb15SPaul Saab 		return (NULL_POSITION);
140a5f0fb15SPaul Saab 	}
141a5f0fb15SPaul Saab 	blankline = (c == '\n' || c == '\r');
142a5f0fb15SPaul Saab 
1437374caaaSXin LI 	/*
1447374caaaSXin LI 	 * Read each character in the line and append to the line buffer.
1457374caaaSXin LI 	 */
146a5f0fb15SPaul Saab 	for (;;)
147a5f0fb15SPaul Saab 	{
148a5f0fb15SPaul Saab 		if (ABORT_SIGS())
149a5f0fb15SPaul Saab 		{
150a5f0fb15SPaul Saab 			null_line();
151a5f0fb15SPaul Saab 			return (NULL_POSITION);
152a5f0fb15SPaul Saab 		}
153a5f0fb15SPaul Saab 		if (c == '\n' || c == EOI)
154a5f0fb15SPaul Saab 		{
155a5f0fb15SPaul Saab 			/*
156a5f0fb15SPaul Saab 			 * End of the line.
157a5f0fb15SPaul Saab 			 */
1586dcb072bSXin LI 			backchars = pflushmbc();
159a5f0fb15SPaul Saab 			new_pos = ch_tell();
1606dcb072bSXin LI 			if (backchars > 0 && !chopline && hshift == 0)
1616dcb072bSXin LI 			{
1626dcb072bSXin LI 				new_pos -= backchars + 1;
1636dcb072bSXin LI 				endline = FALSE;
1646dcb072bSXin LI 			} else
165a5f0fb15SPaul Saab 				endline = TRUE;
166a5f0fb15SPaul Saab 			break;
167a5f0fb15SPaul Saab 		}
1686dcb072bSXin LI 		if (c != '\r')
1696dcb072bSXin LI 			blankline = 0;
170a5f0fb15SPaul Saab 
171a5f0fb15SPaul Saab 		/*
172a5f0fb15SPaul Saab 		 * Append the char to the line and get the next char.
173a5f0fb15SPaul Saab 		 */
1746dcb072bSXin LI 		backchars = pappend(c, ch_tell()-1);
1756dcb072bSXin LI 		if (backchars > 0)
176a5f0fb15SPaul Saab 		{
177a5f0fb15SPaul Saab 			/*
178a5f0fb15SPaul Saab 			 * The char won't fit in the line; the line
179a5f0fb15SPaul Saab 			 * is too long to print in the screen width.
180a5f0fb15SPaul Saab 			 * End the line here.
181a5f0fb15SPaul Saab 			 */
1828ed69c6fSPaul Saab 			if (chopline || hshift > 0)
183a5f0fb15SPaul Saab 			{
184a5f0fb15SPaul Saab 				do
185a5f0fb15SPaul Saab 				{
18633096f16SXin LI 					if (ABORT_SIGS())
18733096f16SXin LI 					{
18833096f16SXin LI 						null_line();
18933096f16SXin LI 						return (NULL_POSITION);
19033096f16SXin LI 					}
191a5f0fb15SPaul Saab 					c = ch_forw_get();
192a5f0fb15SPaul Saab 				} while (c != '\n' && c != EOI);
193a5f0fb15SPaul Saab 				new_pos = ch_tell();
194a5f0fb15SPaul Saab 				endline = TRUE;
195a5f0fb15SPaul Saab 				quit_if_one_screen = FALSE;
196a5f0fb15SPaul Saab 			} else
197a5f0fb15SPaul Saab 			{
1986dcb072bSXin LI 				new_pos = ch_tell() - backchars;
199a5f0fb15SPaul Saab 				endline = FALSE;
200a5f0fb15SPaul Saab 			}
201a5f0fb15SPaul Saab 			break;
202a5f0fb15SPaul Saab 		}
203a5f0fb15SPaul Saab 		c = ch_forw_get();
204a5f0fb15SPaul Saab 	}
2057374caaaSXin LI 
206f0be0a1fSXin LI 	pdone(endline, 1);
2077374caaaSXin LI 
2087374caaaSXin LI #if HILITE_SEARCH
2097374caaaSXin LI 	if (is_filtered(base_pos))
2107374caaaSXin LI 	{
2117374caaaSXin LI 		/*
2127374caaaSXin LI 		 * We don't want to display this line.
2137374caaaSXin LI 		 * Get the next line.
2147374caaaSXin LI 		 */
2157374caaaSXin LI 		curr_pos = new_pos;
2167374caaaSXin LI 		goto get_forw_line;
2177374caaaSXin LI 	}
2187374caaaSXin LI 
2197374caaaSXin LI 	if (status_col && is_hilited(base_pos, ch_tell()-1, 1, NULL))
2207374caaaSXin LI 		set_status_col('*');
2217374caaaSXin LI #endif
222a5f0fb15SPaul Saab 
223a5f0fb15SPaul Saab 	if (squeeze && blankline)
224a5f0fb15SPaul Saab 	{
225a5f0fb15SPaul Saab 		/*
226a5f0fb15SPaul Saab 		 * This line is blank.
227a5f0fb15SPaul Saab 		 * Skip down to the last contiguous blank line
228a5f0fb15SPaul Saab 		 * and pretend it is the one which we are returning.
229a5f0fb15SPaul Saab 		 */
230a5f0fb15SPaul Saab 		while ((c = ch_forw_get()) == '\n' || c == '\r')
231a5f0fb15SPaul Saab 			if (ABORT_SIGS())
232a5f0fb15SPaul Saab 			{
233a5f0fb15SPaul Saab 				null_line();
234a5f0fb15SPaul Saab 				return (NULL_POSITION);
235a5f0fb15SPaul Saab 			}
236a5f0fb15SPaul Saab 		if (c != EOI)
237a5f0fb15SPaul Saab 			(void) ch_back_get();
238a5f0fb15SPaul Saab 		new_pos = ch_tell();
239a5f0fb15SPaul Saab 	}
240a5f0fb15SPaul Saab 
241a5f0fb15SPaul Saab 	return (new_pos);
242a5f0fb15SPaul Saab }
243a5f0fb15SPaul Saab 
244a5f0fb15SPaul Saab /*
245a5f0fb15SPaul Saab  * Get the previous line.
246a5f0fb15SPaul Saab  * A "current" position is passed and a "new" position is returned.
247a5f0fb15SPaul Saab  * The current position is the position of the first character of
248a5f0fb15SPaul Saab  * a line.  The new position is the position of the first character
249a5f0fb15SPaul Saab  * of the PREVIOUS line.  The line obtained is the one starting at new_pos.
250a5f0fb15SPaul Saab  */
251a5f0fb15SPaul Saab 	public POSITION
252a5f0fb15SPaul Saab back_line(curr_pos)
253a5f0fb15SPaul Saab 	POSITION curr_pos;
254a5f0fb15SPaul Saab {
2557374caaaSXin LI 	POSITION new_pos, begin_new_pos, base_pos;
256a5f0fb15SPaul Saab 	int c;
257a5f0fb15SPaul Saab 	int endline;
2586dcb072bSXin LI 	int backchars;
259a5f0fb15SPaul Saab 
2607374caaaSXin LI get_back_line:
261a5f0fb15SPaul Saab 	if (curr_pos == NULL_POSITION || curr_pos <= ch_zero())
262a5f0fb15SPaul Saab 	{
263a5f0fb15SPaul Saab 		null_line();
264a5f0fb15SPaul Saab 		return (NULL_POSITION);
265a5f0fb15SPaul Saab 	}
266a5f0fb15SPaul Saab #if HILITE_SEARCH
2677374caaaSXin LI 	if (hilite_search == OPT_ONPLUS || is_filtering() || status_col)
268a5f0fb15SPaul Saab 		prep_hilite((curr_pos < 3*size_linebuf) ?
269a5f0fb15SPaul Saab 				0 : curr_pos - 3*size_linebuf, curr_pos, -1);
270a5f0fb15SPaul Saab #endif
271a5f0fb15SPaul Saab 	if (ch_seek(curr_pos-1))
272a5f0fb15SPaul Saab 	{
273a5f0fb15SPaul Saab 		null_line();
274a5f0fb15SPaul Saab 		return (NULL_POSITION);
275a5f0fb15SPaul Saab 	}
276a5f0fb15SPaul Saab 
277a5f0fb15SPaul Saab 	if (squeeze)
278a5f0fb15SPaul Saab 	{
279a5f0fb15SPaul Saab 		/*
280a5f0fb15SPaul Saab 		 * Find out if the "current" line was blank.
281a5f0fb15SPaul Saab 		 */
282a5f0fb15SPaul Saab 		(void) ch_forw_get();    /* Skip the newline */
283a5f0fb15SPaul Saab 		c = ch_forw_get();       /* First char of "current" line */
284a5f0fb15SPaul Saab 		(void) ch_back_get();    /* Restore our position */
285a5f0fb15SPaul Saab 		(void) ch_back_get();
286a5f0fb15SPaul Saab 
287a5f0fb15SPaul Saab 		if (c == '\n' || c == '\r')
288a5f0fb15SPaul Saab 		{
289a5f0fb15SPaul Saab 			/*
290a5f0fb15SPaul Saab 			 * The "current" line was blank.
291a5f0fb15SPaul Saab 			 * Skip over any preceding blank lines,
292a5f0fb15SPaul Saab 			 * since we skipped them in forw_line().
293a5f0fb15SPaul Saab 			 */
294a5f0fb15SPaul Saab 			while ((c = ch_back_get()) == '\n' || c == '\r')
295a5f0fb15SPaul Saab 				if (ABORT_SIGS())
296a5f0fb15SPaul Saab 				{
297a5f0fb15SPaul Saab 					null_line();
298a5f0fb15SPaul Saab 					return (NULL_POSITION);
299a5f0fb15SPaul Saab 				}
300a5f0fb15SPaul Saab 			if (c == EOI)
301a5f0fb15SPaul Saab 			{
302a5f0fb15SPaul Saab 				null_line();
303a5f0fb15SPaul Saab 				return (NULL_POSITION);
304a5f0fb15SPaul Saab 			}
305a5f0fb15SPaul Saab 			(void) ch_forw_get();
306a5f0fb15SPaul Saab 		}
307a5f0fb15SPaul Saab 	}
308a5f0fb15SPaul Saab 
309a5f0fb15SPaul Saab 	/*
310a5f0fb15SPaul Saab 	 * Scan backwards until we hit the beginning of the line.
311a5f0fb15SPaul Saab 	 */
312a5f0fb15SPaul Saab 	for (;;)
313a5f0fb15SPaul Saab 	{
314a5f0fb15SPaul Saab 		if (ABORT_SIGS())
315a5f0fb15SPaul Saab 		{
316a5f0fb15SPaul Saab 			null_line();
317a5f0fb15SPaul Saab 			return (NULL_POSITION);
318a5f0fb15SPaul Saab 		}
319a5f0fb15SPaul Saab 		c = ch_back_get();
320a5f0fb15SPaul Saab 		if (c == '\n')
321a5f0fb15SPaul Saab 		{
322a5f0fb15SPaul Saab 			/*
323a5f0fb15SPaul Saab 			 * This is the newline ending the previous line.
324a5f0fb15SPaul Saab 			 * We have hit the beginning of the line.
325a5f0fb15SPaul Saab 			 */
3267374caaaSXin LI 			base_pos = ch_tell() + 1;
327a5f0fb15SPaul Saab 			break;
328a5f0fb15SPaul Saab 		}
329a5f0fb15SPaul Saab 		if (c == EOI)
330a5f0fb15SPaul Saab 		{
331a5f0fb15SPaul Saab 			/*
332a5f0fb15SPaul Saab 			 * We have hit the beginning of the file.
333a5f0fb15SPaul Saab 			 * This must be the first line in the file.
334a5f0fb15SPaul Saab 			 * This must, of course, be the beginning of the line.
335a5f0fb15SPaul Saab 			 */
3367374caaaSXin LI 			base_pos = ch_tell();
337a5f0fb15SPaul Saab 			break;
338a5f0fb15SPaul Saab 		}
339a5f0fb15SPaul Saab 	}
340a5f0fb15SPaul Saab 
341a5f0fb15SPaul Saab 	/*
342a5f0fb15SPaul Saab 	 * Now scan forwards from the beginning of this line.
343a5f0fb15SPaul Saab 	 * We keep discarding "printable lines" (based on screen width)
344a5f0fb15SPaul Saab 	 * until we reach the curr_pos.
345a5f0fb15SPaul Saab 	 *
346a5f0fb15SPaul Saab 	 * {{ This algorithm is pretty inefficient if the lines
347a5f0fb15SPaul Saab 	 *    are much longer than the screen width,
348a5f0fb15SPaul Saab 	 *    but I don't know of any better way. }}
349a5f0fb15SPaul Saab 	 */
3507374caaaSXin LI 	new_pos = base_pos;
351a5f0fb15SPaul Saab 	if (ch_seek(new_pos))
352a5f0fb15SPaul Saab 	{
353a5f0fb15SPaul Saab 		null_line();
354a5f0fb15SPaul Saab 		return (NULL_POSITION);
355a5f0fb15SPaul Saab 	}
356a5f0fb15SPaul Saab 	endline = FALSE;
357a5f0fb15SPaul Saab 	prewind();
358a5f0fb15SPaul Saab 	plinenum(new_pos);
3596dcb072bSXin LI     loop:
3606dcb072bSXin LI 	begin_new_pos = new_pos;
361a5f0fb15SPaul Saab 	(void) ch_seek(new_pos);
362a5f0fb15SPaul Saab 
363a5f0fb15SPaul Saab 	do
364a5f0fb15SPaul Saab 	{
365a5f0fb15SPaul Saab 		c = ch_forw_get();
366a5f0fb15SPaul Saab 		if (c == EOI || ABORT_SIGS())
367a5f0fb15SPaul Saab 		{
368a5f0fb15SPaul Saab 			null_line();
369a5f0fb15SPaul Saab 			return (NULL_POSITION);
370a5f0fb15SPaul Saab 		}
371a5f0fb15SPaul Saab 		new_pos++;
372a5f0fb15SPaul Saab 		if (c == '\n')
373a5f0fb15SPaul Saab 		{
3746dcb072bSXin LI 			backchars = pflushmbc();
3756dcb072bSXin LI 			if (backchars > 0 && !chopline && hshift == 0)
3766dcb072bSXin LI 			{
3776dcb072bSXin LI 				backchars++;
3786dcb072bSXin LI 				goto shift;
3796dcb072bSXin LI 			}
380a5f0fb15SPaul Saab 			endline = TRUE;
381a5f0fb15SPaul Saab 			break;
382a5f0fb15SPaul Saab 		}
3836dcb072bSXin LI 		backchars = pappend(c, ch_tell()-1);
3846dcb072bSXin LI 		if (backchars > 0)
385a5f0fb15SPaul Saab 		{
386a5f0fb15SPaul Saab 			/*
387a5f0fb15SPaul Saab 			 * Got a full printable line, but we haven't
388a5f0fb15SPaul Saab 			 * reached our curr_pos yet.  Discard the line
389a5f0fb15SPaul Saab 			 * and start a new one.
390a5f0fb15SPaul Saab 			 */
3918ed69c6fSPaul Saab 			if (chopline || hshift > 0)
392a5f0fb15SPaul Saab 			{
393a5f0fb15SPaul Saab 				endline = TRUE;
394a5f0fb15SPaul Saab 				quit_if_one_screen = FALSE;
395a5f0fb15SPaul Saab 				break;
396a5f0fb15SPaul Saab 			}
3976dcb072bSXin LI 		shift:
3986dcb072bSXin LI 			pshift_all();
3996dcb072bSXin LI 			while (backchars-- > 0)
4006dcb072bSXin LI 			{
401a5f0fb15SPaul Saab 				(void) ch_back_get();
402a5f0fb15SPaul Saab 				new_pos--;
4036dcb072bSXin LI 			}
404a5f0fb15SPaul Saab 			goto loop;
405a5f0fb15SPaul Saab 		}
406a5f0fb15SPaul Saab 	} while (new_pos < curr_pos);
407a5f0fb15SPaul Saab 
408f0be0a1fSXin LI 	pdone(endline, 0);
4097374caaaSXin LI 
4107374caaaSXin LI #if HILITE_SEARCH
4117374caaaSXin LI 	if (is_filtered(base_pos))
4127374caaaSXin LI 	{
4137374caaaSXin LI 		/*
4147374caaaSXin LI 		 * We don't want to display this line.
4157374caaaSXin LI 		 * Get the previous line.
4167374caaaSXin LI 		 */
4177374caaaSXin LI 		curr_pos = begin_new_pos;
4187374caaaSXin LI 		goto get_back_line;
4197374caaaSXin LI 	}
4207374caaaSXin LI 
42196e55cc7SXin LI 	if (status_col && curr_pos > 0 && is_hilited(base_pos, curr_pos-1, 1, NULL))
4227374caaaSXin LI 		set_status_col('*');
4237374caaaSXin LI #endif
424a5f0fb15SPaul Saab 
425a5f0fb15SPaul Saab 	return (begin_new_pos);
426a5f0fb15SPaul Saab }
427a5f0fb15SPaul Saab 
428a5f0fb15SPaul Saab /*
429a5f0fb15SPaul Saab  * Set attnpos.
430a5f0fb15SPaul Saab  */
431a5f0fb15SPaul Saab 	public void
432a5f0fb15SPaul Saab set_attnpos(pos)
433a5f0fb15SPaul Saab 	POSITION pos;
434a5f0fb15SPaul Saab {
435a5f0fb15SPaul Saab 	int c;
436a5f0fb15SPaul Saab 
437a5f0fb15SPaul Saab 	if (pos != NULL_POSITION)
438a5f0fb15SPaul Saab 	{
439a5f0fb15SPaul Saab 		if (ch_seek(pos))
440a5f0fb15SPaul Saab 			return;
441a5f0fb15SPaul Saab 		for (;;)
442a5f0fb15SPaul Saab 		{
443a5f0fb15SPaul Saab 			c = ch_forw_get();
444a5f0fb15SPaul Saab 			if (c == EOI)
445a5f0fb15SPaul Saab 				break;
446*a15691bfSXin LI 			if (c == '\n' || c == '\r')
447*a15691bfSXin LI 			{
448*a15691bfSXin LI 				(void) ch_back_get();
449*a15691bfSXin LI 				break;
450*a15691bfSXin LI 			}
451a5f0fb15SPaul Saab 			pos++;
452a5f0fb15SPaul Saab 		}
453*a15691bfSXin LI 		end_attnpos = pos;
454*a15691bfSXin LI 		for (;;)
455*a15691bfSXin LI 		{
456*a15691bfSXin LI 			c = ch_back_get();
457*a15691bfSXin LI 			if (c == EOI || c == '\n' || c == '\r')
458*a15691bfSXin LI 				break;
459*a15691bfSXin LI 			pos--;
460*a15691bfSXin LI 		}
461a5f0fb15SPaul Saab 	}
462a5f0fb15SPaul Saab 	start_attnpos = pos;
463a5f0fb15SPaul Saab }
464