home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume36 / friends / part01 < prev    next >
Encoding:
Text File  |  1993-04-18  |  5.7 KB  |  199 lines

  1. Newsgroups: comp.sources.misc
  2. From: boggs@a.cs.okstate.edu (BOGGS RICHARD GRAN)
  3. Subject: v36i110:  friends - list on-line friends, Part01/01
  4. Message-ID: <1993Apr19.024110.8880@sparky.imd.sterling.com>
  5. X-Md4-Signature: 7357ebeb2502d17f6e6f3d17ee2d8bba
  6. Date: Mon, 19 Apr 1993 02:41:10 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: boggs@a.cs.okstate.edu (BOGGS RICHARD GRAN)
  10. Posting-number: Volume 36, Issue 110
  11. Archive-name: friends/part01
  12. Environment: SYSV
  13.  
  14. This is a small and friendly program to list which of your friends are on-line.
  15.  
  16. Questions or comments to:
  17.  
  18. Grant Boggs
  19. boggs@a.cs.okstate.edu
  20.  
  21. ------------------------------< CUT HERE! >----------------------------------
  22. #! /bin/sh
  23. # This is a shell archive.  Remove anything before this line, then feed it
  24. # into a shell via "sh file" or similar.  To overwrite existing files,
  25. # type "sh file -c".
  26. # Contents:  README friends.1 friends.c
  27. # Wrapped by kent@sparky on Sun Apr 18 21:31:32 1993
  28. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  29. echo If this archive is complete, you will see the following message:
  30. echo '          "shar: End of archive 1 (of 1)."'
  31. if test -f 'README' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'README'\"
  33. else
  34.   echo shar: Extracting \"'README'\" \(721 characters\)
  35.   sed "s/^X//" >'README' <<'END_OF_FILE'
  36. XFriends lists which of your friends are online.  I wrote it because I got tired
  37. Xof looking through a big ol' finger or who list.
  38. X
  39. X11/9/92
  40. XTo compile, just type "make friends"!  Nothing to it.
  41. X
  42. XQuestions and comments are always welcome!  Give me a yell if you like, hate,
  43. Xor improve "friends".
  44. X
  45. XGrant Boggs
  46. Xboggs@a.cs.okstate.edu
  47. X
  48. X------------------------------HISTORY-----------------------------------------
  49. X
  50. X12/3/92
  51. XAdded Sequent extension, ut_find_host.  No more strings printed when someone
  52. Xis online.  Works like a who -hall but only shows your friends.  Possible up-
  53. Xgrades for future releases may include sorted output and suppression of all but
  54. Xone occurance of each entry.
  55. X
  56. X01/04/93
  57. XFixed an "off-by-one" error.
  58. END_OF_FILE
  59.   if test 721 -ne `wc -c <'README'`; then
  60.     echo shar: \"'README'\" unpacked with wrong size!
  61.   fi
  62.   # end of 'README'
  63. fi
  64. if test -f 'friends.1' -a "${1}" != "-c" ; then 
  65.   echo shar: Will not clobber existing file \"'friends.1'\"
  66. else
  67.   echo shar: Extracting \"'friends.1'\" \(846 characters\)
  68.   sed "s/^X//" >'friends.1' <<'END_OF_FILE'
  69. X.TH FRIENDS 1 "Dec 3, 1992"
  70. X.UC
  71. X.SH NAME
  72. X.B friends
  73. X\- prints which of your friends are logged in
  74. X.SH SYNOPSIS
  75. X.B friends
  76. X.SH DESCRIPTION
  77. X.B friends
  78. Xprints out a listing of which of your friends are on-line.
  79. X
  80. XYou must define a file
  81. X.B \.friends
  82. Xin your HOME directory containing the login name of each of your friends on
  83. Xa single line.
  84. X
  85. X.B friends
  86. Xsearches the utmp file for any occurance of these strings and prints any
  87. Xmatches.
  88. X
  89. XOutput is composed of the user's login name followed by their tty line, and if
  90. Xcompiled on a Sequent machine, the host machine associated with the user's
  91. Xtty line.
  92. X
  93. X.SH PUBLIC DOMAIN NOTICE
  94. XPermission granted to freely copy and distribute in the public domain.
  95. X
  96. X.SH AUTHOR
  97. XQuestions, comments, and/or bug reports are always welcomed by 
  98. X.B friends
  99. Xauthor, Grant Boggs, who can be reached at boggs@a.cs.okstate.edu.
  100. END_OF_FILE
  101.   if test 846 -ne `wc -c <'friends.1'`; then
  102.     echo shar: \"'friends.1'\" unpacked with wrong size!
  103.   fi
  104.   # end of 'friends.1'
  105. fi
  106. if test -f 'friends.c' -a "${1}" != "-c" ; then 
  107.   echo shar: Will not clobber existing file \"'friends.c'\"
  108. else
  109.   echo shar: Extracting \"'friends.c'\" \(1526 characters\)
  110.   sed "s/^X//" >'friends.c' <<'END_OF_FILE'
  111. X/******************************************************************************
  112. X    FRIENDS 1.0
  113. X
  114. X    friends - which of your friends are on-line?
  115. X
  116. X    Written by: Grant Boggs (boggs@a.cs.okstate.edu)
  117. X    Date      : 12/3/92
  118. X
  119. X    Permission granted to freely copy and distribute.
  120. X******************************************************************************/
  121. X
  122. X#include <stdio.h>
  123. X#include <sys/types.h>
  124. X#include <fcntl.h>
  125. X#include <utmp.h>
  126. X
  127. Xmain()
  128. X{
  129. X    struct utmp *u;                            /* Utmp file pointer */
  130. X    char friend[50][9];                        /* Array of .friends names */
  131. X    char friend_file[80];                    /* File name */
  132. X    int x = 0;
  133. X    FILE *f;
  134. X
  135. X    sprintf(friend_file, "%s/.friends",
  136. X        getenv("HOME"));                    /* Get full file name for .friends*/
  137. X
  138. X    f = fopen(friend_file, "r");            /* Open .friends file for reading */
  139. X
  140. X    if(f == NULL)
  141. X        {
  142. X        printf("No .friends file?!  What's the matter, don't you have any");
  143. X        printf(" friends?\n");
  144. X        exit(-1);
  145. X        }
  146. X
  147. X    x = 0;
  148. X
  149. X    while(!feof(f))                            /* Read in list of friends */
  150. X        fscanf(f, "%s", friend[x++]);
  151. X
  152. X    x--;                                /* Magic */
  153. X
  154. X    u = getutent();                        /* Get first utmp entry */
  155. X
  156. X    while(u != NULL)                    /* While not end of utmp file */
  157. X        {
  158. X        int y;
  159. X
  160. X        /* Compare each utmp entry against all in friend array */
  161. X
  162. X        for(y = 0; y < x; y++)
  163. X            if(u->ut_type == USER_PROCESS && !strcmp(friend[y], u->ut_user))
  164. X                {
  165. X#ifdef _SEQUENT_
  166. X                printf("%-8s %s  %s\n", u->ut_user, u->ut_line,
  167. X                    ut_find_host(u->ut_line));
  168. X#else
  169. X                printf("%-8s %s\n", u->ut_user, u->ut_line);
  170. X#endif
  171. X                }
  172. X
  173. X        u = getutent();                    /* Get next utmp file */
  174. X        }
  175. X}
  176. END_OF_FILE
  177.   if test 1526 -ne `wc -c <'friends.c'`; then
  178.     echo shar: \"'friends.c'\" unpacked with wrong size!
  179.   fi
  180.   # end of 'friends.c'
  181. fi
  182. echo shar: End of archive 1 \(of 1\).
  183. cp /dev/null ark1isdone
  184. MISSING=""
  185. for I in 1 ; do
  186.     if test ! -f ark${I}isdone ; then
  187.     MISSING="${MISSING} ${I}"
  188.     fi
  189. done
  190. if test "${MISSING}" = "" ; then
  191.     echo You have the archive.
  192.     rm -f ark[1-9]isdone
  193. else
  194.     echo You still must unpack the following archives:
  195.     echo "        " ${MISSING}
  196. fi
  197. exit 0
  198. exit 0 # Just in case...
  199.