2 * Copyright (C) 1984-2017 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.
11 * Routines to manipulate the "line buffer".
12 * The line buffer holds a line of output as it is being built
13 * in preparation for output to the screen.
20 #if MSDOS_COMPILER==WIN32C
21 #define WIN32_LEAN_AND_MEAN
25 static char *linebuf = NULL; /* Buffer which holds the current output line */
26 static char *attr = NULL; /* Extension of linebuf to hold attributes */
27 public int size_linebuf = 0; /* Size of line buffer (and attr buffer) */
29 static int cshift; /* Current left-shift of output line buffer */
30 public int hshift; /* Desired left-shift of output line buffer */
31 public int tabstops[TABSTOP_MAX] = { 0 }; /* Custom tabstops */
32 public int ntabstops = 1; /* Number of tabstops */
33 public int tabdefault = 8; /* Default repeated tabstops */
34 public POSITION highest_hilite; /* Pos of last hilite in file found so far */
36 static int curr; /* Index into linebuf */
37 static int column; /* Printable length, accounting for
39 static int right_curr;
40 static int right_column;
41 static int overstrike; /* Next char should overstrike previous char */
42 static int last_overstrike = AT_NORMAL;
43 static int is_null_line; /* There is no current line */
44 static int lmargin; /* Left margin */
46 static POSITION pendpos;
47 static char *end_ansi_chars;
48 static char *mid_ansi_chars;
50 static int attr_swidth LESSPARAMS ((int a));
51 static int attr_ewidth LESSPARAMS ((int a));
52 static int do_append LESSPARAMS ((LWCHAR ch, char *rep, POSITION pos));
60 extern int status_col;
61 extern int auto_wrap, ignaw;
62 extern int bo_s_width, bo_e_width;
63 extern int ul_s_width, ul_e_width;
64 extern int bl_s_width, bl_e_width;
65 extern int so_s_width, so_e_width;
66 extern int sc_width, sc_height;
68 extern POSITION start_attnpos;
69 extern POSITION end_attnpos;
70 extern LWCHAR rscroll_char;
71 extern int rscroll_attr;
73 static char mbc_buf[MAX_UTF_CHAR_LEN];
74 static int mbc_buf_len = 0;
75 static int mbc_buf_index = 0;
76 static POSITION mbc_pos;
79 * Initialize from environment variables.
84 end_ansi_chars = lgetenv("LESSANSIENDCHARS");
85 if (end_ansi_chars == NULL || *end_ansi_chars == '\0')
88 mid_ansi_chars = lgetenv("LESSANSIMIDCHARS");
89 if (mid_ansi_chars == NULL || *mid_ansi_chars == '\0')
90 mid_ansi_chars = "0123456789:;[?!\"'#%()*+ ";
92 linebuf = (char *) ecalloc(LINEBUF_SIZE, sizeof(char));
93 attr = (char *) ecalloc(LINEBUF_SIZE, sizeof(char));
94 size_linebuf = LINEBUF_SIZE;
98 * Expand the line buffer.
103 /* Double the size of the line buffer. */
104 int new_size = size_linebuf * 2;
106 /* Just realloc to expand the buffer, if we can. */
108 char *new_buf = (char *) realloc(linebuf, new_size);
109 char *new_attr = (char *) realloc(attr, new_size);
111 char *new_buf = (char *) calloc(new_size, sizeof(char));
112 char *new_attr = (char *) calloc(new_size, sizeof(char));
114 if (new_buf == NULL || new_attr == NULL)
116 if (new_attr != NULL)
124 * We realloc'd the buffers; they already have the old contents.
127 memset(new_buf + size_linebuf, 0, new_size - size_linebuf);
128 memset(new_attr + size_linebuf, 0, new_size - size_linebuf);
132 * We just calloc'd the buffers; copy the old contents.
134 memcpy(new_buf, linebuf, size_linebuf * sizeof(char));
135 memcpy(new_attr, attr, size_linebuf * sizeof(char));
141 size_linebuf = new_size;
146 * Is a character ASCII?
156 * Rewind the line buffer.
167 last_overstrike = AT_NORMAL;
177 * Set a character in the line buffer.
180 set_linebuf(n, ch, a)
190 * Append a character to the line buffer.
193 add_linebuf(ch, a, w)
198 set_linebuf(curr++, ch, a);
203 * Insert the line number (of the given position) into the line buffer.
212 if (linenums == OPT_ONPLUS)
215 * Get the line number and put it in the current line.
216 * {{ Note: since find_linenum calls forw_raw_line,
217 * it may seek in the input file, requiring the caller
218 * of plinenum to re-seek if necessary. }}
219 * {{ Since forw_raw_line modifies linebuf, we must
220 * do this first, before storing anything in linebuf. }}
222 linenum = find_linenum(pos);
226 * Display a status column if the -J option is set.
231 char c = posmark(pos);
237 if (start_attnpos != NULL_POSITION &&
238 pos >= start_attnpos && pos <= end_attnpos)
241 add_linebuf(c, a, 1); /* column 0: status */
242 add_linebuf(' ', AT_NORMAL, 1); /* column 1: empty */
246 * Display the line number at the start of each line
247 * if the -N option is set.
249 if (linenums == OPT_ONPLUS)
251 char buf[INT_STRLEN_BOUND(linenum) + 2];
255 linenumtoa(linenum, buf);
256 n = (int) strlen(buf);
257 if (n < MIN_LINENUM_WIDTH)
258 pad = MIN_LINENUM_WIDTH - n;
259 for (i = 0; i < pad; i++)
260 add_linebuf(' ', AT_NORMAL, 1);
261 for (i = 0; i < n; i++)
262 add_linebuf(buf[i], AT_BOLD, 1);
263 add_linebuf(' ', AT_NORMAL, 1);
264 lmargin += n + pad + 1;
267 * Append enough spaces to bring us to the lmargin.
269 while (column < lmargin)
271 add_linebuf(' ', AT_NORMAL, 1);
276 * Shift the input line left.
277 * This means discarding N printable chars at the start of the buffer.
293 if (shift > column - lmargin)
294 shift = column - lmargin;
295 if (shift > curr - lmargin)
296 shift = curr - lmargin;
300 * We keep on going when shifted == shift
301 * to get all combining chars.
303 while (shifted <= shift && from < curr)
306 if (ctldisp == OPT_ONPLUS && IS_CSI_START(c))
308 /* Keep cumulative effect. */
310 attr[to++] = attr[from++];
311 while (from < curr && linebuf[from])
313 linebuf[to] = linebuf[from];
314 attr[to++] = attr[from];
315 if (!is_ansi_middle(linebuf[from++]))
323 if (!IS_ASCII_OCTET(c) && utf_mode)
325 /* Assumes well-formedness validation already done. */
329 if (from + len > curr)
331 ch = get_wchar(linebuf + from);
332 if (!is_composing_char(ch) && !is_combining_char(prev_ch, ch))
333 width = is_wide_char(ch) ? 2 : 1;
339 /* XXX - Incorrect if several '\b' in a row. */
340 width = (utf_mode && is_wide_char(prev_ch)) ? -2 : -1;
341 else if (!control_char(c))
346 if (width == 2 && shift - shifted == 1) {
347 /* Should never happen when called by pshift_all(). */
348 attr[to] = attr[from];
350 * Assume a wide_char will never be the first half of a
351 * combining_char pair, so reset prev_ch in case we're
352 * followed by a '\b'.
354 prev_ch = linebuf[to++] = ' ';
360 /* Adjust width for magic cookies. */
361 prev_attr = (to > 0) ? attr[to-1] : AT_NORMAL;
362 next_attr = (from + len < curr) ? attr[from + len] : prev_attr;
363 if (!is_at_equiv(attr[from], prev_attr) &&
364 !is_at_equiv(attr[from], next_attr))
366 width += attr_swidth(attr[from]);
367 if (from + len < curr)
368 width += attr_ewidth(attr[from]);
369 if (is_at_equiv(prev_attr, next_attr))
371 width += attr_ewidth(prev_attr);
372 if (from + len < curr)
373 width += attr_swidth(next_attr);
377 if (shift - shifted < width)
386 linebuf[to] = linebuf[from];
387 attr[to++] = attr[from++];
404 * Return the printing width of the start (enter) sequence
405 * for a given character attribute.
413 a = apply_at_specials(a);
415 if (a & AT_UNDERLINE)
428 * Return the printing width of the end (exit) sequence
429 * for a given character attribute.
437 a = apply_at_specials(a);
439 if (a & AT_UNDERLINE)
452 * Return the printing width of a given character and attribute,
453 * if the character were added to the current position in the line buffer.
454 * Adding a character with a given attribute may cause an enter or exit
455 * attribute sequence to be inserted, so this must be taken into account.
458 pwidth(ch, a, prev_ch)
467 * Backspace moves backwards one or two positions.
468 * XXX - Incorrect if several '\b' in a row.
470 return (utf_mode && is_wide_char(prev_ch)) ? -2 : -1;
472 if (!utf_mode || is_ascii_char(ch))
474 if (control_char((char)ch))
477 * Control characters do unpredictable things,
478 * so we don't even try to guess; say it doesn't move.
479 * This can only happen if the -r flag is in effect.
485 if (is_composing_char(ch) || is_combining_char(prev_ch, ch))
488 * Composing and combining chars take up no space.
490 * Some terminals, upon failure to compose a
491 * composing character with the character(s) that
492 * precede(s) it will actually take up one column
493 * for the composing character; there isn't much
494 * we could do short of testing the (complex)
495 * composition process ourselves and printing
496 * a binary representation when it fails.
503 * Other characters take one or two columns,
504 * plus the width of any attribute enter/exit sequence.
507 if (is_wide_char(ch))
509 if (curr > 0 && !is_at_equiv(attr[curr-1], a))
510 w += attr_ewidth(attr[curr-1]);
511 if ((apply_at_specials(a) != AT_NORMAL) &&
512 (curr == 0 || !is_at_equiv(attr[curr-1], a)))
518 * Delete to the previous base character in the line buffer.
519 * Return 1 if one is found.
525 char *p = linebuf + curr;
526 LWCHAR ch = step_char(&p, -1, linebuf + lmargin);
529 /* This assumes that there is no '\b' in linebuf. */
530 while ( curr > lmargin
532 && (!(attr[curr - 1] & (AT_ANSI|AT_BINARY))))
534 curr = (int) (p - linebuf);
535 prev_ch = step_char(&p, -1, linebuf + lmargin);
536 width = pwidth(ch, attr[curr], prev_ch);
547 * Are we currently within a recognized ANSI escape sequence?
555 * Search backwards for either an ESC (which means we ARE in a seq);
556 * or an end char (which means we're NOT in a seq).
558 for (p = &linebuf[curr]; p > linebuf; )
560 LWCHAR ch = step_char(&p, -1, linebuf);
561 if (IS_CSI_START(ch))
563 if (!is_ansi_middle(ch))
570 * Is a character the end of an ANSI escape sequence?
576 if (!is_ascii_char(ch))
578 return (strchr(end_ansi_chars, (char) ch) != NULL);
582 * Can a char appear in an ANSI escape sequence, before the end char?
588 if (!is_ascii_char(ch))
592 return (strchr(mid_ansi_chars, (char) ch) != NULL);
596 * Skip past an ANSI escape sequence.
597 * pp is initially positioned just after the CSI_START char.
602 constant char *limit;
606 c = step_char(pp, +1, limit);
607 } while (*pp < limit && is_ansi_middle(c));
608 /* Note that we discard final char, for which is_ansi_middle is false. */
613 * Append a character and attribute to the line buffer.
615 #define STORE_CHAR(ch,a,rep,pos) \
617 if (store_char((ch),(a),(rep),(pos))) return (1); \
621 store_char(ch, a, rep, pos)
631 w = (a & (AT_UNDERLINE|AT_BOLD)); /* Pre-use w. */
638 if (is_hilited(pos, pos+1, 0, &matches))
641 * This character should be highlighted.
642 * Override the attribute passed in.
646 if (highest_hilite != NULL_POSITION &&
647 pos > highest_hilite)
648 highest_hilite = pos;
655 if (ctldisp == OPT_ONPLUS && in_ansi_esc_seq())
657 if (!is_ansi_end(ch) && !is_ansi_middle(ch)) {
658 /* Remove whole unrecognized sequence. */
659 char *p = &linebuf[curr];
662 bch = step_char(&p, -1, linebuf);
663 } while (p > linebuf && !IS_CSI_START(bch));
664 curr = (int) (p - linebuf);
667 a = AT_ANSI; /* Will force re-AT_'ing around it. */
670 else if (ctldisp == OPT_ONPLUS && IS_CSI_START(ch))
672 a = AT_ANSI; /* Will force re-AT_'ing around it. */
677 char *p = &linebuf[curr];
678 LWCHAR prev_ch = step_char(&p, -1, linebuf);
679 w = pwidth(ch, a, prev_ch);
682 if (ctldisp != OPT_ON && column + w + attr_ewidth(a) > sc_width)
684 * Won't fit on screen.
695 replen = utf_len(rep[0]);
697 if (curr + replen >= size_linebuf-6)
700 * Won't fit in line buffer.
703 if (expand_linebuf())
707 if (column > right_column && w > 0)
709 right_column = column;
715 add_linebuf(*rep++, a, 0);
722 * Append a tab to the line buffer.
723 * Store spaces to represent the tab.
725 #define STORE_TAB(a,pos) \
726 do { if (store_tab((a),(pos))) return (1); } while (0)
733 int to_tab = column + cshift - lmargin;
736 if (ntabstops < 2 || to_tab >= tabstops[ntabstops-1])
737 to_tab = tabdefault -
738 ((to_tab - tabstops[ntabstops-1]) % tabdefault);
741 for (i = ntabstops - 2; i >= 0; i--)
742 if (to_tab >= tabstops[i])
744 to_tab = tabstops[i+1] - to_tab;
747 if (column + to_tab - 1 + pwidth(' ', attr, 0) + attr_ewidth(attr) > sc_width)
751 STORE_CHAR(' ', attr, " ", pos);
752 } while (--to_tab > 0);
756 #define STORE_PRCHAR(c, pos) \
757 do { if (store_prchar((c), (pos))) return 1; } while (0)
767 * Convert to printable representation.
772 * Make sure we can get the entire representation
773 * of the character on this line.
775 if (column + (int) strlen(s) - 1 +
776 pwidth(' ', binattr, 0) + attr_ewidth(binattr) > sc_width)
779 for ( ; *s != 0; s++)
780 STORE_CHAR(*s, AT_BINARY, NULL, pos);
791 for (i = 0; i < mbc_buf_index; i++)
792 if (store_prchar(mbc_buf[i], pos))
793 return mbc_buf_index - i;
799 * Append a character to the line buffer.
800 * Expand tabs into spaces, handle underlining, boldfacing, etc.
801 * Returns 0 if ok, 1 if couldn't fit in buffer.
812 if (c == '\r' && pendc == '\r')
814 if (do_append(pendc, NULL, pendpos))
816 * Oops. We've probably lost the char which
817 * was in pendc, since caller won't back up.
823 if (c == '\r' && bs_mode == BS_SPECIAL)
825 if (mbc_buf_len > 0) /* utf_mode must be on. */
827 /* Flush incomplete (truncated) sequence. */
828 r = flush_mbc_buf(mbc_pos);
829 mbc_buf_index = r + 1;
832 return (mbc_buf_index);
836 * Don't put the CR into the buffer until we see
837 * the next char. If the next char is a newline,
847 r = do_append(c, NULL, pos);
850 /* Perform strict validation in all possible cases. */
851 if (mbc_buf_len == 0)
856 if (IS_ASCII_OCTET(c))
857 r = do_append(c, NULL, pos);
858 else if (IS_UTF8_LEAD(c))
860 mbc_buf_len = utf_len(c);
864 /* UTF8_INVALID or stray UTF8_TRAIL */
865 r = flush_mbc_buf(pos);
866 } else if (IS_UTF8_TRAIL(c))
868 mbc_buf[mbc_buf_index++] = c;
869 if (mbc_buf_index < mbc_buf_len)
871 if (is_utf8_well_formed(mbc_buf, mbc_buf_index))
872 r = do_append(get_wchar(mbc_buf), mbc_buf, mbc_pos);
874 /* Complete, but not shortest form, sequence. */
875 mbc_buf_index = r = flush_mbc_buf(mbc_pos);
879 /* Flush incomplete (truncated) sequence. */
880 r = flush_mbc_buf(mbc_pos);
881 mbc_buf_index = r + 1;
883 /* Handle new char. */
890 * If we need to shift the line, do it.
891 * But wait until we get to at least the middle of the screen,
892 * so shifting it doesn't affect the chars we're currently
893 * pappending. (Bold & underline can get messed up otherwise.)
895 if (cshift < hshift && column > sc_width / 2)
897 linebuf[curr] = '\0';
898 pshift(hshift - cshift);
902 /* How many chars should caller back up? */
903 r = (!utf_mode) ? 1 : mbc_buf_index;
909 do_append(ch, rep, pos)
921 if (bs_mode == BS_CONTROL)
922 goto do_control_char;
925 * A better test is needed here so we don't
926 * backspace over part of the printed
927 * representation of a binary character.
931 || (attr[curr - 1] & (AT_ANSI|AT_BINARY)))
932 STORE_PRCHAR('\b', pos);
933 else if (bs_mode == BS_NORMAL)
934 STORE_CHAR(ch, AT_NORMAL, NULL, pos);
935 else if (bs_mode == BS_SPECIAL)
936 overstrike = backc();
944 * Overstrike the character at the current position
945 * in the line buffer. This will cause either
946 * underline (if a "_" is overstruck),
947 * bold (if an identical character is overstruck),
948 * or just deletion of the character in the buffer.
950 overstrike = utf_mode ? -1 : 0;
953 /* To be correct, this must be a base character. */
954 prev_ch = get_wchar(linebuf + curr);
957 prev_ch = (unsigned char) linebuf[curr];
963 * Overstriking a char with itself means make it bold.
964 * But overstriking an underscore with itself is
965 * ambiguous. It could mean make it bold, or
966 * it could mean make it underlined.
967 * Use the previous overstrike to resolve it.
971 if ((a & (AT_BOLD|AT_UNDERLINE)) != AT_NORMAL)
972 a |= (AT_BOLD|AT_UNDERLINE);
973 else if (last_overstrike != AT_NORMAL)
974 a |= last_overstrike;
979 } else if (ch == '_')
983 rep = linebuf + curr;
984 } else if (prev_ch == '_')
988 /* Else we replace prev_ch, but we keep its attributes. */
989 } else if (overstrike < 0)
991 if ( is_composing_char(ch)
992 || is_combining_char(get_wchar(linebuf + curr), ch))
993 /* Continuation of the same overstrike. */
1002 * Expand a tab into spaces.
1007 goto do_control_char;
1013 } else if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch))
1016 if (ctldisp == OPT_ON || (ctldisp == OPT_ONPLUS && IS_CSI_START(ch)))
1019 * Output as a normal character.
1021 STORE_CHAR(ch, AT_NORMAL, rep, pos);
1024 STORE_PRCHAR((char) ch, pos);
1026 } else if (utf_mode && ctldisp != OPT_ON && is_ubin_char(ch))
1032 if (column + (int) strlen(s) - 1 +
1033 pwidth(' ', binattr, 0) + attr_ewidth(binattr) > sc_width)
1036 for ( ; *s != 0; s++)
1037 STORE_CHAR(*s, AT_BINARY, NULL, pos);
1040 STORE_CHAR(ch, a, rep, pos);
1053 if (mbc_buf_len > 0)
1055 /* Flush incomplete (truncated) sequence. */
1056 r = flush_mbc_buf(mbc_pos);
1063 * Switch to normal attribute at end of line.
1070 if (ctldisp != OPT_ONPLUS || !is_ansi_end('m'))
1072 for ( ; *p != '\0'; p++)
1073 add_linebuf(*p, AT_ANSI, 0);
1077 * Terminate the line in the line buffer.
1080 pdone(endline, chopped, forw)
1087 if (pendc && (pendc != '\r' || !endline))
1089 * If we had a pending character, put it in the buffer.
1090 * But discard a pending CR if we are at end of line
1091 * (that is, discard the CR in a CR/LF sequence).
1093 (void) do_append(pendc, NULL, pendpos);
1096 * Make sure we've shifted the line, if we need to.
1098 if (cshift < hshift)
1099 pshift(hshift - cshift);
1101 if (chopped && rscroll_char)
1104 * Display the right scrolling char.
1105 * If we've already filled the rightmost screen char
1106 * (in the buffer), overwrite it.
1108 if (column >= sc_width)
1110 /* We've already written in the rightmost char. */
1111 column = right_column;
1115 while (column < sc_width-1)
1118 * Space to last (rightmost) char on screen.
1119 * This may be necessary if the char we overwrote
1122 add_linebuf(' ', AT_NORMAL, 1);
1124 /* Print rscroll char. It must be single-width. */
1125 add_linebuf(rscroll_char, rscroll_attr, 1);
1132 * Add a newline if necessary,
1133 * and append a '\0' to the end of the line.
1134 * We output a newline if we're not at the right edge of the screen,
1135 * or if the terminal doesn't auto wrap,
1136 * or if this is really the end of the line AND the terminal ignores
1137 * a newline at the right edge.
1138 * (In the last case we don't want to output a newline if the terminal
1139 * doesn't ignore it since that would produce an extra blank line.
1140 * But we do want to output a newline if the terminal ignores it in case
1141 * the next line is blank. In that case the single newline output for
1142 * that blank line would be ignored!)
1144 if (column < sc_width || !auto_wrap || (endline && ignaw) || ctldisp == OPT_ON)
1146 add_linebuf('\n', AT_NORMAL, 0);
1148 else if (ignaw && column >= sc_width && forw)
1151 * Terminals with "ignaw" don't wrap until they *really* need
1152 * to, i.e. when the character *after* the last one to fit on a
1153 * line is output. But they are too hard to deal with when they
1154 * get in the state where a full screen width of characters
1155 * have been output but the cursor is sitting on the right edge
1156 * instead of at the start of the next line.
1157 * So we nudge them into wrapping by outputting a space
1158 * character plus a backspace. But do this only if moving
1159 * forward; if we're moving backward and drawing this line at
1160 * the top of the screen, the space would overwrite the first
1161 * char on the next line. We don't need to do this "nudge"
1162 * at the top of the screen anyway.
1164 add_linebuf(' ', AT_NORMAL, 1);
1165 add_linebuf('\b', AT_NORMAL, -1);
1167 set_linebuf(curr, '\0', AT_NORMAL);
1177 set_linebuf(0, c, AT_NORMAL|AT_HILITE);
1181 * Get a character from the current line.
1182 * Return the character as the function return value,
1183 * and the character attribute in *ap.
1193 * If there is no current line, we pretend the line is
1194 * either "~" or "", depending on the "twiddle" flag.
1205 /* Make sure we're back to AT_NORMAL before the '\n'. */
1207 return i ? '\0' : '\n';
1211 return (linebuf[i] & 0xFF);
1215 * Indicate that there is no current line.
1225 * Analogous to forw_line(), but deals with "raw lines":
1226 * lines which are not split for screen width.
1227 * {{ This is supposed to be more efficient than forw_line(). }}
1230 forw_raw_line(curr_pos, linep, line_lenp)
1239 if (curr_pos == NULL_POSITION || ch_seek(curr_pos) ||
1240 (c = ch_forw_get()) == EOI)
1241 return (NULL_POSITION);
1246 if (c == '\n' || c == EOI || ABORT_SIGS())
1248 new_pos = ch_tell();
1251 if (n >= size_linebuf-1)
1253 if (expand_linebuf())
1256 * Overflowed the input buffer.
1257 * Pretend the line ended here.
1259 new_pos = ch_tell() - 1;
1269 if (line_lenp != NULL)
1275 * Analogous to back_line(), but deals with "raw lines".
1276 * {{ This is supposed to be more efficient than back_line(). }}
1279 back_raw_line(curr_pos, linep, line_lenp)
1288 if (curr_pos == NULL_POSITION || curr_pos <= ch_zero() ||
1289 ch_seek(curr_pos-1))
1290 return (NULL_POSITION);
1293 linebuf[--n] = '\0';
1297 if (c == '\n' || ABORT_SIGS())
1300 * This is the newline ending the previous line.
1301 * We have hit the beginning of the line.
1303 new_pos = ch_tell() + 1;
1309 * We have hit the beginning of the file.
1310 * This must be the first line in the file.
1311 * This must, of course, be the beginning of the line.
1313 new_pos = ch_zero();
1318 int old_size_linebuf = size_linebuf;
1321 if (expand_linebuf())
1324 * Overflowed the input buffer.
1325 * Pretend the line ended here.
1327 new_pos = ch_tell() + 1;
1331 * Shift the data to the end of the new linebuf.
1333 for (fm = linebuf + old_size_linebuf - 1,
1334 to = linebuf + size_linebuf - 1;
1335 fm >= linebuf; fm--, to--)
1337 n = size_linebuf - old_size_linebuf;
1342 *linep = &linebuf[n];
1343 if (line_lenp != NULL)
1344 *line_lenp = size_linebuf - 1 - n;
1349 * Find the shift necessary to show the end of the longest displayed line.
1359 save_width = sc_width;
1362 pos = position(TOP);
1363 for (line = 0; line < sc_height && pos != NULL_POSITION; line++)
1365 pos = forw_line(pos);
1366 if (column > longest)
1369 sc_width = save_width;
1370 if (longest < sc_width)
1372 return longest - sc_width;