Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/miscutils/less.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 983 by niro, Fri Apr 24 18:33:46 2009 UTC revision 984 by niro, Sun May 30 11:32:42 2010 UTC
# Line 96  struct globals { Line 96  struct globals {
96   smallint pattern_valid;   smallint pattern_valid;
97  #endif  #endif
98   smallint terminated;   smallint terminated;
  smalluint kbd_input_size;  
99   struct termios term_orig, term_less;   struct termios term_orig, term_less;
100   char kbd_input[KEYCODE_BUFFER_SIZE];   char kbd_input[KEYCODE_BUFFER_SIZE];
101  };  };
# Line 135  struct globals { Line 134  struct globals {
134  #define terminated          (G.terminated        )  #define terminated          (G.terminated        )
135  #define term_orig           (G.term_orig         )  #define term_orig           (G.term_orig         )
136  #define term_less           (G.term_less         )  #define term_less           (G.term_less         )
 #define kbd_input_size      (G.kbd_input_size    )  
137  #define kbd_input           (G.kbd_input         )  #define kbd_input           (G.kbd_input         )
138  #define INIT_G() do { \  #define INIT_G() do { \
139   SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \   SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
# Line 145  struct globals { Line 143  struct globals {
143   current_file = 1; \   current_file = 1; \
144   eof_error = 1; \   eof_error = 1; \
145   terminated = 1; \   terminated = 1; \
146   USE_FEATURE_LESS_REGEXP(wanted_match = -1;) \   IF_FEATURE_LESS_REGEXP(wanted_match = -1;) \
147  } while (0)  } while (0)
148    
149  /* flines[] are lines read from stdin, each in malloc'ed buffer.  /* flines[] are lines read from stdin, each in malloc'ed buffer.
# Line 159  struct globals { Line 157  struct globals {
157  /* Reset terminal input to normal */  /* Reset terminal input to normal */
158  static void set_tty_cooked(void)  static void set_tty_cooked(void)
159  {  {
160   fflush(stdout);   fflush_all();
161   tcsetattr(kbd_fd, TCSANOW, &term_orig);   tcsetattr(kbd_fd, TCSANOW, &term_orig);
162  }  }
163    
# Line 326  static void read_lines(void) Line 324  static void read_lines(void)
324   if (option_mask32 & FLAG_N)   if (option_mask32 & FLAG_N)
325   w -= 8;   w -= 8;
326    
327   USE_FEATURE_LESS_REGEXP(again0:)   IF_FEATURE_LESS_REGEXP(again0:)
328    
329   p = current_line = ((char*)xmalloc(w + 4)) + 4;   p = current_line = ((char*)xmalloc(w + 4)) + 4;
330   max_fline += last_terminated;   max_fline += last_terminated;
# Line 626  static void print_found(const char *line Line 624  static void print_found(const char *line
624    
625   while (match_status == 0) {   while (match_status == 0) {
626   char *new = xasprintf("%s%.*s"HIGHLIGHT"%.*s"NORMAL,   char *new = xasprintf("%s%.*s"HIGHLIGHT"%.*s"NORMAL,
627   growline ? : "",   growline ? growline : "",
628   match_structs.rm_so, str,   match_structs.rm_so, str,
629   match_structs.rm_eo - match_structs.rm_so,   match_structs.rm_eo - match_structs.rm_so,
630   str + match_structs.rm_so);   str + match_structs.rm_so);
# Line 774  static void buffer_line(int linenum) Line 772  static void buffer_line(int linenum)
772  static void open_file_and_read_lines(void)  static void open_file_and_read_lines(void)
773  {  {
774   if (filename) {   if (filename) {
775   int fd = xopen(filename, O_RDONLY);   xmove_fd(xopen(filename, O_RDONLY), STDIN_FILENO);
  dup2(fd, 0);  
  if (fd) close(fd);  
776   } else {   } else {
777   /* "less" with no arguments in argv[] */   /* "less" with no arguments in argv[] */
778   /* For status line only */   /* For status line only */
# Line 808  static void reinitialize(void) Line 804  static void reinitialize(void)
804   buffer_fill_and_print();   buffer_fill_and_print();
805  }  }
806    
807  static ssize_t getch_nowait(void)  static int getch_nowait(void)
808  {  {
809   int rd;   int rd;
810   struct pollfd pfd[2];   struct pollfd pfd[2];
# Line 839  static ssize_t getch_nowait(void) Line 835  static ssize_t getch_nowait(void)
835   /* Position cursor if line input is done */   /* Position cursor if line input is done */
836   if (less_gets_pos >= 0)   if (less_gets_pos >= 0)
837   move_cursor(max_displayed_line + 2, less_gets_pos + 1);   move_cursor(max_displayed_line + 2, less_gets_pos + 1);
838   fflush(stdout);   fflush_all();
839    
840   if (kbd_input_size == 0) {   if (kbd_input[0] == 0) { /* if nothing is buffered */
841  #if ENABLE_FEATURE_LESS_WINCH  #if ENABLE_FEATURE_LESS_WINCH
842   while (1) {   while (1) {
843   int r;   int r;
# Line 858  static ssize_t getch_nowait(void) Line 854  static ssize_t getch_nowait(void)
854    
855   /* We have kbd_fd in O_NONBLOCK mode, read inside read_key()   /* We have kbd_fd in O_NONBLOCK mode, read inside read_key()
856   * would not block even if there is no input available */   * would not block even if there is no input available */
857   rd = read_key(kbd_fd, &kbd_input_size, kbd_input);   rd = read_key(kbd_fd, kbd_input);
858   if (rd == -1) {   if (rd == -1) {
859   if (errno == EAGAIN) {   if (errno == EAGAIN) {
860   /* No keyboard input available. Since poll() did return,   /* No keyboard input available. Since poll() did return,
# Line 874  static ssize_t getch_nowait(void) Line 870  static ssize_t getch_nowait(void)
870   return rd;   return rd;
871  }  }
872    
873  /* Grab a character from input without requiring the return key. If the  /* Grab a character from input without requiring the return key.
874   * character is ASCII \033, get more characters and assign certain sequences   * May return KEYCODE_xxx values.
875   * special return codes. Note that this function works best with raw input. */   * Note that this function works best with raw input. */
876  static int less_getch(int pos)  static int less_getch(int pos)
877  {  {
878   int i;   int i;
# Line 1511  int less_main(int argc, char **argv) Line 1507  int less_main(int argc, char **argv)
1507   /* TODO: -x: do not interpret backspace, -xx: tab also */   /* TODO: -x: do not interpret backspace, -xx: tab also */
1508   /* -xxx: newline also */   /* -xxx: newline also */
1509   /* -w N: assume width N (-xxx -w 32: hex viewer of sorts) */   /* -w N: assume width N (-xxx -w 32: hex viewer of sorts) */
1510   getopt32(argv, "EMmN~I" USE_FEATURE_LESS_DASHCMD("S"));   getopt32(argv, "EMmN~I" IF_FEATURE_LESS_DASHCMD("S"));
1511   argc -= optind;   argc -= optind;
1512   argv += optind;   argv += optind;
1513   num_files = argc;   num_files = argc;

Legend:
Removed from v.983  
changed lines
  Added in v.984