home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / mipsABI / examples / sup / supcname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.7 KB  |  113 lines

  1. /*
  2.  * Copyright (c) 1992 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  12.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  13.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  14.  *
  15.  * Carnegie Mellon requests users of this software to return to
  16.  *
  17.  *  Software Distribution Coordinator  or  Software_Distribution@CS.CMU.EDU
  18.  *  School of Computer Science
  19.  *  Carnegie Mellon University
  20.  *  Pittsburgh PA 15213-3890
  21.  *
  22.  * any improvements or extensions that they make and grant Carnegie Mellon
  23.  * the rights to redistribute these changes.
  24.  */
  25. /*
  26.  * sup client name server interface
  27.  **********************************************************************
  28.  * HISTORY
  29.  * $Log: supcname.c,v $
  30.  * Revision 1.1.1.1  1993/05/21  14:52:18  cgd
  31.  * initial import of CMU's SUP to NetBSD
  32.  *
  33.  * Revision 1.4  92/08/11  12:07:32  mrt
  34.  *     Added copyright.
  35.  *     [92/08/10            mrt]
  36.  * 
  37.  * 21-Dec-87  Glenn Marcy (gm0w) at Carnegie-Mellon University
  38.  *    Changed to no longer use a name server.
  39.  *
  40.  * 26-May-87  Doug Philips (dwp) at Carnegie-Mellon University
  41.  *    Changed getnams and added several new routines to change the
  42.  *    way that sup finds nameservers.  It now builds a tree of
  43.  *    servers to check.  It walks over the tree.  At each node, it
  44.  *    tries to contact the name server and get as many names
  45.  *    resolved as it can.  It stops after either all collections
  46.  *    have host names, or if some collections don't have host names
  47.  *    but either everyone doesn't know what they are, or after too
  48.  *    many tries, none could be reached.
  49.  *
  50.  * 25-May-87  Doug Philips (dwp) at Carnegie-Mellon University
  51.  *    Split off from sup.c
  52.  *
  53.  **********************************************************************
  54.  */
  55.  
  56. #include "supcdefs.h"
  57.  
  58. extern COLLECTION *firstC;        /* collection list pointer */
  59.  
  60. /*****************************************
  61.  ***    G E T   H O S T   N A M E S    ***
  62.  *****************************************/
  63.  
  64. /*
  65.  * For each collection that doesn't have a host name specified, read
  66.  * the file server list for the name of the host for that collection.
  67.  * It's a fatal error if a collection has no file server.
  68.  */
  69.  
  70. getnams ()
  71. {
  72.     register COLLECTION *c;
  73.     char buf[STRINGLENGTH];
  74.     register FILE *f;
  75.     char *p,*q;
  76.  
  77.     for (c = firstC; c && c->Chtree != NULL; c = c->Cnext);
  78.     if (c == NULL) return;
  79.     (void) sprintf (buf,FILEHOSTS,DEFDIR);
  80.     f = fopen (buf,"r");
  81.     if (f == NULL)  logquit (1,"Can't open %s",buf);
  82.     while ((p = fgets (buf,STRINGLENGTH,f)) != NULL) {
  83.         if (q = index (p,'\n'))  *q = '\0';
  84.         if (index ("#;:",*p))  continue;
  85.         q = nxtarg (&p,"= \t");
  86.         p = skipover (p," \t");
  87.         if (*p == '=')  p++;
  88.         p = skipover (p," \t");
  89.         if (*p == '\0')  goaway ("error in collection/host file");
  90.         do {
  91.             if (strcmp (c->Cname, q) == 0) {
  92.                 do {
  93.                     q = nxtarg (&p,", \t");
  94.                     p = skipover (p," \t");
  95.                     if (*p == ',')  p++;
  96.                     p = skipover (p," \t");
  97.                     (void) Tinsert (&c->Chtree,q,FALSE);
  98.                 } while (*p != '\0');
  99.             }
  100.             while ((c = c->Cnext) != NULL && c->Chtree != NULL);
  101.         } while (c != NULL);
  102.         for (c = firstC; c && c->Chtree != NULL; c = c->Cnext);
  103.         if (c == NULL) break;
  104.     }
  105.     (void) fclose (f);
  106.     if (c == NULL)  return;
  107.     do {
  108.         logerr ("Host for collection %s not found",c->Cname);
  109.         while ((c = c->Cnext) != NULL && c->Chtree != NULL);
  110.     } while (c);
  111.     logquit (1,"Hosts not found for all collections");
  112. }
  113.