Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/util-linux/more.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/util-linux/more.c
r1765 r2725 12 12 * Termios corrects by Vladimir Oleynik <dzo@simtreas.ru> 13 13 * 14 * Licensed under GPLv2 or later, see file L icense in this tarball for details.14 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 15 15 */ 16 16 17 17 #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 */ 24 20 25 21 struct globals { … … 27 23 struct termios initial_settings; 28 24 struct termios new_settings; 29 } ;25 } FIX_ALIASING; 30 26 #define G (*(struct globals*)bb_common_bufsiz1) 31 //#define G (*ptr_to_globals)32 27 #define INIT_G() ((void)0) 33 //#define INIT_G() PTR_TO_GLOBALS = xzalloc(sizeof(G))34 28 #define initial_settings (G.initial_settings) 35 29 #define new_settings (G.new_settings ) 36 30 #define cin_fileno (G.cin_fileno ) 37 31 38 #define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp) 32 #define setTermSettings(fd, argp) \ 33 do { \ 34 if (ENABLE_FEATURE_USE_TERMIOS) \ 35 tcsetattr(fd, TCSANOW, argp); \ 36 } while (0) 39 37 #define getTermSettings(fd, argp) tcgetattr(fd, argp) 40 38 41 static void gotsig(int sig )39 static void gotsig(int sig UNUSED_PARAM) 42 40 { 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'); 44 44 setTermSettings(cin_fileno, &initial_settings); 45 exit(EXIT_FAILURE);45 _exit(EXIT_FAILURE); 46 46 } 47 47 48 #else /* !FEATURE_USE_TERMIOS */49 #define INIT_G() ((void)0)50 #define setTermSettings(fd, argp) ((void)0)51 #endif /* FEATURE_USE_TERMIOS */52 53 48 #define CONVERTED_TAB_SIZE 8 54 49 55 int more_main(int argc, char **argv) ;56 int more_main(int argc , char **argv)50 int more_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 51 int more_main(int argc UNUSED_PARAM, char **argv) 57 52 { 58 int c = c; /* for gcc*/53 int c = c; /* for compiler */ 59 54 int lines; 60 55 int input = 0; … … 65 60 FILE *cin; 66 61 int len; 67 intterminal_width;68 intterminal_height;62 unsigned terminal_width; 63 unsigned terminal_height; 69 64 70 65 INIT_G(); … … 75 70 if (!isatty(STDOUT_FILENO)) 76 71 return bb_cat(argv); 77 cin = fopen (CURRENT_TTY, "r");72 cin = fopen_for_read(CURRENT_TTY); 78 73 if (!cin) 79 74 return bb_cat(argv); 80 75 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 } 94 91 95 92 do { … … 118 115 len = printf("--More-- "); 119 116 if (st.st_size > 0) { 120 len += printf("(% d%% of %"OFF_FMT"dbytes)",117 len += printf("(%u%% of %"OFF_FMT"u bytes)", 121 118 (int) (ftello(file)*100 / st.st_size), 122 119 st.st_size); 123 120 } 124 fflush (stdout);121 fflush_all(); 125 122 126 123 /* … … 131 128 input = getc(cin); 132 129 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 */ 136 132 /* Erase the last message */ 137 133 printf("\r%*s\r", len, ""); … … 155 151 /* The user may have resized the terminal. 156 152 * 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 } 161 157 } 162 158 … … 166 162 spaces = CONVERTED_TAB_SIZE - 1; 167 163 c = ' '; 168 164 } 169 165 170 166 /* … … 198 194 } 199 195 fclose(file); 200 fflush (stdout);196 fflush_all(); 201 197 } while (*argv && *++argv); 202 198 end:
Note:
See TracChangeset
for help on using the changeset viewer.