Skip to content

Commit

Permalink
Minor clean up, better distinguish between sline and sindex.
Browse files Browse the repository at this point in the history
Fix off-by-one bug in '$.
Document M and ESC-m commands.
  • Loading branch information
gwsw committed Oct 26, 2017
1 parent aacde3b commit 39ffe1b
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 53 deletions.
4 changes: 2 additions & 2 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ commands()
/*
* Clear a mark.
*/
start_mca(A_SETMARK, "clear mark: ", (void*)NULL, 0);
start_mca(A_CLRMARK, "clear mark: ", (void*)NULL, 0);
c = getcc();
if (is_erase_char(c) || is_newline_char(c))
break;
Expand All @@ -1801,7 +1801,7 @@ commands()
/*
* Jump to a marked position.
*/
start_mca(A_SETMARK, "goto mark: ", (void*)NULL, 0);
start_mca(A_GOMARK, "goto mark: ", (void*)NULL, 0);
c = getcc();
if (is_erase_char(c) || is_newline_char(c))
break;
Expand Down
19 changes: 10 additions & 9 deletions jump.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jump_forw()
end_pos = ch_tell();
pos = back_line(end_pos);
if (pos == NULL_POSITION)
jump_loc((POSITION)0, sc_height-1);
jump_loc(ch_zero(), sc_height-1);
else
{
jump_loc(pos, sc_height-1);
Expand Down Expand Up @@ -119,7 +119,7 @@ repaint()
pos_clear();
if (scrpos.pos == NULL_POSITION)
/* Screen hasn't been drawn yet. */
jump_loc(0, 0);
jump_loc(ch_zero(), 1);
else
jump_loc(scrpos.pos, scrpos.ln);
}
Expand Down Expand Up @@ -194,21 +194,22 @@ jump_loc(pos, sline)
int sline;
{
int nline;
int sindex;
POSITION tpos;
POSITION bpos;

/*
* Normalize sline.
*/
sline = adjsline(sline);
sindex = sindex_from_sline(sline);

if ((nline = onscreen(pos)) >= 0)
{
/*
* The line is currently displayed.
* Just scroll there.
*/
nline -= sline;
nline -= sindex;
if (nline > 0)
forw(nline, position(BOTTOM_PLUS_ONE), 1, 0, 0);
else if (nline < 0)
Expand Down Expand Up @@ -244,7 +245,7 @@ jump_loc(pos, sline)
* call forw() and put the desired line at the
* sline-th line on the screen.
*/
for (nline = 0; nline < sline; nline++)
for (nline = 0; nline < sindex; nline++)
{
if (bpos != NULL_POSITION && pos <= bpos)
{
Expand All @@ -253,7 +254,7 @@ jump_loc(pos, sline)
* close enough to the current screen
* that we can just scroll there after all.
*/
forw(sc_height-sline+nline-1, bpos, 1, 0, 0);
forw(sc_height-sindex+nline-1, bpos, 1, 0, 0);
#if HILITE_SEARCH
if (show_attn)
repaint_hilite(1);
Expand All @@ -275,16 +276,16 @@ jump_loc(pos, sline)
lastmark();
squished = 0;
screen_trashed = 0;
forw(sc_height-1, pos, 1, 0, sline-nline);
forw(sc_height-1, pos, 1, 0, sindex-nline);
} else
{
/*
* The desired line is before the current screen.
* Move forward in the file far enough so that we
* can call back() and put the desired line at the
* sline-th line on the screen.
* sindex-th line on the screen.
*/
for (nline = sline; nline < sc_height - 1; nline++)
for (nline = sindex; nline < sc_height - 1; nline++)
{
pos = forw_line(pos);
if (pos == NULL_POSITION)
Expand Down
4 changes: 3 additions & 1 deletion less.hlp.VER
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@
Each "find open bracket" command goes backward to the open bracket
matching the (_N-th) close bracket in the bottom line.

m_<_l_e_t_t_e_r_> Mark the current position with <letter>.
m_<_l_e_t_t_e_r_> Mark the current top line with <letter>.
M_<_l_e_t_t_e_r_> Mark the current bottom line with <letter>.
'_<_l_e_t_t_e_r_> Go to a previously marked position.
'' Go to the previous position.
^X^X Same as '.
ESC-M_<_l_e_t_t_e_r_> Clear a mark.
---------------------------------------------------
A mark is any upper-case or lower-case letter.
Certain marks are predefined:
Expand Down
6 changes: 3 additions & 3 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ the status column shows the marked line.
.IP M
Acts like m, except the last displayed line is marked
rather than the first displayed line.
.IP "ESC-m"
Followed by any lowercase or uppercase letter,
removes the mark identified by that letter.
.IP "'"
(Single quote.)
Followed by any lowercase or uppercase letter, returns to the position which
Expand All @@ -196,6 +193,9 @@ Marks are preserved when a new file is examined,
so the ' command can be used to switch between input files.
.IP "^X^X"
Same as single quote.
.IP "ESC-m"
Followed by any lowercase or uppercase letter,
clears the mark identified by that letter.
.IP /pattern
Search forward in the file for the N-th line containing the pattern.
N defaults to 1.
Expand Down
2 changes: 1 addition & 1 deletion mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ getmark(c)
}
m = &sm;
m->m_scrpos.pos = ch_tell();
m->m_scrpos.ln = sc_height-1;
m->m_scrpos.ln = sc_height;
m->m_ifile = curr_ifile;
break;
case '.':
Expand Down
23 changes: 12 additions & 11 deletions position.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ extern int sc_width, sc_height;
* the line after the bottom line on the screen
*/
public POSITION
position(where)
int where;
position(sindex)
int sindex;
{
switch (where)
switch (sindex)
{
case BOTTOM:
where = sc_height - 2;
sindex = sc_height - 2;
break;
case BOTTOM_PLUS_ONE:
where = sc_height - 1;
sindex = sc_height - 1;
break;
case MIDDLE:
where = (sc_height - 1) / 2;
sindex = (sc_height - 1) / 2;
break;
}
return (table[where]);
return (table[sindex]);
}

/*
Expand Down Expand Up @@ -213,7 +214,7 @@ get_scrpos(scrpos, where)
* relative to the bottom of the screen.
*/
public int
adjsline(sline)
sindex_from_sline(sline)
int sline;
{
/*
Expand All @@ -223,12 +224,12 @@ adjsline(sline)
if (sline < 0)
sline += sc_height;
/*
* Can't be less than 1 or greater than sc_height-1.
* Can't be less than 1 or greater than sc_height.
*/
if (sline <= 0)
sline = 1;
if (sline >= sc_height)
sline = sc_height - 1;
if (sline > sc_height)
sline = sc_height;
/*
* Return zero-based line number, not one-based.
*/
Expand Down
2 changes: 1 addition & 1 deletion prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ wherechar(p, wp)
case 'm': *wp = MIDDLE; break;
case 'b': *wp = BOTTOM; break;
case 'B': *wp = BOTTOM_PLUS_ONE; break;
case 'j': *wp = adjsline(jump_sline); break;
case 'j': *wp = sindex_from_sline(jump_sline); break;
default: *wp = TOP; p--; break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1914,14 +1914,14 @@ check_winch()
* Goto a specific line on the screen.
*/
public void
goto_line(slinenum)
int slinenum;
goto_line(sindex)
int sindex;
{
#if !MSDOS_COMPILER
tputs(tgoto(sc_move, 0, slinenum), 1, putchr);
tputs(tgoto(sc_move, 0, sindex), 1, putchr);
#else
flush();
_settextposition(slinenum+1, 1);
_settextposition(sindex+1, 1);
#endif
}

Expand Down
42 changes: 21 additions & 21 deletions search.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ prev_pattern(info)
repaint_hilite(on)
int on;
{
int slinenum;
int sindex;
POSITION pos;
int save_hide_hilite;

Expand All @@ -273,13 +273,13 @@ repaint_hilite(on)
return;
}

for (slinenum = TOP; slinenum < TOP + sc_height-1; slinenum++)
for (sindex = TOP; sindex < TOP + sc_height-1; sindex++)
{
pos = position(slinenum);
pos = position(sindex);
if (pos == NULL_POSITION)
continue;
(void) forw_line(pos);
goto_line(slinenum);
goto_line(sindex);
put_line();
}
lower_left();
Expand All @@ -292,7 +292,7 @@ repaint_hilite(on)
public void
clear_attn()
{
int slinenum;
int sindex;
POSITION old_start_attnpos;
POSITION old_end_attnpos;
POSITION pos;
Expand All @@ -313,17 +313,17 @@ clear_attn()
if (squished)
repaint();

for (slinenum = TOP; slinenum < TOP + sc_height-1; slinenum++)
for (sindex = TOP; sindex < TOP + sc_height-1; sindex++)
{
pos = position(slinenum);
pos = position(sindex);
if (pos == NULL_POSITION)
continue;
epos = position(slinenum+1);
epos = position(sindex+1);
if (pos <= old_end_attnpos &&
(epos == NULL_POSITION || epos > old_start_attnpos))
{
(void) forw_line(pos);
goto_line(slinenum);
goto_line(sindex);
put_line();
moved = 1;
}
Expand Down Expand Up @@ -1059,7 +1059,7 @@ search_pos(search_type)
int search_type;
{
POSITION pos;
int linenum;
int sindex;

if (empty_screen())
{
Expand All @@ -1082,7 +1082,7 @@ search_pos(search_type)
pos = ch_length();
}
}
linenum = 0;
sindex = 0;
} else
{
int add_one = 0;
Expand All @@ -1093,30 +1093,30 @@ search_pos(search_type)
* Search does not include current screen.
*/
if (search_type & SRCH_FORW)
linenum = sc_height-1; /* BOTTOM_PLUS_ONE */
sindex = sc_height-1; /* BOTTOM_PLUS_ONE */
else
linenum = 0; /* TOP */
sindex = 0; /* TOP */
} else if (how_search == OPT_ONPLUS && !(search_type & SRCH_AFTER_TARGET))
{
/*
* Search includes all of displayed screen.
*/
if (search_type & SRCH_FORW)
linenum = 0; /* TOP */
sindex = 0; /* TOP */
else
linenum = sc_height-1; /* BOTTOM_PLUS_ONE */
sindex = sc_height-1; /* BOTTOM_PLUS_ONE */
} else
{
/*
* Search includes the part of current screen beyond the jump target.
* It starts at the jump target (if searching backwards),
* or at the jump target plus one (if forwards).
*/
linenum = adjsline(jump_sline);
sindex = sindex_from_sline(jump_sline);
if (search_type & SRCH_FORW)
add_one = 1;
}
pos = position(linenum);
pos = position(sindex);
if (add_one)
pos = forw_raw_line(pos, (char **)NULL, (int *)NULL);
}
Expand All @@ -1128,17 +1128,17 @@ search_pos(search_type)
{
while (pos == NULL_POSITION)
{
if (++linenum >= sc_height)
if (++sindex >= sc_height)
break;
pos = position(linenum);
pos = position(sindex);
}
} else
{
while (pos == NULL_POSITION)
{
if (--linenum < 0)
if (--sindex < 0)
break;
pos = position(linenum);
pos = position(sindex);
}
}
return (pos);
Expand Down

0 comments on commit 39ffe1b

Please sign in to comment.