xref: /csrg-svn/usr.bin/uucp/uulog/uulog.c (revision 18625)
113685Ssam #ifndef lint
2*18625Sralph static char sccsid[] = "@(#)uulog.c	5.3 (Berkeley) 04/10/85";
313685Ssam #endif
413685Ssam 
513685Ssam #include "uucp.h"
613685Ssam 
713685Ssam #ifndef	SYSBUF
813685Ssam static char SYSBUF[BUFSIZ];
913685Ssam #endif
1013685Ssam 
1113685Ssam main(argc, argv)
1213685Ssam char *argv[];
1313685Ssam {
1413685Ssam 	FILE *plogf;
15*18625Sralph 	char *sys, *user;
1613685Ssam 
17*18625Sralph 	char buf[BUFSIZ], u[64], s[64];
1813685Ssam 
1913685Ssam 	setbuf(stdout, SYSBUF);
2013685Ssam 	strcpy(Progname, "uulog");
21*18625Sralph 	sys = user = NULL;
2213685Ssam 
2313685Ssam 
2413685Ssam 	while (argc>1 && argv[1][0] == '-') {
2513685Ssam 		switch (argv[1][1]) {
2613685Ssam 		case 's':
27*18625Sralph 			sys = &argv[1][2];
28*18625Sralph 			if (*sys == NULL && argc > 2 && argv[2][0] != '-') {
29*18625Sralph 				sys = &argv[2][0];
3013685Ssam 				argv++;
3113685Ssam 				argc--;
3213685Ssam 			}
33*18625Sralph 			if (strlen(sys) > 7)
34*18625Sralph 				sys[7] = '\0';
35*18625Sralph 			if (versys(&sys) != SUCCESS){
36*18625Sralph 				fprintf(stderr,"uulog: unknown system %s\n", sys);
37*18625Sralph 				sys = NULL;
38*18625Sralph 			}
3913685Ssam 			break;
4013685Ssam 		case 'u':
4113685Ssam 			user = &argv[1][2];
4213685Ssam 			if (*user == NULL && argc > 2 && argv[2][0] != '-') {
4313685Ssam 				user = &argv[2][0];
4413685Ssam 				argv++;
4513685Ssam 				argc--;
4613685Ssam 			}
4713685Ssam 			break;
4813685Ssam 		default:
4913685Ssam 			printf("unknown flag %s\n", argv[1]); break;
5013685Ssam 		}
5113685Ssam 		--argc;  argv++;
5213685Ssam 	}
5313685Ssam 
5413685Ssam 
55*18625Sralph 	if (user == NULL && sys == NULL) {
56*18625Sralph 		fprintf(stderr, "usage: uulog [-u user] [-s sys]\n");
5713685Ssam 		exit(1);
5813685Ssam 	}
5913685Ssam 
60*18625Sralph #ifdef LOGBYSITE
61*18625Sralph 	if (chdir(SPOOL) < 0) {
62*18625Sralph 		perror(SPOOL);
63*18625Sralph 		exit(1);
64*18625Sralph 	}
65*18625Sralph 	/* this program is really obsolete, this is a rude backward compat */
66*18625Sralph 	if (user) {
67*18625Sralph 		sprintf(buf, "exec cat LOG/uu*/* | egrep '^%s '", user);
68*18625Sralph 		system(buf);
69*18625Sralph 	}
70*18625Sralph 	if (sys) {
71*18625Sralph 		sprintf(buf,"exec cat LOG/uu*/%s", sys);
72*18625Sralph 		system(buf);
73*18625Sralph 	}
74*18625Sralph #else !LOGBYSITE
7513685Ssam 	plogf = fopen(LOGFILE, "r");
7613685Ssam 	ASSERT(plogf != NULL, "CAN NOT OPEN", LOGFILE, 0);
7713685Ssam 	while (fgets(buf, BUFSIZ, plogf) != NULL) {
7813685Ssam 		sscanf(buf, "%s%s", u, s);
7913685Ssam 		if (user != NULL && !prefix(user, u))
8013685Ssam 			continue;
81*18625Sralph 		if (sys != NULL && !prefix(sys, s))
8213685Ssam 			continue;
8313685Ssam 		fputs(buf, stdout);
8413685Ssam 		fflush(stdout);
8513685Ssam 	}
86*18625Sralph #endif !LOGBYSITE
8713685Ssam 	exit(0);
8813685Ssam }
8913685Ssam 
9013685Ssam cleanup(code)
9113685Ssam int code;
9213685Ssam {
9313685Ssam 	exit(code);
9413685Ssam }
95