xref: /csrg-svn/usr.bin/uucp/uulog/uulog.c (revision 62397)
148667Sbostic /*-
2*62397Sbostic  * Copyright (c) 1985, 1988, 1993
3*62397Sbostic  *	The Regents of the University of California.  All rights reserved.
448667Sbostic  *
548667Sbostic  * %sccs.include.proprietary.c%
648667Sbostic  */
748667Sbostic 
813685Ssam #ifndef lint
9*62397Sbostic static char copyright[] =
10*62397Sbostic "@(#) Copyright (c) 1985, 1988, 1993\n\
11*62397Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1248667Sbostic #endif /* not lint */
1313685Ssam 
1448667Sbostic #ifndef lint
15*62397Sbostic static char sccsid[] = "@(#)uulog.c	8.1 (Berkeley) 06/06/93";
1648667Sbostic #endif /* not lint */
1748667Sbostic 
1813685Ssam #include "uucp.h"
1913685Ssam 
2034173Srick struct timeb Now;
2134173Srick 
main(argc,argv)2213685Ssam main(argc, argv)
2313685Ssam char *argv[];
2413685Ssam {
2533961Srick #ifndef LOGBYSITE
2613685Ssam 	FILE *plogf;
2733961Srick 	char u[64], s[64];
2833961Srick #endif /* !LOGBYSITE */
2918625Sralph 	char *sys, *user;
3033961Srick 	int c;
3133961Srick 	extern char *optarg;
3233961Srick 	extern int optind;
3313685Ssam 
3433961Srick 	char buf[BUFSIZ];
3513685Ssam 
3613685Ssam 	strcpy(Progname, "uulog");
3718625Sralph 	sys = user = NULL;
3813685Ssam 
3933961Srick 	while ((c = getopt(argc, argv, "s:u:")) != EOF)
4033961Srick 		switch (c) {
4113685Ssam 		case 's':
4233961Srick 			sys = optarg;
4323687Sbloom 			if (strlen(sys) > MAXBASENAME)
4423687Sbloom 				sys[MAXBASENAME] = '\0';
4518625Sralph 			if (versys(&sys) != SUCCESS){
4618625Sralph 				fprintf(stderr,"uulog: unknown system %s\n", sys);
4718625Sralph 				sys = NULL;
4818625Sralph 			}
4913685Ssam 			break;
5013685Ssam 		case 'u':
5133961Srick 			user = optarg;
5213685Ssam 			break;
5333961Srick 		case '?':
5413685Ssam 		default:
5533961Srick 			fprintf(stderr, "unknown flag %s\n", argv[optind-1]);
5633961Srick 			break;
5713685Ssam 		}
5813685Ssam 
5918625Sralph 	if (user == NULL && sys == NULL) {
6018625Sralph 		fprintf(stderr, "usage: uulog [-u user] [-s sys]\n");
6113685Ssam 		exit(1);
6213685Ssam 	}
6313685Ssam 
6418625Sralph #ifdef LOGBYSITE
6518625Sralph 	if (chdir(SPOOL) < 0) {
6618625Sralph 		perror(SPOOL);
6718625Sralph 		exit(1);
6818625Sralph 	}
6918625Sralph 	/* this program is really obsolete, this is a rude backward compat */
7018625Sralph 	if (user) {
7118625Sralph 		sprintf(buf, "exec cat LOG/uu*/* | egrep '^%s '", user);
7218625Sralph 		system(buf);
7318625Sralph 	}
7418625Sralph 	if (sys) {
7518625Sralph 		sprintf(buf,"exec cat LOG/uu*/%s", sys);
7618625Sralph 		system(buf);
7718625Sralph 	}
7818625Sralph #else !LOGBYSITE
7913685Ssam 	plogf = fopen(LOGFILE, "r");
8033961Srick 	if (plogf == NULL) {
8133961Srick 		syslog(LOG_WARNING, "fopen(%s) failed: %m", LOGFILE);
8233961Srick 		cleanup(1);
8333961Srick 	}
8413685Ssam 	while (fgets(buf, BUFSIZ, plogf) != NULL) {
8513685Ssam 		sscanf(buf, "%s%s", u, s);
8633961Srick 		if (user != NULL && !(prefix(user, u) || prefix(u, user)))
8713685Ssam 			continue;
8833961Srick 		if (sys != NULL && !(prefix(sys, s) || prefix(s, sys)))
8913685Ssam 			continue;
9013685Ssam 		fputs(buf, stdout);
9113685Ssam 		fflush(stdout);
9213685Ssam 	}
9318625Sralph #endif !LOGBYSITE
9413685Ssam 	exit(0);
9513685Ssam }
9613685Ssam 
cleanup(code)9713685Ssam cleanup(code)
9813685Ssam int code;
9913685Ssam {
10013685Ssam 	exit(code);
10113685Ssam }
102