Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

A simpler watch log



A friend of mine (joe@xxxxxxxxxxxxx) has suggested that the log
command should accept a parameter to tell it to print the log in a
simple format, like the 'users' command.

I have implemented a '-u' option to the log builtin which makes it
print only the username on each line. It adds an argument to the
dowatch(), which, if set, means "simple" watch, which in turns sets
the fmt to "%n".

This is not completely compatible with 'users' output, since each
username is on a separate line. A little more tweaking by someone who
knows more about watch.c could result in dowatch() not calling
watchlog() at all, if simple is set.

Here is the patch:
*** watch.c.orig	Tue Jun 11 17:46:28 1996
--- watch.c	Tue Jun 11 17:18:37 1996
***************
*** 374,380 ****
  
  /**/
  void
! dowatch(void)
  {
      FILE *in;
      STRUCT_UTMP *utab, *uptr, *wptr;
--- 374,380 ----
  
  /**/
  void
! dowatch(int simple_format)
  {
      FILE *in;
      STRUCT_UTMP *utab, *uptr, *wptr;
***************
*** 385,391 ****
      int uct, wct;
  
      s = watch;
!     if (!(fmt = getsparam("WATCHFMT")))
  	fmt = DEFAULT_WATCHFMT;
  
      holdintr();
--- 385,393 ----
      int uct, wct;
  
      s = watch;
!     if (simple_format)
!     	fmt = SIMPLE_WATCHFMT;
!     else if (!(fmt = getsparam("WATCHFMT")))
  	fmt = DEFAULT_WATCHFMT;
  
      holdintr();
***************
*** 460,466 ****
      wtab = (STRUCT_UTMP *)zalloc(1);
      wtabsz = 0;
      lastutmpcheck = 0;
!     dowatch();
      return 0;
  }
  
--- 462,471 ----
      wtab = (STRUCT_UTMP *)zalloc(1);
      wtabsz = 0;
      lastutmpcheck = 0;
!     if (ops['u'])
!     	dowatch(1);
!     else
!     	dowatch(0);
      return 0;
  }
  
*** hashtable.h.orig	Tue Jun 11 17:46:49 1996
--- hashtable.h	Tue Jun 11 17:35:32 1996
***************
*** 282,288 ****
      {NULL, "let", 0, bin_let, 1, -1, 0, NULL, NULL},
      {NULL, "limit", 0, bin_limit, 0, -1, 0, "sh", NULL},
      {NULL, "local", BINF_TYPEOPTS | BINF_MAGICEQUALS, bin_typeset, 0, -1, 0, "LRUZilrtu", NULL},
!     {NULL, "log", 0, bin_log, 0, 0, 0, NULL, NULL},
      {NULL, "logout", 0, bin_break, 0, 1, BIN_LOGOUT, NULL, NULL},
  
  #if defined(ZSH_MEM) & defined(ZSH_MEM_DEBUG)
--- 282,288 ----
      {NULL, "let", 0, bin_let, 1, -1, 0, NULL, NULL},
      {NULL, "limit", 0, bin_limit, 0, -1, 0, "sh", NULL},
      {NULL, "local", BINF_TYPEOPTS | BINF_MAGICEQUALS, bin_typeset, 0, -1, 0, "LRUZilrtu", NULL},
!     {NULL, "log", 0, bin_log, 0, 0, 0, "u", NULL},
      {NULL, "logout", 0, bin_break, 0, 1, BIN_LOGOUT, NULL, NULL},
  
  #if defined(ZSH_MEM) & defined(ZSH_MEM_DEBUG)
*** system.h.orig	Tue Jun 11 17:47:02 1996
--- system.h	Tue Jun 11 17:14:13 1996
***************
*** 305,310 ****
--- 305,312 ----
  # define DEFAULT_WATCHFMT "%n has %a %l."
  #endif
  
+ #define SIMPLE_WATCHFMT "%n"
+ 
  #define DEFAULT_WORDCHARS "*?_-.[]~=/&;!#$%^(){}<>"
  #define DEFAULT_TIMEFMT   "%J  %U user %S system %P cpu %*E total"
  


-- 
hniksic@xxxxxxx              |  Student of electrical engineering
hniksic@xxxxxxxxxxxxx        |  University of Zagreb, Croatia
------------------------------------------------------------------
I'm a Lisp variable -- bind me!




Messages sorted by: Reverse Date, Date, Thread, Author