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

  1. /*
  2.  *  UUHOSTS  -- List all UUCP sites connected to our system
  3.  *
  4.  *  Copyright 1988 by William Loftus.  All rights reserved.
  5.  *  Copyright 1993 by Michael B. Smith. All rights reserved.
  6.  *
  7.  *  Performs a subfunction of UUNAME -- use it instead.
  8.  */
  9.  
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include "version.h"
  14. #include "protos.h"
  15.  
  16. IDENT (".03");
  17.  
  18. void listsites (void);
  19.  
  20. int
  21. main (int argc, char **argv)
  22. {
  23.     if (argc != 1) {
  24.         fprintf (stderr, "usage: %s\n", argv [0]);
  25.         exit (30);
  26.     }
  27.  
  28.     listsites ();
  29.  
  30.     exit (0);
  31. }
  32.  
  33. void
  34. listsites (void)
  35. {
  36.     /*
  37.     **  listsites
  38.     **
  39.     **    Read UULib:L.Sys and print out the unique sites listed there.
  40.     */
  41.     char
  42.         *p,
  43.         buf [256];
  44.     struct Node
  45.         *n;
  46.     struct List
  47.         list;
  48.     FILE
  49.         *fd;
  50.     int
  51.         unique;
  52.  
  53.     if (!(fd = fopen (MakeConfigPath (UULIB, "L.sys"), "r"))) {
  54.         fprintf (stderr, "Couldn't open L.sys file\n");
  55.         exit (30);
  56.     }
  57.  
  58.     NewList (&list);
  59.  
  60.     while (fgets (buf, sizeof buf, fd)) {
  61.         if (buf [0] == '#' || buf [0] == '\n')
  62.             continue;
  63.  
  64.         if (p = strchr (buf, ' '))
  65.             *p = '\0';
  66.         else
  67.             buf [79] = '\0';
  68.  
  69.         unique = 1;
  70.         for (n = list.lh_Head; n->ln_Succ; n = n->ln_Succ) {
  71.             if (stricmp (buf, n->ln_Name) == 0) {
  72.                 unique = 0;
  73.                 break;
  74.             }
  75.         }
  76.  
  77.         if (unique) {
  78.             n = malloc (sizeof (struct Node) + strlen (buf) + 2);
  79.             n->ln_Name = ((char *) n) + sizeof (struct Node);
  80.             strcpy (n->ln_Name, buf);
  81.             AddTail (&list, n);
  82.         }
  83.     }
  84.  
  85.     fclose (fd);
  86.  
  87.     while (n = RemHead (&list)) {
  88.         printf ("%s\n", n->ln_Name);
  89.         free (n);
  90.     }
  91.  
  92.     return;
  93. }
  94.