]> granicus.if.org Git - procps-ng/commitdiff
w: bassman emulation with -o option
authorCraig Small <csmall@debian.org>
Tue, 24 Nov 2009 00:00:39 +0000 (11:00 +1100)
committerCraig Small <csmall@enc.com.au>
Sun, 18 Dec 2011 11:56:41 +0000 (22:56 +1100)
A patch from Debian.

Bug-Debian: http://bugs.debian.org/414906
Backported-by: Sami Kerola <kerolasa@iki.fi>
w.1
w.c

diff --git a/w.1 b/w.1
index d35be87cfa79a5983de11df59a6aa6cca92d53de..c20eb5726f622bb95a2712655b53878aaafb6de7 100644 (file)
--- a/w.1
+++ b/w.1
@@ -5,7 +5,7 @@
 w \- Show who is logged on and what they are doing.
 .SH SYNOPSIS
 .B w
-.RB [ \-husfV ]
+.RB [ \-husfV- ]
 .RI [ user ]
 .SH DESCRIPTION
 .B w
@@ -55,6 +55,9 @@ field is shown by default.
 .B "\-V "
 Display version information.
 .TP 0.5i
+.B "\-o "
+Old style output. Prints blank space for idle times less than one minute.
+.TP 0.5i
 .B "user "
 Show information about the specified user only.
 
diff --git a/w.c b/w.c
index f479433c4b395c77cf60a92b6185c8c4aec0e708..d429612c4ce87d7c62c74aaf8f9e6b12e7d53cee 100644 (file)
--- a/w.c
+++ b/w.c
@@ -31,6 +31,7 @@
 #include <termios.h>
 
 static int ignoreuser = 0;     /* for '-u' */
+static int oldstyle = 0;       /* for '-o' */
 static proc_t **procs;         /* our snapshot of the process table */
 
 typedef struct utmp utmp_t;
@@ -77,6 +78,16 @@ static void print_time_ival7(time_t t, int centi_sec, FILE* fout) {
       printf("   ?   ");
       return;
     }
+    if (oldstyle) {
+      if (t >= 48*60*60)               /* > 2 days */
+        fprintf(fout, " %2ludays", t/(24*60*60));
+      else if (t >= 60*60)            /* > 1 hour */
+        fprintf(fout, " %2lu:%02u ", t/(60*60), (unsigned) ((t/60)%60));
+      else if (t > 60)               /* > 1 minute */
+        fprintf(fout, " %2lu:%02um", t/60, (unsigned) t%60);
+      else
+        fprintf(fout, "       ");
+    } else {
     if (t >= 48*60*60)                         /* > 2 days */
        fprintf(fout, " %2ludays", t/(24*60*60));
     else if (t >= 60*60)                       /* > 1 hour */
@@ -85,6 +96,7 @@ static void print_time_ival7(time_t t, int centi_sec, FILE* fout) {
        fprintf(fout, " %2lu:%02u ", t/60, (unsigned) t%60);
     else
        fprintf(fout, " %2lu.%02us", t, centi_sec);
+    }
 }
 
 /**** stat the device file to get an idle time */
@@ -240,7 +252,7 @@ int main(int argc, char **argv) {
 #endif
 
     setlocale(LC_ALL, "");
-    for (args=0; (ch = getopt(argc, argv, "hlusfV")) != EOF; args++)
+    for (args=0; (ch = getopt(argc, argv, "hlusfVo")) != EOF; args++)
        switch (ch) {
          case 'h': header = 0;         break;
          case 'l': longform = 1;       break;
@@ -248,6 +260,7 @@ int main(int argc, char **argv) {
          case 'f': from = !from;       break;
          case 'V': display_version();  exit(0);
          case 'u': ignoreuser = 1;     break;
+         case 'o': oldstyle = 1;       break;
          default:
            printf("usage: w -hlsufV [user]\n"
                   "    -h    skip header\n"
@@ -255,6 +268,7 @@ int main(int argc, char **argv) {
                   "    -s    short listing\n"
                   "    -u    ignore uid of processes\n"
                   "    -f    toggle FROM field (default %s)\n"
+                  "    -o    old-style output\n"
                   "    -V    display version\n", FROM_STRING);
            exit(1);
        }