Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/less/line.c
Show All 34 Lines | |||||
static int last_overstrike = AT_NORMAL; | static int last_overstrike = AT_NORMAL; | ||||
static int is_null_line; /* There is no current line */ | static int is_null_line; /* There is no current line */ | ||||
static int lmargin; /* Left margin */ | static int lmargin; /* Left margin */ | ||||
static LWCHAR pendc; | static LWCHAR pendc; | ||||
static POSITION pendpos; | static POSITION pendpos; | ||||
static char *end_ansi_chars; | static char *end_ansi_chars; | ||||
static char *mid_ansi_chars; | static char *mid_ansi_chars; | ||||
static int attr_swidth(); | static int attr_swidth(int); | ||||
static int attr_ewidth(); | static int attr_ewidth(int); | ||||
static int do_append(); | static int do_append(LWCHAR, char *, POSITION); | ||||
extern int sigs; | extern int sigs; | ||||
extern int bs_mode; | extern int bs_mode; | ||||
extern int linenums; | extern int linenums; | ||||
extern int ctldisp; | extern int ctldisp; | ||||
extern int twiddle; | extern int twiddle; | ||||
extern int binattr; | extern int binattr; | ||||
extern int status_col; | extern int status_col; | ||||
Show All 11 Lines | |||||
static int mbc_buf_len = 0; | static int mbc_buf_len = 0; | ||||
static int mbc_buf_index = 0; | static int mbc_buf_index = 0; | ||||
static POSITION mbc_pos; | static POSITION mbc_pos; | ||||
/* | /* | ||||
* Initialize from environment variables. | * Initialize from environment variables. | ||||
*/ | */ | ||||
public void | public void | ||||
init_line() | init_line(void) | ||||
{ | { | ||||
end_ansi_chars = lgetenv("LESSANSIENDCHARS"); | end_ansi_chars = lgetenv("LESSANSIENDCHARS"); | ||||
if (end_ansi_chars == NULL || *end_ansi_chars == '\0') | if (end_ansi_chars == NULL || *end_ansi_chars == '\0') | ||||
end_ansi_chars = "m"; | end_ansi_chars = "m"; | ||||
mid_ansi_chars = lgetenv("LESSANSIMIDCHARS"); | mid_ansi_chars = lgetenv("LESSANSIMIDCHARS"); | ||||
if (mid_ansi_chars == NULL || *mid_ansi_chars == '\0') | if (mid_ansi_chars == NULL || *mid_ansi_chars == '\0') | ||||
mid_ansi_chars = "0123456789:;[?!\"'#%()*+ "; | mid_ansi_chars = "0123456789:;[?!\"'#%()*+ "; | ||||
linebuf = (char *) ecalloc(LINEBUF_SIZE, sizeof(char)); | linebuf = (char *) ecalloc(LINEBUF_SIZE, sizeof(char)); | ||||
attr = (char *) ecalloc(LINEBUF_SIZE, sizeof(char)); | attr = (char *) ecalloc(LINEBUF_SIZE, sizeof(char)); | ||||
size_linebuf = LINEBUF_SIZE; | size_linebuf = LINEBUF_SIZE; | ||||
} | } | ||||
/* | /* | ||||
* Expand the line buffer. | * Expand the line buffer. | ||||
*/ | */ | ||||
static int | static int | ||||
expand_linebuf() | expand_linebuf(void) | ||||
{ | { | ||||
/* Double the size of the line buffer. */ | /* Double the size of the line buffer. */ | ||||
int new_size = size_linebuf * 2; | int new_size = size_linebuf * 2; | ||||
/* Just realloc to expand the buffer, if we can. */ | /* Just realloc to expand the buffer, if we can. */ | ||||
#if HAVE_REALLOC | #if HAVE_REALLOC | ||||
char *new_buf = (char *) realloc(linebuf, new_size); | char *new_buf = (char *) realloc(linebuf, new_size); | ||||
char *new_attr = (char *) realloc(attr, new_size); | char *new_attr = (char *) realloc(attr, new_size); | ||||
Show All 31 Lines | #endif | ||||
size_linebuf = new_size; | size_linebuf = new_size; | ||||
return 0; | return 0; | ||||
} | } | ||||
/* | /* | ||||
* Is a character ASCII? | * Is a character ASCII? | ||||
*/ | */ | ||||
public int | public int | ||||
is_ascii_char(ch) | is_ascii_char(LWCHAR ch) | ||||
LWCHAR ch; | |||||
{ | { | ||||
return (ch <= 0x7F); | return (ch <= 0x7F); | ||||
} | } | ||||
/* | /* | ||||
* Rewind the line buffer. | * Rewind the line buffer. | ||||
*/ | */ | ||||
public void | public void | ||||
prewind() | prewind(void) | ||||
{ | { | ||||
curr = 0; | curr = 0; | ||||
column = 0; | column = 0; | ||||
cshift = 0; | cshift = 0; | ||||
overstrike = 0; | overstrike = 0; | ||||
last_overstrike = AT_NORMAL; | last_overstrike = AT_NORMAL; | ||||
mbc_buf_len = 0; | mbc_buf_len = 0; | ||||
is_null_line = 0; | is_null_line = 0; | ||||
pendc = '\0'; | pendc = '\0'; | ||||
lmargin = 0; | lmargin = 0; | ||||
if (status_col) | if (status_col) | ||||
lmargin += 1; | lmargin += 1; | ||||
} | } | ||||
/* | /* | ||||
* Insert the line number (of the given position) into the line buffer. | * Insert the line number (of the given position) into the line buffer. | ||||
*/ | */ | ||||
public void | public void | ||||
plinenum(pos) | plinenum(POSITION pos) | ||||
POSITION pos; | |||||
{ | { | ||||
register LINENUM linenum = 0; | LINENUM linenum = 0; | ||||
register int i; | int i; | ||||
if (linenums == OPT_ONPLUS) | if (linenums == OPT_ONPLUS) | ||||
{ | { | ||||
/* | /* | ||||
* Get the line number and put it in the current line. | * Get the line number and put it in the current line. | ||||
* {{ Note: since find_linenum calls forw_raw_line, | * {{ Note: since find_linenum calls forw_raw_line, | ||||
* it may seek in the input file, requiring the caller | * it may seek in the input file, requiring the caller | ||||
* of plinenum to re-seek if necessary. }} | * of plinenum to re-seek if necessary. }} | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | plinenum(POSITION pos) | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Shift the input line left. | * Shift the input line left. | ||||
* This means discarding N printable chars at the start of the buffer. | * This means discarding N printable chars at the start of the buffer. | ||||
*/ | */ | ||||
static void | static void | ||||
pshift(shift) | pshift(int shift) | ||||
int shift; | |||||
{ | { | ||||
LWCHAR prev_ch = 0; | LWCHAR prev_ch = 0; | ||||
unsigned char c; | unsigned char c; | ||||
int shifted = 0; | int shifted = 0; | ||||
int to; | int to; | ||||
int from; | int from; | ||||
int len; | int len; | ||||
int width; | int width; | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | pshift(int shift) | ||||
column -= shifted; | column -= shifted; | ||||
cshift += shifted; | cshift += shifted; | ||||
} | } | ||||
/* | /* | ||||
* | * | ||||
*/ | */ | ||||
public void | public void | ||||
pshift_all() | pshift_all(void) | ||||
{ | { | ||||
pshift(column); | pshift(column); | ||||
} | } | ||||
/* | /* | ||||
* Return the printing width of the start (enter) sequence | * Return the printing width of the start (enter) sequence | ||||
* for a given character attribute. | * for a given character attribute. | ||||
*/ | */ | ||||
static int | static int | ||||
attr_swidth(a) | attr_swidth(int a) | ||||
int a; | |||||
{ | { | ||||
int w = 0; | int w = 0; | ||||
a = apply_at_specials(a); | a = apply_at_specials(a); | ||||
if (a & AT_UNDERLINE) | if (a & AT_UNDERLINE) | ||||
w += ul_s_width; | w += ul_s_width; | ||||
if (a & AT_BOLD) | if (a & AT_BOLD) | ||||
w += bo_s_width; | w += bo_s_width; | ||||
if (a & AT_BLINK) | if (a & AT_BLINK) | ||||
w += bl_s_width; | w += bl_s_width; | ||||
if (a & AT_STANDOUT) | if (a & AT_STANDOUT) | ||||
w += so_s_width; | w += so_s_width; | ||||
return w; | return w; | ||||
} | } | ||||
/* | /* | ||||
* Return the printing width of the end (exit) sequence | * Return the printing width of the end (exit) sequence | ||||
* for a given character attribute. | * for a given character attribute. | ||||
*/ | */ | ||||
static int | static int | ||||
attr_ewidth(a) | attr_ewidth(int a) | ||||
int a; | |||||
{ | { | ||||
int w = 0; | int w = 0; | ||||
a = apply_at_specials(a); | a = apply_at_specials(a); | ||||
if (a & AT_UNDERLINE) | if (a & AT_UNDERLINE) | ||||
w += ul_e_width; | w += ul_e_width; | ||||
if (a & AT_BOLD) | if (a & AT_BOLD) | ||||
w += bo_e_width; | w += bo_e_width; | ||||
if (a & AT_BLINK) | if (a & AT_BLINK) | ||||
w += bl_e_width; | w += bl_e_width; | ||||
if (a & AT_STANDOUT) | if (a & AT_STANDOUT) | ||||
w += so_e_width; | w += so_e_width; | ||||
return w; | return w; | ||||
} | } | ||||
/* | /* | ||||
* Return the printing width of a given character and attribute, | * Return the printing width of a given character and attribute, | ||||
* if the character were added to the current position in the line buffer. | * if the character were added to the current position in the line buffer. | ||||
* Adding a character with a given attribute may cause an enter or exit | * Adding a character with a given attribute may cause an enter or exit | ||||
* attribute sequence to be inserted, so this must be taken into account. | * attribute sequence to be inserted, so this must be taken into account. | ||||
*/ | */ | ||||
static int | static int | ||||
pwidth(ch, a, prev_ch) | pwidth(LWCHAR ch, int a, LWCHAR prev_ch) | ||||
LWCHAR ch; | |||||
int a; | |||||
LWCHAR prev_ch; | |||||
{ | { | ||||
int w; | int w; | ||||
if (ch == '\b') | if (ch == '\b') | ||||
/* | /* | ||||
* Backspace moves backwards one or two positions. | * Backspace moves backwards one or two positions. | ||||
* XXX - Incorrect if several '\b' in a row. | * XXX - Incorrect if several '\b' in a row. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | pwidth(LWCHAR ch, int a, LWCHAR prev_ch) | ||||
return (w); | return (w); | ||||
} | } | ||||
/* | /* | ||||
* Delete to the previous base character in the line buffer. | * Delete to the previous base character in the line buffer. | ||||
* Return 1 if one is found. | * Return 1 if one is found. | ||||
*/ | */ | ||||
static int | static int | ||||
backc() | backc(void) | ||||
{ | { | ||||
LWCHAR prev_ch; | LWCHAR prev_ch; | ||||
char *p = linebuf + curr; | constant char *p = linebuf + curr; | ||||
LWCHAR ch = step_char(&p, -1, linebuf + lmargin); | LWCHAR ch = step_char(&p, -1, linebuf + lmargin); | ||||
int width; | int width; | ||||
/* This assumes that there is no '\b' in linebuf. */ | /* This assumes that there is no '\b' in linebuf. */ | ||||
while ( curr > lmargin | while ( curr > lmargin | ||||
&& column > lmargin | && column > lmargin | ||||
&& (!(attr[curr - 1] & (AT_ANSI|AT_BINARY)))) | && (!(attr[curr - 1] & (AT_ANSI|AT_BINARY)))) | ||||
{ | { | ||||
curr = (int) (p - linebuf); | curr = (int) (p - linebuf); | ||||
prev_ch = step_char(&p, -1, linebuf + lmargin); | prev_ch = step_char(&p, -1, linebuf + lmargin); | ||||
width = pwidth(ch, attr[curr], prev_ch); | width = pwidth(ch, attr[curr], prev_ch); | ||||
column -= width; | column -= width; | ||||
if (width > 0) | if (width > 0) | ||||
return 1; | return 1; | ||||
ch = prev_ch; | ch = prev_ch; | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
/* | /* | ||||
* Are we currently within a recognized ANSI escape sequence? | * Are we currently within a recognized ANSI escape sequence? | ||||
*/ | */ | ||||
static int | static int | ||||
in_ansi_esc_seq() | in_ansi_esc_seq(void) | ||||
{ | { | ||||
char *p; | constant char *p; | ||||
/* | /* | ||||
* Search backwards for either an ESC (which means we ARE in a seq); | * Search backwards for either an ESC (which means we ARE in a seq); | ||||
* or an end char (which means we're NOT in a seq). | * or an end char (which means we're NOT in a seq). | ||||
*/ | */ | ||||
for (p = &linebuf[curr]; p > linebuf; ) | for (p = &linebuf[curr]; p > linebuf; ) | ||||
{ | { | ||||
LWCHAR ch = step_char(&p, -1, linebuf); | LWCHAR ch = step_char(&p, -1, linebuf); | ||||
if (IS_CSI_START(ch)) | if (IS_CSI_START(ch)) | ||||
return (1); | return (1); | ||||
if (!is_ansi_middle(ch)) | if (!is_ansi_middle(ch)) | ||||
return (0); | return (0); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Is a character the end of an ANSI escape sequence? | * Is a character the end of an ANSI escape sequence? | ||||
*/ | */ | ||||
public int | public int | ||||
is_ansi_end(ch) | is_ansi_end(LWCHAR ch) | ||||
LWCHAR ch; | |||||
{ | { | ||||
if (!is_ascii_char(ch)) | if (!is_ascii_char(ch)) | ||||
return (0); | return (0); | ||||
return (strchr(end_ansi_chars, (char) ch) != NULL); | return (strchr(end_ansi_chars, (char) ch) != NULL); | ||||
} | } | ||||
/* | /* | ||||
* | * | ||||
*/ | */ | ||||
public int | public int | ||||
is_ansi_middle(ch) | is_ansi_middle(LWCHAR ch) | ||||
LWCHAR ch; | |||||
{ | { | ||||
if (!is_ascii_char(ch)) | if (!is_ascii_char(ch)) | ||||
return (0); | return (0); | ||||
if (is_ansi_end(ch)) | if (is_ansi_end(ch)) | ||||
return (0); | return (0); | ||||
return (strchr(mid_ansi_chars, (char) ch) != NULL); | return (strchr(mid_ansi_chars, (char) ch) != NULL); | ||||
} | } | ||||
/* | /* | ||||
* Append a character and attribute to the line buffer. | * Append a character and attribute to the line buffer. | ||||
*/ | */ | ||||
#define STORE_CHAR(ch,a,rep,pos) \ | #define STORE_CHAR(ch,a,rep,pos) \ | ||||
do { \ | do { \ | ||||
if (store_char((ch),(a),(rep),(pos))) return (1); \ | if (store_char((ch),(a),(rep),(pos))) return (1); \ | ||||
} while (0) | } while (0) | ||||
static int | static int | ||||
store_char(ch, a, rep, pos) | store_char(LWCHAR ch, int a, char *rep, POSITION pos) | ||||
LWCHAR ch; | |||||
int a; | |||||
char *rep; | |||||
POSITION pos; | |||||
{ | { | ||||
int w; | int w; | ||||
int replen; | int replen; | ||||
char cs; | char cs; | ||||
w = (a & (AT_UNDERLINE|AT_BOLD)); /* Pre-use w. */ | w = (a & (AT_UNDERLINE|AT_BOLD)); /* Pre-use w. */ | ||||
if (w != AT_NORMAL) | if (w != AT_NORMAL) | ||||
last_overstrike = w; | last_overstrike = w; | ||||
Show All 17 Lines | #if HILITE_SEARCH | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
if (ctldisp == OPT_ONPLUS && in_ansi_esc_seq()) | if (ctldisp == OPT_ONPLUS && in_ansi_esc_seq()) | ||||
{ | { | ||||
if (!is_ansi_end(ch) && !is_ansi_middle(ch)) { | if (!is_ansi_end(ch) && !is_ansi_middle(ch)) { | ||||
/* Remove whole unrecognized sequence. */ | /* Remove whole unrecognized sequence. */ | ||||
char *p = &linebuf[curr]; | constant char *p = &linebuf[curr]; | ||||
LWCHAR bch; | LWCHAR bch; | ||||
do { | do { | ||||
bch = step_char(&p, -1, linebuf); | bch = step_char(&p, -1, linebuf); | ||||
} while (p > linebuf && !IS_CSI_START(bch)); | } while (p > linebuf && !IS_CSI_START(bch)); | ||||
curr = (int) (p - linebuf); | curr = (int) (p - linebuf); | ||||
return 0; | return 0; | ||||
} | } | ||||
a = AT_ANSI; /* Will force re-AT_'ing around it. */ | a = AT_ANSI; /* Will force re-AT_'ing around it. */ | ||||
w = 0; | w = 0; | ||||
} | } | ||||
else if (ctldisp == OPT_ONPLUS && IS_CSI_START(ch)) | else if (ctldisp == OPT_ONPLUS && IS_CSI_START(ch)) | ||||
{ | { | ||||
a = AT_ANSI; /* Will force re-AT_'ing around it. */ | a = AT_ANSI; /* Will force re-AT_'ing around it. */ | ||||
w = 0; | w = 0; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
char *p = &linebuf[curr]; | constant char *p = &linebuf[curr]; | ||||
LWCHAR prev_ch = step_char(&p, -1, linebuf); | LWCHAR prev_ch = step_char(&p, -1, linebuf); | ||||
w = pwidth(ch, a, prev_ch); | w = pwidth(ch, a, prev_ch); | ||||
} | } | ||||
if (ctldisp != OPT_ON && column + w + attr_ewidth(a) > sc_width) | if (ctldisp != OPT_ON && column + w + attr_ewidth(a) > sc_width) | ||||
/* | /* | ||||
* Won't fit on screen. | * Won't fit on screen. | ||||
*/ | */ | ||||
Show All 31 Lines | |||||
/* | /* | ||||
* Append a tab to the line buffer. | * Append a tab to the line buffer. | ||||
* Store spaces to represent the tab. | * Store spaces to represent the tab. | ||||
*/ | */ | ||||
#define STORE_TAB(a,pos) \ | #define STORE_TAB(a,pos) \ | ||||
do { if (store_tab((a),(pos))) return (1); } while (0) | do { if (store_tab((a),(pos))) return (1); } while (0) | ||||
static int | static int | ||||
store_tab(attr, pos) | store_tab(int attr, POSITION pos) | ||||
int attr; | |||||
POSITION pos; | |||||
{ | { | ||||
int to_tab = column + cshift - lmargin; | int to_tab = column + cshift - lmargin; | ||||
int i; | int i; | ||||
if (ntabstops < 2 || to_tab >= tabstops[ntabstops-1]) | if (ntabstops < 2 || to_tab >= tabstops[ntabstops-1]) | ||||
to_tab = tabdefault - | to_tab = tabdefault - | ||||
((to_tab - tabstops[ntabstops-1]) % tabdefault); | ((to_tab - tabstops[ntabstops-1]) % tabdefault); | ||||
else | else | ||||
Show All 12 Lines | store_tab(int attr, POSITION pos) | ||||
} while (--to_tab > 0); | } while (--to_tab > 0); | ||||
return 0; | return 0; | ||||
} | } | ||||
#define STORE_PRCHAR(c, pos) \ | #define STORE_PRCHAR(c, pos) \ | ||||
do { if (store_prchar((c), (pos))) return 1; } while (0) | do { if (store_prchar((c), (pos))) return 1; } while (0) | ||||
static int | static int | ||||
store_prchar(c, pos) | store_prchar(LWCHAR c, POSITION pos) | ||||
LWCHAR c; | |||||
POSITION pos; | |||||
{ | { | ||||
char *s; | char *s; | ||||
/* | /* | ||||
* Convert to printable representation. | * Convert to printable representation. | ||||
*/ | */ | ||||
s = prchar(c); | s = prchar(c); | ||||
/* | /* | ||||
* Make sure we can get the entire representation | * Make sure we can get the entire representation | ||||
* of the character on this line. | * of the character on this line. | ||||
*/ | */ | ||||
if (column + (int) strlen(s) - 1 + | if (column + (int) strlen(s) - 1 + | ||||
pwidth(' ', binattr, 0) + attr_ewidth(binattr) > sc_width) | pwidth(' ', binattr, 0) + attr_ewidth(binattr) > sc_width) | ||||
return 1; | return 1; | ||||
for ( ; *s != 0; s++) | for ( ; *s != 0; s++) | ||||
STORE_CHAR(*s, AT_BINARY, NULL, pos); | STORE_CHAR(*s, AT_BINARY, NULL, pos); | ||||
return 0; | return 0; | ||||
} | } | ||||
static int | static int | ||||
flush_mbc_buf(pos) | flush_mbc_buf(POSITION pos) | ||||
POSITION pos; | |||||
{ | { | ||||
int i; | int i; | ||||
for (i = 0; i < mbc_buf_index; i++) | for (i = 0; i < mbc_buf_index; i++) | ||||
if (store_prchar(mbc_buf[i], pos)) | if (store_prchar(mbc_buf[i], pos)) | ||||
return mbc_buf_index - i; | return mbc_buf_index - i; | ||||
return 0; | return 0; | ||||
} | } | ||||
/* | /* | ||||
* Append a character to the line buffer. | * Append a character to the line buffer. | ||||
* Expand tabs into spaces, handle underlining, boldfacing, etc. | * Expand tabs into spaces, handle underlining, boldfacing, etc. | ||||
* Returns 0 if ok, 1 if couldn't fit in buffer. | * Returns 0 if ok, 1 if couldn't fit in buffer. | ||||
*/ | */ | ||||
public int | public int | ||||
pappend(c, pos) | pappend(unsigned char c, POSITION pos) | ||||
unsigned char c; | |||||
POSITION pos; | |||||
{ | { | ||||
int r; | int r; | ||||
if (pendc) | if (pendc) | ||||
{ | { | ||||
if (c == '\r' && pendc == '\r') | if (c == '\r' && pendc == '\r') | ||||
return (0); | return (0); | ||||
if (do_append(pendc, NULL, pendpos)) | if (do_append(pendc, NULL, pendpos)) | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | pappend(unsigned char c, POSITION pos) | ||||
{ | { | ||||
/* How many chars should caller back up? */ | /* How many chars should caller back up? */ | ||||
r = (!utf_mode) ? 1 : mbc_buf_index; | r = (!utf_mode) ? 1 : mbc_buf_index; | ||||
} | } | ||||
return (r); | return (r); | ||||
} | } | ||||
static int | static int | ||||
do_append(ch, rep, pos) | do_append(LWCHAR ch, char *rep, POSITION pos) | ||||
LWCHAR ch; | |||||
char *rep; | |||||
POSITION pos; | |||||
{ | { | ||||
register int a; | int a; | ||||
LWCHAR prev_ch; | LWCHAR prev_ch; | ||||
a = AT_NORMAL; | a = AT_NORMAL; | ||||
if (ch == '\b') | if (ch == '\b') | ||||
{ | { | ||||
if (bs_mode == BS_CONTROL) | if (bs_mode == BS_CONTROL) | ||||
goto do_control_char; | goto do_control_char; | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | do_append(LWCHAR ch, char *rep, POSITION pos) | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* | * | ||||
*/ | */ | ||||
public int | public int | ||||
pflushmbc() | pflushmbc(void) | ||||
{ | { | ||||
int r = 0; | int r = 0; | ||||
if (mbc_buf_len > 0) | if (mbc_buf_len > 0) | ||||
{ | { | ||||
/* Flush incomplete (truncated) sequence. */ | /* Flush incomplete (truncated) sequence. */ | ||||
r = flush_mbc_buf(mbc_pos); | r = flush_mbc_buf(mbc_pos); | ||||
mbc_buf_len = 0; | mbc_buf_len = 0; | ||||
} | } | ||||
return r; | return r; | ||||
} | } | ||||
/* | /* | ||||
* Terminate the line in the line buffer. | * Terminate the line in the line buffer. | ||||
*/ | */ | ||||
public void | public void | ||||
pdone(endline, forw) | pdone(int endline, int forw) | ||||
int endline; | |||||
int forw; | |||||
{ | { | ||||
(void) pflushmbc(); | (void) pflushmbc(); | ||||
if (pendc && (pendc != '\r' || !endline)) | if (pendc && (pendc != '\r' || !endline)) | ||||
/* | /* | ||||
* If we had a pending character, put it in the buffer. | * If we had a pending character, put it in the buffer. | ||||
* But discard a pending CR if we are at end of line | * But discard a pending CR if we are at end of line | ||||
* (that is, discard the CR in a CR/LF sequence). | * (that is, discard the CR in a CR/LF sequence). | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | pdone(int endline, int forw) | ||||
linebuf[curr] = '\0'; | linebuf[curr] = '\0'; | ||||
attr[curr] = AT_NORMAL; | attr[curr] = AT_NORMAL; | ||||
} | } | ||||
/* | /* | ||||
* | * | ||||
*/ | */ | ||||
public void | public void | ||||
set_status_col(c) | set_status_col(char c) | ||||
char c; | |||||
{ | { | ||||
linebuf[0] = c; | linebuf[0] = c; | ||||
attr[0] = AT_NORMAL|AT_HILITE; | attr[0] = AT_NORMAL|AT_HILITE; | ||||
} | } | ||||
/* | /* | ||||
* Get a character from the current line. | * Get a character from the current line. | ||||
* Return the character as the function return value, | * Return the character as the function return value, | ||||
* and the character attribute in *ap. | * and the character attribute in *ap. | ||||
*/ | */ | ||||
public int | public int | ||||
gline(i, ap) | gline(int i, int *ap) | ||||
register int i; | |||||
register int *ap; | |||||
{ | { | ||||
if (is_null_line) | if (is_null_line) | ||||
{ | { | ||||
/* | /* | ||||
* If there is no current line, we pretend the line is | * If there is no current line, we pretend the line is | ||||
* either "~" or "", depending on the "twiddle" flag. | * either "~" or "", depending on the "twiddle" flag. | ||||
*/ | */ | ||||
if (twiddle) | if (twiddle) | ||||
Show All 13 Lines | gline(int i, int *ap) | ||||
*ap = attr[i]; | *ap = attr[i]; | ||||
return (linebuf[i] & 0xFF); | return (linebuf[i] & 0xFF); | ||||
} | } | ||||
/* | /* | ||||
* Indicate that there is no current line. | * Indicate that there is no current line. | ||||
*/ | */ | ||||
public void | public void | ||||
null_line() | null_line(void) | ||||
{ | { | ||||
is_null_line = 1; | is_null_line = 1; | ||||
cshift = 0; | cshift = 0; | ||||
} | } | ||||
/* | /* | ||||
* Analogous to forw_line(), but deals with "raw lines": | * Analogous to forw_line(), but deals with "raw lines": | ||||
* lines which are not split for screen width. | * lines which are not split for screen width. | ||||
* {{ This is supposed to be more efficient than forw_line(). }} | * {{ This is supposed to be more efficient than forw_line(). }} | ||||
*/ | */ | ||||
public POSITION | public POSITION | ||||
forw_raw_line(curr_pos, linep, line_lenp) | forw_raw_line(POSITION curr_pos, char **linep, int *line_lenp) | ||||
POSITION curr_pos; | |||||
char **linep; | |||||
int *line_lenp; | |||||
{ | { | ||||
register int n; | int n; | ||||
register int c; | int c; | ||||
POSITION new_pos; | POSITION new_pos; | ||||
if (curr_pos == NULL_POSITION || ch_seek(curr_pos) || | if (curr_pos == NULL_POSITION || ch_seek(curr_pos) || | ||||
(c = ch_forw_get()) == EOI) | (c = ch_forw_get()) == EOI) | ||||
return (NULL_POSITION); | return (NULL_POSITION); | ||||
n = 0; | n = 0; | ||||
for (;;) | for (;;) | ||||
Show All 26 Lines | forw_raw_line(POSITION curr_pos, char **linep, int *line_lenp) | ||||
return (new_pos); | return (new_pos); | ||||
} | } | ||||
/* | /* | ||||
* Analogous to back_line(), but deals with "raw lines". | * Analogous to back_line(), but deals with "raw lines". | ||||
* {{ This is supposed to be more efficient than back_line(). }} | * {{ This is supposed to be more efficient than back_line(). }} | ||||
*/ | */ | ||||
public POSITION | public POSITION | ||||
back_raw_line(curr_pos, linep, line_lenp) | back_raw_line(POSITION curr_pos, char **linep, int *line_lenp) | ||||
POSITION curr_pos; | |||||
char **linep; | |||||
int *line_lenp; | |||||
{ | { | ||||
register int n; | int n; | ||||
register int c; | int c; | ||||
POSITION new_pos; | POSITION new_pos; | ||||
if (curr_pos == NULL_POSITION || curr_pos <= ch_zero() || | if (curr_pos == NULL_POSITION || curr_pos <= ch_zero() || | ||||
ch_seek(curr_pos-1)) | ch_seek(curr_pos-1)) | ||||
return (NULL_POSITION); | return (NULL_POSITION); | ||||
n = size_linebuf; | n = size_linebuf; | ||||
linebuf[--n] = '\0'; | linebuf[--n] = '\0'; | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |