mirror of
https://github.com/sheumann/hush.git
synced 2025-02-09 17:30:36 +00:00
Be entirely consistant when using ioctl(0, TIOCGWINSZ, &winsize)
to ensure proper fallback behavior on, i.e. serial consoles. -Erik
This commit is contained in:
parent
c4f72d1426
commit
8efe967018
@ -203,7 +203,7 @@ static int is_flask_enabled_flag;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||||
static unsigned short terminal_width = TERMINAL_WIDTH;
|
static int terminal_width = TERMINAL_WIDTH;
|
||||||
static unsigned short tabstops = COLUMN_GAP;
|
static unsigned short tabstops = COLUMN_GAP;
|
||||||
#else
|
#else
|
||||||
#define tabstops COLUMN_GAP
|
#define tabstops COLUMN_GAP
|
||||||
@ -915,10 +915,6 @@ extern int ls_main(int argc, char **argv)
|
|||||||
is_flask_enabled_flag = is_flask_enabled();
|
is_flask_enabled_flag = is_flask_enabled();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
|
||||||
struct winsize win = { 0, 0, 0, 0 };
|
|
||||||
#endif
|
|
||||||
|
|
||||||
all_fmt = LIST_SHORT | DISP_NORMAL | STYLE_AUTO
|
all_fmt = LIST_SHORT | DISP_NORMAL | STYLE_AUTO
|
||||||
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
||||||
| TIME_MOD
|
| TIME_MOD
|
||||||
@ -927,11 +923,10 @@ extern int ls_main(int argc, char **argv)
|
|||||||
| SORT_NAME | SORT_ORDER_FORWARD
|
| SORT_NAME | SORT_ORDER_FORWARD
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
/* Obtain the terminal width. */
|
||||||
ioctl(fileno(stdout), TIOCGWINSZ, &win);
|
get_terminal_width_height(0, &terminal_width, NULL);
|
||||||
if (win.ws_col > 0)
|
/* Go one less... */
|
||||||
terminal_width = win.ws_col - 1;
|
terminal_width--;
|
||||||
#endif
|
|
||||||
nfiles = 0;
|
nfiles = 0;
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_LS_COLOR
|
#ifdef CONFIG_FEATURE_LS_COLOR
|
||||||
|
36
editors/vi.c
36
editors/vi.c
@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static const char vi_Version[] =
|
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:
|
* To compile for standalone use:
|
||||||
@ -197,9 +197,6 @@ static jmp_buf restart; // catch_sig()
|
|||||||
#if defined(CONFIG_FEATURE_VI_USE_SIGNALS) || defined(CONFIG_FEATURE_VI_CRASHME)
|
#if defined(CONFIG_FEATURE_VI_USE_SIGNALS) || defined(CONFIG_FEATURE_VI_CRASHME)
|
||||||
static int my_pid;
|
static int my_pid;
|
||||||
#endif
|
#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
|
#ifdef CONFIG_FEATURE_VI_DOT_CMD
|
||||||
static int adding2q; // are we currently adding user input to q
|
static int adding2q; // are we currently adding user input to q
|
||||||
static Byte *last_modifying_cmd; // last modifying cmd for "."
|
static Byte *last_modifying_cmd; // last modifying cmd for "."
|
||||||
@ -412,6 +409,14 @@ extern int vi_main(int argc, char **argv)
|
|||||||
return (0);
|
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)
|
static void edit_file(Byte * fn)
|
||||||
{
|
{
|
||||||
Byte c;
|
Byte c;
|
||||||
@ -2122,29 +2127,6 @@ static void cookmode(void)
|
|||||||
tcsetattr(0, TCSANOW, &term_orig);
|
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 ---------
|
//----- Come here when we get a window resize signal ---------
|
||||||
#ifdef CONFIG_FEATURE_VI_USE_SIGNALS
|
#ifdef CONFIG_FEATURE_VI_USE_SIGNALS
|
||||||
static void winch_sig(int sig)
|
static void winch_sig(int sig)
|
||||||
|
@ -462,9 +462,10 @@ typedef struct llist_s {
|
|||||||
} llist_t;
|
} llist_t;
|
||||||
extern llist_t *llist_add_to(llist_t *old_head, char *new_item);
|
extern llist_t *llist_add_to(llist_t *old_head, char *new_item);
|
||||||
|
|
||||||
void print_login_issue(const char *issue_file, const char *tty);
|
extern void print_login_issue(const char *issue_file, const char *tty);
|
||||||
void print_login_prompt(void);
|
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__ */
|
#endif /* __LIBCONFIG_H__ */
|
||||||
|
66
libbb/get_terminal_width_height.c
Normal file
66
libbb/get_terminal_width_height.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/* 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:
|
||||||
|
*/
|
||||||
|
|
@ -44,10 +44,6 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
|
||||||
# include <sys/ioctl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static const int DOTRACE = 1;
|
static const int DOTRACE = 1;
|
||||||
#endif
|
#endif
|
||||||
@ -585,11 +581,7 @@ extern int telnet_main(int argc, char** argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||||
struct winsize winp;
|
get_terminal_width_height(0, &win_width, &win_height);
|
||||||
if( ioctl(0, TIOCGWINSZ, &winp) == 0 ) {
|
|
||||||
win_width = winp.ws_col;
|
|
||||||
win_height = winp.ws_row;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_TELNET_TTYPE
|
#ifdef CONFIG_FEATURE_TELNET_TTYPE
|
||||||
|
@ -679,12 +679,9 @@ static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf)
|
|||||||
static int
|
static int
|
||||||
getttywidth(void)
|
getttywidth(void)
|
||||||
{
|
{
|
||||||
struct winsize winsize;
|
int width=0;
|
||||||
|
get_terminal_width_height(0, &width, NULL);
|
||||||
if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) != -1)
|
return (width);
|
||||||
return (winsize.ws_col ? winsize.ws_col : 80);
|
|
||||||
else
|
|
||||||
return (80);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -841,7 +838,7 @@ progressmeter(int flag)
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* 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 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
14
procps/ps.c
14
procps/ps.c
@ -44,12 +44,7 @@ extern int ps_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
procps_status_t * p;
|
procps_status_t * p;
|
||||||
int i, len;
|
int i, len;
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
|
||||||
struct winsize win = { 0, 0, 0, 0 };
|
|
||||||
int terminal_width = TERMINAL_WIDTH;
|
int terminal_width = TERMINAL_WIDTH;
|
||||||
#else
|
|
||||||
#define terminal_width TERMINAL_WIDTH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_SELINUX
|
#ifdef CONFIG_SELINUX
|
||||||
int use_selinux = 0;
|
int use_selinux = 0;
|
||||||
@ -58,12 +53,9 @@ extern int ps_main(int argc, char **argv)
|
|||||||
use_selinux = 1;
|
use_selinux = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
get_terminal_width_height(0, &terminal_width, NULL);
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
/* Go one less... */
|
||||||
ioctl(fileno(stdout), TIOCGWINSZ, &win);
|
terminal_width--;
|
||||||
if (win.ws_col > 0)
|
|
||||||
terminal_width = win.ws_col - 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_SELINUX
|
#ifdef CONFIG_SELINUX
|
||||||
if(use_selinux)
|
if(use_selinux)
|
||||||
|
21
procps/top.c
21
procps/top.c
@ -373,10 +373,11 @@ static void display_status(int count, int col)
|
|||||||
sprintf(rss_str_buf, "%6ldM", s->rss/1024);
|
sprintf(rss_str_buf, "%6ldM", s->rss/1024);
|
||||||
else
|
else
|
||||||
sprintf(rss_str_buf, "%7ld", s->rss);
|
sprintf(rss_str_buf, "%7ld", s->rss);
|
||||||
|
printf(
|
||||||
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
|
#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
|
#else
|
||||||
printf("%5d %-8s %s %s %5d %2u.%u ",
|
"%5d %-8s %s %s %5d %2u.%u ",
|
||||||
#endif
|
#endif
|
||||||
s->pid, s->user, s->state, rss_str_buf, s->ppid,
|
s->pid, s->user, s->state, rss_str_buf, s->ppid,
|
||||||
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
|
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
|
||||||
@ -432,9 +433,6 @@ int top_main(int argc, char **argv)
|
|||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
#if defined CONFIG_FEATURE_AUTOWIDTH
|
|
||||||
struct winsize win = { 0, 0, 0, 0 };
|
|
||||||
#endif
|
|
||||||
#endif /* CONFIG_FEATURE_USE_TERMIOS */
|
#endif /* CONFIG_FEATURE_USE_TERMIOS */
|
||||||
|
|
||||||
/* Default update rate is 5 seconds */
|
/* Default update rate is 5 seconds */
|
||||||
@ -478,17 +476,16 @@ int top_main(int argc, char **argv)
|
|||||||
sigaction (SIGINT, &sa, (struct sigaction *) 0);
|
sigaction (SIGINT, &sa, (struct sigaction *) 0);
|
||||||
tcsetattr(0, TCSANOW, (void *) &new_settings);
|
tcsetattr(0, TCSANOW, (void *) &new_settings);
|
||||||
atexit(reset_term);
|
atexit(reset_term);
|
||||||
#if defined CONFIG_FEATURE_AUTOWIDTH
|
|
||||||
ioctl(0, TIOCGWINSZ, &win);
|
get_terminal_width_height(0, &col, &lines);
|
||||||
if (win.ws_row > 4) {
|
if (lines > 4) {
|
||||||
lines = win.ws_row - 5;
|
lines -= 5;
|
||||||
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
|
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
|
||||||
col = win.ws_col - 80 + 35 - 6;
|
col = col - 80 + 35 - 6;
|
||||||
#else
|
#else
|
||||||
col = win.ws_col - 80 + 35;
|
col = col - 80 + 35;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#endif /* CONFIG_FEATURE_USE_TERMIOS */
|
#endif /* CONFIG_FEATURE_USE_TERMIOS */
|
||||||
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
|
#ifdef FEATURE_CPU_USAGE_PERCENTAGE
|
||||||
sort_function[0] = pcpu_sort;
|
sort_function[0] = pcpu_sort;
|
||||||
|
@ -167,15 +167,13 @@ static void cmdedit_setwidth(int w, int redraw_flg);
|
|||||||
|
|
||||||
static void win_changed(int nsig)
|
static void win_changed(int nsig)
|
||||||
{
|
{
|
||||||
struct winsize win = { 0, 0, 0, 0 };
|
|
||||||
static sighandler_t previous_SIGWINCH_handler; /* for reset */
|
static sighandler_t previous_SIGWINCH_handler; /* for reset */
|
||||||
|
|
||||||
/* emulate || signal call */
|
/* emulate || signal call */
|
||||||
if (nsig == -SIGWINCH || nsig == SIGWINCH) {
|
if (nsig == -SIGWINCH || nsig == SIGWINCH) {
|
||||||
ioctl(0, TIOCGWINSZ, &win);
|
int width = 0;
|
||||||
if (win.ws_col > 0) {
|
get_terminal_width_height(0, &width, NULL);
|
||||||
cmdedit_setwidth(win.ws_col, nsig == SIGWINCH);
|
cmdedit_setwidth(width, nsig == SIGWINCH);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* Unix not all standart in recall signal */
|
/* Unix not all standart in recall signal */
|
||||||
|
|
||||||
|
@ -69,10 +69,6 @@ extern int more_main(int argc, char **argv)
|
|||||||
FILE *file;
|
FILE *file;
|
||||||
int len, page_height;
|
int len, page_height;
|
||||||
|
|
||||||
#if defined CONFIG_FEATURE_AUTOWIDTH && defined CONFIG_FEATURE_USE_TERMIOS
|
|
||||||
struct winsize win = { 0, 0, 0, 0 };
|
|
||||||
#endif
|
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
|
||||||
@ -115,13 +111,12 @@ extern int more_main(int argc, char **argv)
|
|||||||
if(please_display_more_prompt>0)
|
if(please_display_more_prompt>0)
|
||||||
please_display_more_prompt = 0;
|
please_display_more_prompt = 0;
|
||||||
|
|
||||||
#if defined CONFIG_FEATURE_AUTOWIDTH && defined CONFIG_FEATURE_USE_TERMIOS
|
get_terminal_width_height(0, &terminal_width, &terminal_height);
|
||||||
ioctl(fileno(stdout), TIOCGWINSZ, &win);
|
if (terminal_height > 4)
|
||||||
if (win.ws_row > 4)
|
terminal_height -= 2;
|
||||||
terminal_height = win.ws_row - 2;
|
if (terminal_width > 0)
|
||||||
if (win.ws_col > 0)
|
terminal_width -= 1;
|
||||||
terminal_width = win.ws_col - 1;
|
|
||||||
#endif
|
|
||||||
len=0;
|
len=0;
|
||||||
lines = 0;
|
lines = 0;
|
||||||
page_height = terminal_height;
|
page_height = terminal_height;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user