to ensure proper fallback behavior on, i.e. serial consoles.
-Erik
#endif
#ifdef CONFIG_FEATURE_AUTOWIDTH
-static unsigned short terminal_width = TERMINAL_WIDTH;
+static int terminal_width = TERMINAL_WIDTH;
static unsigned short tabstops = COLUMN_GAP;
#else
#define tabstops COLUMN_GAP
is_flask_enabled_flag = is_flask_enabled();
#endif
-#ifdef CONFIG_FEATURE_AUTOWIDTH
- struct winsize win = { 0, 0, 0, 0 };
-#endif
-
all_fmt = LIST_SHORT | DISP_NORMAL | STYLE_AUTO
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
| TIME_MOD
| SORT_NAME | SORT_ORDER_FORWARD
#endif
;
-#ifdef CONFIG_FEATURE_AUTOWIDTH
- ioctl(fileno(stdout), TIOCGWINSZ, &win);
- if (win.ws_col > 0)
- terminal_width = win.ws_col - 1;
-#endif
+ /* Obtain the terminal width. */
+ get_terminal_width_height(0, &terminal_width, NULL);
+ /* Go one less... */
+ terminal_width--;
nfiles = 0;
#ifdef CONFIG_FEATURE_LS_COLOR
*/
static const char vi_Version[] =
- "$Id: vi.c,v 1.28 2003/03/19 09:11:45 mjn3 Exp $";
+ "$Id: vi.c,v 1.29 2003/09/15 08:33:36 andersen Exp $";
/*
* To compile for standalone use:
#if defined(CONFIG_FEATURE_VI_USE_SIGNALS) || defined(CONFIG_FEATURE_VI_CRASHME)
static int my_pid;
#endif
-#ifdef CONFIG_FEATURE_VI_WIN_RESIZE
-static struct winsize winsize; // remember the window size
-#endif /* CONFIG_FEATURE_VI_WIN_RESIZE */
#ifdef CONFIG_FEATURE_VI_DOT_CMD
static int adding2q; // are we currently adding user input to q
static Byte *last_modifying_cmd; // last modifying cmd for "."
return (0);
}
+#ifdef CONFIG_FEATURE_VI_WIN_RESIZE
+//----- See what the window size currently is --------------------
+static inline void window_size_get(int fd)
+{
+ get_terminal_width_height(fd, &columns, &rows);
+}
+#endif /* CONFIG_FEATURE_VI_WIN_RESIZE */
+
static void edit_file(Byte * fn)
{
Byte c;
tcsetattr(0, TCSANOW, &term_orig);
}
-#ifdef CONFIG_FEATURE_VI_WIN_RESIZE
-//----- See what the window size currently is --------------------
-static void window_size_get(int sig)
-{
- int i;
-
- i = ioctl(0, TIOCGWINSZ, &winsize);
- if (i != 0) {
- // force 24x80
- winsize.ws_row = 24;
- winsize.ws_col = 80;
- }
- if (winsize.ws_row <= 1) {
- winsize.ws_row = 24;
- }
- if (winsize.ws_col <= 1) {
- winsize.ws_col = 80;
- }
- rows = (int) winsize.ws_row;
- columns = (int) winsize.ws_col;
-}
-#endif /* CONFIG_FEATURE_VI_WIN_RESIZE */
-
//----- Come here when we get a window resize signal ---------
#ifdef CONFIG_FEATURE_VI_USE_SIGNALS
static void winch_sig(int sig)
} llist_t;
extern llist_t *llist_add_to(llist_t *old_head, char *new_item);
-void print_login_issue(const char *issue_file, const char *tty);
-void print_login_prompt(void);
+extern void print_login_issue(const char *issue_file, const char *tty);
+extern void print_login_prompt(void);
-void vfork_daemon_rexec(int argc, char **argv, char *foreground_opt);
+extern void vfork_daemon_rexec(int argc, char **argv, char *foreground_opt);
+extern void get_terminal_width_height(int fd, int *width, int *height);
#endif /* __LIBCONFIG_H__ */
--- /dev/null
+/* vi: set sw=4 ts=4: */
+/*
+ * Determine the width and height of the terminal.
+ *
+ * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <unistd.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include "busybox.h"
+
+/* It is perfectly ok to pass in a NULL for either width or for
+ * height, in which case that value will not be set. It is also
+ * perfectly ok to have CONFIG_FEATURE_AUTOWIDTH disabled, in
+ * which case you will always get 80x24 */
+void get_terminal_width_height(int fd, int *width, int *height)
+{
+ struct winsize win = { 0, 0, 0, 0 };
+#ifdef CONFIG_FEATURE_AUTOWIDTH
+ if (ioctl(0, TIOCGWINSZ, &win) != 0) {
+ win.ws_row = 24;
+ win.ws_col = 80;
+ }
+#endif
+ if (win.ws_row <= 1) {
+ win.ws_row = 24;
+ }
+ if (win.ws_col <= 1) {
+ win.ws_col = 80;
+ }
+ if (height) {
+ *height = (int) win.ws_row;
+ }
+ if (width) {
+ *width = (int) win.ws_col;
+ }
+}
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
+
#include <netinet/in.h>
#include "busybox.h"
-#ifdef CONFIG_FEATURE_AUTOWIDTH
-# include <sys/ioctl.h>
-#endif
-
#if 0
static const int DOTRACE = 1;
#endif
#endif
#ifdef CONFIG_FEATURE_AUTOWIDTH
- struct winsize winp;
- if( ioctl(0, TIOCGWINSZ, &winp) == 0 ) {
- win_width = winp.ws_col;
- win_height = winp.ws_row;
- }
+ get_terminal_width_height(0, &win_width, &win_height);
#endif
#ifdef CONFIG_FEATURE_TELNET_TTYPE
static int
getttywidth(void)
{
- struct winsize winsize;
-
- if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) != -1)
- return (winsize.ws_col ? winsize.ws_col : 80);
- else
- return (80);
+ int width=0;
+ get_terminal_width_height(0, &width, NULL);
+ return (width);
}
static void
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: wget.c,v 1.59 2003/09/11 08:25:11 andersen Exp $
+ * $Id: wget.c,v 1.60 2003/09/15 08:33:37 andersen Exp $
*/
{
procps_status_t * p;
int i, len;
-#ifdef CONFIG_FEATURE_AUTOWIDTH
- struct winsize win = { 0, 0, 0, 0 };
int terminal_width = TERMINAL_WIDTH;
-#else
-#define terminal_width TERMINAL_WIDTH
-#endif
#ifdef CONFIG_SELINUX
int use_selinux = 0;
use_selinux = 1;
#endif
-
-#ifdef CONFIG_FEATURE_AUTOWIDTH
- ioctl(fileno(stdout), TIOCGWINSZ, &win);
- if (win.ws_col > 0)
- terminal_width = win.ws_col - 1;
-#endif
+ get_terminal_width_height(0, &terminal_width, NULL);
+ /* Go one less... */
+ terminal_width--;
#ifdef CONFIG_SELINUX
if(use_selinux)
sprintf(rss_str_buf, "%6ldM", s->rss/1024);
else
sprintf(rss_str_buf, "%7ld", s->rss);
+ printf(
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
- printf("%5d %-8s %s %s %5d %2d.%d %2u.%u ",
+ "%5d %-8s %s %s %5d %2d.%d %2u.%u ",
#else
- printf("%5d %-8s %s %s %5d %2u.%u ",
+ "%5d %-8s %s %s %5d %2u.%u ",
#endif
s->pid, s->user, s->state, rss_str_buf, s->ppid,
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
fd_set readfds;
unsigned char c;
struct sigaction sa;
-#if defined CONFIG_FEATURE_AUTOWIDTH
- struct winsize win = { 0, 0, 0, 0 };
-#endif
#endif /* CONFIG_FEATURE_USE_TERMIOS */
/* Default update rate is 5 seconds */
sigaction (SIGINT, &sa, (struct sigaction *) 0);
tcsetattr(0, TCSANOW, (void *) &new_settings);
atexit(reset_term);
-#if defined CONFIG_FEATURE_AUTOWIDTH
- ioctl(0, TIOCGWINSZ, &win);
- if (win.ws_row > 4) {
- lines = win.ws_row - 5;
+
+ get_terminal_width_height(0, &col, &lines);
+ if (lines > 4) {
+ lines -= 5;
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
- col = win.ws_col - 80 + 35 - 6;
+ col = col - 80 + 35 - 6;
#else
- col = win.ws_col - 80 + 35;
+ col = col - 80 + 35;
#endif
}
-#endif
#endif /* CONFIG_FEATURE_USE_TERMIOS */
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
sort_function[0] = pcpu_sort;
static void win_changed(int nsig)
{
- struct winsize win = { 0, 0, 0, 0 };
static sighandler_t previous_SIGWINCH_handler; /* for reset */
/* emulate || signal call */
if (nsig == -SIGWINCH || nsig == SIGWINCH) {
- ioctl(0, TIOCGWINSZ, &win);
- if (win.ws_col > 0) {
- cmdedit_setwidth(win.ws_col, nsig == SIGWINCH);
- }
+ int width = 0;
+ get_terminal_width_height(0, &width, NULL);
+ cmdedit_setwidth(width, nsig == SIGWINCH);
}
/* Unix not all standart in recall signal */
FILE *file;
int len, page_height;
-#if defined CONFIG_FEATURE_AUTOWIDTH && defined CONFIG_FEATURE_USE_TERMIOS
- struct winsize win = { 0, 0, 0, 0 };
-#endif
-
argc--;
argv++;
if(please_display_more_prompt>0)
please_display_more_prompt = 0;
-#if defined CONFIG_FEATURE_AUTOWIDTH && defined CONFIG_FEATURE_USE_TERMIOS
- ioctl(fileno(stdout), TIOCGWINSZ, &win);
- if (win.ws_row > 4)
- terminal_height = win.ws_row - 2;
- if (win.ws_col > 0)
- terminal_width = win.ws_col - 1;
-#endif
+ get_terminal_width_height(0, &terminal_width, &terminal_height);
+ if (terminal_height > 4)
+ terminal_height -= 2;
+ if (terminal_width > 0)
+ terminal_width -= 1;
+
len=0;
lines = 0;
page_height = terminal_height;