New message added to messages.c: full_version
[oweals/busybox.git] / ps.c
diff --git a/ps.c b/ps.c
index 0842a22c2c0836cb22b9fce1422e62502253a60c..fc58a9bb7215506f8cbaf026525a0f3143ea0eca 100644 (file)
--- a/ps.c
+++ b/ps.c
@@ -40,6 +40,9 @@
 #define bb_need_help
 #include "messages.c"
 
+#define TERMINAL_WIDTH  79      /* not 80 in case terminal has linefold bug */
+
+
 
 #if ! defined BB_FEATURE_USE_DEVPS_PATCH
 
@@ -94,24 +97,23 @@ static void parse_proc_status(char *S, proc_t * P)
        if (tmp)
                sscanf(tmp, "Pid:\t%d\n" "PPid:\t%d\n", &P->pid, &P->ppid);
        else
-               fprintf(stderr, "Internal error!\n");
+               errorMsg("Internal error!\n");
 
        /* For busybox, ignoring effective, saved, etc */
        tmp = strstr(S, "Uid:");
        if (tmp)
                sscanf(tmp, "Uid:\t%d", &P->ruid);
        else
-               fprintf(stderr, "Internal error!\n");
+               errorMsg("Internal error!\n");
 
        tmp = strstr(S, "Gid:");
        if (tmp)
                sscanf(tmp, "Gid:\t%d", &P->rgid);
        else
-               fprintf(stderr, "Internal error!\n");
+               errorMsg("Internal error!\n");
 
 }
 
-
 extern int ps_main(int argc, char **argv)
 {
        proc_t p;
@@ -123,26 +125,20 @@ extern int ps_main(int argc, char **argv)
        char groupName[10] = "";
        int len, i, c;
 #ifdef BB_FEATURE_AUTOWIDTH
-       struct winsize win = { 0, 0 };
-       int terminal_width = 0;
+       struct winsize win = { 0, 0, 0, 0 };
+       int terminal_width = TERMINAL_WIDTH;
 #else
-#define terminal_width  79
+#define terminal_width  TERMINAL_WIDTH
 #endif
 
 
 
-       if (argc > 1 && strcmp(argv[1], dash_dash_help) == 0) {
-               usage ("ps\n"
-#ifndef BB_FEATURE_TRIVIAL_HELP
-                               "\nReport process status\n"
-                               "\nThis version of ps accepts no options.\n"
-#endif
-                               );
-       }
+       if (argc > 1 && strcmp(argv[1], dash_dash_help) == 0)
+               usage(ps_usage);
 
        dir = opendir("/proc");
        if (!dir)
-               fatalError("Can't open /proc");
+               fatalError("Can't open /proc\n");
 
 #ifdef BB_FEATURE_AUTOWIDTH
                ioctl(fileno(stdout), TIOCGWINSZ, &win);
@@ -189,7 +185,7 @@ extern int ps_main(int argc, char **argv)
                fprintf(stdout, "\n");
        }
        closedir(dir);
-       exit(TRUE);
+       return(TRUE);
 }
 
 
@@ -200,7 +196,7 @@ extern int ps_main(int argc, char **argv)
  * this one uses the nifty new devps kernel device.
  */
 
-#include <linux/devps.h>
+#include <linux/devps.h> /* For Erik's nifty devps device driver */
 
 
 extern int ps_main(int argc, char **argv)
@@ -213,14 +209,14 @@ extern int ps_main(int argc, char **argv)
        char uidName[10] = "";
        char groupName[10] = "";
 #ifdef BB_FEATURE_AUTOWIDTH
-       struct winsize win = { 0, 0 };
-       int terminal_width = 0;
+       struct winsize win = { 0, 0, 0, 0 };
+       int terminal_width = TERMINAL_WIDTH;
 #else
-#define terminal_width  79
+#define terminal_width  TERMINAL_WIDTH
 #endif
 
        if (argc > 1 && **(argv + 1) == '-') 
-               usage("ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n");
+               usage(ps_usage);
 
        /* open device */ 
        fd = open(device, O_RDONLY);