xref: /original-bsd/usr.bin/uucp/uuname/uuname.c (revision 2598cae2)
1 /*-
2  * Copyright (c) 1983, 1988, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1983, 1988, 1993\n\
11 	The Regents of the University of California.  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)uuname.c	8.1 (Berkeley) 06/06/93";
16 #endif /* not lint */
17 
18 #include "uucp.h"
19 
20 /*
21  * return list of all remote systems recognized by uucp, or  (with -l) the
22  * local  uucp name.
23  *
24  * return codes: 0 | 1  (can't read)
25  */
26 
27 struct timeb Now;
28 
29 main(argc, argv)
30 char *argv[];
31 int argc;
32 {
33 	register FILE *np;
34 	register char *buf;
35 	char s[BUFSIZ];
36 	char prev[BUFSIZ];
37 
38 	strcpy(Progname, "uuname");
39 
40 	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'l') {
41 		uucpname(s);
42 		puts(s);
43 		exit(0);
44 	}
45 	if (argc != 1) {
46 		fprintf(stderr, "Usage: uuname [-l]\n");
47 		exit(1);
48 	}
49 	if ((np = fopen(SYSFILE, "r")) == NULL) {
50 		syslog(LOG_WARNING, "fopen(%s) failed: %m", SYSFILE);
51 		exit(1);
52 	}
53 	buf = s;
54 	while (cfgets(buf, sizeof(s), np) != NULL) {
55 		register char *cp;
56 		cp = strpbrk(buf, " \t");
57 		if (cp)
58 			*cp = '\0';
59 		if (strcmp(s, prev) == SAME)
60 			continue;
61 		if (*buf == 'x' && buf[1] == 'x' && buf[2] == 'x')
62 			continue;
63 		puts(buf);
64 		if (buf == s)
65 			buf = prev;
66 		else
67 			buf = s;
68 	}
69 	exit(0);
70 }
71 
72 cleanup(code)
73 int code;
74 {
75 	exit(code);
76 }
77