xref: /csrg-svn/usr.bin/uucp/uulog/uulog.c (revision 33961)
113685Ssam #ifndef lint
2*33961Srick static char sccsid[] = "@(#)uulog.c	5.5	(Berkeley) 04/05/88";
313685Ssam #endif
413685Ssam 
513685Ssam #include "uucp.h"
613685Ssam 
713685Ssam main(argc, argv)
813685Ssam char *argv[];
913685Ssam {
10*33961Srick #ifndef LOGBYSITE
1113685Ssam 	FILE *plogf;
12*33961Srick 	char u[64], s[64];
13*33961Srick #endif /* !LOGBYSITE */
1418625Sralph 	char *sys, *user;
15*33961Srick 	int c;
16*33961Srick 	extern char *optarg;
17*33961Srick 	extern int optind;
1813685Ssam 
19*33961Srick 	char buf[BUFSIZ];
2013685Ssam 
2113685Ssam 	strcpy(Progname, "uulog");
2218625Sralph 	sys = user = NULL;
2313685Ssam 
24*33961Srick 	while ((c = getopt(argc, argv, "s:u:")) != EOF)
25*33961Srick 		switch (c) {
2613685Ssam 		case 's':
27*33961Srick 			sys = optarg;
2823687Sbloom 			if (strlen(sys) > MAXBASENAME)
2923687Sbloom 				sys[MAXBASENAME] = '\0';
3018625Sralph 			if (versys(&sys) != SUCCESS){
3118625Sralph 				fprintf(stderr,"uulog: unknown system %s\n", sys);
3218625Sralph 				sys = NULL;
3318625Sralph 			}
3413685Ssam 			break;
3513685Ssam 		case 'u':
36*33961Srick 			user = optarg;
3713685Ssam 			break;
38*33961Srick 		case '?':
3913685Ssam 		default:
40*33961Srick 			fprintf(stderr, "unknown flag %s\n", argv[optind-1]);
41*33961Srick 			break;
4213685Ssam 		}
4313685Ssam 
4418625Sralph 	if (user == NULL && sys == NULL) {
4518625Sralph 		fprintf(stderr, "usage: uulog [-u user] [-s sys]\n");
4613685Ssam 		exit(1);
4713685Ssam 	}
4813685Ssam 
4918625Sralph #ifdef LOGBYSITE
5018625Sralph 	if (chdir(SPOOL) < 0) {
5118625Sralph 		perror(SPOOL);
5218625Sralph 		exit(1);
5318625Sralph 	}
5418625Sralph 	/* this program is really obsolete, this is a rude backward compat */
5518625Sralph 	if (user) {
5618625Sralph 		sprintf(buf, "exec cat LOG/uu*/* | egrep '^%s '", user);
5718625Sralph 		system(buf);
5818625Sralph 	}
5918625Sralph 	if (sys) {
6018625Sralph 		sprintf(buf,"exec cat LOG/uu*/%s", sys);
6118625Sralph 		system(buf);
6218625Sralph 	}
6318625Sralph #else !LOGBYSITE
6413685Ssam 	plogf = fopen(LOGFILE, "r");
65*33961Srick 	if (plogf == NULL) {
66*33961Srick 		syslog(LOG_WARNING, "fopen(%s) failed: %m", LOGFILE);
67*33961Srick 		cleanup(1);
68*33961Srick 	}
6913685Ssam 	while (fgets(buf, BUFSIZ, plogf) != NULL) {
7013685Ssam 		sscanf(buf, "%s%s", u, s);
71*33961Srick 		if (user != NULL && !(prefix(user, u) || prefix(u, user)))
7213685Ssam 			continue;
73*33961Srick 		if (sys != NULL && !(prefix(sys, s) || prefix(s, sys)))
7413685Ssam 			continue;
7513685Ssam 		fputs(buf, stdout);
7613685Ssam 		fflush(stdout);
7713685Ssam 	}
7818625Sralph #endif !LOGBYSITE
7913685Ssam 	exit(0);
8013685Ssam }
8113685Ssam 
8213685Ssam cleanup(code)
8313685Ssam int code;
8413685Ssam {
8513685Ssam 	exit(code);
8613685Ssam }
87