Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/util-linux/more.c

    r1765 r2725  
    1212 * Termios corrects by Vladimir Oleynik <dzo@simtreas.ru>
    1313 *
    14  * Licensed under GPLv2 or later, see file License in this tarball for details.
     14 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1515 */
    1616
    1717#include "libbb.h"
    18 #if ENABLE_FEATURE_USE_TERMIOS
    19 #include <termios.h>
    20 #endif /* FEATURE_USE_TERMIOS */
    21 
    22 
    23 #if ENABLE_FEATURE_USE_TERMIOS
     18
     19/* Support for FEATURE_USE_TERMIOS */
    2420
    2521struct globals {
     
    2723    struct termios initial_settings;
    2824    struct termios new_settings;
    29 };
     25} FIX_ALIASING;
    3026#define G (*(struct globals*)bb_common_bufsiz1)
    31 //#define G (*ptr_to_globals)
    3227#define INIT_G() ((void)0)
    33 //#define INIT_G() PTR_TO_GLOBALS = xzalloc(sizeof(G))
    3428#define initial_settings (G.initial_settings)
    3529#define new_settings     (G.new_settings    )
    3630#define cin_fileno       (G.cin_fileno      )
    3731
    38 #define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp)
     32#define setTermSettings(fd, argp) \
     33do { \
     34    if (ENABLE_FEATURE_USE_TERMIOS) \
     35        tcsetattr(fd, TCSANOW, argp); \
     36} while (0)
    3937#define getTermSettings(fd, argp) tcgetattr(fd, argp)
    4038
    41 static void gotsig(int sig)
     39static void gotsig(int sig UNUSED_PARAM)
    4240{
    43     putchar('\n');
     41    /* bb_putchar_stderr doesn't use stdio buffering,
     42     * therefore it is safe in signal handler */
     43    bb_putchar_stderr('\n');
    4444    setTermSettings(cin_fileno, &initial_settings);
    45     exit(EXIT_FAILURE);
     45    _exit(EXIT_FAILURE);
    4646}
    4747
    48 #else /* !FEATURE_USE_TERMIOS */
    49 #define INIT_G() ((void)0)
    50 #define setTermSettings(fd, argp) ((void)0)
    51 #endif /* FEATURE_USE_TERMIOS */
    52 
    5348#define CONVERTED_TAB_SIZE 8
    5449
    55 int more_main(int argc, char **argv);
    56 int more_main(int argc, char **argv)
     50int more_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     51int more_main(int argc UNUSED_PARAM, char **argv)
    5752{
    58     int c = c; /* for gcc */
     53    int c = c; /* for compiler */
    5954    int lines;
    6055    int input = 0;
     
    6560    FILE *cin;
    6661    int len;
    67     int terminal_width;
    68     int terminal_height;
     62    unsigned terminal_width;
     63    unsigned terminal_height;
    6964
    7065    INIT_G();
     
    7570    if (!isatty(STDOUT_FILENO))
    7671        return bb_cat(argv);
    77     cin = fopen(CURRENT_TTY, "r");
     72    cin = fopen_for_read(CURRENT_TTY);
    7873    if (!cin)
    7974        return bb_cat(argv);
    8075
    81 #if ENABLE_FEATURE_USE_TERMIOS
    82     cin_fileno = fileno(cin);
    83     getTermSettings(cin_fileno, &initial_settings);
    84     new_settings = initial_settings;
    85     new_settings.c_lflag &= ~ICANON;
    86     new_settings.c_lflag &= ~ECHO;
    87     new_settings.c_cc[VMIN] = 1;
    88     new_settings.c_cc[VTIME] = 0;
    89     setTermSettings(cin_fileno, &new_settings);
    90     signal(SIGINT, gotsig);
    91     signal(SIGQUIT, gotsig);
    92     signal(SIGTERM, gotsig);
    93 #endif
     76    if (ENABLE_FEATURE_USE_TERMIOS) {
     77        cin_fileno = fileno(cin);
     78        getTermSettings(cin_fileno, &initial_settings);
     79        new_settings = initial_settings;
     80        new_settings.c_lflag &= ~ICANON;
     81        new_settings.c_lflag &= ~ECHO;
     82        new_settings.c_cc[VMIN] = 1;
     83        new_settings.c_cc[VTIME] = 0;
     84        setTermSettings(cin_fileno, &new_settings);
     85        bb_signals(0
     86            + (1 << SIGINT)
     87            + (1 << SIGQUIT)
     88            + (1 << SIGTERM)
     89            , gotsig);
     90    }
    9491
    9592    do {
     
    118115                len = printf("--More-- ");
    119116                if (st.st_size > 0) {
    120                     len += printf("(%d%% of %"OFF_FMT"d bytes)",
     117                    len += printf("(%u%% of %"OFF_FMT"u bytes)",
    121118                        (int) (ftello(file)*100 / st.st_size),
    122119                        st.st_size);
    123120                }
    124                 fflush(stdout);
     121                fflush_all();
    125122
    126123                /*
     
    131128                    input = getc(cin);
    132129                    input = tolower(input);
    133 #if !ENABLE_FEATURE_USE_TERMIOS
    134                     printf("\033[A"); /* up cursor */
    135 #endif
     130                    if (!ENABLE_FEATURE_USE_TERMIOS)
     131                        printf("\033[A"); /* cursor up */
    136132                    /* Erase the last message */
    137133                    printf("\r%*s\r", len, "");
     
    155151                /* The user may have resized the terminal.
    156152                 * Re-read the dimensions. */
    157 #if ENABLE_FEATURE_USE_TERMIOS
    158                 get_terminal_width_height(cin_fileno, &terminal_width, &terminal_height);
    159                 terminal_height -= 1;
    160 #endif
     153                if (ENABLE_FEATURE_USE_TERMIOS) {
     154                    get_terminal_width_height(cin_fileno, &terminal_width, &terminal_height);
     155                    terminal_height -= 1;
     156                }
    161157            }
    162158
     
    166162                spaces = CONVERTED_TAB_SIZE - 1;
    167163                c = ' ';
    168             }
     164            }
    169165
    170166            /*
     
    198194        }
    199195        fclose(file);
    200         fflush(stdout);
     196        fflush_all();
    201197    } while (*argv && *++argv);
    202198 end:
Note: See TracChangeset for help on using the changeset viewer.