line.c (60786) | line.c (63128) |
---|---|
1/* 2 * Copyright (C) 1984-2000 Mark Nudelman 3 * 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. 6 * 7 * For more information about less, or for information on how to 8 * contact the author, see the README file. --- 4 unchanged lines hidden (view full) --- 13 * Routines to manipulate the "line buffer". 14 * The line buffer holds a line of output as it is being built 15 * in preparation for output to the screen. 16 */ 17 18#include "less.h" 19 20#define IS_CONT(c) (((c) & 0xC0) == 0x80) | 1/* 2 * Copyright (C) 1984-2000 Mark Nudelman 3 * 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. 6 * 7 * For more information about less, or for information on how to 8 * contact the author, see the README file. --- 4 unchanged lines hidden (view full) --- 13 * Routines to manipulate the "line buffer". 14 * The line buffer holds a line of output as it is being built 15 * in preparation for output to the screen. 16 */ 17 18#include "less.h" 19 20#define IS_CONT(c) (((c) & 0xC0) == 0x80) |
21#define LINENUM_WIDTH 8 /* Chars to use for line number */ |
|
21 22/* Buffer which holds the current output line */ 23public char linebuf[LINEBUF_SIZE]; 24public int size_linebuf = sizeof(linebuf); 25 26public int cshift; /* Current left-shift of output line buffer */ 27public int hshift; /* Desired left-shift of output line buffer */ 28 29static char attr[LINEBUF_SIZE]; /* Extension of linebuf to hold attributes */ 30static int curr; /* Index into linebuf */ 31static int column; /* Printable length, accounting for 32 backspaces, etc. */ 33static int overstrike; /* Next char should overstrike previous char */ 34static int is_null_line; /* There is no current line */ | 22 23/* Buffer which holds the current output line */ 24public char linebuf[LINEBUF_SIZE]; 25public int size_linebuf = sizeof(linebuf); 26 27public int cshift; /* Current left-shift of output line buffer */ 28public int hshift; /* Desired left-shift of output line buffer */ 29 30static char attr[LINEBUF_SIZE]; /* Extension of linebuf to hold attributes */ 31static int curr; /* Index into linebuf */ 32static int column; /* Printable length, accounting for 33 backspaces, etc. */ 34static int overstrike; /* Next char should overstrike previous char */ 35static int is_null_line; /* There is no current line */ |
36static int lmargin; /* Left margin */ |
|
35static char pendc; 36static POSITION pendpos; 37static char *end_ansi_chars; 38 39static int do_append(); 40 41extern int bs_mode; 42extern int tabstop; 43extern int linenums; 44extern int ctldisp; 45extern int twiddle; 46extern int binattr; | 37static char pendc; 38static POSITION pendpos; 39static char *end_ansi_chars; 40 41static int do_append(); 42 43extern int bs_mode; 44extern int tabstop; 45extern int linenums; 46extern int ctldisp; 47extern int twiddle; 48extern int binattr; |
49extern int status_col; |
|
47extern int auto_wrap, ignaw; 48extern int bo_s_width, bo_e_width; 49extern int ul_s_width, ul_e_width; 50extern int bl_s_width, bl_e_width; 51extern int so_s_width, so_e_width; 52extern int sc_width, sc_height; 53extern int utf_mode; | 50extern int auto_wrap, ignaw; 51extern int bo_s_width, bo_e_width; 52extern int ul_s_width, ul_e_width; 53extern int bl_s_width, bl_e_width; 54extern int so_s_width, so_e_width; 55extern int sc_width, sc_height; 56extern int utf_mode; |
57extern POSITION start_attnpos; 58extern POSITION end_attnpos; |
|
54 55/* 56 * Initialize from environment variables. 57 */ 58 public void 59init_line() 60{ 61 end_ansi_chars = lgetenv("LESSANSIENDCHARS"); --- 7 unchanged lines hidden (view full) --- 69 public void 70prewind() 71{ 72 curr = 0; 73 column = 0; 74 overstrike = 0; 75 is_null_line = 0; 76 pendc = '\0'; | 59 60/* 61 * Initialize from environment variables. 62 */ 63 public void 64init_line() 65{ 66 end_ansi_chars = lgetenv("LESSANSIENDCHARS"); --- 7 unchanged lines hidden (view full) --- 74 public void 75prewind() 76{ 77 curr = 0; 78 column = 0; 79 overstrike = 0; 80 is_null_line = 0; 81 pendc = '\0'; |
82 lmargin = 0; 83 if (status_col) 84 lmargin += 1; 85 if (linenums == OPT_ONPLUS) 86 lmargin += LINENUM_WIDTH+1; |
|
77} 78 79/* 80 * Insert the line number (of the given position) into the line buffer. 81 */ 82 public void 83plinenum(pos) 84 POSITION pos; 85{ 86 register int lno; 87 register int i; | 87} 88 89/* 90 * Insert the line number (of the given position) into the line buffer. 91 */ 92 public void 93plinenum(pos) 94 POSITION pos; 95{ 96 register int lno; 97 register int i; |
88 register int n; | |
89 | 98 |
99 if (linenums == OPT_ONPLUS) 100 { 101 /* 102 * Get the line number and put it in the current line. 103 * {{ Note: since find_linenum calls forw_raw_line, 104 * it may seek in the input file, requiring the caller 105 * of plinenum to re-seek if necessary. }} 106 * {{ Since forw_raw_line modifies linebuf, we must 107 * do this first, before storing anything in linebuf. }} 108 */ 109 lno = find_linenum(pos); 110 } 111 |
|
90 /* | 112 /* |
91 * We display the line number at the start of each line 92 * only if the -N option is set. | 113 * Display a status column if the -J option is set. |
93 */ | 114 */ |
94 if (linenums != OPT_ONPLUS) 95 return; 96 | 115 if (status_col) 116 { 117 linebuf[curr] = ' '; 118 if (start_attnpos != NULL_POSITION && 119 pos >= start_attnpos && pos < end_attnpos) 120 attr[curr] = AT_STANDOUT; 121 else 122 attr[curr] = 0; 123 curr++; 124 column++; 125 } |
97 /* | 126 /* |
98 * Get the line number and put it in the current line. 99 * {{ Note: since find_linenum calls forw_raw_line, 100 * it may seek in the input file, requiring the caller 101 * of plinenum to re-seek if necessary. }} | 127 * Display the line number at the start of each line 128 * if the -N option is set. |
102 */ | 129 */ |
103 lno = find_linenum(pos); 104 105 sprintf(&linebuf[curr], "%6d", lno); 106 n = strlen(&linebuf[curr]); 107 column += n; 108 for (i = 0; i < n; i++) 109 attr[curr++] = 0; 110 | 130 if (linenums == OPT_ONPLUS) 131 { 132 sprintf(&linebuf[curr], "%*d", LINENUM_WIDTH, lno); 133 column += LINENUM_WIDTH; 134 for (i = 0; i < LINENUM_WIDTH; i++) 135 attr[curr++] = 0; 136 } |
111 /* | 137 /* |
112 * Append enough spaces to bring us to the next tab stop. 113 * {{ We could avoid this at the cost of adding some 114 * complication to the tab stop logic in pappend(). }} | 138 * Append enough spaces to bring us to the lmargin. |
115 */ | 139 */ |
116 if (tabstop == 0) 117 tabstop = 1; 118 do | 140 while (column < lmargin) |
119 { 120 linebuf[curr] = ' '; 121 attr[curr++] = AT_NORMAL; 122 column++; | 141 { 142 linebuf[curr] = ' '; 143 attr[curr++] = AT_NORMAL; 144 column++; |
123 } while (((column + cshift) % tabstop) != 0); | 145 } |
124} 125 126/* 127 * 128 */ 129 static int 130utf_len(char *s, int len) 131{ --- 20 unchanged lines hidden (view full) --- 152 */ 153 static void 154pshift(shift) 155 int shift; 156{ 157 int i; 158 int real_shift; 159 | 146} 147 148/* 149 * 150 */ 151 static int 152utf_len(char *s, int len) 153{ --- 20 unchanged lines hidden (view full) --- 174 */ 175 static void 176pshift(shift) 177 int shift; 178{ 179 int i; 180 int real_shift; 181 |
160 if (shift > column) 161 shift = column; 162 if (shift > curr) 163 shift = curr; | 182 if (shift > column - lmargin) 183 shift = column - lmargin; 184 if (shift > curr - lmargin) 185 shift = curr - lmargin; |
164 165 if (!utf_mode) 166 real_shift = shift; 167 else 168 { | 186 187 if (!utf_mode) 188 real_shift = shift; 189 else 190 { |
169 real_shift = utf_len(linebuf, shift); | 191 real_shift = utf_len(linebuf + lmargin, shift); |
170 if (real_shift > curr) 171 real_shift = curr; 172 } 173 for (i = 0; i < curr - real_shift; i++) 174 { | 192 if (real_shift > curr) 193 real_shift = curr; 194 } 195 for (i = 0; i < curr - real_shift; i++) 196 { |
175 linebuf[i] = linebuf[i + real_shift]; 176 attr[i] = attr[i + real_shift]; | 197 linebuf[lmargin + i] = linebuf[lmargin + i + real_shift]; 198 attr[lmargin + i] = attr[lmargin + i + real_shift]; |
177 } 178 column -= shift; 179 curr -= real_shift; 180 cshift += shift; 181} 182 183/* 184 * Return the printing width of the start (enter) sequence --- 284 unchanged lines hidden (view full) --- 469 { 470 case BS_CONTROL: 471 goto do_control_char; 472 case BS_NORMAL: 473 case BS_SPECIAL: 474 do 475 { 476 STOREC(' ', AT_NORMAL); | 199 } 200 column -= shift; 201 curr -= real_shift; 202 cshift += shift; 203} 204 205/* 206 * Return the printing width of the start (enter) sequence --- 284 unchanged lines hidden (view full) --- 491 { 492 case BS_CONTROL: 493 goto do_control_char; 494 case BS_NORMAL: 495 case BS_SPECIAL: 496 do 497 { 498 STOREC(' ', AT_NORMAL); |
477 } while (((column + cshift) % tabstop) != 0); | 499 } while (((column + cshift - lmargin) % tabstop) != 0); |
478 break; 479 } 480 } else if (control_char(c)) 481 { 482 do_control_char: 483 if (ctldisp == OPT_ON || (ctldisp == OPT_ONPLUS && c == ESC)) 484 { 485 /* --- 211 unchanged lines hidden --- | 500 break; 501 } 502 } else if (control_char(c)) 503 { 504 do_control_char: 505 if (ctldisp == OPT_ON || (ctldisp == OPT_ONPLUS && c == ESC)) 506 { 507 /* --- 211 unchanged lines hidden --- |