home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume36 / friends / part01 / friends.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-18  |  1.5 KB  |  66 lines

  1. /******************************************************************************
  2.     FRIENDS 1.0
  3.  
  4.     friends - which of your friends are on-line?
  5.  
  6.     Written by: Grant Boggs (boggs@a.cs.okstate.edu)
  7.     Date      : 12/3/92
  8.  
  9.     Permission granted to freely copy and distribute.
  10. ******************************************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #include <fcntl.h>
  15. #include <utmp.h>
  16.  
  17. main()
  18. {
  19.     struct utmp *u;                            /* Utmp file pointer */
  20.     char friend[50][9];                        /* Array of .friends names */
  21.     char friend_file[80];                    /* File name */
  22.     int x = 0;
  23.     FILE *f;
  24.  
  25.     sprintf(friend_file, "%s/.friends",
  26.         getenv("HOME"));                    /* Get full file name for .friends*/
  27.  
  28.     f = fopen(friend_file, "r");            /* Open .friends file for reading */
  29.  
  30.     if(f == NULL)
  31.         {
  32.         printf("No .friends file?!  What's the matter, don't you have any");
  33.         printf(" friends?\n");
  34.         exit(-1);
  35.         }
  36.  
  37.     x = 0;
  38.  
  39.     while(!feof(f))                            /* Read in list of friends */
  40.         fscanf(f, "%s", friend[x++]);
  41.  
  42.     x--;                                /* Magic */
  43.  
  44.     u = getutent();                        /* Get first utmp entry */
  45.  
  46.     while(u != NULL)                    /* While not end of utmp file */
  47.         {
  48.         int y;
  49.  
  50.         /* Compare each utmp entry against all in friend array */
  51.  
  52.         for(y = 0; y < x; y++)
  53.             if(u->ut_type == USER_PROCESS && !strcmp(friend[y], u->ut_user))
  54.                 {
  55. #ifdef _SEQUENT_
  56.                 printf("%-8s %s  %s\n", u->ut_user, u->ut_line,
  57.                     ut_find_host(u->ut_line));
  58. #else
  59.                 printf("%-8s %s\n", u->ut_user, u->ut_line);
  60. #endif
  61.                 }
  62.  
  63.         u = getutent();                    /* Get next utmp file */
  64.         }
  65. }
  66.