2 * Copyright (C) 1984-2020 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 char 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 (isnullenv(end_ansi_chars))
88 mid_ansi_chars = lgetenv("LESSANSIMIDCHARS");
89 if (isnullenv(mid_ansi_chars))
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.
101 expand_linebuf(VOID_PARAM)
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 just calloc'd the buffers; copy the old contents.
126 memcpy(new_buf, linebuf, size_linebuf * sizeof(char));
127 memcpy(new_attr, attr, size_linebuf * sizeof(char));
133 size_linebuf = new_size;
138 * Is a character ASCII?
148 * Rewind the line buffer.
159 last_overstrike = AT_NORMAL;
169 * Set a character in the line buffer.
172 set_linebuf(n, ch, a)
182 * Append a character to the line buffer.
185 add_linebuf(ch, a, w)
190 set_linebuf(curr++, ch, a);
195 * Insert the line number (of the given position) into the line buffer.
204 if (linenums == OPT_ONPLUS)
207 * Get the line number and put it in the current line.
208 * {{ Note: since find_linenum calls forw_raw_line,
209 * it may seek in the input file, requiring the caller
210 * of plinenum to re-seek if necessary. }}
211 * {{ Since forw_raw_line modifies linebuf, we must
212 * do this first, before storing anything in linebuf. }}
214 linenum = find_linenum(pos);
218 * Display a status column if the -J option is set.
223 char c = posmark(pos);
229 if (start_attnpos != NULL_POSITION &&
230 pos >= start_attnpos && pos <= end_attnpos)
233 add_linebuf(c, a, 1); /* column 0: status */
234 add_linebuf(' ', AT_NORMAL, 1); /* column 1: empty */
238 * Display the line number at the start of each line
239 * if the -N option is set.
241 if (linenums == OPT_ONPLUS)
243 char buf[INT_STRLEN_BOUND(linenum) + 2];
247 linenumtoa(linenum, buf);
248 n = (int) strlen(buf);
249 if (n < MIN_LINENUM_WIDTH)
250 pad = MIN_LINENUM_WIDTH - n;
251 for (i = 0; i < pad; i++)
252 add_linebuf(' ', AT_NORMAL, 1);
253 for (i = 0; i < n; i++)
254 add_linebuf(buf[i], AT_BOLD, 1);
255 add_linebuf(' ', AT_NORMAL, 1);
256 lmargin += n + pad + 1;
259 * Append enough spaces to bring us to the lmargin.
261 while (column < lmargin)
263 add_linebuf(' ', AT_NORMAL, 1);
268 * Shift the input line left.
269 * This means discarding N printable chars at the start of the buffer.
285 if (shift > column - lmargin)
286 shift = column - lmargin;
287 if (shift > curr - lmargin)
288 shift = curr - lmargin;
292 * We keep on going when shifted == shift
293 * to get all combining chars.
295 while (shifted <= shift && from < curr)
298 if (ctldisp == OPT_ONPLUS && IS_CSI_START(c))
300 /* Keep cumulative effect. */
302 attr[to++] = attr[from++];
303 while (from < curr && linebuf[from])
305 linebuf[to] = linebuf[from];
306 attr[to++] = attr[from];
307 if (!is_ansi_middle(linebuf[from++]))
315 if (!IS_ASCII_OCTET(c) && utf_mode)
317 /* Assumes well-formedness validation already done. */
321 if (from + len > curr)
323 ch = get_wchar(linebuf + from);
324 if (!is_composing_char(ch) && !is_combining_char(prev_ch, ch))
325 width = is_wide_char(ch) ? 2 : 1;
331 /* XXX - Incorrect if several '\b' in a row. */
332 width = (utf_mode && is_wide_char(prev_ch)) ? -2 : -1;
333 else if (!control_char(c))
338 if (width == 2 && shift - shifted == 1) {
339 /* Should never happen when called by pshift_all(). */
340 attr[to] = attr[from];
342 * Assume a wide_char will never be the first half of a
343 * combining_char pair, so reset prev_ch in case we're
344 * followed by a '\b'.
346 prev_ch = linebuf[to++] = ' ';
352 /* Adjust width for magic cookies. */
353 prev_attr = (to > 0) ? attr[to-1] : AT_NORMAL;
354 next_attr = (from + len < curr) ? attr[from + len] : prev_attr;
355 if (!is_at_equiv(attr[from], prev_attr) &&
356 !is_at_equiv(attr[from], next_attr))
358 width += attr_swidth(attr[from]);
359 if (from + len < curr)
360 width += attr_ewidth(attr[from]);
361 if (is_at_equiv(prev_attr, next_attr))
363 width += attr_ewidth(prev_attr);
364 if (from + len < curr)
365 width += attr_swidth(next_attr);
369 if (shift - shifted < width)
378 linebuf[to] = linebuf[from];
379 attr[to++] = attr[from++];
390 pshift_all(VOID_PARAM)
396 * Return the printing width of the start (enter) sequence
397 * for a given character attribute.
405 a = apply_at_specials(a);
407 if (a & AT_UNDERLINE)
420 * Return the printing width of the end (exit) sequence
421 * for a given character attribute.
429 a = apply_at_specials(a);
431 if (a & AT_UNDERLINE)
444 * Return the printing width of a given character and attribute,
445 * if the character were added to the current position in the line buffer.
446 * Adding a character with a given attribute may cause an enter or exit
447 * attribute sequence to be inserted, so this must be taken into account.
450 pwidth(ch, a, prev_ch)
459 * Backspace moves backwards one or two positions.
460 * XXX - Incorrect if several '\b' in a row.
462 return (utf_mode && is_wide_char(prev_ch)) ? -2 : -1;
464 if (!utf_mode || is_ascii_char(ch))
466 if (control_char((char)ch))
469 * Control characters do unpredictable things,
470 * so we don't even try to guess; say it doesn't move.
471 * This can only happen if the -r flag is in effect.
477 if (is_composing_char(ch) || is_combining_char(prev_ch, ch))
480 * Composing and combining chars take up no space.
482 * Some terminals, upon failure to compose a
483 * composing character with the character(s) that
484 * precede(s) it will actually take up one column
485 * for the composing character; there isn't much
486 * we could do short of testing the (complex)
487 * composition process ourselves and printing
488 * a binary representation when it fails.
495 * Other characters take one or two columns,
496 * plus the width of any attribute enter/exit sequence.
499 if (is_wide_char(ch))
501 if (curr > 0 && !is_at_equiv(attr[curr-1], a))
502 w += attr_ewidth(attr[curr-1]);
503 if ((apply_at_specials(a) != AT_NORMAL) &&
504 (curr == 0 || !is_at_equiv(attr[curr-1], a)))
510 * Delete to the previous base character in the line buffer.
511 * Return 1 if one is found.
517 char *p = linebuf + curr;
518 LWCHAR ch = step_char(&p, -1, linebuf + lmargin);
521 /* This assumes that there is no '\b' in linebuf. */
522 while ( curr > lmargin
524 && (!(attr[curr - 1] & (AT_ANSI|AT_BINARY))))
526 curr = (int) (p - linebuf);
527 prev_ch = step_char(&p, -1, linebuf + lmargin);
528 width = pwidth(ch, attr[curr], prev_ch);
539 * Are we currently within a recognized ANSI escape sequence?
542 in_ansi_esc_seq(VOID_PARAM)
547 * Search backwards for either an ESC (which means we ARE in a seq);
548 * or an end char (which means we're NOT in a seq).
550 for (p = &linebuf[curr]; p > linebuf; )
552 LWCHAR ch = step_char(&p, -1, linebuf);
553 if (IS_CSI_START(ch))
555 if (!is_ansi_middle(ch))
562 * Is a character the end of an ANSI escape sequence?
568 if (!is_ascii_char(ch))
570 return (strchr(end_ansi_chars, (char) ch) != NULL);
574 * Can a char appear in an ANSI escape sequence, before the end char?
580 if (!is_ascii_char(ch))
584 return (strchr(mid_ansi_chars, (char) ch) != NULL);
588 * Skip past an ANSI escape sequence.
589 * pp is initially positioned just after the CSI_START char.
594 constant char *limit;
598 c = step_char(pp, +1, limit);
599 } while (*pp < limit && is_ansi_middle(c));
600 /* Note that we discard final char, for which is_ansi_middle is false. */
605 * Append a character and attribute to the line buffer.
607 #define STORE_CHAR(ch,a,rep,pos) \
609 if (store_char((ch),(a),(rep),(pos))) return (1); \
613 store_char(ch, a, rep, pos)
623 w = (a & (AT_UNDERLINE|AT_BOLD)); /* Pre-use w. */
630 if (is_hilited(pos, pos+1, 0, &matches))
633 * This character should be highlighted.
634 * Override the attribute passed in.
638 if (highest_hilite != NULL_POSITION &&
639 pos > highest_hilite)
640 highest_hilite = pos;
647 if (ctldisp == OPT_ONPLUS && in_ansi_esc_seq())
649 if (!is_ansi_end(ch) && !is_ansi_middle(ch)) {
650 /* Remove whole unrecognized sequence. */
651 char *p = &linebuf[curr];
654 bch = step_char(&p, -1, linebuf);
655 } while (p > linebuf && !IS_CSI_START(bch));
656 curr = (int) (p - linebuf);
659 a = AT_ANSI; /* Will force re-AT_'ing around it. */
662 else if (ctldisp == OPT_ONPLUS && IS_CSI_START(ch))
664 a = AT_ANSI; /* Will force re-AT_'ing around it. */
669 char *p = &linebuf[curr];
670 LWCHAR prev_ch = step_char(&p, -1, linebuf);
671 w = pwidth(ch, a, prev_ch);
674 if (ctldisp != OPT_ON && column + w + attr_ewidth(a) > sc_width)
676 * Won't fit on screen.
687 replen = utf_len(rep[0]);
689 if (curr + replen >= size_linebuf-6)
692 * Won't fit in line buffer.
695 if (expand_linebuf())
699 if (column > right_column && w > 0)
701 right_column = column;
707 add_linebuf(*rep++, a, 0);
714 * Append a tab to the line buffer.
715 * Store spaces to represent the tab.
717 #define STORE_TAB(a,pos) \
718 do { if (store_tab((a),(pos))) return (1); } while (0)
725 int to_tab = column + cshift - lmargin;
728 if (ntabstops < 2 || to_tab >= tabstops[ntabstops-1])
729 to_tab = tabdefault -
730 ((to_tab - tabstops[ntabstops-1]) % tabdefault);
733 for (i = ntabstops - 2; i >= 0; i--)
734 if (to_tab >= tabstops[i])
736 to_tab = tabstops[i+1] - to_tab;
739 if (column + to_tab - 1 + pwidth(' ', attr, 0) + attr_ewidth(attr) > sc_width)
743 STORE_CHAR(' ', attr, " ", pos);
744 } while (--to_tab > 0);
748 #define STORE_PRCHAR(c, pos) \
749 do { if (store_prchar((c), (pos))) return 1; } while (0)
759 * Convert to printable representation.
764 * Make sure we can get the entire representation
765 * of the character on this line.
767 if (column + (int) strlen(s) - 1 +
768 pwidth(' ', binattr, 0) + attr_ewidth(binattr) > sc_width)
771 for ( ; *s != 0; s++)
772 STORE_CHAR(*s, AT_BINARY, NULL, pos);
783 for (i = 0; i < mbc_buf_index; i++)
784 if (store_prchar(mbc_buf[i], pos))
785 return mbc_buf_index - i;
791 * Append a character to the line buffer.
792 * Expand tabs into spaces, handle underlining, boldfacing, etc.
793 * Returns 0 if ok, 1 if couldn't fit in buffer.
804 if (c == '\r' && pendc == '\r')
806 if (do_append(pendc, NULL, pendpos))
808 * Oops. We've probably lost the char which
809 * was in pendc, since caller won't back up.
815 if (c == '\r' && bs_mode == BS_SPECIAL)
817 if (mbc_buf_len > 0) /* utf_mode must be on. */
819 /* Flush incomplete (truncated) sequence. */
820 r = flush_mbc_buf(mbc_pos);
821 mbc_buf_index = r + 1;
824 return (mbc_buf_index);
828 * Don't put the CR into the buffer until we see
829 * the next char. If the next char is a newline,
839 r = do_append(c, NULL, pos);
842 /* Perform strict validation in all possible cases. */
843 if (mbc_buf_len == 0)
848 if (IS_ASCII_OCTET(c))
849 r = do_append(c, NULL, pos);
850 else if (IS_UTF8_LEAD(c))
852 mbc_buf_len = utf_len(c);
856 /* UTF8_INVALID or stray UTF8_TRAIL */
857 r = flush_mbc_buf(pos);
858 } else if (IS_UTF8_TRAIL(c))
860 mbc_buf[mbc_buf_index++] = c;
861 if (mbc_buf_index < mbc_buf_len)
863 if (is_utf8_well_formed(mbc_buf, mbc_buf_index))
864 r = do_append(get_wchar(mbc_buf), mbc_buf, mbc_pos);
866 /* Complete, but not shortest form, sequence. */
867 mbc_buf_index = r = flush_mbc_buf(mbc_pos);
871 /* Flush incomplete (truncated) sequence. */
872 r = flush_mbc_buf(mbc_pos);
873 mbc_buf_index = r + 1;
875 /* Handle new char. */
882 * If we need to shift the line, do it.
883 * But wait until we get to at least the middle of the screen,
884 * so shifting it doesn't affect the chars we're currently
885 * pappending. (Bold & underline can get messed up otherwise.)
887 if (cshift < hshift && column > sc_width / 2)
889 linebuf[curr] = '\0';
890 pshift(hshift - cshift);
894 /* How many chars should caller back up? */
895 r = (!utf_mode) ? 1 : mbc_buf_index;
901 do_append(ch, rep, pos)
913 if (bs_mode == BS_CONTROL)
914 goto do_control_char;
917 * A better test is needed here so we don't
918 * backspace over part of the printed
919 * representation of a binary character.
923 || (attr[curr - 1] & (AT_ANSI|AT_BINARY)))
924 STORE_PRCHAR('\b', pos);
925 else if (bs_mode == BS_NORMAL)
926 STORE_CHAR(ch, AT_NORMAL, NULL, pos);
927 else if (bs_mode == BS_SPECIAL)
928 overstrike = backc();
936 * Overstrike the character at the current position
937 * in the line buffer. This will cause either
938 * underline (if a "_" is overstruck),
939 * bold (if an identical character is overstruck),
940 * or just deletion of the character in the buffer.
942 overstrike = utf_mode ? -1 : 0;
945 /* To be correct, this must be a base character. */
946 prev_ch = get_wchar(linebuf + curr);
949 prev_ch = (unsigned char) linebuf[curr];
955 * Overstriking a char with itself means make it bold.
956 * But overstriking an underscore with itself is
957 * ambiguous. It could mean make it bold, or
958 * it could mean make it underlined.
959 * Use the previous overstrike to resolve it.
963 if ((a & (AT_BOLD|AT_UNDERLINE)) != AT_NORMAL)
964 a |= (AT_BOLD|AT_UNDERLINE);
965 else if (last_overstrike != AT_NORMAL)
966 a |= last_overstrike;
971 } else if (ch == '_')
975 rep = linebuf + curr;
976 } else if (prev_ch == '_')
980 /* Else we replace prev_ch, but we keep its attributes. */
981 } else if (overstrike < 0)
983 if ( is_composing_char(ch)
984 || is_combining_char(get_wchar(linebuf + curr), ch))
985 /* Continuation of the same overstrike. */
994 * Expand a tab into spaces.
999 goto do_control_char;
1005 } else if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch))
1008 if (ctldisp == OPT_ON || (ctldisp == OPT_ONPLUS && IS_CSI_START(ch)))
1011 * Output as a normal character.
1013 STORE_CHAR(ch, AT_NORMAL, rep, pos);
1016 STORE_PRCHAR((char) ch, pos);
1018 } else if (utf_mode && ctldisp != OPT_ON && is_ubin_char(ch))
1024 if (column + (int) strlen(s) - 1 +
1025 pwidth(' ', binattr, 0) + attr_ewidth(binattr) > sc_width)
1028 for ( ; *s != 0; s++)
1029 STORE_CHAR(*s, AT_BINARY, NULL, pos);
1032 STORE_CHAR(ch, a, rep, pos);
1041 pflushmbc(VOID_PARAM)
1045 if (mbc_buf_len > 0)
1047 /* Flush incomplete (truncated) sequence. */
1048 r = flush_mbc_buf(mbc_pos);
1055 * Switch to normal attribute at end of line.
1058 add_attr_normal(VOID_PARAM)
1062 if (ctldisp != OPT_ONPLUS || !is_ansi_end('m'))
1064 for ( ; *p != '\0'; p++)
1065 add_linebuf(*p, AT_ANSI, 0);
1069 * Terminate the line in the line buffer.
1072 pdone(endline, chopped, forw)
1079 if (pendc && (pendc != '\r' || !endline))
1081 * If we had a pending character, put it in the buffer.
1082 * But discard a pending CR if we are at end of line
1083 * (that is, discard the CR in a CR/LF sequence).
1085 (void) do_append(pendc, NULL, pendpos);
1088 * Make sure we've shifted the line, if we need to.
1090 if (cshift < hshift)
1091 pshift(hshift - cshift);
1093 if (chopped && rscroll_char)
1096 * Display the right scrolling char.
1097 * If we've already filled the rightmost screen char
1098 * (in the buffer), overwrite it.
1100 if (column >= sc_width)
1102 /* We've already written in the rightmost char. */
1103 column = right_column;
1107 while (column < sc_width-1)
1110 * Space to last (rightmost) char on screen.
1111 * This may be necessary if the char we overwrote
1114 add_linebuf(' ', AT_NORMAL, 1);
1116 /* Print rscroll char. It must be single-width. */
1117 add_linebuf(rscroll_char, rscroll_attr, 1);
1124 * Add a newline if necessary,
1125 * and append a '\0' to the end of the line.
1126 * We output a newline if we're not at the right edge of the screen,
1127 * or if the terminal doesn't auto wrap,
1128 * or if this is really the end of the line AND the terminal ignores
1129 * a newline at the right edge.
1130 * (In the last case we don't want to output a newline if the terminal
1131 * doesn't ignore it since that would produce an extra blank line.
1132 * But we do want to output a newline if the terminal ignores it in case
1133 * the next line is blank. In that case the single newline output for
1134 * that blank line would be ignored!)
1136 if (column < sc_width || !auto_wrap || (endline && ignaw) || ctldisp == OPT_ON)
1138 add_linebuf('\n', AT_NORMAL, 0);
1140 else if (ignaw && column >= sc_width && forw)
1143 * Terminals with "ignaw" don't wrap until they *really* need
1144 * to, i.e. when the character *after* the last one to fit on a
1145 * line is output. But they are too hard to deal with when they
1146 * get in the state where a full screen width of characters
1147 * have been output but the cursor is sitting on the right edge
1148 * instead of at the start of the next line.
1149 * So we nudge them into wrapping by outputting a space
1150 * character plus a backspace. But do this only if moving
1151 * forward; if we're moving backward and drawing this line at
1152 * the top of the screen, the space would overwrite the first
1153 * char on the next line. We don't need to do this "nudge"
1154 * at the top of the screen anyway.
1156 add_linebuf(' ', AT_NORMAL, 1);
1157 add_linebuf('\b', AT_NORMAL, -1);
1159 set_linebuf(curr, '\0', AT_NORMAL);
1169 set_linebuf(0, c, AT_NORMAL|AT_HILITE);
1173 * Get a character from the current line.
1174 * Return the character as the function return value,
1175 * and the character attribute in *ap.
1185 * If there is no current line, we pretend the line is
1186 * either "~" or "", depending on the "twiddle" flag.
1197 /* Make sure we're back to AT_NORMAL before the '\n'. */
1199 return i ? '\0' : '\n';
1203 return (linebuf[i] & 0xFF);
1207 * Indicate that there is no current line.
1210 null_line(VOID_PARAM)
1217 * Analogous to forw_line(), but deals with "raw lines":
1218 * lines which are not split for screen width.
1219 * {{ This is supposed to be more efficient than forw_line(). }}
1222 forw_raw_line(curr_pos, linep, line_lenp)
1231 if (curr_pos == NULL_POSITION || ch_seek(curr_pos) ||
1232 (c = ch_forw_get()) == EOI)
1233 return (NULL_POSITION);
1238 if (c == '\n' || c == EOI || ABORT_SIGS())
1240 new_pos = ch_tell();
1243 if (n >= size_linebuf-1)
1245 if (expand_linebuf())
1248 * Overflowed the input buffer.
1249 * Pretend the line ended here.
1251 new_pos = ch_tell() - 1;
1261 if (line_lenp != NULL)
1267 * Analogous to back_line(), but deals with "raw lines".
1268 * {{ This is supposed to be more efficient than back_line(). }}
1271 back_raw_line(curr_pos, linep, line_lenp)
1280 if (curr_pos == NULL_POSITION || curr_pos <= ch_zero() ||
1281 ch_seek(curr_pos-1))
1282 return (NULL_POSITION);
1285 linebuf[--n] = '\0';
1289 if (c == '\n' || ABORT_SIGS())
1292 * This is the newline ending the previous line.
1293 * We have hit the beginning of the line.
1295 new_pos = ch_tell() + 1;
1301 * We have hit the beginning of the file.
1302 * This must be the first line in the file.
1303 * This must, of course, be the beginning of the line.
1305 new_pos = ch_zero();
1310 int old_size_linebuf = size_linebuf;
1313 if (expand_linebuf())
1316 * Overflowed the input buffer.
1317 * Pretend the line ended here.
1319 new_pos = ch_tell() + 1;
1323 * Shift the data to the end of the new linebuf.
1325 for (fm = linebuf + old_size_linebuf - 1,
1326 to = linebuf + size_linebuf - 1;
1327 fm >= linebuf; fm--, to--)
1329 n = size_linebuf - old_size_linebuf;
1334 *linep = &linebuf[n];
1335 if (line_lenp != NULL)
1336 *line_lenp = size_linebuf - 1 - n;
1341 * Find the shift necessary to show the end of the longest displayed line.
1351 save_width = sc_width;
1354 pos = position(TOP);
1355 for (line = 0; line < sc_height && pos != NULL_POSITION; line++)
1357 pos = forw_line(pos);
1358 if (column > longest)
1361 sc_width = save_width;
1362 if (longest < sc_width)
1364 return longest - sc_width;