summaryrefslogtreecommitdiffstats
path: root/usr.bin/more
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1994-09-22 01:19:13 +0000
committerache <ache@FreeBSD.org>1994-09-22 01:19:13 +0000
commite45f1435202cb2bf1c3a97dfc122d11155b5925a (patch)
treeb6391df45c81d39478b6e261fb9b24420643e912 /usr.bin/more
parent6c7f19942f7afda8224cd0d083cde770c20e3a02 (diff)
downloadFreeBSD-src-e45f1435202cb2bf1c3a97dfc122d11155b5925a.zip
FreeBSD-src-e45f1435202cb2bf1c3a97dfc122d11155b5925a.tar.gz
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
Diffstat (limited to 'usr.bin/more')
-rw-r--r--usr.bin/more/ch.c12
-rw-r--r--usr.bin/more/command.c16
-rw-r--r--usr.bin/more/less.h2
-rw-r--r--usr.bin/more/line.c52
-rw-r--r--usr.bin/more/output.c25
-rw-r--r--usr.bin/more/prim.c6
-rw-r--r--usr.bin/more/screen.c23
-rw-r--r--usr.bin/more/ttyin.c2
8 files changed, 85 insertions, 53 deletions
diff --git a/usr.bin/more/ch.c b/usr.bin/more/ch.c
index 668e601..a971c76 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 @@ read_more:
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 @@ found:
*/
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 51f5847..dcab842 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 70de6de..c4dd23f 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 7634f35..bdef948 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 @@ enter_boldface:
* 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 @@ enter_underline:
* 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 @@ enter_underline:
/*
* 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 @@ enter_underline:
}
ln_ul_xb_case:
if (c == '_')
- c = curr[-2];
+ c = curr[-2] & 0xff;
curr -= 2;
ln_state = LN_UNDERLINE;
break;
@@ -268,7 +267,7 @@ ln_ul_xb_case:
/*
* 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 @@ ln_bo_xb_case:
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 @@ ln_bo_xb_case:
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 @@ ln_bo_xb_case:
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 2205f1f..4524bd5 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 d5af8f3..99361cc 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 edfae1e..2dc99ec 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 52ff92e..2d3567e 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);
}
OpenPOWER on IntegriCloud