From c8939366a1439286328a3e35068ac1b20d84e7c7 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Thu, 22 Sep 1994 01:19:13 +0000 Subject: [PATCH] 1) Make ctype-aware expect chars in range 0200-0204 treated as controls in any case. 2) Fix bug with incorrect column position when standouts occurse 3) Fix bug when last standouted char cause clearing next line in standout --- usr.bin/more/ch.c | 12 +++++----- usr.bin/more/command.c | 16 ++++++++----- usr.bin/more/less.h | 2 +- usr.bin/more/line.c | 52 +++++++++++++++++++++--------------------- usr.bin/more/output.c | 25 ++++++++++++-------- usr.bin/more/prim.c | 6 ++--- usr.bin/more/screen.c | 23 +++++++++++++++++++ usr.bin/more/ttyin.c | 2 +- 8 files changed, 85 insertions(+), 53 deletions(-) diff --git a/usr.bin/more/ch.c b/usr.bin/more/ch.c index 668e601cb40d..a971c76b8732 100644 --- a/usr.bin/more/ch.c +++ b/usr.bin/more/ch.c @@ -96,7 +96,7 @@ static off_t last_piped_pos; #define ch_get() \ ((buf_head->block == ch_block && \ ch_offset < buf_head->datasize) ? \ - buf_head->data[ch_offset] : fch_get()) + buf_head->data[ch_offset] & 0xff : fch_get()) static fch_get() @@ -130,7 +130,7 @@ fch_get() * find it already buffered. */ if (ispipe) - return(bp->data[ch_offset]); + return(bp->data[ch_offset] & 0xff); goto found; } /* @@ -189,15 +189,15 @@ fch_get() if (bs_mode) { for (p = &bp->data[bp->datasize]; --n >= 0;) { - *--p &= 0177; + *--p; if (*p == EOI) *p = 0200; } } else { for (t = p; --n >= 0; ++p) { - ch = *p & 0177; - if (ch == '\r' && n && (p[1] & 0177) == '\n') { + ch = *p; + if (ch == '\r' && n && p[1] == '\n') { ++p; *t++ = '\n'; } @@ -233,7 +233,7 @@ fch_get() */ goto read_more; - return(bp->data[ch_offset]); + return(bp->data[ch_offset] & 0xff); } /* diff --git a/usr.bin/more/command.c b/usr.bin/more/command.c index 51f58470f495..dcab84268931 100644 --- a/usr.bin/more/command.c +++ b/usr.bin/more/command.c @@ -76,6 +76,7 @@ static int wsearch; /* Search for matches (1) or non-matches (0) */ static cmd_erase() { + int c; /* * backspace past beginning of the string: this usually means * abort the command. @@ -84,7 +85,8 @@ cmd_erase() return(1); /* erase an extra character, for the carat. */ - if (CONTROL_CHAR(*--cp)) { + c = *--cp & 0xff; + if (CONTROL_CHAR(c)) { backspace(); --cmd_col; } @@ -119,9 +121,9 @@ cmd_char(c) /* in this order, in case werase == erase_char */ if (c == werase_char) { if (cp > cmdbuf) { - while (isspace(cp[-1]) && !cmd_erase()); - while (!isspace(cp[-1]) && !cmd_erase()); - while (isspace(cp[-1]) && !cmd_erase()); + while (isspace(cp[-1] & 0xff) && !cmd_erase()); + while (!isspace(cp[-1] & 0xff) && !cmd_erase()); + while (isspace(cp[-1] & 0xff) && !cmd_erase()); } return(cp == cmdbuf); } @@ -141,6 +143,7 @@ cmd_char(c) if (CONTROL_CHAR(c)) { putchr('^'); cmd_col++; + c &= ~0200; c = CARAT_CHAR(c); } putchr(c); @@ -273,11 +276,11 @@ exec_mca() (void)search(0, cmdbuf, number, wsearch); break; case A_EXAMINE: - for (p = cmdbuf; isspace(*p); ++p); + for (p = cmdbuf; isspace(*p & 0xff); ++p); (void)edit(glob(p)); break; case A_TAGFILE: - for (p = cmdbuf; isspace(*p); ++p); + for (p = cmdbuf; isspace(*p & 0xff); ++p); findtag(p); if (tagfile == NULL) break; @@ -573,6 +576,7 @@ again: if (sigs) start_mca(A_PREFIX, ""); if (CONTROL_CHAR(c)) { putchr('^'); + c &= ~0200; c = CARAT_CHAR(c); } putchr(c); diff --git a/usr.bin/more/less.h b/usr.bin/more/less.h index 70de6de4e94e..c4dd23f338df 100644 --- a/usr.bin/more/less.h +++ b/usr.bin/more/less.h @@ -47,7 +47,7 @@ #define BO_CHAR '\203' /* Enter boldface mode */ #define BE_CHAR '\204' /* Exit boldface mode */ -#define CONTROL_CHAR(c) (iscntrl(c)) +#define CONTROL_CHAR(c) (!isprint(c)) #define CARAT_CHAR(c) ((c == '\177') ? '?' : (c | 0100)) #define TOP (0) diff --git a/usr.bin/more/line.c b/usr.bin/more/line.c index 7634f3596390..bdef948616c6 100644 --- a/usr.bin/more/line.c +++ b/usr.bin/more/line.c @@ -167,10 +167,9 @@ pappend(c) switch (ln_state) { case LN_NORMAL: if (curr <= linebuf + 1 - || curr[-1] != (char)('H' | 0200)) + || curr[-1] != '\b') break; - column -= 2; - if (c == curr[-2]) + if (c == (curr[-2] & 0xff)) goto enter_boldface; if (c == '_' || curr[-2] == '_') goto enter_underline; @@ -183,7 +182,7 @@ pappend(c) * Switch into boldface mode. */ column--; - if (column + bo_width + be_width + 1 >= sc_width) + if (column + bo_width + be_width >= sc_width) /* * Not enough room left on the screen to * enter and exit boldface mode. @@ -213,7 +212,7 @@ pappend(c) * the current char). Switch into underline mode. */ column--; - if (column + ul_width + ue_width + 1 >= sc_width) + if (column + ul_width + ue_width >= sc_width) /* * Not enough room left on the screen to * enter and exit underline mode. @@ -243,7 +242,7 @@ pappend(c) /* * Termination of a sequence "_\bX" or "X\b_". */ - if (c != '_' && curr[-2] != '_' && c == curr[-2]) + if (c != '_' && curr[-2] != '_' && c == (curr[-2] & 0xff)) { /* * We seem to have run on from underlining @@ -260,7 +259,7 @@ pappend(c) } ln_ul_xb_case: if (c == '_') - c = curr[-2]; + c = curr[-2] & 0xff; curr -= 2; ln_state = LN_UNDERLINE; break; @@ -268,7 +267,7 @@ pappend(c) /* * Termination of a sequnce "X\bX". */ - if (c != curr[-2] && (c == '_' || curr[-2] == '_')) + if (c != (curr[-2] & 0xff) && (c == '_' || curr[-2] == '_')) { /* * We seem to have run on from @@ -286,7 +285,7 @@ pappend(c) ln_state = LN_BOLDFACE; break; case LN_UNDERLINE: - if (column + ue_width + bo_width + 1 + be_width >= sc_width) + if (column + ue_width + bo_width + be_width >= sc_width) /* * We have just barely enough room to * exit underline mode and handle a possible @@ -301,7 +300,7 @@ pappend(c) ln_state = LN_BO_XB; break; } - if (column + be_width + ul_width + 1 + ue_width >= sc_width) + if (column + be_width + ul_width + ue_width >= sc_width) /* * We have just barely enough room to * exit underline mode and handle a possible @@ -378,30 +377,31 @@ pappend(c) if (c == '\b') { if (ln_state == LN_NORMAL) - NEW_COLUMN(2); + NEW_COLUMN(0); else column--; - *curr++ = ('H' | 0200); + *curr++ = c; return(0); } - if (CONTROL_CHAR(c)) { - /* - * Put a "^X" into the buffer. The 0200 bit is used to tell - * put_line() to prefix the char with a ^. We don't actually - * put the ^ in the buffer because we sometimes need to move - * chars around, and such movement might separate the ^ from - * its following character. - */ + switch ((char)c) { + case UL_CHAR: + case UE_CHAR: + case BO_CHAR: + case BE_CHAR: + c &= ~0200; + /* fall through */ + case '\200': NEW_COLUMN(2); - *curr++ = (CARAT_CHAR(c) | 0200); - return(0); + break; + default: + if (CONTROL_CHAR(c)) + NEW_COLUMN(2); + else + NEW_COLUMN(1); + break; } - /* - * Ordinary character. Just put it in the buffer. - */ - NEW_COLUMN(1); *curr++ = c; return (0); } diff --git a/usr.bin/more/output.c b/usr.bin/more/output.c index 2205f1f8972c..4524bd5985fc 100644 --- a/usr.bin/more/output.c +++ b/usr.bin/more/output.c @@ -54,6 +54,8 @@ extern int tabstop; extern int screen_trashed; extern int any_display; extern char *line; +extern int mode_flags; +static int last_pos_highlighted = 0; /* display the line which is in the line buffer. */ put_line() @@ -75,14 +77,19 @@ put_line() if (line == NULL) line = ""; + if (last_pos_highlighted) + { + clear_eol(); + last_pos_highlighted = 0; + } column = 0; for (p = line; *p != '\0'; p++) { - switch (c = *p) + switch ((char)(c = *p & 0xff)) { case UL_CHAR: ul_enter(); - column += ul_width +1; + column += ul_width; break; case UE_CHAR: ul_exit(); @@ -90,7 +97,7 @@ put_line() break; case BO_CHAR: bo_enter(); - column += bo_width +1; + column += bo_width; break; case BE_CHAR: bo_exit(); @@ -108,15 +115,11 @@ put_line() column--; break; default: - if (c & 0200) + if (c == 0200 || CONTROL_CHAR(c)) { - /* - * Control characters arrive here as the - * normal character [CARAT_CHAR(c)] with - * the 0200 bit set. See pappend(). - */ + c &= ~0200; putchr('^'); - putchr(c & 0177); + putchr(CARAT_CHAR(c)); column += 2; } else { @@ -124,6 +127,8 @@ put_line() column++; } } + if (column == sc_width && mode_flags) + last_pos_highlighted = 1; } if (column < sc_width || !auto_wrap || ignaw) putchr('\n'); diff --git a/usr.bin/more/prim.c b/usr.bin/more/prim.c index d5af8f397089..99361cc4266f 100644 --- a/usr.bin/more/prim.c +++ b/usr.bin/more/prim.c @@ -611,8 +611,8 @@ search(search_forward, pattern, n, wantmatch) */ if (caseless && pattern != NULL) for (p = pattern; *p; p++) - if (isupper(*p)) - *p = tolower(*p); + if (isupper(*p & 0xff)) + *p = tolower(*p & 0xff); #ifdef RECOMP /* @@ -764,7 +764,7 @@ search(search_forward, pattern, n, wantmatch) */ if (caseless) for (p = q = line; *p; p++, q++) - *q = isupper(*p) ? tolower(*p) : *p; + *q = isupper(*p & 0xff) ? tolower(*p & 0xff) : *p; /* * Remove any backspaces along with the preceeding char. diff --git a/usr.bin/more/screen.c b/usr.bin/more/screen.c index edfae1e13b43..2dc99ecfbfca 100644 --- a/usr.bin/more/screen.c +++ b/usr.bin/more/screen.c @@ -106,6 +106,11 @@ int bo_width, be_width; /* Printing width of boldface sequences */ int ul_width, ue_width; /* Printing width of underline sequences */ int so_width, se_width; /* Printing width of standout sequences */ +int mode_flags = 0; +#define M_SO 1 +#define M_UL 2 +#define M_BO 4 + /* * These two variables are sometimes defined in, * and needed by, the termcap library. @@ -503,6 +508,12 @@ bell() */ clear() { + if (mode_flags & M_SO) + so_exit(); + if (mode_flags & M_UL) + ul_exit(); + if (mode_flags & M_BO) + bo_exit(); tputs(sc_clear, sc_height, putchr); } @@ -512,6 +523,12 @@ clear() */ clear_eol() { + if (mode_flags & M_SO) + so_exit(); + if (mode_flags & M_UL) + ul_exit(); + if (mode_flags & M_BO) + bo_exit(); tputs(sc_eol_clear, 1, putchr); } @@ -521,6 +538,7 @@ clear_eol() so_enter() { tputs(sc_s_in, 1, putchr); + mode_flags |= M_SO; } /* @@ -529,6 +547,7 @@ so_enter() so_exit() { tputs(sc_s_out, 1, putchr); + mode_flags &= ~M_SO; } /* @@ -538,6 +557,7 @@ so_exit() ul_enter() { tputs(sc_u_in, 1, putchr); + mode_flags |= M_UL; } /* @@ -546,6 +566,7 @@ ul_enter() ul_exit() { tputs(sc_u_out, 1, putchr); + mode_flags &= ~M_UL; } /* @@ -554,6 +575,7 @@ ul_exit() bo_enter() { tputs(sc_b_in, 1, putchr); + mode_flags |= M_BO; } /* @@ -562,6 +584,7 @@ bo_enter() bo_exit() { tputs(sc_b_out, 1, putchr); + mode_flags &= ~M_BO; } /* diff --git a/usr.bin/more/ttyin.c b/usr.bin/more/ttyin.c index 52ff92e66ac1..2d3567ed0492 100644 --- a/usr.bin/more/ttyin.c +++ b/usr.bin/more/ttyin.c @@ -75,5 +75,5 @@ getchr() quit(); } } while (result != 1); - return (c & 0177); + return (c & 0xff); }