xref: /titanic_50/usr/src/cmd/bnu/uuname.c (revision 34f9b3eef6fdadbda0a846aa4d68691ac40eace5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include "uucp.h"
34 
35 /*
36  * returns a list of remote systems accessible to uucico
37  * option:
38  *	-l	-> returns only the local system name.
39  *	-c	-> print remote systems accessible to cu
40  */
41 int
42 main(argc,argv)
43 int argc;
44 char **argv;
45 {
46 	int c, lflg = 0, cflg = 0;
47 	char s[BUFSIZ], prev[BUFSIZ], name[BUFSIZ];
48 	extern void setservice();
49 	extern int sysaccess(), getsysline();
50 
51 	/* Set locale environment variables local definitions */
52 	(void) setlocale(LC_ALL, "");
53 #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
54 #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it wasn't */
55 #endif
56 	(void) textdomain(TEXT_DOMAIN);
57 
58 	while ( (c = getopt(argc, argv, "lc")) != EOF )
59 		switch(c) {
60 		case 'c':
61 			cflg++;
62 			break;
63 		case 'l':
64 			lflg++;
65 			break;
66 		default:
67 			(void) fprintf(stderr, gettext("usage: uuname [-l|-c]\n"));
68 			exit(1);
69 		}
70 
71 	if (lflg) {
72 		if ( cflg )
73 			(void) fprintf(stderr,
74 			gettext("uuname: -l overrides -c ... -c option ignored\n"));
75 		uucpname(name);
76 
77 		puts(name);
78 		exit(0);
79 	}
80 
81 	if ( cflg )
82 		setservice("cu");
83 	else
84 		setservice("uucico");
85 
86 	if ( sysaccess(EACCESS_SYSTEMS) != 0 ) {
87 		(void)fprintf(stderr, gettext(
88 		    "%s: cannot access Systems files\n"), argv[0]);
89 		exit(1);
90 	}
91 
92 	while ( getsysline(s, sizeof(s)) ) {
93 		if((s[0] == '#') || (s[0] == ' ') || (s[0] == '\t') ||
94 		    (s[0] == '\n'))
95 			continue;
96 		(void) sscanf(s, "%s", name);
97 		if (EQUALS(name, prev))
98 		    continue;
99 		puts(name);
100 		(void) strcpy(prev, name);
101 	}
102 	return (0);
103 }
104 
105 /* small, private copies of assert(), logent(), */
106 /* cleanup() so we can use routines in sysfiles.c */
107 
108 /*ARGSUSED*/
109 void
110 assert(s1, s2, i1, file, line)
111 char *s1, *s2, *file; int i1, line;
112 {
113 	(void)fprintf(stderr, "uuname: %s %s\n", s2, s1);
114 	return;
115 }
116 
117 /*ARGSUSED*/
118 void logent(s1, s2)
119 char *s1, *s2;
120 {}
121 
122 void cleanup(code) 	{ exit(code);	}
123