gzip: speed up send_bits()
[oweals/busybox.git] / coreutils / stty.c
index e818d579c6446e84563239ce7b5fc9de67fa5544..424d909cf3c40a4601f7481c1ab6e56e7ed11e9e 100644 (file)
@@ -1,31 +1,32 @@
 /* vi: set sw=4 ts=4: */
-/* stty -- change and print terminal line settings
-   Copyright (C) 1990-1999 Free Software Foundation, Inc.
-
-   Licensed under GPLv2 or later, see file LICENSE in this source tree.
-*/
+/*
+ * stty -- change and print terminal line settings
+ * Copyright (C) 1990-1999 Free Software Foundation, Inc.
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
 /* Usage: stty [-ag] [-F device] [setting...]
-
  Options:
  -a Write all current settings to stdout in human-readable form.
  -g Write all current settings to stdout in stty-readable form.
  -F Open and use the specified device instead of stdin
-
  If no args are given, write to stdout the baud rate and settings that
  have been changed from their defaults.  Mode reading and changes
  are done on the specified device, or stdin if none was specified.
-
  David MacKenzie <djm@gnu.ai.mit.edu>
-
  Special for busybox ported by Vladimir Oleynik <dzo@simtreas.ru> 2001
-*/
+ *
* Options:
* -a Write all current settings to stdout in human-readable form.
* -g Write all current settings to stdout in stty-readable form.
* -F Open and use the specified device instead of stdin
+ *
* If no args are given, write to stdout the baud rate and settings that
* have been changed from their defaults.  Mode reading and changes
* are done on the specified device, or stdin if none was specified.
+ *
* David MacKenzie <djm@gnu.ai.mit.edu>
+ *
* Special for busybox ported by Vladimir Oleynik <dzo@simtreas.ru> 2001
+ */
 //config:config STTY
-//config:      bool "stty"
+//config:      bool "stty (8.6 kb)"
 //config:      default y
 //config:      help
-//config:        stty is used to change and print terminal line settings.
+//config:      stty is used to change and print terminal line settings.
 
-//applet:IF_STTY(APPLET(stty, BB_DIR_BIN, BB_SUID_DROP))
+//applet:IF_STTY(APPLET_NOEXEC(stty, stty, BB_DIR_BIN, BB_SUID_DROP, stty))
 
 //kbuild:lib-$(CONFIG_STTY) += stty.o
 
 #ifndef CRDLY
 # define CRDLY 0
 #endif
+#ifndef CMSPAR
+# define CMSPAR 0
+#endif
 #ifndef CRTSCTS
 # define CRTSCTS 0
 #endif
@@ -352,6 +356,9 @@ static const char mode_name[] ALIGN1 =
 #endif
        MI_ENTRY("parenb",   control,     REV,               PARENB,     0 )
        MI_ENTRY("parodd",   control,     REV,               PARODD,     0 )
+#if CMSPAR
+       MI_ENTRY("cmspar",   control,     REV,               CMSPAR,     0 )
+#endif
        MI_ENTRY("cs5",      control,     0,                 CS5,     CSIZE)
        MI_ENTRY("cs6",      control,     0,                 CS6,     CSIZE)
        MI_ENTRY("cs7",      control,     0,                 CS7,     CSIZE)
@@ -476,6 +483,10 @@ static const char mode_name[] ALIGN1 =
 #if ECHOKE
        MI_ENTRY("echoke",   local,       SANE_SET   | REV,  ECHOKE,     0 )
        MI_ENTRY("crtkill",  local,       OMIT       | REV,  ECHOKE,     0 )
+#endif
+       MI_ENTRY("flusho",   local,       SANE_UNSET | REV,  FLUSHO,     0 )
+#ifdef EXTPROC
+       MI_ENTRY("extproc",  local,       SANE_UNSET | REV,  EXTPROC,    0 )
 #endif
        ;
 
@@ -509,6 +520,9 @@ static const struct mode_info mode_info[] = {
 #endif
        MI_ENTRY("parenb",   control,     REV,               PARENB,     0 )
        MI_ENTRY("parodd",   control,     REV,               PARODD,     0 )
+#if CMSPAR
+       MI_ENTRY("cmspar",   control,     REV,               CMSPAR,     0 )
+#endif
        MI_ENTRY("cs5",      control,     0,                 CS5,     CSIZE)
        MI_ENTRY("cs6",      control,     0,                 CS6,     CSIZE)
        MI_ENTRY("cs7",      control,     0,                 CS7,     CSIZE)
@@ -633,6 +647,10 @@ static const struct mode_info mode_info[] = {
 #if ECHOKE
        MI_ENTRY("echoke",   local,       SANE_SET   | REV,  ECHOKE,     0 )
        MI_ENTRY("crtkill",  local,       OMIT       | REV,  ECHOKE,     0 )
+#endif
+       MI_ENTRY("flusho",   local,       SANE_UNSET | REV,  FLUSHO,     0 )
+#ifdef EXTPROC
+       MI_ENTRY("extproc",  local,       SANE_UNSET | REV,  EXTPROC,    0 )
 #endif
 };
 
@@ -782,12 +800,13 @@ struct globals {
        unsigned max_col;
        /* Current position, to know when to wrap */
        unsigned current_col;
-       char buf[10];
 } FIX_ALIASING;
 #define G (*(struct globals*)bb_common_bufsiz1)
 #define INIT_G() do { \
+       setup_common_bufsiz(); \
        G.device_name = bb_msg_standard_input; \
        G.max_col = 80; \
+       G.current_col = 0; /* we are noexec, must clear */ \
 } while (0)
 
 static void set_speed_or_die(enum speed_setting type, const char *arg,
@@ -835,10 +854,11 @@ static void wrapf(const char *message, ...)
                G.current_col++;
                if (buf[0] != '\n') {
                        if (G.current_col + buflen >= G.max_col) {
-                               bb_putchar('\n');
                                G.current_col = 0;
-                       } else
+                               bb_putchar('\n');
+                       } else {
                                bb_putchar(' ');
+                       }
                }
        }
        fputs(buf, stdout);
@@ -1018,6 +1038,8 @@ static void do_display(const struct termios *mode, int all)
 
        for (i = 0; i != CIDX_min; ++i) {
                char ch;
+               char buf10[10];
+
                /* If swtch is the same as susp, don't print both */
 #if VSWTCH == VSUSP
                if (i == CIDX_swtch)
@@ -1033,10 +1055,10 @@ static void do_display(const struct termios *mode, int all)
 #endif
                ch = mode->c_cc[control_info[i].offset];
                if (ch == _POSIX_VDISABLE)
-                       strcpy(G.buf, "<undef>");
+                       strcpy(buf10, "<undef>");
                else
-                       visible(ch, G.buf, 0);
-               wrapf("%s = %s;", nth_string(control_name, i), G.buf);
+                       visible(ch, buf10, 0);
+               wrapf("%s = %s;", nth_string(control_name, i), buf10);
        }
 #if VEOF == VMIN
        if ((mode->c_lflag & ICANON) == 0)