home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume9 / rwhoparse.p1 < prev    next >
Text File  |  1989-12-18  |  13KB  |  470 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Colorado State University, Fort Collins, CO  80523
  3. subject: v09i069: rwhop patch one
  4. from: robert@elbert.LANCE.ColoState.Edu (Robert Thompson)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 9, Issue 69
  8. Submitted-by: robert@elbert.LANCE.ColoState.Edu (Robert Thompson)
  9. Archive-name: rwhoparse.p1
  10.  
  11. I ahve received several inquiries into the rwho parses posted recently.
  12. This patch incorporates the changes and improvements suggested.   -Robert
  13.  
  14. +------------------------------------------+---------------------+
  15. |                                          | Ask me a riddle and |
  16. |              |                   |       | I'll reply:         |
  17. |              |                   |       |                     |
  18. |  /---\ /---\ |---\ /---\  /---\  |---    | "Cottleston,        |
  19. |  |     |   | |   | |---/  |      |       |  Cottleston,        |
  20. |  |     \---/ \---/ \----  |      \---/   |  Cottleston Pie."   |
  21. |------------------------------------------|                     |
  22. | ARPA: robert@longs.LANCE.ColoState.Edu   |  Winnie-the-Pooh    |
  23. |------------------------------------------|---------------------|
  24. | Center for Computer Assisted Engineering | Got something on    |
  25. | Department of Electrical Engineering     | your mind ?         |
  26. | Colorado State University                | >> send me mail  << |
  27. +------------------------------------------+---------------------+
  28.  
  29.  
  30. ------- CUT HERE -------
  31.  
  32. *** Makefile.old    Sun Dec 17 13:07:42 1989
  33. --- Makefile    Sun Dec 17 13:07:08 1989
  34. ***************
  35. *** 5,14
  36.   # No copyrights inplied or requested.  This code is supplied as is
  37.   # have fun using it and report any bugs to:
  38.   #
  39.   #      robert@longs.LANCE.ColoState.edu
  40.   #
  41.   #################################################################
  42.   OBJS=    rwhoparse.o
  43.   SRCS=    rwhoparse.c
  44.   
  45.   TARGET= rwhop
  46.  
  47. --- 5,16 -----
  48.   # No copyrights inplied or requested.  This code is supplied as is
  49.   # have fun using it and report any bugs to:
  50.   #
  51.   #      robert@longs.LANCE.ColoState.edu
  52.   #
  53. + # See rwhoparse.c for modification history
  54. + #
  55.   #################################################################
  56.   OBJS=    rwhoparse.o
  57.   SRCS=    rwhoparse.c
  58.   
  59.   TARGET= rwhop
  60. *** README.OLD    Sun Dec 17 13:06:13 1989
  61. --- README    Sun Dec 17 13:05:49 1989
  62. ***************
  63. *** 1,11
  64.   rwhop is a program I wrote one bored Sunday night for something to do.  I
  65.   was prompted to post this code for others to use.  The main reason for the
  66.   program is to return the users real name instead of just the login name.
  67.   If there are any problems, send me mail and I will try to rectify the bug.
  68.   
  69. ! This coed is supplied without copyright, do with it what you please.  (Tell
  70.   me of any improvements you have.)  I was thinking of making the program
  71.   search for a host rather than just a user (maybe someday).  
  72.   
  73.   Robert
  74.   CSU - Center forComputer Assisted Engineering
  75.  
  76. --- 1,11 -----
  77.   rwhop is a program I wrote one bored Sunday night for something to do.  I
  78.   was prompted to post this code for others to use.  The main reason for the
  79.   program is to return the users real name instead of just the login name.
  80.   If there are any problems, send me mail and I will try to rectify the bug.
  81.   
  82. ! This code is supplied without copyright, do with it what you please.  (Tell
  83.   me of any improvements you have.)  I was thinking of making the program
  84.   search for a host rather than just a user (maybe someday).  
  85.   
  86.   I have received some suggestions for improvement.  They have been imployed
  87.   for the most part.  See the source code for information.
  88. ***************
  89. *** 4,13
  90.   If there are any problems, send me mail and I will try to rectify the bug.
  91.   
  92.   This coed is supplied without copyright, do with it what you please.  (Tell
  93.   me of any improvements you have.)  I was thinking of making the program
  94.   search for a host rather than just a user (maybe someday).  
  95.   
  96.   Robert
  97.   CSU - Center forComputer Assisted Engineering
  98.   
  99.   robert@longs.LANCE.ColoState.Edu
  100.  
  101. --- 4,16 -----
  102.   If there are any problems, send me mail and I will try to rectify the bug.
  103.   
  104.   This code is supplied without copyright, do with it what you please.  (Tell
  105.   me of any improvements you have.)  I was thinking of making the program
  106.   search for a host rather than just a user (maybe someday).  
  107. + I have received some suggestions for improvement.  They have been imployed
  108. + for the most part.  See the source code for information.
  109.   
  110.   Robert
  111.   CSU - Center forComputer Assisted Engineering
  112.   
  113.   robert@longs.LANCE.ColoState.Edu
  114. *** rwhoparse.c.old    Sun Dec 17 12:52:40 1989
  115. --- rwhoparse.c    Sun Dec 17 12:16:25 1989
  116. ***************
  117. *** 1,5
  118.   #include <stdio.h>
  119.   #include <pwd.h>
  120.   
  121.   main(argc,argv)
  122.   int    argc;
  123.  
  124. --- 1,29 -----
  125. + /*
  126. +  * This software is provided without claims.  Bugs/suggestions can be sent
  127. +  * to robert@longs.LANCE.ColoState.Edu.  Below is a new version employing
  128. +  * changes as reported.
  129. +  *
  130. +  * mod date    description            who
  131. +  * --------     -----------                     ----------------------------
  132. +  * Dec 18, 89    Took care of missing argument    emb978@leah.Albany.Edu
  133. +  *              problem.            (I dont know the name, sorry)
  134. +  *
  135. +  * Dec 18, 89   Put the null at the right     same as above
  136. +  *        place in the rean_name string.
  137. +  *
  138. +  * Dec 18, 89    Added some comments        Rober
  139. +  *
  140. +  * Dec 18, 89    If the user is unknown      Robert
  141. +  *        a message is printed.        
  142. +  *
  143. +  * Note:  It was suggested by Heiji Horde (horde@reed.BITNET) to account
  144. +  *        for tty names that are longer than 6 characters.  Since this 
  145. +  *      dependent on the site.  I leave this up to you.  -robert
  146. +  *        (I hope that Heiji Horde is your correct name, sorry if it is not)
  147. +  */
  148.   #include <stdio.h>
  149.   #include <pwd.h>
  150.   
  151.   main(argc,argv)
  152.   int    argc;
  153. ***************
  154. *** 3,13
  155.   
  156.   main(argc,argv)
  157.   int    argc;
  158.   char    *argv[];
  159.   {
  160. !     FILE    *pipe;
  161.   
  162.       char    real_name[30], inline[80];
  163.       char    *user, *host, *time, *gecos, *tty, *strtok();
  164.   
  165.       register int i;
  166.  
  167. --- 27,37 -----
  168.   
  169.   main(argc,argv)
  170.   int    argc;
  171.   char    *argv[];
  172.   {
  173. !     FILE    *pipe;        /* The pipe opened to rwho        */
  174.   
  175.       char    real_name[20],    /* the users real name goes here    */
  176.           inline[80],    /* the input from rwho            */
  177.           *user,        /* the following 5 vars are the fields    */
  178.           *host,        /* obtained from the output of rwho.    */
  179. ***************
  180. *** 5,16
  181.   int    argc;
  182.   char    *argv[];
  183.   {
  184.       FILE    *pipe;
  185.   
  186. !     char    real_name[30], inline[80];
  187. !     char    *user, *host, *time, *gecos, *tty, *strtok();
  188.   
  189.       register int i;
  190.   
  191.       struct    passwd    *pw;
  192.   
  193.  
  194. --- 29,46 -----
  195.   int    argc;
  196.   char    *argv[];
  197.   {
  198.       FILE    *pipe;        /* The pipe opened to rwho        */
  199.   
  200. !     char    real_name[20],    /* the users real name goes here    */
  201. !         inline[80],    /* the input from rwho            */
  202. !         *user,        /* the following 5 vars are the fields    */
  203. !         *host,        /* obtained from the output of rwho.    */
  204. !         *time,
  205. !         *gecos,
  206. !         *tty,
  207. !         *strtok();
  208.   
  209.       register int i;
  210.   
  211.       struct    passwd    *pw;    /* to get the gecos info.        */
  212.   
  213. ***************
  214. *** 10,20
  215.       char    real_name[30], inline[80];
  216.       char    *user, *host, *time, *gecos, *tty, *strtok();
  217.   
  218.       register int i;
  219.   
  220. !     struct    passwd    *pw;
  221.   
  222.       argv++;
  223.       strcpy(inline,"/usr/ucb/rwho ");
  224.       strcat(inline,*argv);
  225.   
  226.  
  227. --- 40,50 -----
  228.           *tty,
  229.           *strtok();
  230.   
  231.       register int i;
  232.   
  233. !     struct    passwd    *pw;    /* to get the gecos info.        */
  234.   
  235.       argv++;
  236.       strcpy(inline,"/usr/ucb/rwho ");
  237.       if (*argv) strcat(inline,*argv);
  238.   
  239. ***************
  240. *** 14,24
  241.   
  242.       struct    passwd    *pw;
  243.   
  244.       argv++;
  245.       strcpy(inline,"/usr/ucb/rwho ");
  246. !     strcat(inline,*argv);
  247.   
  248.       if ((pipe = popen(inline,"r")) == NULL)
  249.           {
  250.           fprintf (stderr,"Broken pipe\n");
  251.           exit(-1);
  252.  
  253. --- 44,54 -----
  254.   
  255.       struct    passwd    *pw;    /* to get the gecos info.        */
  256.   
  257.       argv++;
  258.       strcpy(inline,"/usr/ucb/rwho ");
  259. !     if (*argv) strcat(inline,*argv);
  260.   
  261.       /* open a pipe to rwho and read the output.  Parse as we go    */
  262.       if ((pipe = popen(inline,"r")) == NULL)
  263.           {
  264.           fprintf (stderr,"Broken pipe\n");
  265. ***************
  266. *** 16,25
  267.   
  268.       argv++;
  269.       strcpy(inline,"/usr/ucb/rwho ");
  270.       strcat(inline,*argv);
  271.   
  272.       if ((pipe = popen(inline,"r")) == NULL)
  273.           {
  274.           fprintf (stderr,"Broken pipe\n");
  275.           exit(-1);
  276.           }
  277.  
  278. --- 46,56 -----
  279.   
  280.       argv++;
  281.       strcpy(inline,"/usr/ucb/rwho ");
  282.       if (*argv) strcat(inline,*argv);
  283.   
  284. +     /* open a pipe to rwho and read the output.  Parse as we go    */
  285.       if ((pipe = popen(inline,"r")) == NULL)
  286.           {
  287.           fprintf (stderr,"Broken pipe\n");
  288.           exit(-1);
  289.           }
  290. ***************
  291. *** 28,41
  292.       for (i=0;i<80;i++) printf ("-");
  293.       printf ("\n");
  294.   
  295.       while (fgets(inline,80,pipe) != NULL)
  296.           {
  297. !         user = strtok(inline," ");
  298. !         host = strtok(NULL,":");
  299. !         tty = strtok(NULL," ");
  300. !         time = strtok(NULL,"\n");
  301.   
  302.           if ((pw = getpwnam(user)) != NULL)
  303.               {
  304.               gecos = strtok(pw->pw_gecos,",");
  305.               
  306.  
  307. --- 59,72 -----
  308.       for (i=0;i<80;i++) printf ("-");
  309.       printf ("\n");
  310.   
  311.       while (fgets(inline,80,pipe) != NULL)
  312.           {
  313. !         user     = strtok(inline," ");
  314. !         host     = strtok(NULL,":");
  315. !         tty     = strtok(NULL," ");
  316. !         time     = strtok(NULL,"\n");
  317.   
  318.           if ((pw = getpwnam(user)) != NULL)
  319.               {
  320.               gecos = strtok(pw->pw_gecos,",");
  321.               
  322. ***************
  323. *** 38,56
  324.           if ((pw = getpwnam(user)) != NULL)
  325.               {
  326.               gecos = strtok(pw->pw_gecos,",");
  327.               
  328.               strncpy(real_name,gecos,20);
  329. !             real_name[20] = NULL;
  330. !             
  331. !             while(time[0] == ' ') time++;
  332. !             while(host[0] == ' ') host++;
  333. !             
  334. !             printf ("%8s  %20s  %10s  %6s  %s\n",
  335. !                 user,
  336. !                 real_name,
  337. !                 strtok(host,"."),
  338. !                 tty,
  339. !                 time);
  340.               }
  341.           }
  342.   }
  343.  
  344. --- 69,79 -----
  345.           if ((pw = getpwnam(user)) != NULL)
  346.               {
  347.               gecos = strtok(pw->pw_gecos,",");
  348.               
  349.               strncpy(real_name,gecos,20);
  350. !             real_name[19] = NULL;
  351.               }
  352.           else
  353.               {
  354.               strcpy(real_name,"gecos unavailable");
  355.               }
  356. ***************
  357. *** 50,56
  358.                   real_name,
  359.                   strtok(host,"."),
  360.                   tty,
  361.                   time);
  362.               }
  363.           }
  364.   }
  365.  
  366. --- 71,92 -----
  367.               gecos = strtok(pw->pw_gecos,",");
  368.               
  369.               strncpy(real_name,gecos,20);
  370.               real_name[19] = NULL;
  371.               }
  372. +         else
  373. +             {
  374. +             strcpy(real_name,"gecos unavailable");
  375. +             }
  376. +         /* strip leading spaces    */
  377. +         while(time[0] == ' ') time++;
  378. +         while(host[0] == ' ') host++;
  379. +         
  380. +         printf ("%8s  %20s  %10s  %6s  %s\n",
  381. +             user,
  382. +             real_name,
  383. +             strtok(host,"."),
  384. +             tty,
  385. +             time);
  386.           }
  387.   }
  388. *** rwhop.n.old    Sun Dec 17 12:59:44 1989
  389. --- rwhop.n    Sun Dec 17 13:26:53 1989
  390. ***************
  391. *** 13,23
  392.   command takes the output from rwho(1) via a pipe stream connection.
  393.   The returned information is the same as that of rwho with the following
  394.   exceptions: 1) fully qualified host names are truncated to the first level.
  395.   2) The users' gecos information is retreived via the getpwnam(3) call.
  396.   The first field of the gecos information is printed un the heading of 'Real
  397. ! Name'
  398.   .SH OPTIONS
  399.   .IP \fB\-a\fR 20
  400.   Lists all users.  Normally,
  401.   .PN rwhop
  402.   omits users who have not typed to the system for an hour or
  403.  
  404. --- 13,26 -----
  405.   command takes the output from rwho(1) via a pipe stream connection.
  406.   The returned information is the same as that of rwho with the following
  407.   exceptions: 1) fully qualified host names are truncated to the first level.
  408.   2) The users' gecos information is retreived via the getpwnam(3) call.
  409.   The first field of the gecos information is printed un the heading of 'Real
  410. ! Name'  If a user's gecos information cannot be retreived, the message
  411. ! 'gecos unavailable' is printed.
  412.   .SH OPTIONS
  413.   .IP \fB\-a\fR 20
  414.   Lists all users.  Normally,
  415.   .PN rwhop
  416.   omits users who have not typed to the system for an hour or
  417. ***************
  418. *** 28,37
  419.   Sorts users by host name.  Normally,
  420.   .PN rwhop
  421.   prints its output sorted by user name.  If the
  422.   .B \-h
  423.   flag is specified, the results are sorted by host name.
  424.   .SH FILES
  425.   /usr/spool/rwho/whod.*    Information about other machines
  426.   .SH SEE ALSO
  427.   ruptime(1c), rwhod(8c)
  428.   .SH AUTHOR
  429.  
  430. --- 31,43 -----
  431.   Sorts users by host name.  Normally,
  432.   .PN rwhop
  433.   prints its output sorted by user name.  If the
  434.   .B \-h
  435.   flag is specified, the results are sorted by host name.
  436. + .SH BUGS
  437. + If the tty name is longer than six characters, the time and idle columns
  438. + become misaligned.
  439.   .SH FILES
  440.   /usr/spool/rwho/whod.*    Information about other machines
  441.   .SH SEE ALSO
  442.   ruptime(1c), rwhod(8c), rwho(1), passwd(5)
  443.   .SH AUTHOR
  444. ***************
  445. *** 31,38
  446.   .B \-h
  447.   flag is specified, the results are sorted by host name.
  448.   .SH FILES
  449.   /usr/spool/rwho/whod.*    Information about other machines
  450.   .SH SEE ALSO
  451. ! ruptime(1c), rwhod(8c)
  452.   .SH AUTHOR
  453.   Robert D. Thompson - Colorado State University  December 10, 1989
  454.  
  455. --- 37,44 -----
  456.   If the tty name is longer than six characters, the time and idle columns
  457.   become misaligned.
  458.   .SH FILES
  459.   /usr/spool/rwho/whod.*    Information about other machines
  460.   .SH SEE ALSO
  461. ! ruptime(1c), rwhod(8c), rwho(1), passwd(5)
  462.   .SH AUTHOR
  463.   Robert D. Thompson - Colorado State University  December 10, 1989
  464.  
  465.