Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/miscutils/less.c


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/miscutils/less.c

    r2725 r3232  
    2222 */
    2323
     24//config:config LESS
     25//config:   bool "less"
     26//config:   default y
     27//config:   help
     28//config:     'less' is a pager, meaning that it displays text files. It possesses
     29//config:     a wide array of features, and is an improvement over 'more'.
     30//config:
     31//config:config FEATURE_LESS_MAXLINES
     32//config:   int "Max number of input lines less will try to eat"
     33//config:   default 9999999
     34//config:   depends on LESS
     35//config:
     36//config:config FEATURE_LESS_BRACKETS
     37//config:   bool "Enable bracket searching"
     38//config:   default y
     39//config:   depends on LESS
     40//config:   help
     41//config:     This option adds the capability to search for matching left and right
     42//config:     brackets, facilitating programming.
     43//config:
     44//config:config FEATURE_LESS_FLAGS
     45//config:   bool "Enable -m/-M"
     46//config:   default y
     47//config:   depends on LESS
     48//config:   help
     49//config:     The -M/-m flag enables a more sophisticated status line.
     50//config:
     51//config:config FEATURE_LESS_MARKS
     52//config:   bool "Enable marks"
     53//config:   default y
     54//config:   depends on LESS
     55//config:   help
     56//config:     Marks enable positions in a file to be stored for easy reference.
     57//config:
     58//config:config FEATURE_LESS_REGEXP
     59//config:   bool "Enable regular expressions"
     60//config:   default y
     61//config:   depends on LESS
     62//config:   help
     63//config:     Enable regular expressions, allowing complex file searches.
     64//config:
     65//config:config FEATURE_LESS_WINCH
     66//config:   bool "Enable automatic resizing on window size changes"
     67//config:   default y
     68//config:   depends on LESS
     69//config:   help
     70//config:     Makes less track window size changes.
     71//config:
     72//config:config FEATURE_LESS_ASK_TERMINAL
     73//config:   bool "Use 'tell me cursor position' ESC sequence to measure window"
     74//config:   default y
     75//config:   depends on FEATURE_LESS_WINCH
     76//config:   help
     77//config:     Makes less track window size changes.
     78//config:     If terminal size can't be retrieved and $LINES/$COLUMNS are not set,
     79//config:     this option makes less perform a last-ditch effort to find it:
     80//config:     position cursor to 999,999 and ask terminal to report real
     81//config:     cursor position using "ESC [ 6 n" escape sequence, then read stdin.
     82//config:
     83//config:     This is not clean but helps a lot on serial lines and such.
     84//config:
     85//config:config FEATURE_LESS_DASHCMD
     86//config:   bool "Enable flag changes ('-' command)"
     87//config:   default y
     88//config:   depends on LESS
     89//config:   help
     90//config:     This enables the ability to change command-line flags within
     91//config:     less itself ('-' keyboard command).
     92//config:
     93//config:config FEATURE_LESS_LINENUMS
     94//config:   bool "Enable dynamic switching of line numbers"
     95//config:   default y
     96//config:   depends on FEATURE_LESS_DASHCMD
     97//config:   help
     98//config:     Enables "-N" command.
     99
     100//usage:#define less_trivial_usage
     101//usage:       "[-E" IF_FEATURE_LESS_FLAGS("Mm") "Nh~I?] [FILE]..."
     102//usage:#define less_full_usage "\n\n"
     103//usage:       "View FILE (or stdin) one screenful at a time\n"
     104//usage:     "\n    -E  Quit once the end of a file is reached"
     105//usage:    IF_FEATURE_LESS_FLAGS(
     106//usage:     "\n    -M,-m   Display status line with line numbers"
     107//usage:     "\n        and percentage through the file"
     108//usage:    )
     109//usage:     "\n    -N  Prefix line number to each line"
     110//usage:     "\n    -I  Ignore case in all searches"
     111//usage:     "\n    -~  Suppress ~s displayed past EOF"
     112
    24113#include <sched.h>  /* sched_yield() */
    25114
     
    97186    regex_t pattern;
    98187    smallint pattern_valid;
     188#endif
     189#if ENABLE_FEATURE_LESS_ASK_TERMINAL
     190    smallint winsize_err;
    99191#endif
    100192    smallint terminated;
     
    618710
    619711    /* Each part of the line that matches has the HIGHLIGHT
    620        and NORMAL escape sequences placed around it.
    621        NB: we regex against line, but insert text
    622        from quarantined copy (buf[]) */
     712     * and NORMAL escape sequences placed around it.
     713     * NB: we regex against line, but insert text
     714     * from quarantined copy (buf[]) */
    623715    str = buf;
    624716    growline = NULL;
     
    629721        char *new = xasprintf("%s%.*s"HIGHLIGHT"%.*s"NORMAL,
    630722                growline ? growline : "",
    631                 match_structs.rm_so, str,
    632                 match_structs.rm_eo - match_structs.rm_so,
     723                (int)match_structs.rm_so, str,
     724                (int)(match_structs.rm_eo - match_structs.rm_so),
    633725                        str + match_structs.rm_so);
    634726        free(growline);
     
    805897    max_lineno = 0;
    806898    open_file_and_read_lines();
     899#if ENABLE_FEATURE_LESS_ASK_TERMINAL
     900    if (G.winsize_err)
     901        printf("\033[999;999H" "\033[6n");
     902#endif
    807903    buffer_fill_and_print();
    808904}
    809905
    810 static int getch_nowait(void)
     906static int64_t getch_nowait(void)
    811907{
    812908    int rd;
     909    int64_t key64;
    813910    struct pollfd pfd[2];
    814911
     
    858955    /* We have kbd_fd in O_NONBLOCK mode, read inside read_key()
    859956     * would not block even if there is no input available */
    860     rd = read_key(kbd_fd, kbd_input, /*timeout off:*/ -2);
    861     if (rd == -1) {
     957    key64 = read_key(kbd_fd, kbd_input, /*timeout off:*/ -2);
     958    if ((int)key64 == -1) {
    862959        if (errno == EAGAIN) {
    863960            /* No keyboard input available. Since poll() did return,
     
    871968    }
    872969    set_tty_cooked();
    873     return rd;
     970    return key64;
    874971}
    875972
     
    877974 * May return KEYCODE_xxx values.
    878975 * Note that this function works best with raw input. */
    879 static int less_getch(int pos)
    880 {
    881     int i;
     976static int64_t less_getch(int pos)
     977{
     978    int64_t key64;
     979    int key;
    882980
    883981 again:
    884982    less_gets_pos = pos;
    885     i = getch_nowait();
     983    key = key64 = getch_nowait();
    886984    less_gets_pos = -1;
    887985
    888     /* Discard Ctrl-something chars */
    889     if (i >= 0 && i < ' ' && i != 0x0d && i != 8)
     986    /* Discard Ctrl-something chars.
     987     * (checking only lower 32 bits is a size optimization:
     988     * upper 32 bits are used only by KEYCODE_CURSOR_POS)
     989     */
     990    if (key >= 0 && key < ' ' && key != 0x0d && key != 8)
    890991        goto again;
    891     return i;
     992
     993    return key64;
    892994}
    893995
     
    14291531#endif
    14301532    case 'r': case 'R':
     1533        /* TODO: (1) also bind ^R, ^L to this?
     1534         * (2) re-measure window size?
     1535         */
    14311536        buffer_print();
    14321537        break;
     
    15041609int less_main(int argc, char **argv)
    15051610{
    1506     int keypress;
    1507 
    15081611    INIT_G();
    15091612
     
    15481651    term_less.c_cc[VTIME] = 0;
    15491652
    1550     get_terminal_width_height(kbd_fd, &width, &max_displayed_line);
     1653    IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(kbd_fd, &width, &max_displayed_line);
    15511654    /* 20: two tabstops + 4 */
    15521655    if (width < 20 || max_displayed_line < 3)
     
    15631666    reinitialize();
    15641667    while (1) {
     1668        int64_t keypress;
     1669
    15651670#if ENABLE_FEATURE_LESS_WINCH
    15661671        while (WINCH_COUNTER) {
    15671672 again:
    15681673            winch_counter--;
    1569             get_terminal_width_height(kbd_fd, &width, &max_displayed_line);
     1674            IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(kbd_fd, &width, &max_displayed_line);
     1675 IF_FEATURE_LESS_ASK_TERMINAL(got_size:)
    15701676            /* 20: two tabstops + 4 */
    15711677            if (width < 20)
     
    15871693             * were there another SIGWINCH? */
    15881694        }
    1589 #endif
    15901695        keypress = less_getch(-1); /* -1: do not position cursor */
     1696# if ENABLE_FEATURE_LESS_ASK_TERMINAL
     1697        if ((int32_t)keypress == KEYCODE_CURSOR_POS) {
     1698            uint32_t rc = (keypress >> 32);
     1699            width = (rc & 0x7fff);
     1700            max_displayed_line = ((rc >> 16) & 0x7fff);
     1701            goto got_size;
     1702        }
     1703# endif
     1704#else
     1705        keypress = less_getch(-1); /* -1: do not position cursor */
     1706#endif
    15911707        keypress_process(keypress);
    15921708    }
Note: See TracChangeset for help on using the changeset viewer.