diff options
| author | Eric Andersen <andersen@codepoet.org> | 2001-01-26 01:52:43 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 2001-01-26 01:52:43 +0000 |
| commit | 5307eca7de2caf1d4efb8ee3e802a69a1a076376 (patch) | |
| tree | 2886cc812856a1f2fa060cdaaf224810e99e3ff0 /coreutils | |
| parent | 114ad9c753aeefac32a2d53b861790a4ecd5da30 (diff) | |
| download | busybox-w32-5307eca7de2caf1d4efb8ee3e802a69a1a076376.tar.gz busybox-w32-5307eca7de2caf1d4efb8ee3e802a69a1a076376.tar.bz2 busybox-w32-5307eca7de2caf1d4efb8ee3e802a69a1a076376.zip | |
Make ls understand termios.
-Erik
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/ls.c | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 64e5bf828..215c58bb6 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
| @@ -60,6 +60,10 @@ static const int COLUMN_GAP = 2; /* includes the file type char, if present */ | |||
| 60 | #endif | 60 | #endif |
| 61 | #include <string.h> | 61 | #include <string.h> |
| 62 | 62 | ||
| 63 | #include <fcntl.h> | ||
| 64 | #include <signal.h> | ||
| 65 | #include <sys/ioctl.h> | ||
| 66 | |||
| 63 | #ifndef NAJOR | 67 | #ifndef NAJOR |
| 64 | #define MAJOR(dev) (((dev)>>8)&0xff) | 68 | #define MAJOR(dev) (((dev)>>8)&0xff) |
| 65 | #define MINOR(dev) ((dev)&0xff) | 69 | #define MINOR(dev) ((dev)&0xff) |
| @@ -181,6 +185,31 @@ static int status = EXIT_SUCCESS; | |||
| 181 | unsigned long ls_disp_hr = KILOBYTE; | 185 | unsigned long ls_disp_hr = KILOBYTE; |
| 182 | #endif | 186 | #endif |
| 183 | 187 | ||
| 188 | /* sparc termios is broken -- use old termio handling. */ | ||
| 189 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 190 | # if #cpu(sparc) | ||
| 191 | # include <termio.h> | ||
| 192 | # define termios termio | ||
| 193 | # define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp) | ||
| 194 | # define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp) | ||
| 195 | # else | ||
| 196 | # include <termios.h> | ||
| 197 | # define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp) | ||
| 198 | # define getTermSettings(fd,argp) tcgetattr(fd, argp); | ||
| 199 | # endif | ||
| 200 | |||
| 201 | FILE *cin; | ||
| 202 | |||
| 203 | static struct termios initial_settings, new_settings; | ||
| 204 | |||
| 205 | static void gotsig(int sig) | ||
| 206 | { | ||
| 207 | setTermSettings(fileno(cin), &initial_settings); | ||
| 208 | putchar('\n'); | ||
| 209 | exit(EXIT_FAILURE); | ||
| 210 | } | ||
| 211 | #endif /* BB_FEATURE_USE_TERMIOS */ | ||
| 212 | |||
| 184 | static int my_stat(struct dnode *cur) | 213 | static int my_stat(struct dnode *cur) |
| 185 | { | 214 | { |
| 186 | #ifdef BB_FEATURE_LS_FOLLOWLINKS | 215 | #ifdef BB_FEATURE_LS_FOLLOWLINKS |
| @@ -707,6 +736,9 @@ extern int ls_main(int argc, char **argv) | |||
| 707 | int opt; | 736 | int opt; |
| 708 | int oi, ac; | 737 | int oi, ac; |
| 709 | char **av; | 738 | char **av; |
| 739 | #if defined BB_FEATURE_AUTOWIDTH && defined BB_FEATURE_USE_TERMIOS | ||
| 740 | struct winsize win = { 0, 0, 0, 0 }; | ||
| 741 | #endif | ||
| 710 | 742 | ||
| 711 | disp_opts= DISP_NORMAL; | 743 | disp_opts= DISP_NORMAL; |
| 712 | style_fmt= STYLE_AUTO; | 744 | style_fmt= STYLE_AUTO; |
| @@ -719,10 +751,34 @@ extern int ls_main(int argc, char **argv) | |||
| 719 | time_fmt= TIME_MOD; | 751 | time_fmt= TIME_MOD; |
| 720 | #endif | 752 | #endif |
| 721 | #ifdef BB_FEATURE_AUTOWIDTH | 753 | #ifdef BB_FEATURE_AUTOWIDTH |
| 754 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 755 | cin = fopen("/dev/tty", "r"); | ||
| 756 | if (!cin) | ||
| 757 | cin = fopen("/dev/console", "r"); | ||
| 758 | getTermSettings(fileno(cin), &initial_settings); | ||
| 759 | new_settings = initial_settings; | ||
| 760 | new_settings.c_cc[VMIN] = 1; | ||
| 761 | new_settings.c_cc[VTIME] = 0; | ||
| 762 | new_settings.c_lflag &= ~ICANON; | ||
| 763 | new_settings.c_lflag &= ~ECHO; | ||
| 764 | setTermSettings(fileno(cin), &new_settings); | ||
| 765 | |||
| 766 | ioctl(fileno(stdout), TIOCGWINSZ, &win); | ||
| 767 | if (win.ws_row > 4) | ||
| 768 | column_width = win.ws_row - 2; | ||
| 769 | if (win.ws_col > 0) | ||
| 770 | terminal_width = win.ws_col - 1; | ||
| 771 | |||
| 772 | (void) signal(SIGINT, gotsig); | ||
| 773 | (void) signal(SIGQUIT, gotsig); | ||
| 774 | (void) signal(SIGTERM, gotsig); | ||
| 775 | #else | ||
| 776 | |||
| 722 | terminal_width = TERMINAL_WIDTH; | 777 | terminal_width = TERMINAL_WIDTH; |
| 723 | column_width = COLUMN_WIDTH; | 778 | column_width = COLUMN_WIDTH; |
| 724 | tabstops = 8; | ||
| 725 | #endif | 779 | #endif |
| 780 | #endif | ||
| 781 | tabstops = 8; | ||
| 726 | nfiles=0; | 782 | nfiles=0; |
| 727 | 783 | ||
| 728 | /* process options */ | 784 | /* process options */ |
| @@ -908,6 +964,9 @@ extern int ls_main(int argc, char **argv) | |||
| 908 | } | 964 | } |
| 909 | } | 965 | } |
| 910 | 966 | ||
| 967 | #ifdef BB_FEATURE_USE_TERMIOS | ||
| 968 | gotsig(0); | ||
| 969 | #endif | ||
| 911 | return(status); | 970 | return(status); |
| 912 | 971 | ||
| 913 | print_usage_message: | 972 | print_usage_message: |
