home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: boggs@a.cs.okstate.edu (BOGGS RICHARD GRAN)
- Subject: v36i110: friends - list on-line friends, Part01/01
- Message-ID: <1993Apr19.024110.8880@sparky.imd.sterling.com>
- X-Md4-Signature: 7357ebeb2502d17f6e6f3d17ee2d8bba
- Date: Mon, 19 Apr 1993 02:41:10 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: boggs@a.cs.okstate.edu (BOGGS RICHARD GRAN)
- Posting-number: Volume 36, Issue 110
- Archive-name: friends/part01
- Environment: SYSV
-
- This is a small and friendly program to list which of your friends are on-line.
-
- Questions or comments to:
-
- Grant Boggs
- boggs@a.cs.okstate.edu
-
- ------------------------------< CUT HERE! >----------------------------------
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # Contents: README friends.1 friends.c
- # Wrapped by kent@sparky on Sun Apr 18 21:31:32 1993
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 1 (of 1)."'
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(721 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- XFriends lists which of your friends are online. I wrote it because I got tired
- Xof looking through a big ol' finger or who list.
- X
- X11/9/92
- XTo compile, just type "make friends"! Nothing to it.
- X
- XQuestions and comments are always welcome! Give me a yell if you like, hate,
- Xor improve "friends".
- X
- XGrant Boggs
- Xboggs@a.cs.okstate.edu
- X
- X------------------------------HISTORY-----------------------------------------
- X
- X12/3/92
- XAdded Sequent extension, ut_find_host. No more strings printed when someone
- Xis online. Works like a who -hall but only shows your friends. Possible up-
- Xgrades for future releases may include sorted output and suppression of all but
- Xone occurance of each entry.
- X
- X01/04/93
- XFixed an "off-by-one" error.
- END_OF_FILE
- if test 721 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'friends.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'friends.1'\"
- else
- echo shar: Extracting \"'friends.1'\" \(846 characters\)
- sed "s/^X//" >'friends.1' <<'END_OF_FILE'
- X.TH FRIENDS 1 "Dec 3, 1992"
- X.UC
- X.SH NAME
- X.B friends
- X\- prints which of your friends are logged in
- X.SH SYNOPSIS
- X.B friends
- X.SH DESCRIPTION
- X.B friends
- Xprints out a listing of which of your friends are on-line.
- X
- XYou must define a file
- X.B \.friends
- Xin your HOME directory containing the login name of each of your friends on
- Xa single line.
- X
- X.B friends
- Xsearches the utmp file for any occurance of these strings and prints any
- Xmatches.
- X
- XOutput is composed of the user's login name followed by their tty line, and if
- Xcompiled on a Sequent machine, the host machine associated with the user's
- Xtty line.
- X
- X.SH PUBLIC DOMAIN NOTICE
- XPermission granted to freely copy and distribute in the public domain.
- X
- X.SH AUTHOR
- XQuestions, comments, and/or bug reports are always welcomed by
- X.B friends
- Xauthor, Grant Boggs, who can be reached at boggs@a.cs.okstate.edu.
- END_OF_FILE
- if test 846 -ne `wc -c <'friends.1'`; then
- echo shar: \"'friends.1'\" unpacked with wrong size!
- fi
- # end of 'friends.1'
- fi
- if test -f 'friends.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'friends.c'\"
- else
- echo shar: Extracting \"'friends.c'\" \(1526 characters\)
- sed "s/^X//" >'friends.c' <<'END_OF_FILE'
- X/******************************************************************************
- X FRIENDS 1.0
- X
- X friends - which of your friends are on-line?
- X
- X Written by: Grant Boggs (boggs@a.cs.okstate.edu)
- X Date : 12/3/92
- X
- X Permission granted to freely copy and distribute.
- X******************************************************************************/
- X
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <fcntl.h>
- X#include <utmp.h>
- X
- Xmain()
- X{
- X struct utmp *u; /* Utmp file pointer */
- X char friend[50][9]; /* Array of .friends names */
- X char friend_file[80]; /* File name */
- X int x = 0;
- X FILE *f;
- X
- X sprintf(friend_file, "%s/.friends",
- X getenv("HOME")); /* Get full file name for .friends*/
- X
- X f = fopen(friend_file, "r"); /* Open .friends file for reading */
- X
- X if(f == NULL)
- X {
- X printf("No .friends file?! What's the matter, don't you have any");
- X printf(" friends?\n");
- X exit(-1);
- X }
- X
- X x = 0;
- X
- X while(!feof(f)) /* Read in list of friends */
- X fscanf(f, "%s", friend[x++]);
- X
- X x--; /* Magic */
- X
- X u = getutent(); /* Get first utmp entry */
- X
- X while(u != NULL) /* While not end of utmp file */
- X {
- X int y;
- X
- X /* Compare each utmp entry against all in friend array */
- X
- X for(y = 0; y < x; y++)
- X if(u->ut_type == USER_PROCESS && !strcmp(friend[y], u->ut_user))
- X {
- X#ifdef _SEQUENT_
- X printf("%-8s %s %s\n", u->ut_user, u->ut_line,
- X ut_find_host(u->ut_line));
- X#else
- X printf("%-8s %s\n", u->ut_user, u->ut_line);
- X#endif
- X }
- X
- X u = getutent(); /* Get next utmp file */
- X }
- X}
- END_OF_FILE
- if test 1526 -ne `wc -c <'friends.c'`; then
- echo shar: \"'friends.c'\" unpacked with wrong size!
- fi
- # end of 'friends.c'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-