#include "uucp.h"
#if USE_RCS_ID
const char uuname_rcsid[] = "$Id: uuname.c,v 1.24 2002/03/05 19:10:42 ian Rel $";
#endif
#include "getopt.h"
#include "uudefs.h"
#include "uuconf.h"
#include "system.h"
static void unusage P((void));
static void unhelp P((void));
static const struct option asNlongopts[] =
{
{ "aliases", no_argument, NULL, 'a' },
{ "local", no_argument, NULL, 'l' },
{ "config", required_argument, NULL, 'I' },
{ "debug", required_argument, NULL, 'x' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 1 },
{ NULL, 0, NULL, 0 }
};
int
main (argc, argv)
int argc;
char **argv;
{
boolean falias = FALSE;
boolean flocal = FALSE;
const char *zconfig = NULL;
int iopt;
pointer puuconf;
int iuuconf;
if (argc < 1)
{
zProgram = "uuname";
unusage ();
}
zProgram = argv[0];
while ((iopt = getopt_long (argc, argv, "alI:vx:", asNlongopts,
(int *) NULL)) != EOF)
{
switch (iopt)
{
case 'a':
falias = TRUE;
break;
case 'l':
flocal = TRUE;
break;
case 'I':
if (fsysdep_other_config (optarg))
zconfig = optarg;
break;
case 'x':
#if DEBUG > 1
iDebug |= idebug_parse (optarg);
#endif
break;
case 'v':
printf ("uuname (Taylor UUCP) %s\n", VERSION);
printf ("Copyright (C) 1991, 92, 93, 94, 1995, 2002 Ian Lance Taylor\n");
printf ("This program is free software; you may redistribute it under the terms of\n");
printf ("the GNU General Public LIcense. This program has ABSOLUTELY NO WARRANTY.\n");
exit (EXIT_SUCCESS);
case 1:
unhelp ();
exit (EXIT_SUCCESS);
case 0:
break;
default:
unusage ();
}
}
if (optind != argc)
unusage ();
iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
#if DEBUG > 1
{
const char *zdebug;
iuuconf = uuconf_debuglevel (puuconf, &zdebug);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
if (zdebug != NULL)
iDebug |= idebug_parse (zdebug);
}
#endif
usysdep_initialize (puuconf, INIT_SUID | INIT_NOCHDIR);
if (flocal)
{
const char *zlocalname;
iuuconf = uuconf_localname (puuconf, &zlocalname);
if (iuuconf == UUCONF_NOT_FOUND)
{
zlocalname = zsysdep_localname ();
if (zlocalname == NULL)
usysdep_exit (FALSE);
}
else if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
printf ("%s\n", zlocalname);
}
else
{
char **pznames, **pz;
iuuconf = uuconf_system_names (puuconf, &pznames, falias);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
for (pz = pznames; *pz != NULL; pz++)
printf ("%s\n", *pz);
}
usysdep_exit (TRUE);
return 0;
}
static void
unusage ()
{
fprintf (stderr,
"Usage: %s [-a] [-l] [-I file]\n", zProgram);
fprintf (stderr, "Use %s --help for help\n", zProgram);
exit (EXIT_FAILURE);
}
static void unhelp ()
{
printf ("Taylor UUCP %s, copyright (C) 1991, 92, 93, 94, 1995, 2002 Ian Lance Taylor\n",
VERSION);
printf ("Usage: %s [-a] [-l] [-I file]\n", zProgram);
printf (" -a,--aliases: display aliases\n");
printf (" -l,--local: print local name\n");
#if HAVE_TAYLOR_CONFIG
printf (" -I,--config file: Set configuration file to use\n");
#endif
printf (" -v,--version: Print version and exit\n");
printf (" --help: Print help and exit\n");
printf ("Report bugs to taylor-uucp@gnu.org\n");
}