home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / duucp-1.17 / AU-117b4-src.lha / src / uucico / uuname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-24  |  2.1 KB  |  147 lines

  1. /*
  2.  *  UUNAME.C
  3.  *
  4.  *    uuname [-c] [-l]
  5.  *
  6.  *    List all UUCP sites connected to our system
  7.  *
  8.  *        -c: list all "cu" site known to our system (same list)
  9.  *
  10.  *        -l: local nodename only
  11.  *
  12.  *  Copyright 1988 by William Loftus.  All rights reserved.
  13.  *  Copyright 1993 by Michael B. Smith. All rights reserved.
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "version.h"
  20. #include "protos.h"
  21.  
  22. IDENT (".03");
  23.  
  24. void listsites (void);
  25. void usage (const char *name);
  26.  
  27. void
  28. usage (const char *name)
  29. {
  30.     fprintf (stderr, "usage: %s [-c | -l]\n", name);
  31.     exit (30);
  32. }
  33.  
  34. int
  35. main (int argc, char **argv)
  36. {
  37.     char
  38.         *nm = argv [0],
  39.         *p;
  40.     int
  41.         i,
  42.         opt_c = 0,
  43.         opt_l = 0;
  44.  
  45.     for (i = 1; i < argc; i++) {
  46.         p = argv [i];
  47.         if (*p != '-')
  48.             usage (nm);
  49.         p++;
  50.         switch (*p) {
  51.             case 'l':
  52.                 opt_l = 1;
  53.                 break;
  54.             case 'c':
  55.                 opt_c = 1;
  56.                 break;
  57.             default:
  58.                 usage (nm);
  59.         }
  60.     }
  61.  
  62.     if (opt_c && opt_l)
  63.         usage (nm);
  64.  
  65.     if (opt_l) {
  66.         char
  67.             *nodename = FindConfig (NODENAME);
  68.  
  69.         if (nodename == NULL) {
  70.             fprintf (stderr, "Can't find nodename\n");
  71.             exit (30);
  72.         }
  73.         puts (nodename);
  74.         exit (0);
  75.     }
  76.  
  77.     if (opt_c) {
  78.         printf ("listing UUCP sites\n");
  79.     }
  80.  
  81.     listsites ();
  82.  
  83.     exit (0);
  84. }
  85.  
  86. void
  87. listsites (void)
  88. {
  89.     /*
  90.     **  listsites
  91.     **
  92.     **    Read UULib:L.Sys and print out the unique sites listed there.
  93.     */
  94.     char
  95.         *p,
  96.         buf [256];
  97.     struct Node
  98.         *n;
  99.     struct List
  100.         list;
  101.     FILE
  102.         *fd;
  103.     int
  104.         unique;
  105.  
  106.     if (!(fd = fopen (MakeConfigPath (UULIB, "L.sys"), "r"))) {
  107.         fprintf (stderr, "Couldn't open L.sys file\n");
  108.         exit (30);
  109.     }
  110.  
  111.     NewList (&list);
  112.  
  113.     while (fgets (buf, sizeof buf, fd)) {
  114.         if (buf [0] == '#' || buf [0] == '\n')
  115.             continue;
  116.  
  117.         if (p = strchr (buf, ' '))
  118.             *p = '\0';
  119.         else
  120.             buf [79] = '\0';
  121.  
  122.         unique = 1;
  123.         for (n = list.lh_Head; n->ln_Succ; n = n->ln_Succ) {
  124.             if (stricmp (buf, n->ln_Name) == 0) {
  125.                 unique = 0;
  126.                 break;
  127.             }
  128.         }
  129.  
  130.         if (unique) {
  131.             n = malloc (sizeof (struct Node) + strlen (buf) + 2);
  132.             n->ln_Name = ((char *) n) + sizeof (struct Node);
  133.             strcpy (n->ln_Name, buf);
  134.             AddTail (&list, n);
  135.         }
  136.     }
  137.  
  138.     fclose (fd);
  139.  
  140.     while (n = RemHead (&list)) {
  141.         printf ("%s\n", n->ln_Name);
  142.         free (n);
  143.     }
  144.  
  145.     return;
  146. }
  147.