Friday, December 17, 2004
Further proof that I invented the Buddy List
(yes, this is the long-lost code referred to in this post)
/*****************************************************
* watch.c --- continously finger internet addresses *
* until one of them logs on. *
* must be able to find finger and grep. *
* this program is best run in the back- *
* ground, as it will not exit until one *
* of the specified user is logged in. *
* *
* by Jeff Robertson, 8/28/94 *
* *
******************************************************/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define AT '@'
#define DEFAULT_FILE ".watchrc"
void parse_address( char *, char *, char *);
int grep_for_address( char *);
main( int argc, char *argv[])
{
char address[32];
FILE *fp;
int i, grep_status = 1;
while ( grep_status)
{
/* finger the addresses from the command line */
for(i=1; i<argc; i++)
grep_status = grep_for_address( argv[i]) && grep_status;
/* read from .watchrc is it exists */
fp = fopen( DEFAULT_FILE, "r");
if (fp != NULL)
{
while ( fgets( address, sizeof(address), fp) != NULL)
{
address[ strlen(address) - 1 ] = '\0';
grep_status = grep_for_address( address) && grep_status;
}
fclose( fp);
}
}
return 0;
}
/* do the actual work */
int grep_for_address( char *address)
{
char user[16], host[32], command_line[64];
parse_address( address, user, host);
sprintf(command_line, "finger %s | grep %s", host, user);
return (system( command_line));
}
/* get separate user and host names from an internet address */
void parse_address( char *a, char *u, char *h)
{
while( *a && ( *a != AT))
*u++ = *a++;
*u = '\0';
while( *h++ = *a++ );
if (!strcmp(h,""))
strcpy(h,"@");
}
/*****************************************************
* watch.c --- continously finger internet addresses *
* until one of them logs on. *
* must be able to find finger and grep. *
* this program is best run in the back- *
* ground, as it will not exit until one *
* of the specified user is logged in. *
* *
* by Jeff Robertson, 8/28/94 *
* *
******************************************************/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define AT '@'
#define DEFAULT_FILE ".watchrc"
void parse_address( char *, char *, char *);
int grep_for_address( char *);
main( int argc, char *argv[])
{
char address[32];
FILE *fp;
int i, grep_status = 1;
while ( grep_status)
{
/* finger the addresses from the command line */
for(i=1; i<argc; i++)
grep_status = grep_for_address( argv[i]) && grep_status;
/* read from .watchrc is it exists */
fp = fopen( DEFAULT_FILE, "r");
if (fp != NULL)
{
while ( fgets( address, sizeof(address), fp) != NULL)
{
address[ strlen(address) - 1 ] = '\0';
grep_status = grep_for_address( address) && grep_status;
}
fclose( fp);
}
}
return 0;
}
/* do the actual work */
int grep_for_address( char *address)
{
char user[16], host[32], command_line[64];
parse_address( address, user, host);
sprintf(command_line, "finger %s | grep %s", host, user);
return (system( command_line));
}
/* get separate user and host names from an internet address */
void parse_address( char *a, char *u, char *h)
{
while( *a && ( *a != AT))
*u++ = *a++;
*u = '\0';
while( *h++ = *a++ );
if (!strcmp(h,""))
strcpy(h,"@");
}