#define TERM_COLS "cols"
#define TERM_CURSOR_ADDRESS "cup"
#define TERM_EAT_NEW_LINE "xenl"
-#define TERM_ENTER_UNDERLINE "smul"
#define TERM_EXIT_STANDARD_MODE "rmso"
-#define TERM_EXIT_UNDERLINE "rmul"
#define TERM_HARD_COPY "hc"
#define TERM_HOME "home"
#define TERM_LINE_DOWN "cud1"
#define TERM_OVER_STRIKE "os"
#define TERM_STANDARD_MODE "smso"
#define TERM_STD_MODE_GLITCH "xmc"
-#define TERM_UNDERLINE_CHAR "uc"
-#define TERM_UNDERLINE "ul"
struct more_control {
struct termios output_tty; /* output terminal */
char *erase_line; /* erase line */
char *enter_std; /* enter standout mode */
char *exit_std; /* exit standout mode */
- char *enter_underline; /* enter underline mode */
- char *exit_underline; /* exit underline mode */
- char *underline_ch; /* underline character */
char *backspace_ch; /* backspace character */
char *go_home; /* go to home */
char *move_line_down; /* move line down */
clear_first:1, /* is first character in file \f */
dumb_tty:1, /* is terminal type known */
eat_newline:1, /* is newline ignored after 80 cols */
- enable_underlining:1, /* underline as best we can */
erase_input_ok:1, /* is erase input supported */
erase_previous_ok:1, /* is erase previous supported */
first_file:1, /* is the input file the first in list */
stdout_glitch:1, /* terminal has standout mode glitch */
stop_after_formfeed:1, /* stop after form feeds */
suppress_bell:1, /* suppress bell */
- underline_glitch:1, /* terminal has underline mode glitch */
- underline_state:1, /* current UL state */
wrap_margin:1; /* set if automargins */
};
fputs(_(" -c do not scroll, display text and clean line ends\n"), out);
fputs(_(" -p do not scroll, clean screen and display text\n"), out);
fputs(_(" -s squeeze multiple blank lines into one\n"), out);
- fputs(_(" -u suppress underlining\n"), out);
fputs(_(" -<number> the number of lines per screenful\n"), out);
fputs(_(" +<number> display file beginning from line number\n"), out);
fputs(_(" +/<string> display file beginning from search string match\n"), out);
ctl->squeeze_spaces = 1;
break;
case 'u':
- ctl->enable_underlining = 0;
break;
case '-':
case ' ':
ctl->prompt_len = col;
}
-#ifdef HAVE_WIDECHAR
-static UL_ASAN_BLACKLIST size_t xmbrtowc(wchar_t *wc, const char *s, size_t n,
- mbstate_t *mbstate)
-{
- const size_t mblength = mbrtowc(wc, s, n, mbstate);
- if (mblength == (size_t)-2 || mblength == (size_t)-1)
- return 1;
- return mblength;
-}
-#endif
-
-static int would_underline(char *s, int n)
-{
- if (n < 2)
- return 0;
- if ((s[0] == '_' && s[1] == '\b') || (s[1] == '\b' && s[2] == '_'))
- return 1;
- return 0;
-}
-
-/* Print a buffer of n characters */
-static void print_buf(struct more_control *ctl, char *s, int n)
-{
- char c; /* next output character */
- int state; /* next output char's UL state */
-
- while (--n >= 0) {
- if (!ctl->enable_underlining) {
- putchar(*s++);
- continue;
- }
- if (*s == ' ' && ctl->underline_state == 0 && ctl->underline_glitch
- && would_underline(s + 1, n - 1)) {
- s++;
- continue;
- }
- if ((state = would_underline(s, n)) != 0) {
- c = (*s == '_') ? s[2] : *s;
- n -= 2;
- s += 3;
- } else
- c = *s++;
- if (state != ctl->underline_state) {
- if (c == ' ' && state == 0 && ctl->underline_glitch
- && would_underline(s, n - 1))
- state = 1;
- else
- putp(state ? ctl->enter_underline : ctl->exit_underline);
- }
- if (c != ' ' || ctl->underline_state == 0 || state != 0
- || ctl->underline_glitch == 0) {
-#ifdef HAVE_WIDECHAR
- wchar_t wc;
- size_t mblength;
- mbstate_t mbstate;
-
- memset(&mbstate, '\0', sizeof(mbstate_t));
- s--;
- n++;
- mblength = xmbrtowc(&wc, s, n, &mbstate);
- while (mblength--)
- putchar(*s++);
- n += mblength;
-#else
- putchar(c);
-#endif
- }
- if (state && *ctl->underline_ch) {
- fputs(ctl->move_line_down, stdout);
- putp(ctl->underline_ch);
- }
- ctl->underline_state = state;
- }
-}
-
static void output_prompt(struct more_control *ctl, char *filename)
{
if (ctl->clear_line_ends)
{
if (ctl->no_tty_out)
return;
- if (ctl->underline_state) {
- putp(ctl->exit_underline);
- ctl->underline_state = 0;
- }
fflush(NULL);
ctl->output_tty.c_lflag |= ICANON | ECHO;
ctl->output_tty.c_cc[VMIN] = ctl->original_tty.c_cc[VMIN];
* over. */
if (ctl->clear_line_ends)
putp(ctl->erase_line);
- print_buf(ctl, ctl->line_buf, length);
+ fwrite(ctl->line_buf, length, 1, stdout);
if (nchars < ctl->prompt_len)
erase_to_col(ctl, nchars);
ctl->prompt_len = 0;
if (nchars < ctl->num_columns || !ctl->fold_long_lines)
- print_buf(ctl, "\n", 1); /* will turn off UL if necessary */
+ putchar('\n');
num_lines--;
}
- if (ctl->underline_state) {
- putp(ctl->exit_underline);
- ctl->underline_state = 0;
- }
fflush(NULL);
if ((c = more_getc(ctl)) == EOF) {
if (ctl->clear_line_ends)
ctl->erase_input_ok = (ctl->output_tty.c_cc[VKILL] != 255);
if ((term = getenv("TERM")) == NULL) {
ctl->dumb_tty = 1;
- ctl->enable_underlining = 0;
}
setupterm(term, 1, &ret);
if (ret <= 0) {
ctl->dumb_tty = 1;
- ctl->enable_underlining = 0;
return;
}
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) < 0) {
ctl->stdout_glitch = 1;
}
- /*
- * Set up for underlining. Some terminals don't need it, others have
- * start/stop sequences, still others have an underline char sequence
- * which is assumed to move the cursor forward one character. If
- * underline sequence isn't available, settle for standout sequence.
- */
- if (tigetflag(TERM_UNDERLINE) || tigetflag(TERM_OVER_STRIKE))
- ctl->enable_underlining = 0;
- ctl->enter_underline = tigetstr(TERM_ENTER_UNDERLINE);
- ctl->exit_underline = tigetstr(TERM_EXIT_UNDERLINE);
- ctl->underline_ch = tigetstr(TERM_UNDERLINE_CHAR);
- if (!ctl->underline_ch) {
- ctl->underline_ch = "";
- if (!ctl->enter_underline || !ctl->exit_underline) {
- if (!ctl->enter_std || !ctl->exit_std) {
- ctl->enter_underline = "";
- ctl->exit_underline = "";
- } else {
- ctl->enter_underline = ctl->enter_std;
- ctl->exit_underline = ctl->exit_std;
- ctl->underline_glitch = ctl->stdout_glitch;
- }
- } else
- ctl->underline_glitch = 0;
- }
-
cursor_addr = tigetstr(TERM_HOME);
if (cursor_addr == NULL || *cursor_addr == '\0') {
cursor_addr = tigetstr(TERM_CURSOR_ADDRESS);
.fold_long_lines = 1,
.no_quit_dialog = 1,
.stop_after_formfeed = 1,
- .enable_underlining = 1,
.wrap_margin = 1,
.lines_per_page = LINES_PER_PAGE,
.num_columns = NUM_COLUMNS,