[BusyBox] [patch] ps w
Vladimir N. Oleynik
dzo at simtreas.ru
Fri Feb 4 10:17:41 UTC 2005
Rainer,
>>The attached patch adds an option CONFIG_PS_FEATURE_WIDE which adds
>>support for the argument w for printing up to 511 chars of command and
>>args.
>>While at it, i added another option -- CONFIG_PS_FEATURE_WIDEPIPE --
>>which looks if stdout is a fifo and if so, also sets the maximum
>>line-length to 511.
I have analyzed a source code procps-3.0.3.
If "-w" selected then use 132 cols, if it is specified more once
or non tty output, infinite value of width is used.
I think:
1) must change libbb/get_terminal_width_height for can see result
of ioctl(fd, TIOCGWINSZ, &win):
+#ifdef CONFIG_FEATURE_AUTOWIDTH
+int get_terminal_width_height(int fd, int *width, int *height)
+#else
void get_terminal_width_height(int fd, int *width, int *height)
+#endif
{
struct winsize win = { 0, 0, 0, 0 };
#ifdef CONFIG_FEATURE_AUTOWIDTH
+ int rez = ioctl(fd, TIOCGWINSZ, &win);
- if (ioctl(fd, TIOCGWINSZ, &win) != 0) {
+ if (rez != 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;
}
+#ifdef CONFIG_FEATURE_AUTOWIDTH
+ return rez;
+#endif
}
> +config CONFIG_PS_FEATURE_WIDEPIPE
> + bool " Default to wide on descriptors not refering to tty devices"
> + default n
> + depends on CONFIG_PS
> + help
> + Automatically use wide format if output goes to a descriptor
> + that does not refer to a terminal device.
2) It is better to not do it in general.
> +
> +config CONFIG_PS_FEATURE_WIDE
> + bool " Support argument for wide output"
> + default y
> + depends on CONFIG_PS
> + help
> + Support argument 'w' for untruncated output.
> +
3) usind isatty() is not require
-> +#ifdef CONFIG_PS_FEATURE_WIDEPIPE
-> +#include <sys/stat.h>
-> +#endif
-> +#ifdef CONFIG_PS_FEATURE_WIDEPIPE
-> + struct stat stat_buf;
-> +#endif
+#ifdef CONFIG_PS_FEATURE_WIDE
+ int w_opt = 0;
+#else
+#define w_opt 0
+#endif
-> +#ifdef CONFIG_PS_FEATURE_WIDEPIPE
-> + /* do not truncate the output if it goes to a non-tty device */
-> + if (!isatty(STDOUT_FILENO)) terminal_width = 512;
-> + else
-> +#endif
+#ifdef CONFIG_FEATURE_AUTOWIDTH
+ if(get_terminal_width_height(0, &terminal_width, NULL) == 0)
+ w_opt = 2;
+#else
+ get_terminal_width_height(0, &terminal_width, NULL);
+#endif
> +#ifdef CONFIG_PS_FEATURE_WIDE
> + /* handle argument w */
> + if (argv[1]) {
> + while (*(argv[1])!='\0' && *(argv[1]) != 'w') { (argv[1])++; }
> + if (*argv[1] == 'w')
-> + terminal_width = 512;
+ w_opt++;
-> + } else
+ if(w_opt == 1)
+ terminal_width = 132;
> +#endif
> +
-> get_terminal_width_height(0, &terminal_width, NULL);
> /* Go one less... */
> terminal_width--;
> @@ -90,7 +110,7 @@
>
> if(namecmd != 0 && namecmd[0] != 0) {
> if(i < 0)
> - i = 0;
> + i = 0;
-> if(strlen(namecmd) > i)
+> if(w_opt < 2 && strlen(namecmd) > i)
> namecmd[i] = 0;
> printf("%s\n", namecmd);
--w
vodz
More information about the busybox
mailing list