Updates from both Vladimir and Larry
[oweals/busybox.git] / more.c
diff --git a/more.c b/more.c
index 732396f03341a918b974136b3911f1cb97b85c2b..9f07633c3269b753c3bfeb71bdc45c50a86a5bbf 100644 (file)
--- a/more.c
+++ b/more.c
@@ -31,9 +31,6 @@
 #include <stdlib.h>
 #include <sys/ioctl.h>
 #include "busybox.h"
-#define BB_DECLARE_EXTERN
-#define bb_need_help
-#include "messages.c"
 
 /* ED: sparc termios is broken: revert back to old termio handling. */
 #ifdef BB_FEATURE_USE_TERMIOS
@@ -164,6 +161,9 @@ extern int more_main(int argc, char **argv)
                                lines = 0;
                                page_height = terminal_height;
                                please_display_more_prompt = 0;
+
+                               if (input == 'q')
+                                       goto end;
                        }
 
                        /* 
@@ -177,24 +177,21 @@ extern int more_main(int argc, char **argv)
                         * allows the user to quit while in the middle of a file.
                         */
                        if (c == '\n') {
-                               switch (input) {
-                               case 'q':
-                                       goto end;
-                               case '\n':
-                                       /* increment by just one line if we are at 
-                                        * the end of this line*/
+                               /* increment by just one line if we are at
+                                * the end of this line */
+                               if (input == '\n')
                                        please_display_more_prompt = 1;
-                                       break;
-                               }
                                /* Adjust the terminal height for any overlap, so that
                                 * no lines get lost off the top. */
                                if (len >= terminal_width) {
-                                       div_t result = div( len, terminal_width); 
-                                       if (result.quot) {
-                                               if (result.rem)
-                                                       page_height-=result.quot;
+                                       int quot, rem;
+                                       quot = len / terminal_width;
+                                       rem  = len - (quot * terminal_width);
+                                       if (quot) {
+                                               if (rem)
+                                                       page_height-=quot;
                                                else
-                                                       page_height-=(result.quot-1);
+                                                       page_height-=(quot-1);
                                        }
                                }
                                if (++lines >= page_height) {
@@ -216,7 +213,7 @@ extern int more_main(int argc, char **argv)
        } while (--argc > 0);
   end:
 #ifdef BB_FEATURE_USE_TERMIOS
-       gotsig(0);
+       setTermSettings(fileno(cin), &initial_settings);
 #endif
-       return(TRUE);
+       return 0;
 }