xref: /csrg-svn/usr.bin/uucp/uuname/uuname.c (revision 33962)
113687Ssam #ifndef lint
2*33962Srick static char sccsid[] = "@(#)uuname.c	5.4	(Berkeley) 04/05/88";
313687Ssam #endif
413687Ssam 
513687Ssam #include "uucp.h"
613687Ssam 
725143Sbloom /*
8*33962Srick  * return list of all remote systems recognized by uucp, or  (with -l) the
9*33962Srick  * local  uucp name.
1013687Ssam  *
11*33962Srick  * return codes: 0 | 1  (can't read)
1213687Ssam  */
1325143Sbloom 
1425143Sbloom struct timeb Now;
15*33962Srick 
16*33962Srick main(argc, argv)
1713687Ssam char *argv[];
1813687Ssam int argc;
1913687Ssam {
20*33962Srick 	register FILE *np;
21*33962Srick 	register char *buf;
22*33962Srick 	char s[BUFSIZ];
23*33962Srick 	char prev[BUFSIZ];
2413687Ssam 
2513687Ssam 	strcpy(Progname, "uuname");
2613687Ssam 
27*33962Srick 	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'l') {
2813687Ssam 		uucpname(s);
29*33962Srick 		puts(s);
3013687Ssam 		exit(0);
3113687Ssam 	}
32*33962Srick 	if (argc != 1) {
33*33962Srick 		fprintf(stderr, "Usage: uuname [-l]\n");
3413687Ssam 		exit(1);
3513687Ssam 	}
36*33962Srick 	if ((np = fopen(SYSFILE, "r")) == NULL) {
37*33962Srick 		syslog(LOG_WARNING, "fopen(%s) failed: %m", SYSFILE);
38*33962Srick 		exit(1);
39*33962Srick 	}
40*33962Srick 	buf = s;
41*33962Srick 	while (cfgets(buf, sizeof(s), np) != NULL) {
42*33962Srick 		register char *cp;
43*33962Srick 		cp = strpbrk(buf, " \t");
44*33962Srick 		if (cp)
45*33962Srick 			*cp = '\0';
4613687Ssam 		if (strcmp(s, prev) == SAME)
4713687Ssam 			continue;
48*33962Srick 		if (*buf == 'x' && buf[1] == 'x' && buf[2] == 'x')
4913687Ssam 			continue;
50*33962Srick 		puts(buf);
51*33962Srick 		if (buf == s)
52*33962Srick 			buf = prev;
53*33962Srick 		else
54*33962Srick 			buf = s;
5513687Ssam 	}
5613687Ssam 	exit(0);
5713687Ssam }
5817844Sralph 
5917844Sralph cleanup(code)
6017844Sralph int code;
6117844Sralph {
6217844Sralph 	exit(code);
6317844Sralph }
64