more: rename functions

This clarifies what various function calls are doing.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2018-05-28 09:49:26 +01:00
parent d910f31110
commit 275d47c9b7
No known key found for this signature in database
GPG Key ID: A9553245FDE9B739
1 changed files with 86 additions and 85 deletions

View File

@ -227,7 +227,7 @@ static void __attribute__((__noreturn__)) usage(void)
} }
static void argscan(struct more_control *ctl, char *s) static void arg_parser(struct more_control *ctl, char *s)
{ {
int seen_num = 0; int seen_num = 0;
@ -309,7 +309,7 @@ static int more_ungetc(struct more_control *ctl, int c, FILE *stream)
* check for file magic numbers. This code would best be shared * check for file magic numbers. This code would best be shared
* with the file(1) program or, perhaps, more should not try to be * with the file(1) program or, perhaps, more should not try to be
* so smart. */ * so smart. */
static int magic(FILE *f, char *fs) static int check_magic(FILE *f, char *fs)
{ {
signed char twobytes[2]; signed char twobytes[2];
@ -361,7 +361,7 @@ static FILE *checkf(struct more_control *ctl, char *fs, int *clearfirst)
warn(_("cannot open %s"), fs); warn(_("cannot open %s"), fs);
return NULL; return NULL;
} }
if (magic(f, fs)) { if (check_magic(f, fs)) {
fclose(f); fclose(f);
return NULL; return NULL;
} }
@ -585,7 +585,7 @@ static int get_line(struct more_control *ctl, FILE *f, int *length)
} }
/* Erase the rest of the prompt, assuming we are starting at column col. */ /* Erase the rest of the prompt, assuming we are starting at column col. */
static void erasep(struct more_control *ctl, int col) static void erase_prompt(struct more_control *ctl, int col)
{ {
if (ctl->prompt_len == 0) if (ctl->prompt_len == 0)
@ -614,7 +614,7 @@ static UL_ASAN_BLACKLIST size_t xmbrtowc(wchar_t *wc, const char *s, size_t n,
} }
#endif #endif
static int wouldul(char *s, int n) static int would_underline(char *s, int n)
{ {
if (n < 2) if (n < 2)
return 0; return 0;
@ -624,7 +624,7 @@ static int wouldul(char *s, int n)
} }
/* Print a buffer of n characters */ /* Print a buffer of n characters */
static void prbuf(struct more_control *ctl, char *s, int n) static void print_buf(struct more_control *ctl, char *s, int n)
{ {
char c; /* next output character */ char c; /* next output character */
int state; /* next output char's UL state */ int state; /* next output char's UL state */
@ -634,11 +634,11 @@ static void prbuf(struct more_control *ctl, char *s, int n)
putchar(*s++); putchar(*s++);
else { else {
if (*s == ' ' && ctl->underline_state == 0 && ctl->underline_glitch if (*s == ' ' && ctl->underline_state == 0 && ctl->underline_glitch
&& wouldul(s + 1, n - 1)) { && would_underline(s + 1, n - 1)) {
s++; s++;
continue; continue;
} }
if ((state = wouldul(s, n)) != 0) { if ((state = would_underline(s, n)) != 0) {
c = (*s == '_') ? s[2] : *s; c = (*s == '_') ? s[2] : *s;
n -= 2; n -= 2;
s += 3; s += 3;
@ -646,7 +646,7 @@ static void prbuf(struct more_control *ctl, char *s, int n)
c = *s++; c = *s++;
if (state != ctl->underline_state) { if (state != ctl->underline_state) {
if (c == ' ' && state == 0 && ctl->underline_glitch if (c == ' ' && state == 0 && ctl->underline_glitch
&& wouldul(s, n - 1)) && would_underline(s, n - 1))
state = 1; state = 1;
else else
putp(state ? ctl->enter_underline : ctl->exit_underline); putp(state ? ctl->enter_underline : ctl->exit_underline);
@ -680,12 +680,12 @@ static void prbuf(struct more_control *ctl, char *s, int n)
/* Erase the current line entirely */ /* Erase the current line entirely */
static void kill_line(struct more_control *ctl) static void kill_line(struct more_control *ctl)
{ {
erasep(ctl, 0); erase_prompt(ctl, 0);
if (!ctl->erase_line || ctl->dumb_tty) if (!ctl->erase_line || ctl->dumb_tty)
putchar('\r'); putchar('\r');
} }
static void prompt(struct more_control *ctl, char *filename) static void output_prompt(struct more_control *ctl, char *filename)
{ {
if (ctl->clear_line_ends) if (ctl->clear_line_ends)
putp(ctl->erase_line); putp(ctl->erase_line);
@ -737,7 +737,7 @@ static void reset_tty(void)
} }
/* Clean up terminal state and exit. Also come here if interrupt signal received */ /* Clean up terminal state and exit. Also come here if interrupt signal received */
static void __attribute__((__noreturn__)) end_it(int dummy __attribute__((__unused__))) static void __attribute__((__noreturn__)) more_exit(int dummy __attribute__((__unused__)))
{ {
/* May be executed as a signal handler as well as by main process. /* May be executed as a signal handler as well as by main process.
* *
@ -762,14 +762,14 @@ static void __attribute__((__noreturn__)) end_it(int dummy __attribute__((__unus
_exit(EXIT_SUCCESS); _exit(EXIT_SUCCESS);
} }
static int readch(struct more_control *ctl) static int read_user_input(struct more_control *ctl)
{ {
unsigned char c; unsigned char c;
errno = 0; errno = 0;
if (read(STDERR_FILENO, &c, 1) <= 0) { if (read(STDERR_FILENO, &c, 1) <= 0) {
if (errno != EINTR) if (errno != EINTR)
end_it(0); more_exit(0);
else else
c = ctl->output_tty.c_cc[VKILL]; c = ctl->output_tty.c_cc[VKILL];
} }
@ -778,7 +778,7 @@ static int readch(struct more_control *ctl)
/* Read a decimal number from the terminal. Set cmd to the non-digit /* Read a decimal number from the terminal. Set cmd to the non-digit
* which terminates the number. */ * which terminates the number. */
static int number(struct more_control *ctl, char *cmd) static int read_number(struct more_control *ctl, char *cmd)
{ {
int i; int i;
char ch; char ch;
@ -786,7 +786,7 @@ static int number(struct more_control *ctl, char *cmd)
i = 0; i = 0;
ch = ctl->output_tty.c_cc[VKILL]; ch = ctl->output_tty.c_cc[VKILL];
for (;;) { for (;;) {
ch = readch(ctl); ch = read_user_input(ctl);
if (isdigit(ch)) if (isdigit(ch))
i = i * 10 + ch - '0'; i = i * 10 + ch - '0';
else if ((cc_t) ch == ctl->output_tty.c_cc[VKILL]) else if ((cc_t) ch == ctl->output_tty.c_cc[VKILL])
@ -799,9 +799,10 @@ static int number(struct more_control *ctl, char *cmd)
return i; return i;
} }
/* Skip nskip files in the file list (from the command line). Nskip may /* Change displayed file from command line list to next nskip, where nskip
* be negative. */ * is relative position in argv and can be negative, that is a previous
static void skipf(struct more_control *ctl, int nskip) * file. */
static void change_file(struct more_control *ctl, int nskip)
{ {
if (nskip == 0) if (nskip == 0)
return; return;
@ -876,7 +877,7 @@ static void ttyin(struct more_control *ctl, char buf[], int nmax, char pchar)
while (sp - buf < nmax) { while (sp - buf < nmax) {
if (ctl->prompt_len > maxlen) if (ctl->prompt_len > maxlen)
maxlen = ctl->prompt_len; maxlen = ctl->prompt_len;
c = readch(ctl); c = read_user_input(ctl);
if (c == '\\') { if (c == '\\') {
slash++; slash++;
} else if (((cc_t) c == ctl->output_tty.c_cc[VERASE]) && !slash) { } else if (((cc_t) c == ctl->output_tty.c_cc[VERASE]) && !slash) {
@ -955,7 +956,7 @@ static void ttyin(struct more_control *ctl, char buf[], int nmax, char pchar)
putchar('\r'); putchar('\r');
putchar(pchar); putchar(pchar);
if (ctl->erase_line) if (ctl->erase_line)
erasep(ctl, 1); erase_prompt(ctl, 1);
else if (ctl->erase_input_ok) else if (ctl->erase_input_ok)
while (ctl->prompt_len-- > 1) while (ctl->prompt_len-- > 1)
fputs(BSB, stderr); fputs(BSB, stderr);
@ -1053,13 +1054,13 @@ static void set_tty(struct more_control *ctl)
} }
/* Come here if a quit signal is received */ /* Come here if a quit signal is received */
static void onquit(int dummy __attribute__((__unused__))) static void sigquit_handler(int dummy __attribute__((__unused__)))
{ {
signal(SIGQUIT, SIG_IGN); signal(SIGQUIT, SIG_IGN);
if (!global_ctl->waiting_input) { if (!global_ctl->waiting_input) {
putchar('\n'); putchar('\n');
if (!global_ctl->starting_up) { if (!global_ctl->starting_up) {
signal(SIGQUIT, onquit); signal(SIGQUIT, sigquit_handler);
siglongjmp(global_ctl->destination, 1); siglongjmp(global_ctl->destination, 1);
} else } else
global_ctl->is_paused = 1; global_ctl->is_paused = 1;
@ -1067,11 +1068,11 @@ static void onquit(int dummy __attribute__((__unused__)))
global_ctl->prompt_len += fprintf(stderr, _("[Use q or Q to quit]")); global_ctl->prompt_len += fprintf(stderr, _("[Use q or Q to quit]"));
global_ctl->no_quit_dialog = 0; global_ctl->no_quit_dialog = 0;
} }
signal(SIGQUIT, onquit); signal(SIGQUIT, sigquit_handler);
} }
/* Come here when we get a suspend signal from the terminal */ /* Come here when we get a suspend signal from the terminal */
static void onsusp(int dummy __attribute__((__unused__))) static void sigtstp_handler(int dummy __attribute__((__unused__)))
{ {
sigset_t signals, oldmask; sigset_t signals, oldmask;
@ -1094,7 +1095,7 @@ static void onsusp(int dummy __attribute__((__unused__)))
sigprocmask(SIG_SETMASK, &oldmask, NULL); sigprocmask(SIG_SETMASK, &oldmask, NULL);
/* We're back */ /* We're back */
signal(SIGTSTP, onsusp); signal(SIGTSTP, sigtstp_handler);
set_tty(global_ctl); set_tty(global_ctl);
if (global_ctl->waiting_input) if (global_ctl->waiting_input)
siglongjmp(global_ctl->destination, 1); siglongjmp(global_ctl->destination, 1);
@ -1154,18 +1155,18 @@ static void execute(struct more_control *ctl, char *filename, char *cmd, ...)
signal(SIGTSTP, SIG_DFL); signal(SIGTSTP, SIG_DFL);
while (wait(NULL) > 0) while (wait(NULL) > 0)
/* nothing */ ; /* nothing */ ;
signal(SIGINT, end_it); signal(SIGINT, more_exit);
signal(SIGQUIT, onquit); signal(SIGQUIT, sigquit_handler);
if (ctl->catch_suspend) if (ctl->catch_suspend)
signal(SIGTSTP, onsusp); signal(SIGTSTP, sigtstp_handler);
} else } else
fputs(_("can't fork\n"), stderr); fputs(_("can't fork\n"), stderr);
set_tty(ctl); set_tty(ctl);
puts("------------------------"); puts("------------------------");
prompt(ctl, filename); output_prompt(ctl, filename);
} }
static void do_shell(struct more_control *ctl, char *filename) static void run_shell(struct more_control *ctl, char *filename)
{ {
char cmdbuf[COMMAND_BUF]; char cmdbuf[COMMAND_BUF];
int rc; int rc;
@ -1190,7 +1191,7 @@ static void do_shell(struct more_control *ctl, char *filename)
} }
if (rc < 0) { if (rc < 0) {
fputs(_(" Overflow\n"), stderr); fputs(_(" Overflow\n"), stderr);
prompt(ctl, filename); output_prompt(ctl, filename);
return; return;
} else if (rc > 0) { } else if (rc > 0) {
kill_line(ctl); kill_line(ctl);
@ -1206,12 +1207,12 @@ static void do_shell(struct more_control *ctl, char *filename)
/* Execute a colon-prefixed command. Returns <0 if not a command that /* Execute a colon-prefixed command. Returns <0 if not a command that
* should cause more of the file to be printed. */ * should cause more of the file to be printed. */
static int colon(struct more_control *ctl, char *filename, int cmd, int nlines) static int colon_command(struct more_control *ctl, char *filename, int cmd, int nlines)
{ {
char ch; char ch;
if (cmd == 0) if (cmd == 0)
ch = readch(ctl); ch = read_user_input(ctl);
else else
ch = cmd; ch = cmd;
ctl->last_colon_command = ch; ctl->last_colon_command = ch;
@ -1228,12 +1229,12 @@ static int colon(struct more_control *ctl, char *filename, int cmd, int nlines)
case 'n': case 'n':
if (nlines == 0) { if (nlines == 0) {
if (ctl->argv_position >= ctl->num_files - 1) if (ctl->argv_position >= ctl->num_files - 1)
end_it(0); more_exit(0);
nlines++; nlines++;
} }
putchar('\r'); putchar('\r');
erasep(ctl, 0); erase_prompt(ctl, 0);
skipf(ctl, nlines); change_file(ctl, nlines);
return 0; return 0;
case 'p': case 'p':
if (ctl->no_tty_in) { if (ctl->no_tty_in) {
@ -1241,17 +1242,17 @@ static int colon(struct more_control *ctl, char *filename, int cmd, int nlines)
return -1; return -1;
} }
putchar('\r'); putchar('\r');
erasep(ctl, 0); erase_prompt(ctl, 0);
if (nlines == 0) if (nlines == 0)
nlines++; nlines++;
skipf(ctl, -nlines); change_file(ctl, -nlines);
return 0; return 0;
case '!': case '!':
do_shell(ctl, filename); run_shell(ctl, filename);
return -1; return -1;
case 'q': case 'q':
case 'Q': case 'Q':
end_it(0); more_exit(0);
default: default:
fputc(RINGBELL, stderr); fputc(RINGBELL, stderr);
return -1; return -1;
@ -1259,7 +1260,7 @@ static int colon(struct more_control *ctl, char *filename, int cmd, int nlines)
} }
/* Skip n lines in the file f */ /* Skip n lines in the file f */
static void skiplns(struct more_control *ctl, int n, FILE *f) static void skip_lines(struct more_control *ctl, int n, FILE *f)
{ {
int c; int c;
@ -1273,7 +1274,7 @@ static void skiplns(struct more_control *ctl, int n, FILE *f)
} }
/* Clear the screen */ /* Clear the screen */
static void doclear(struct more_control *ctl) static void more_clear_screen(struct more_control *ctl)
{ {
if (ctl->clear && !ctl->hard_tty) { if (ctl->clear && !ctl->hard_tty) {
putp(ctl->clear); putp(ctl->clear);
@ -1284,7 +1285,7 @@ static void doclear(struct more_control *ctl)
} }
} }
static void rdline(struct more_control *ctl, FILE *f) static void read_line(struct more_control *ctl, FILE *f)
{ {
int c; int c;
char *p; char *p;
@ -1326,7 +1327,7 @@ static void search(struct more_control *ctl, char buf[], FILE *file, int n)
line3 = line2; line3 = line2;
line2 = line1; line2 = line1;
line1 = ctl->file_position; line1 = ctl->file_position;
rdline(ctl, file); read_line(ctl, file);
lncount++; lncount++;
if (regexec(&re, ctl->line_buf, 0, NULL, 0) == 0) { if (regexec(&re, ctl->line_buf, 0, NULL, 0) == 0) {
if (--n == 0) { if (--n == 0) {
@ -1345,7 +1346,7 @@ static void search(struct more_control *ctl, char buf[], FILE *file, int n)
putp(ctl->go_home); putp(ctl->go_home);
putp(ctl->erase_line); putp(ctl->erase_line);
} else } else
doclear(ctl); more_clear_screen(ctl);
} }
} else { } else {
kill_line(ctl); kill_line(ctl);
@ -1354,7 +1355,7 @@ static void search(struct more_control *ctl, char buf[], FILE *file, int n)
putp(ctl->go_home); putp(ctl->go_home);
putp(ctl->erase_line); putp(ctl->erase_line);
} else } else
doclear(ctl); more_clear_screen(ctl);
} }
puts(ctl->line_buf); puts(ctl->line_buf);
} }
@ -1369,7 +1370,7 @@ static void search(struct more_control *ctl, char buf[], FILE *file, int n)
more_fseek(ctl, file, startline); more_fseek(ctl, file, startline);
} else { } else {
fputs(_("\nPattern not found\n"), stdout); fputs(_("\nPattern not found\n"), stdout);
end_it(0); more_exit(0);
} }
free(ctl->previous_search); free(ctl->previous_search);
ctl->previous_search = NULL; ctl->previous_search = NULL;
@ -1382,7 +1383,7 @@ notfound:
* argument followed by the command character. Return the number of * argument followed by the command character. Return the number of
* lines to display in the next screenful. If there is nothing more to * lines to display in the next screenful. If there is nothing more to
* display in the current file, zero is returned. */ * display in the current file, zero is returned. */
static int command(struct more_control *ctl, char *filename, FILE *f) static int more_key_command(struct more_control *ctl, char *filename, FILE *f)
{ {
int nlines; int nlines;
int retval = 0; int retval = 0;
@ -1393,11 +1394,11 @@ static int command(struct more_control *ctl, char *filename, FILE *f)
done = 0; done = 0;
if (!ctl->report_errors) if (!ctl->report_errors)
prompt(ctl, filename); output_prompt(ctl, filename);
else else
ctl->report_errors = 0; ctl->report_errors = 0;
for (;;) { for (;;) {
nlines = number(ctl, &comchar); nlines = read_number(ctl, &comchar);
ctl->run_previous_command = colonch = 0; ctl->run_previous_command = colonch = 0;
if (comchar == '.') { /* Repeat last command */ if (comchar == '.') { /* Repeat last command */
ctl->run_previous_command++; ctl->run_previous_command++;
@ -1410,12 +1411,12 @@ static int command(struct more_control *ctl, char *filename, FILE *f)
ctl->last_key_arg = nlines; ctl->last_key_arg = nlines;
if ((cc_t) comchar == ctl->output_tty.c_cc[VERASE]) { if ((cc_t) comchar == ctl->output_tty.c_cc[VERASE]) {
kill_line(ctl); kill_line(ctl);
prompt(ctl, filename); output_prompt(ctl, filename);
continue; continue;
} }
switch (comchar) { switch (comchar) {
case ':': case ':':
retval = colon(ctl, filename, colonch, nlines); retval = colon_command(ctl, filename, colonch, nlines);
if (retval >= 0) if (retval >= 0)
done++; done++;
break; break;
@ -1433,7 +1434,7 @@ static int command(struct more_control *ctl, char *filename, FILE *f)
nlines++; nlines++;
putchar('\r'); putchar('\r');
erasep(ctl, 0); erase_prompt(ctl, 0);
putchar('\n'); putchar('\n');
if (ctl->clear_line_ends) if (ctl->clear_line_ends)
putp(ctl->erase_line); putp(ctl->erase_line);
@ -1450,8 +1451,8 @@ static int command(struct more_control *ctl, char *filename, FILE *f)
if (initline < 0) if (initline < 0)
initline = 0; initline = 0;
more_fseek(ctl, f, 0L); more_fseek(ctl, f, 0L);
ctl->current_line = 0; /* skiplns() will make current_line correct */ ctl->current_line = 0; /* skip_lines() will make current_line correct */
skiplns(ctl, initline, f); skip_lines(ctl, initline, f);
if (!ctl->no_scroll) { if (!ctl->no_scroll) {
retval = ctl->lines_per_screen + 1; retval = ctl->lines_per_screen + 1;
} else { } else {
@ -1478,7 +1479,7 @@ static int command(struct more_control *ctl, char *filename, FILE *f)
break; break;
case 'q': case 'q':
case 'Q': case 'Q':
end_it(0); more_exit(0);
case 's': case 's':
case 'f': case 'f':
case ctrl('F'): case ctrl('F'):
@ -1487,7 +1488,7 @@ static int command(struct more_control *ctl, char *filename, FILE *f)
if (comchar == 'f') if (comchar == 'f')
nlines *= ctl->lines_per_screen; nlines *= ctl->lines_per_screen;
putchar('\r'); putchar('\r');
erasep(ctl, 0); erase_prompt(ctl, 0);
putchar('\n'); putchar('\n');
if (ctl->clear_line_ends) if (ctl->clear_line_ends)
putp(ctl->erase_line); putp(ctl->erase_line);
@ -1522,7 +1523,7 @@ static int command(struct more_control *ctl, char *filename, FILE *f)
break; break;
case '\f': case '\f':
if (!ctl->no_tty_in) { if (!ctl->no_tty_in) {
doclear(ctl); more_clear_screen(ctl);
more_fseek(ctl, f, ctl->screen_start.row_num); more_fseek(ctl, f, ctl->screen_start.row_num);
ctl->current_line = ctl->screen_start.line_num; ctl->current_line = ctl->screen_start.line_num;
retval = ctl->lines_per_screen; retval = ctl->lines_per_screen;
@ -1578,12 +1579,12 @@ static int command(struct more_control *ctl, char *filename, FILE *f)
done = 1; done = 1;
break; break;
case '!': case '!':
do_shell(ctl, filename); run_shell(ctl, filename);
break; break;
case '?': case '?':
case 'h': case 'h':
if (ctl->no_scroll) if (ctl->no_scroll)
doclear(ctl); more_clear_screen(ctl);
fputs(_("\n" fputs(_("\n"
"Most commands optionally preceded by integer argument k. " "Most commands optionally preceded by integer argument k. "
"Defaults in brackets.\n" "Defaults in brackets.\n"
@ -1612,7 +1613,7 @@ static int command(struct more_control *ctl, char *filename, FILE *f)
". Repeat previous command\n"), stdout); ". Repeat previous command\n"), stdout);
puts("---------------------------------------" puts("---------------------------------------"
"----------------------------------------"); "----------------------------------------");
prompt(ctl, filename); output_prompt(ctl, filename);
break; break;
case 'v': /* This case should go right before default */ case 'v': /* This case should go right before default */
if (!ctl->no_tty_in) { if (!ctl->no_tty_in) {
@ -1706,19 +1707,19 @@ static void screen(struct more_control *ctl, FILE *f, int num_lines)
prev_len = length; prev_len = length;
if (ctl->bad_stdout if (ctl->bad_stdout
|| ((ctl->enter_std && *ctl->enter_std == ' ') && (ctl->prompt_len > 0))) || ((ctl->enter_std && *ctl->enter_std == ' ') && (ctl->prompt_len > 0)))
erasep(ctl, 0); erase_prompt(ctl, 0);
/* must clear before drawing line since tabs on /* must clear before drawing line since tabs on
* some terminals do not erase what they tab * some terminals do not erase what they tab
* over. */ * over. */
if (ctl->clear_line_ends) if (ctl->clear_line_ends)
putp(ctl->erase_line); putp(ctl->erase_line);
prbuf(ctl, ctl->line_buf, length); print_buf(ctl, ctl->line_buf, length);
if (nchars < ctl->prompt_len) if (nchars < ctl->prompt_len)
erasep(ctl, nchars); /* erasep () sets prompt_len to 0 */ erase_prompt(ctl, nchars); /* erase_prompt () sets prompt_len to 0 */
else else
ctl->prompt_len = 0; ctl->prompt_len = 0;
if (nchars < ctl->num_columns || !ctl->fold_long_lines) if (nchars < ctl->num_columns || !ctl->fold_long_lines)
prbuf(ctl, "\n", 1); /* will turn off UL if necessary */ print_buf(ctl, "\n", 1); /* will turn off UL if necessary */
num_lines--; num_lines--;
} }
if (ctl->underline_state) { if (ctl->underline_state) {
@ -1738,15 +1739,15 @@ static void screen(struct more_control *ctl, FILE *f, int num_lines)
sigsetjmp(ctl->destination, 1); sigsetjmp(ctl->destination, 1);
ctl->is_paused = 0; ctl->is_paused = 0;
ctl->starting_up = 0; ctl->starting_up = 0;
if ((num_lines = command(ctl, NULL, f)) == 0) if ((num_lines = more_key_command(ctl, NULL, f)) == 0)
return; return;
if (ctl->hard_tty && ctl->prompt_len > 0) if (ctl->hard_tty && ctl->prompt_len > 0)
erasep(ctl, 0); erase_prompt(ctl, 0);
if (ctl->no_scroll && num_lines >= ctl->lines_per_screen) { if (ctl->no_scroll && num_lines >= ctl->lines_per_screen) {
if (ctl->clear_line_ends) if (ctl->clear_line_ends)
putp(ctl->go_home); putp(ctl->go_home);
else else
doclear(ctl); more_clear_screen(ctl);
} }
ctl->screen_start.line_num = ctl->current_line; ctl->screen_start.line_num = ctl->current_line;
ctl->screen_start.row_num = ctl->file_position; ctl->screen_start.row_num = ctl->file_position;
@ -1754,7 +1755,7 @@ static void screen(struct more_control *ctl, FILE *f, int num_lines)
} }
/* Come here if a signal for a window size change is received */ /* Come here if a signal for a window size change is received */
static void chgwinsz(int dummy __attribute__((__unused__))) static void sigwinch_handler(int dummy __attribute__((__unused__)))
{ {
struct winsize win; struct winsize win;
@ -1770,7 +1771,7 @@ static void chgwinsz(int dummy __attribute__((__unused__)))
if (win.ws_col != 0) if (win.ws_col != 0)
global_ctl->num_columns = win.ws_col; global_ctl->num_columns = win.ws_col;
} }
signal(SIGWINCH, chgwinsz); signal(SIGWINCH, sigwinch_handler);
} }
static void copy_file(FILE *f) static void copy_file(FILE *f)
@ -1947,11 +1948,11 @@ int main(int argc, char **argv)
ctl.d_scroll_len = 1; ctl.d_scroll_len = 1;
if ((s = getenv("MORE")) != NULL) if ((s = getenv("MORE")) != NULL)
argscan(&ctl, s); arg_parser(&ctl, s);
while (--ctl.num_files > 0) { while (--ctl.num_files > 0) {
if ((chr = (*++ctl.file_names)[0]) == '-') { if ((chr = (*++ctl.file_names)[0]) == '-') {
argscan(&ctl, *ctl.file_names + 1); arg_parser(&ctl, *ctl.file_names + 1);
} else if (chr == '+') { } else if (chr == '+') {
s = *ctl.file_names; s = *ctl.file_names;
if (*++s == '/') { if (*++s == '/') {
@ -1989,11 +1990,11 @@ int main(int argc, char **argv)
} else } else
f = stdin; f = stdin;
if (!ctl.no_tty_out) { if (!ctl.no_tty_out) {
signal(SIGQUIT, onquit); signal(SIGQUIT, sigquit_handler);
signal(SIGINT, end_it); signal(SIGINT, more_exit);
signal(SIGWINCH, chgwinsz); signal(SIGWINCH, sigwinch_handler);
if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) { if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) {
signal(SIGTSTP, onsusp); signal(SIGTSTP, sigtstp_handler);
ctl.catch_suspend++; ctl.catch_suspend++;
} }
tcsetattr(STDERR_FILENO, TCSANOW, &ctl.output_tty); tcsetattr(STDERR_FILENO, TCSANOW, &ctl.output_tty);
@ -2003,14 +2004,14 @@ int main(int argc, char **argv)
copy_file(stdin); copy_file(stdin);
else { else {
if ((chr = getc(f)) == '\f') if ((chr = getc(f)) == '\f')
doclear(&ctl); more_clear_screen(&ctl);
else { else {
ungetc(chr, f); ungetc(chr, f);
if (ctl.no_scroll && (chr != EOF)) { if (ctl.no_scroll && (chr != EOF)) {
if (ctl.clear_line_ends) if (ctl.clear_line_ends)
putp(ctl.go_home); putp(ctl.go_home);
else else
doclear(&ctl); more_clear_screen(&ctl);
} }
} }
if (search_at_start) { if (search_at_start) {
@ -2020,7 +2021,7 @@ int main(int argc, char **argv)
if (ctl.no_scroll) if (ctl.no_scroll)
left--; left--;
} else if (init) } else if (init)
skiplns(&ctl, start_at_line, stdin); skip_lines(&ctl, start_at_line, stdin);
screen(&ctl, stdin, left); screen(&ctl, stdin, left);
} }
ctl.no_tty_in = 0; ctl.no_tty_in = 0;
@ -2043,10 +2044,10 @@ int main(int argc, char **argv)
if (ctl.no_scroll) if (ctl.no_scroll)
left--; left--;
} else if (init) } else if (init)
skiplns(&ctl, start_at_line, f); skip_lines(&ctl, start_at_line, f);
} else if (ctl.argv_position < ctl.num_files && !ctl.no_tty_out) { } else if (ctl.argv_position < ctl.num_files && !ctl.no_tty_out) {
sigsetjmp(ctl.destination, 1); sigsetjmp(ctl.destination, 1);
left = command(&ctl, ctl.file_names[ctl.argv_position], f); left = more_key_command(&ctl, ctl.file_names[ctl.argv_position], f);
} }
if (left != 0) { if (left != 0) {
if ((ctl.no_scroll || skip_file) if ((ctl.no_scroll || skip_file)
@ -2054,16 +2055,16 @@ int main(int argc, char **argv)
if (ctl.clear_line_ends) if (ctl.clear_line_ends)
putp(ctl.go_home); putp(ctl.go_home);
else else
doclear(&ctl); more_clear_screen(&ctl);
} }
if (print_names) { if (print_names) {
if (ctl.bad_stdout) if (ctl.bad_stdout)
erasep(&ctl, 0); erase_prompt(&ctl, 0);
if (ctl.clear_line_ends) if (ctl.clear_line_ends)
putp(ctl.erase_line); putp(ctl.erase_line);
fputs("::::::::::::::", stdout); fputs("::::::::::::::", stdout);
if (ctl.prompt_len > 14) if (ctl.prompt_len > 14)
erasep(&ctl, 14); erase_prompt(&ctl, 14);
putchar('\n'); putchar('\n');
if (ctl.clear_line_ends) if (ctl.clear_line_ends)
putp(ctl.erase_line); putp(ctl.erase_line);