|
|
1.1 root 1: /* uuname.c
2: List the names of known remote UUCP sites.
3:
4: Copyright (C) 1991, 1992 Ian Lance Taylor
5:
6: This file is part of the Taylor UUCP package.
7:
8: This program is free software; you can redistribute it and/or
9: modify it under the terms of the GNU General Public License as
10: published by the Free Software Foundation; either version 2 of the
11: License, or (at your option) any later version.
12:
13: This program is distributed in the hope that it will be useful, but
14: WITHOUT ANY WARRANTY; without even the implied warranty of
15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: General Public License for more details.
17:
18: You should have received a copy of the GNU General Public License
19: along with this program; if not, write to the Free Software
20: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21:
22: The author of the program may be contacted at [email protected] or
23: c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
24: */
25:
26: #include "uucp.h"
27:
28: #if USE_RCS_ID
29: const char uuname_rcsid[] = "$Id: uuname.c,v 1.1 93/07/30 07:59:05 bin Exp Locker: bin $";
30: #endif
31:
32: #include "getopt.h"
33:
34: #include "uudefs.h"
35: #include "uuconf.h"
36: #include "system.h"
37:
38: /* The program name. */
39: char abProgram[] = "uuname";
40:
41: /* Local functions. */
42:
43: static void unusage P((void));
44: static void unuuconf_error P((pointer puuconf, int iuuconf));
45:
46: /* Long getopt options. */
47: static const struct option asNlongopts[] = { { NULL, 0, NULL, 0 } };
48:
49: int
50: main (argc, argv)
51: int argc;
52: char **argv;
53: {
54: /* -a: display aliases. */
55: boolean falias = FALSE;
56: /* -l: if true, output local node name. */
57: boolean flocal = FALSE;
58: /* -I: configuration file name. */
59: const char *zconfig = NULL;
60: int iopt;
61: pointer puuconf;
62: int iuuconf;
63:
64: while ((iopt = getopt_long (argc, argv, "alI:x:", asNlongopts,
65: (int *) NULL)) != EOF)
66: {
67: switch (iopt)
68: {
69: case 'a':
70: /* Display aliases. */
71: falias = TRUE;
72: break;
73:
74: case 'l':
75: /* Output local node name. */
76: flocal = TRUE;
77: break;
78:
79: case 'I':
80: /* Configuration file name. */
81: if (fsysdep_other_config (optarg))
82: zconfig = optarg;
83: break;
84:
85: case 'x':
86: #if DEBUG > 1
87: /* Set debugging level. */
88: iDebug |= idebug_parse (optarg);
89: #endif
90: break;
91:
92: case 0:
93: /* Long option found and flag set. */
94: break;
95:
96: default:
97: unusage ();
98: break;
99: }
100: }
101:
102: if (optind != argc)
103: unusage ();
104:
105: iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
106: if (iuuconf != UUCONF_SUCCESS)
107: unuuconf_error (puuconf, iuuconf);
108:
109: #if DEBUG > 1
110: {
111: const char *zdebug;
112:
113: iuuconf = uuconf_debuglevel (puuconf, &zdebug);
114: if (iuuconf != UUCONF_SUCCESS)
115: ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
116: if (zdebug != NULL)
117: iDebug |= idebug_parse (zdebug);
118: }
119: #endif
120:
121: usysdep_initialize (puuconf, INIT_SUID);
122:
123: if (flocal)
124: {
125: const char *zlocalname;
126:
127: iuuconf = uuconf_localname (puuconf, &zlocalname);
128: if (iuuconf == UUCONF_NOT_FOUND)
129: {
130: zlocalname = zsysdep_localname ();
131: if (zlocalname == NULL)
132: usysdep_exit (FALSE);
133: }
134: else if (iuuconf != UUCONF_SUCCESS)
135: unuuconf_error (puuconf, iuuconf);
136: printf ("%s\n", zlocalname);
137: }
138: else
139: {
140: char **pznames, **pz;
141:
142: iuuconf = uuconf_system_names (puuconf, &pznames, falias);
143: if (iuuconf != UUCONF_SUCCESS)
144: unuuconf_error (puuconf, iuuconf);
145:
146: for (pz = pznames; *pz != NULL; pz++)
147: printf ("%s\n", *pz);
148: }
149:
150: usysdep_exit (TRUE);
151:
152: /* Avoid warnings about not returning a value. */
153: return 0;
154: }
155:
156: /* Print a usage message and die. */
157:
158: static void
159: unusage ()
160: {
161: fprintf (stderr,
162: "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
163: VERSION);
164: fprintf (stderr,
165: "Usage: uuname [-a] [-l] [-I file]\n");
166: fprintf (stderr,
167: " -a: display aliases\n");
168: fprintf (stderr,
169: " -l: print local name\n");
170: #if HAVE_TAYLOR_CONFIG
171: fprintf (stderr,
172: " -I file: Set configuration file to use\n");
173: #endif /* HAVE_TAYLOR_CONFIG */
174: exit (EXIT_FAILURE);
175: }
176:
177: /* Display a uuconf error and exit. */
178:
179: static void
180: unuuconf_error (puuconf, iret)
181: pointer puuconf;
182: int iret;
183: {
184: char ab[512];
185:
186: (void) uuconf_error_string (puuconf, iret, ab, sizeof ab);
187: if ((iret & UUCONF_ERROR_FILENAME) == 0)
188: fprintf (stderr, "uuname: %s\n", ab);
189: else
190: fprintf (stderr, "uuname:%s\n", ab);
191: exit (EXIT_FAILURE);
192: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.