home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume09 / rwhopars.p1 < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  12.9 KB

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