Skip to content

Commit

Permalink
Minor cleanup.
Browse files Browse the repository at this point in the history
Privatize global variable screen_trashed,
add screen_trashed() and related functions
  • Loading branch information
gwsw committed Sep 12, 2023
1 parent fa07889 commit d1ed82b
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 38 deletions.
3 changes: 1 addition & 2 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ static int maxbufs = -1;
extern int autobuf;
extern int sigs;
extern int secure;
extern int screen_trashed;
extern int follow_mode;
extern int waiting_for_data;
extern constant char helpdata[];
Expand Down Expand Up @@ -325,7 +324,7 @@ static int ch_get(void)
if (ignore_eoi && follow_mode == FOLLOW_NAME && curr_ifile_changed())
{
/* screen_trashed=2 causes make_display to reopen the file. */
screen_trashed = 2;
screen_trashed_num(2);
return (EOI);
}
if (sigs)
Expand Down
29 changes: 22 additions & 7 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ extern void *ml_shell;
extern char *editor;
extern char *editproto;
#endif
extern int screen_trashed; /* The screen has been overwritten */
extern int shift_count;
extern int oldbot;
extern int forw_prompt;
Expand All @@ -86,6 +85,7 @@ static POSITION bottompos;
static int save_hshift;
static int save_bs_mode;
static int save_proc_backspace;
static int screen_trashed_value = 0;
#if PIPEC
static char pipec;
#endif
Expand Down Expand Up @@ -765,6 +765,21 @@ static void clear_buffers(void)
#endif
}

public void screen_trashed_num(int trashed)
{
screen_trashed_value = trashed;
}

public void screen_trashed(void)
{
screen_trashed_num(1);
}

public int is_screen_trashed(void)
{
return screen_trashed_value;
}

/*
* Make sure the screen is displayed.
*/
Expand All @@ -785,13 +800,13 @@ static void make_display(void)
jump_loc(ch_zero(), 1);
else
jump_loc(initial_scrpos.pos, initial_scrpos.ln);
} else if (screen_trashed || !full_screen)
} else if (is_screen_trashed() || !full_screen)
{
int save_top_scroll = top_scroll;
int save_ignore_eoi = ignore_eoi;
top_scroll = 1;
ignore_eoi = 0;
if (screen_trashed == 2)
if (is_screen_trashed() == 2)
{
/* Special case used by ignore_eoi: re-open the input file
* and jump to the end of the file. */
Expand Down Expand Up @@ -2048,7 +2063,7 @@ public void commands(void)
number = hshift;
pos_rehead();
hshift -= number;
screen_trashed = 1;
screen_trashed();
break;

case A_RSHIFT:
Expand All @@ -2061,7 +2076,7 @@ public void commands(void)
number = (shift_count > 0) ? shift_count : sc_width / 2;
pos_rehead();
hshift += number;
screen_trashed = 1;
screen_trashed();
break;

case A_LLSHIFT:
Expand All @@ -2070,7 +2085,7 @@ public void commands(void)
*/
pos_rehead();
hshift = 0;
screen_trashed = 1;
screen_trashed();
break;

case A_RRSHIFT:
Expand All @@ -2079,7 +2094,7 @@ public void commands(void)
*/
pos_rehead();
hshift = rrshift();
screen_trashed = 1;
screen_trashed();
break;

case A_PREFIX:
Expand Down
3 changes: 1 addition & 2 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
extern int erase_char, erase2_char, kill_char;
extern int secure;
extern int mousecap;
extern int screen_trashed;
extern int sc_height;

#define SK(k) \
Expand Down Expand Up @@ -451,7 +450,7 @@ static int mouse_button_rel(int x, int y)
if (y < sc_height-1)
{
setmark('#', y);
screen_trashed = 1;
screen_trashed();
}
return (A_NOACTION);
}
Expand Down
1 change: 0 additions & 1 deletion forwback.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "less.h"
#include "position.h"

public int screen_trashed;
public int squished;
public int no_back_scroll = 0;
public int forw_prompt;
Expand Down
5 changes: 2 additions & 3 deletions jump.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

extern int jump_sline;
extern int squished;
extern int screen_trashed;
extern int sc_width, sc_height;
extern int show_attn;
extern int top_scroll;
Expand Down Expand Up @@ -273,7 +272,7 @@ public void jump_loc(POSITION pos, int sline)
}
lastmark();
squished = 0;
screen_trashed = 0;
screen_trashed_num(0);
forw(sc_height-1, pos, 1, 0, sindex-nline);
} else
{
Expand Down Expand Up @@ -318,7 +317,7 @@ public void jump_loc(POSITION pos, int sline)
clear();
else
home();
screen_trashed = 0;
screen_trashed_num(0);
add_back_pos(pos);
back(sc_height-1, pos, 1, 0);
}
Expand Down
3 changes: 1 addition & 2 deletions linenum.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public int scanning_eof = FALSE;
extern int linenums;
extern int sigs;
extern int sc_height;
extern int screen_trashed;
extern int header_lines;
extern int nonum_headers;

Expand Down Expand Up @@ -248,7 +247,7 @@ static void abort_long(void)
/*
* We were displaying line numbers, so need to repaint.
*/
screen_trashed = 1;
screen_trashed();
linenums = 0;
error("Line numbers turned off", NULL_PARG);
}
Expand Down
5 changes: 2 additions & 3 deletions lsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#endif
#endif

extern int screen_trashed;
extern IFILE curr_ifile;


Expand Down Expand Up @@ -193,7 +192,7 @@ public void lsystem(char *cmd, char *donemsg)
flush();
}
init();
screen_trashed = 1;
screen_trashed();

#if MSDOS_COMPILER && MSDOS_COMPILER!=WIN32C
/*
Expand Down Expand Up @@ -353,7 +352,7 @@ public int pipe_data(char *cmd, POSITION spos, POSITION epos)
init_signals(1);
raw_mode(1);
init();
screen_trashed = 1;
screen_trashed();
#if defined(SIGWINCH) || defined(SIGWIND)
/* {{ Probably don't need this here. }} */
winch(0);
Expand Down
3 changes: 1 addition & 2 deletions option.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public int plusoption = FALSE;
static char *optstring(char *s, char **p_str, char *printopt, char *validchars);
static int flip_triple(int val, int lc);

extern int screen_trashed;
extern int less_is_more;
extern int quit_at_eof;
extern char *every_first_cmd;
Expand Down Expand Up @@ -470,7 +469,7 @@ public void toggle_option(struct loption *o, int lower, char *s, int how_toggle)
}

if (how_toggle != OPT_NO_TOGGLE && (o->otype & REPAINT))
screen_trashed = TRUE;
screen_trashed();
}

/*
Expand Down
9 changes: 4 additions & 5 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public int at_prompt;
extern int sigs;
extern int sc_width;
extern int so_s_width, so_e_width;
extern int screen_trashed;
extern int is_tty;
extern int oldbot;
extern char intr_char;
Expand Down Expand Up @@ -60,7 +59,7 @@ public void put_line(void)
/*
* Don't output if a signal is pending.
*/
screen_trashed = 1;
screen_trashed();
return;
}

Expand Down Expand Up @@ -373,7 +372,7 @@ public void flush(void)
#endif

if (write(outfd, obuf, n) != n)
screen_trashed = 1;
screen_trashed();
}

/*
Expand Down Expand Up @@ -632,7 +631,7 @@ public void error(char *fmt, PARG *parg)
* {{ Unless the terminal doesn't have auto margins,
* in which case we just hammered on the right margin. }}
*/
screen_trashed = 1;
screen_trashed();

flush();
}
Expand Down Expand Up @@ -690,7 +689,7 @@ public int query(char *fmt, PARG *parg)
{
lower_left();
if (col >= sc_width)
screen_trashed = 1;
screen_trashed();
flush();
} else
{
Expand Down
4 changes: 1 addition & 3 deletions position.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ static int table_size = 0;

extern int sc_width, sc_height;
extern int header_lines;
extern int screen_trashed;
extern int hshift;
extern int chopline;

/*
* Return the starting file position of a line displayed on the screen.
Expand Down Expand Up @@ -300,5 +298,5 @@ public void pos_rehead(void)
return;
table[TOP] = linepos;
hshift = pos_shift(linepos, tpos - linepos);
screen_trashed = 1;
screen_trashed();
}
3 changes: 1 addition & 2 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ extern int no_init;
extern int no_keypad;
extern int sigs;
extern int wscroll;
extern int screen_trashed;
extern int top_scroll;
extern int quit_if_one_screen;
extern int oldbot;
Expand Down Expand Up @@ -2150,7 +2149,7 @@ public void check_winch(void)
SetConsoleScreenBufferSize(con_out, size);
pos_init();
wscroll = (sc_height + 1) / 2;
screen_trashed = 1;
screen_trashed();
}
#endif
}
Expand Down
5 changes: 2 additions & 3 deletions search.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ extern void *ml_search;
extern POSITION start_attnpos;
extern POSITION end_attnpos;
extern int utf_mode;
extern int screen_trashed;
extern int sc_width;
extern int sc_height;
extern int hshift;
Expand Down Expand Up @@ -581,7 +580,7 @@ static void shift_visible(int start_off, int end_off)
if (start_off >= hshift && end_off < hshift + swidth)
return; /* already visible */
hshift = (end_off < swidth) ? 0 : (start_off < found_shift) ? 0 : (start_off - found_shift);
screen_trashed = 1;
screen_trashed();
}

/*
Expand Down Expand Up @@ -1843,7 +1842,7 @@ public void set_filter_pattern(char *pattern, int search_type)
filter->next = filter_infos;
filter_infos = filter;
}
screen_trashed = 1;
screen_trashed();
}

/*
Expand Down
5 changes: 2 additions & 3 deletions signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
public int sigs;

extern int sc_width, sc_height;
extern int screen_trashed;
extern int lnloop;
extern int linenums;
extern int wscroll;
Expand Down Expand Up @@ -230,7 +229,7 @@ public void psignals(void)
LSIGNAL(SIGTSTP, stop);
raw_mode(1);
init();
screen_trashed = 1;
screen_trashed();
tsignals |= S_WINCH;
}
#endif
Expand All @@ -250,7 +249,7 @@ public void psignals(void)
calc_jump_sline();
calc_shift_count();
}
screen_trashed = 1;
screen_trashed();
}
#endif
if (tsignals & S_INTERRUPT)
Expand Down

0 comments on commit d1ed82b

Please sign in to comment.