1 /* vi: set sw=4 ts=4: */
3 * Mini less implementation for busybox
5 * Copyright (C) 2005 by Rob Sullivan <cogito.ergo.cogito@gmail.com>
7 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
12 * - Add more regular expression support - search modifiers, certain matches, etc.
13 * - Add more complex bracket searching - currently, nested brackets are
15 * - Add support for "F" as an input. This causes less to act in
16 * a similar way to tail -f.
17 * - Allow horizontal scrolling.
20 * - the inp file pointer is used so that keyboard input works after
21 * redirected input has been read from stdin
24 #include <sched.h> /* sched_yield() */
27 #if ENABLE_FEATURE_LESS_REGEXP
31 /* FIXME: currently doesn't work right */
32 #undef ENABLE_FEATURE_LESS_FLAGCS
33 #define ENABLE_FEATURE_LESS_FLAGCS 0
35 /* The escape codes for highlighted and normal text */
36 #define HIGHLIGHT "\033[7m"
37 #define NORMAL "\033[0m"
38 /* The escape code to clear the screen */
39 #define CLEAR "\033[H\033[J"
40 /* The escape code to clear to end of line */
41 #define CLEAR_2_EOL "\033[K"
43 /* These are the escape sequences corresponding to special keys */
51 REAL_KEY_HOME = '7', // vt100? linux vt? or what?
53 REAL_KEY_HOME_ALT = '1', // ESC [1~ (vt100? linux vt? or what?)
54 REAL_KEY_END_ALT = '4', // ESC [4~
55 REAL_KEY_HOME_XTERM = 'H',
56 REAL_KEY_END_XTERM = 'F',
58 /* These are the special codes assigned by this program to the special keys */
68 /* Absolute max of lines eaten */
69 MAXLINES = CONFIG_FEATURE_LESS_MAXLINES,
71 /* This many "after the end" lines we will show (at max) */
75 static unsigned max_displayed_line;
76 static unsigned width;
77 static const char *empty_line_marker = "~";
79 static char *filename;
81 static unsigned num_files = 1;
82 static unsigned current_file = 1;
83 static const char **buffer;
84 static const char **flines;
85 static int cur_fline; /* signed */
86 static unsigned max_fline;
87 static unsigned max_lineno; /* this one tracks linewrap */
89 static ssize_t eof_error = 1; /* eof if 0, error if < 0 */
90 static char terminated = 1;
91 static size_t readpos;
92 static size_t readeof;
93 /* last position in last line, taking into account tabs */
94 static size_t linepos;
96 /* Command line options */
103 /* hijack command line options variable for internal state vars */
104 LESS_STATE_MATCH_BACKWARDS = 1 << 15,
107 #if ENABLE_FEATURE_LESS_MARKS
108 static unsigned mark_lines[15][2];
109 static unsigned num_marks;
112 #if ENABLE_FEATURE_LESS_REGEXP
113 static unsigned *match_lines;
114 static int match_pos; /* signed! */
115 static unsigned num_matches;
116 static regex_t pattern;
117 static unsigned pattern_valid;
119 enum { pattern_valid = 0 };
122 static struct termios term_orig, term_vi;
124 /* File pointer to get input from */
127 /* Reset terminal input to normal */
128 static void set_tty_cooked(void)
131 tcsetattr(kbd_fd, TCSANOW, &term_orig);
134 /* Exit the program gracefully */
135 static void less_exit(int code)
137 /* TODO: We really should save the terminal state when we start,
138 * and restore it when we exit. Less does this with the
139 * "ti" and "te" termcap commands; can this be done with
142 fflush_stdout_and_exit(code);
145 /* Move the cursor to a position (x,y), where (0,0) is the
146 top-left corner of the console */
147 static void move_cursor(int line, int row)
149 printf("\033[%u;%uH", line, row);
152 static void clear_line(void)
154 printf("\033[%u;0H" CLEAR_2_EOL, max_displayed_line + 2);
157 static void print_hilite(const char *str)
159 printf(HIGHLIGHT"%s"NORMAL, str);
162 static void print_statusline(const char *str)
165 printf(HIGHLIGHT"%.*s"NORMAL, width - 1, str);
168 #if ENABLE_FEATURE_LESS_REGEXP
169 static void fill_match_lines(unsigned pos);
171 #define fill_match_lines(pos) ((void)0)
175 static void read_lines(void)
177 #define readbuf bb_common_bufsiz1
178 char *current_line, *p;
179 USE_FEATURE_LESS_REGEXP(unsigned old_max_fline = max_fline;)
181 char last_terminated = terminated;
183 if (option_mask32 & FLAG_N)
186 current_line = xmalloc(w);
188 max_fline += last_terminated;
189 if (!last_terminated) {
190 const char *cp = flines[max_fline];
191 if (option_mask32 & FLAG_N)
193 strcpy(current_line, cp);
194 p += strlen(current_line);
205 /* if no unprocessed chars left, eat more */
206 if (readpos >= readeof) {
207 smallint yielded = 0;
211 eof_error = safe_read(0, readbuf, sizeof(readbuf));
215 if (errno == EAGAIN && !yielded) {
216 /* We can hit EAGAIN while searching for regexp match.
217 * Yield is not 100% reliable solution in general,
218 * but for less it should be good enough -
219 * we give stdin supplier some CPU time to produce
220 * more input. We do it just once.
221 * Currently, we do not stop when we found the Nth
222 * occurrence we were looking for. We read till end
223 * (or double EAGAIN). TODO? */
230 print_statusline("read error");
234 if (eof_error <= 0) {
238 c = readbuf[readpos];
239 /* backspace? [needed for manpages] */
240 /* <tab><bs> is (a) insane and */
241 /* (b) harder to do correctly, so we refuse to do it */
242 if (c == '\x8' && linepos && p[-1] != '\t') {
243 readpos++; /* eat it */
249 linepos += (linepos^7) & 7;
253 /* ok, we will eat this char */
255 if (c == '\n') { terminated = 1; break; }
256 /* NUL is substituted by '\n'! */
257 if (c == '\0') c = '\n';
261 /* Corner case: linewrap with only "" wrapping to next line */
262 /* Looks ugly on screen, so we do not store this empty line */
263 if (!last_terminated && !current_line[0]) {
269 last_terminated = terminated;
270 flines = xrealloc(flines, (max_fline+1) * sizeof(char *));
271 if (option_mask32 & FLAG_N) {
272 /* Width of 7 preserves tab spacing in the text */
273 flines[max_fline] = xasprintf(
274 (max_lineno <= 9999999) ? "%7u %s" : "%07u %s",
275 max_lineno % 10000000, current_line);
280 flines[max_fline] = xrealloc(current_line, strlen(current_line)+1);
282 if (max_fline >= MAXLINES)
284 if (max_fline > cur_fline + max_displayed_line)
286 if (eof_error <= 0) {
287 if (eof_error < 0 && errno == EAGAIN) {
288 /* not yet eof or error, reset flag (or else
289 * we will hog CPU - select() will return
296 current_line = xmalloc(w);
300 fill_match_lines(old_max_fline);
304 #if ENABLE_FEATURE_LESS_FLAGS
305 /* Interestingly, writing calc_percent as a function saves around 32 bytes
307 static int calc_percent(void)
309 unsigned p = (100 * (cur_fline+max_displayed_line+1) + max_fline/2) / (max_fline+1);
310 return p <= 100 ? p : 100;
313 /* Print a status line if -M was specified */
314 static void m_status_print(void)
319 printf(HIGHLIGHT"%s", filename);
321 printf(" (file %i of %i)", current_file, num_files);
322 printf(" lines %i-%i/%i ",
323 cur_fline + 1, cur_fline + max_displayed_line + 1,
325 if (cur_fline >= max_fline - max_displayed_line) {
326 printf("(END)"NORMAL);
327 if (num_files > 1 && current_file != num_files)
328 printf(HIGHLIGHT" - next: %s"NORMAL, files[current_file]);
331 percentage = calc_percent();
332 printf("%i%%"NORMAL, percentage);
336 /* Print the status line */
337 static void status_print(void)
341 /* Change the status if flags have been set */
342 #if ENABLE_FEATURE_LESS_FLAGS
343 if (option_mask32 & (FLAG_M|FLAG_m)) {
351 if (cur_fline && cur_fline < max_fline - max_displayed_line) {
359 printf(HIGHLIGHT"%s (file %i of %i)"NORMAL,
360 p, current_file, num_files);
366 static void cap_cur_fline(int nlines)
371 if (cur_fline + max_displayed_line > max_fline + TILDES) {
375 diff = max_fline - (cur_fline + max_displayed_line) + TILDES;
376 /* As the number of lines requested was too large, we just move
377 to the end of the file */
383 static char controls[] =
384 /* NUL: never encountered; TAB: not converted */
385 /**/"\x01\x02\x03\x04\x05\x06\x07\x08" "\x0a\x0b\x0c\x0d\x0e\x0f"
386 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
387 "\x7f\x9b"; /* DEL and infamous Meta-ESC :( */
388 static char ctrlconv[] =
389 /* '\n': it's a former NUL - subst with '@', not 'J' */
390 "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x40\x4b\x4c\x4d\x4e\x4f"
391 "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f";
393 #if ENABLE_FEATURE_LESS_REGEXP
394 static void print_found(const char *line)
399 regmatch_t match_structs;
402 const char *str = line;
407 n = strcspn(str, controls);
414 n = strspn(str, controls);
421 /* buf[] holds quarantined version of str */
423 /* Each part of the line that matches has the HIGHLIGHT
424 and NORMAL escape sequences placed around it.
425 NB: we regex against line, but insert text
426 from quarantined copy (buf[]) */
432 while (match_status == 0) {
433 char *new = xasprintf("%s%.*s"HIGHLIGHT"%.*s"NORMAL,
435 match_structs.rm_so, str,
436 match_structs.rm_eo - match_structs.rm_so,
437 str + match_structs.rm_so);
438 free(growline); growline = new;
439 str += match_structs.rm_eo;
440 line += match_structs.rm_eo;
443 /* Most of the time doesn't find the regex, optimize for that */
444 match_status = regexec(&pattern, line, 1, &match_structs, eflags);
448 printf(CLEAR_2_EOL"%s\n", str);
451 printf(CLEAR_2_EOL"%s%s\n", growline, str);
455 void print_found(const char *line);
458 static void print_ascii(const char *str)
466 n = strcspn(str, controls);
469 printf("%.*s", (int) n, str);
472 n = strspn(str, controls);
477 else if (*str == (char)0x9b)
478 /* VT100's CSI, aka Meta-ESC. Who's inventor? */
479 /* I want to know who committed this sin */
482 *p++ = ctrlconv[(unsigned char)*str];
491 /* Print the buffer */
492 static void buffer_print(void)
497 for (i = 0; i <= max_displayed_line; i++)
499 print_found(buffer[i]);
501 print_ascii(buffer[i]);
505 static void buffer_fill_and_print(void)
508 for (i = 0; i <= max_displayed_line && cur_fline + i <= max_fline; i++) {
509 buffer[i] = flines[cur_fline + i];
511 for (; i <= max_displayed_line; i++) {
512 buffer[i] = empty_line_marker;
517 /* Move the buffer up and down in the file in order to scroll */
518 static void buffer_down(int nlines)
522 cap_cur_fline(nlines);
523 buffer_fill_and_print();
526 static void buffer_up(int nlines)
529 if (cur_fline < 0) cur_fline = 0;
531 buffer_fill_and_print();
534 static void buffer_line(int linenum)
540 if (linenum + max_displayed_line > max_fline)
541 linenum = max_fline - max_displayed_line + TILDES;
545 buffer_fill_and_print();
548 static void open_file_and_read_lines(void)
551 int fd = xopen(filename, O_RDONLY);
555 /* "less" with no arguments in argv[] */
556 /* For status line only */
557 filename = xstrdup(bb_msg_standard_input);
566 /* Reinitialize everything for a new file - free the memory and start over */
567 static void reinitialize(void)
572 for (i = 0; i <= max_fline; i++)
573 free((void*)(flines[i]));
581 open_file_and_read_lines();
582 buffer_fill_and_print();
585 static void getch_nowait(char* input, int sz)
592 /* NB: select returns whenever read will not block. Therefore:
593 * (a) with O_NONBLOCK'ed fds select will return immediately
594 * (b) if eof is reached, select will also return
595 * because read will immediately return 0 bytes.
596 * Even if select says that input is available, read CAN block
597 * (switch fd into O_NONBLOCK'ed mode to avoid it)
600 if (max_fline <= cur_fline + max_displayed_line
601 && eof_error > 0 /* did NOT reach eof yet */
603 /* We are interested in stdin */
606 FD_SET(kbd_fd, &readfds);
607 tcsetattr(kbd_fd, TCSANOW, &term_vi);
608 select(kbd_fd + 1, &readfds, NULL, NULL, NULL);
612 rd = read(kbd_fd, input, sz);
615 /* No keyboard input, but we have input on stdin! */
616 if (errno != EAGAIN) /* Huh?? */
619 buffer_fill_and_print();
624 /* Grab a character from input without requiring the return key. If the
625 * character is ASCII \033, get more characters and assign certain sequences
626 * special return codes. Note that this function works best with raw input. */
627 static int less_getch(void)
632 getch_nowait(input, sizeof(input));
633 /* Detect escape sequences (i.e. arrow keys) and handle
634 * them accordingly */
636 if (input[0] == '\033' && input[1] == '[') {
638 i = input[2] - REAL_KEY_UP;
641 i = input[2] - REAL_PAGE_UP;
644 if (input[2] == REAL_KEY_HOME_XTERM)
646 if (input[2] == REAL_KEY_HOME_ALT)
648 if (input[2] == REAL_KEY_END_XTERM)
650 if (input[2] == REAL_KEY_END_ALT)
654 /* Reject almost all control chars */
656 if (i < ' ' && i != 0x0d && i != 8) goto again;
661 static char* less_gets(int sz)
665 char *result = xzalloc(1);
669 /* I be damned if I know why is it needed *repeatedly*,
670 * but it is needed. Is it because of stdio? */
671 tcsetattr(kbd_fd, TCSANOW, &term_vi);
684 if (i >= width - sz - 1)
685 continue; /* len limit */
688 result = xrealloc(result, i+1);
693 static void examine_file(void)
695 print_statusline("Examine: ");
697 filename = less_gets(sizeof("Examine: ")-1);
698 /* files start by = argv. why we assume that argv is infinitely long??
699 files[num_files] = filename;
700 current_file = num_files + 1;
703 num_files = current_file = 1;
707 /* This function changes the file currently being paged. direction can be one of the following:
708 * -1: go back one file
709 * 0: go to the first file
710 * 1: go forward one file */
711 static void change_file(int direction)
713 if (current_file != ((direction > 0) ? num_files : 1)) {
714 current_file = direction ? current_file + direction : 1;
716 filename = xstrdup(files[current_file - 1]);
719 print_statusline(direction > 0 ? "No next file" : "No previous file");
723 static void remove_current_file(void)
730 if (current_file != 1) {
732 for (i = 3; i <= num_files; i++)
733 files[i - 2] = files[i - 1];
737 for (i = 2; i <= num_files; i++)
738 files[i - 2] = files[i - 1];
744 static void colon_process(void)
748 /* Clear the current line and print a prompt */
749 print_statusline(" :");
751 keypress = less_getch();
754 remove_current_file();
759 #if ENABLE_FEATURE_LESS_FLAGS
779 #if ENABLE_FEATURE_LESS_REGEXP
780 static void normalize_match_pos(int match)
782 if (match >= num_matches)
783 match = num_matches - 1;
789 static void goto_match(int match)
795 /* Try to find next match if eof isn't reached yet */
796 if (match >= num_matches && eof_error > 0) {
797 cur_fline = MAXLINES; /* look as far as needed */
799 cap_cur_fline(cur_fline);
802 normalize_match_pos(match);
803 buffer_line(match_lines[match_pos]);
807 static void fill_match_lines(unsigned pos)
811 /* Run the regex on each line of the current file */
812 while (pos <= max_fline) {
813 /* If this line matches */
814 if (regexec(&pattern, flines[pos], 0, NULL, 0) == 0
815 /* and we didn't match it last time */
816 && !(num_matches && match_lines[num_matches-1] == pos)
818 match_lines = xrealloc(match_lines, (num_matches+1) * sizeof(int));
819 match_lines[num_matches++] = pos;
825 static void regex_process(void)
827 char *uncomp_regex, *err;
829 /* Reset variables */
839 /* Get the uncompiled regular expression from the user */
841 putchar((option_mask32 & LESS_STATE_MATCH_BACKWARDS) ? '?' : '/');
842 uncomp_regex = less_gets(1);
843 if (!uncomp_regex[0]) {
849 /* Compile the regex and check for errors */
850 err = regcomp_or_errmsg(&pattern, uncomp_regex, 0);
853 print_statusline(err);
861 while (match_pos < num_matches) {
862 if (match_lines[match_pos] > cur_fline)
866 if (option_mask32 & LESS_STATE_MATCH_BACKWARDS)
869 /* It's possible that no matches are found yet.
870 * goto_match() will read input looking for match,
872 goto_match(match_pos);
876 static void number_process(int first_digit)
880 char num_input[sizeof(int)*4]; /* more than enough */
883 num_input[0] = first_digit;
885 /* Clear the current line, print a prompt, and then print the digit */
887 printf(":%c", first_digit);
889 /* Receive input until a letter is given */
890 while (i < sizeof(num_input)-1) {
891 num_input[i] = less_getch();
892 if (!num_input[i] || !isdigit(num_input[i]))
894 putchar(num_input[i]);
898 /* Take the final letter out of the digits string */
899 keypress = num_input[i];
901 num = bb_strtou(num_input, NULL, 10);
902 /* on format error, num == -1 */
903 if (num < 1 || num > MAXLINES) {
908 /* We now know the number and the letter entered, so we process them */
910 case KEY_DOWN: case 'z': case 'd': case 'e': case ' ': case '\015':
913 case KEY_UP: case 'b': case 'w': case 'y': case 'u':
916 case 'g': case '<': case 'G': case '>':
917 cur_fline = num + max_displayed_line;
919 buffer_line(num - 1);
922 num = num * (max_fline / 100); /* + max_fline / 2; */
923 cur_fline = num + max_displayed_line;
927 #if ENABLE_FEATURE_LESS_REGEXP
929 goto_match(match_pos + num);
932 option_mask32 &= ~LESS_STATE_MATCH_BACKWARDS;
936 option_mask32 |= LESS_STATE_MATCH_BACKWARDS;
943 #if ENABLE_FEATURE_LESS_FLAGCS
944 static void flag_change(void)
950 keypress = less_getch();
954 option_mask32 ^= FLAG_M;
957 option_mask32 ^= FLAG_m;
960 option_mask32 ^= FLAG_E;
963 option_mask32 ^= FLAG_TILDE;
968 static void show_flag_status(void)
975 keypress = less_getch();
979 flag_val = option_mask32 & FLAG_M;
982 flag_val = option_mask32 & FLAG_m;
985 flag_val = option_mask32 & FLAG_TILDE;
988 flag_val = option_mask32 & FLAG_N;
991 flag_val = option_mask32 & FLAG_E;
999 printf(HIGHLIGHT"The status of the flag is: %u"NORMAL, flag_val != 0);
1003 static void save_input_to_file(void)
1005 const char *msg = "";
1010 print_statusline("Log file: ");
1011 current_line = less_gets(sizeof("Log file: ")-1);
1012 if (strlen(current_line) > 0) {
1013 fp = fopen(current_line, "w");
1015 msg = "Error opening log file";
1018 for (i = 0; i <= max_fline; i++)
1019 fprintf(fp, "%s\n", flines[i]);
1024 print_statusline(msg);
1028 #if ENABLE_FEATURE_LESS_MARKS
1029 static void add_mark(void)
1033 print_statusline("Mark: ");
1034 letter = less_getch();
1036 if (isalpha(letter)) {
1037 /* If we exceed 15 marks, start overwriting previous ones */
1038 if (num_marks == 14)
1041 mark_lines[num_marks][0] = letter;
1042 mark_lines[num_marks][1] = cur_fline;
1045 print_statusline("Invalid mark letter");
1049 static void goto_mark(void)
1054 print_statusline("Go to mark: ");
1055 letter = less_getch();
1058 if (isalpha(letter)) {
1059 for (i = 0; i <= num_marks; i++)
1060 if (letter == mark_lines[i][0]) {
1061 buffer_line(mark_lines[i][1]);
1064 if (num_marks == 14 && letter != mark_lines[14][0])
1065 print_statusline("Mark not set");
1067 print_statusline("Invalid mark letter");
1071 #if ENABLE_FEATURE_LESS_BRACKETS
1072 static char opp_bracket(char bracket)
1087 static void match_right_bracket(char bracket)
1089 int bracket_line = -1;
1092 if (strchr(flines[cur_fline], bracket) == NULL) {
1093 print_statusline("No bracket in top line");
1096 for (i = cur_fline + 1; i < max_fline; i++) {
1097 if (strchr(flines[i], opp_bracket(bracket)) != NULL) {
1102 if (bracket_line == -1)
1103 print_statusline("No matching bracket found");
1104 buffer_line(bracket_line - max_displayed_line);
1107 static void match_left_bracket(char bracket)
1109 int bracket_line = -1;
1112 if (strchr(flines[cur_fline + max_displayed_line], bracket) == NULL) {
1113 print_statusline("No bracket in bottom line");
1117 for (i = cur_fline + max_displayed_line; i >= 0; i--) {
1118 if (strchr(flines[i], opp_bracket(bracket)) != NULL) {
1123 if (bracket_line == -1)
1124 print_statusline("No matching bracket found");
1125 buffer_line(bracket_line);
1127 #endif /* FEATURE_LESS_BRACKETS */
1129 static void keypress_process(int keypress)
1132 case KEY_DOWN: case 'e': case 'j': case 0x0d:
1135 case KEY_UP: case 'y': case 'k':
1138 case PAGE_DOWN: case ' ': case 'z':
1139 buffer_down(max_displayed_line + 1);
1141 case PAGE_UP: case 'w': case 'b':
1142 buffer_up(max_displayed_line + 1);
1145 buffer_down((max_displayed_line + 1) / 2);
1148 buffer_up((max_displayed_line + 1) / 2);
1150 case KEY_HOME: case 'g': case 'p': case '<': case '%':
1153 case KEY_END: case 'G': case '>':
1154 cur_fline = MAXLINES;
1156 buffer_line(cur_fline);
1161 #if ENABLE_FEATURE_LESS_MARKS
1178 save_input_to_file();
1183 #if ENABLE_FEATURE_LESS_FLAGS
1188 #if ENABLE_FEATURE_LESS_REGEXP
1190 option_mask32 &= ~LESS_STATE_MATCH_BACKWARDS;
1194 goto_match(match_pos + 1);
1197 goto_match(match_pos - 1);
1200 option_mask32 |= LESS_STATE_MATCH_BACKWARDS;
1204 #if ENABLE_FEATURE_LESS_FLAGCS
1213 #if ENABLE_FEATURE_LESS_BRACKETS
1214 case '{': case '(': case '[':
1215 match_right_bracket(keypress);
1217 case '}': case ')': case ']':
1218 match_left_bracket(keypress);
1226 if (isdigit(keypress))
1227 number_process(keypress);
1230 static void sig_catcher(int sig ATTRIBUTE_UNUSED)
1236 int less_main(int argc, char **argv);
1237 int less_main(int argc, char **argv)
1241 /* TODO: -x: do not interpret backspace, -xx: tab also */
1242 /* -xxx: newline also */
1243 /* -w N: assume width N (-xxx -w 32: hex viewer of sorts) */
1244 getopt32(argc, argv, "EMmN~");
1250 /* Another popular pager, most, detects when stdout
1251 * is not a tty and turns into cat. This makes sense. */
1252 if (!isatty(STDOUT_FILENO))
1253 return bb_cat(argv);
1254 kbd_fd = open(CURRENT_TTY, O_RDONLY);
1256 return bb_cat(argv);
1259 if (isatty(STDIN_FILENO)) {
1260 /* Just "less"? No args and no redirection? */
1261 bb_error_msg("missing filename");
1265 filename = xstrdup(files[0]);
1267 get_terminal_width_height(kbd_fd, &width, &max_displayed_line);
1268 /* 20: two tabstops + 4 */
1269 if (width < 20 || max_displayed_line < 3)
1270 bb_error_msg_and_die("too narrow here");
1271 max_displayed_line -= 2;
1273 buffer = xmalloc((max_displayed_line+1) * sizeof(char *));
1274 if (option_mask32 & FLAG_TILDE)
1275 empty_line_marker = "";
1277 tcgetattr(kbd_fd, &term_orig);
1278 signal(SIGTERM, sig_catcher);
1279 signal(SIGINT, sig_catcher);
1280 term_vi = term_orig;
1281 term_vi.c_lflag &= ~(ICANON | ECHO);
1282 term_vi.c_iflag &= ~(IXON | ICRNL);
1283 /*term_vi.c_oflag &= ~ONLCR;*/
1284 term_vi.c_cc[VMIN] = 1;
1285 term_vi.c_cc[VTIME] = 0;
1287 /* Want to do it just once, but it doesn't work, */
1288 /* so we are redoing it (see code above). Mystery... */
1289 /*tcsetattr(kbd_fd, TCSANOW, &term_vi);*/
1293 keypress = less_getch();
1294 keypress_process(keypress);