home *** CD-ROM | disk | FTP | other *** search
- /*
- * UUNAME.C
- *
- * uuname [-c] [-l]
- *
- * List all UUCP sites connected to our system
- *
- * -c: list all "cu" site known to our system (same list)
- *
- * -l: local nodename only
- *
- * Copyright 1988 by William Loftus. All rights reserved.
- * Copyright 1993 by Michael B. Smith. All rights reserved.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "version.h"
- #include "protos.h"
-
- IDENT (".03");
-
- void listsites (void);
- void usage (const char *name);
-
- void
- usage (const char *name)
- {
- fprintf (stderr, "usage: %s [-c | -l]\n", name);
- exit (30);
- }
-
- int
- main (int argc, char **argv)
- {
- char
- *nm = argv [0],
- *p;
- int
- i,
- opt_c = 0,
- opt_l = 0;
-
- for (i = 1; i < argc; i++) {
- p = argv [i];
- if (*p != '-')
- usage (nm);
- p++;
- switch (*p) {
- case 'l':
- opt_l = 1;
- break;
- case 'c':
- opt_c = 1;
- break;
- default:
- usage (nm);
- }
- }
-
- if (opt_c && opt_l)
- usage (nm);
-
- if (opt_l) {
- char
- *nodename = FindConfig (NODENAME);
-
- if (nodename == NULL) {
- fprintf (stderr, "Can't find nodename\n");
- exit (30);
- }
- puts (nodename);
- exit (0);
- }
-
- if (opt_c) {
- printf ("listing UUCP sites\n");
- }
-
- listsites ();
-
- exit (0);
- }
-
- void
- listsites (void)
- {
- /*
- ** listsites
- **
- ** Read UULib:L.Sys and print out the unique sites listed there.
- */
- char
- *p,
- buf [256];
- struct Node
- *n;
- struct List
- list;
- FILE
- *fd;
- int
- unique;
-
- if (!(fd = fopen (MakeConfigPath (UULIB, "L.sys"), "r"))) {
- fprintf (stderr, "Couldn't open L.sys file\n");
- exit (30);
- }
-
- NewList (&list);
-
- while (fgets (buf, sizeof buf, fd)) {
- if (buf [0] == '#' || buf [0] == '\n')
- continue;
-
- if (p = strchr (buf, ' '))
- *p = '\0';
- else
- buf [79] = '\0';
-
- unique = 1;
- for (n = list.lh_Head; n->ln_Succ; n = n->ln_Succ) {
- if (stricmp (buf, n->ln_Name) == 0) {
- unique = 0;
- break;
- }
- }
-
- if (unique) {
- n = malloc (sizeof (struct Node) + strlen (buf) + 2);
- n->ln_Name = ((char *) n) + sizeof (struct Node);
- strcpy (n->ln_Name, buf);
- AddTail (&list, n);
- }
- }
-
- fclose (fd);
-
- while (n = RemHead (&list)) {
- printf ("%s\n", n->ln_Name);
- free (n);
- }
-
- return;
- }
-