1: #include    <stdio.h>
   2: #include    "newsgate.h"
   3: 
   4: #ifdef  RCSIDENT
   5: static char *rcsid = "$Header: newspath.c,v 1.7 85/01/18 15:40:17 notes Rel $";
   6: #endif	RCSIDENT
   7: 
   8: 
   9: /*
  10:  *	char *getpath(dest) char *dest;
  11:  *
  12:  *	look in the routing tables for a path from here to that
  13:  *	specified host.  Return the path.
  14:  *	Return NULL if there is no such path.
  15:  *
  16:  *	The returned path is of the form:
  17:  *		a!b!c!d!dest!		(note trailing !)
  18:  *
  19:  *	The path is saved in a static buffer so you have to save
  20:  *	it or it is destroyed in the next call.
  21:  *
  22:  *	A re-write of what Jeff Donnelly did a while back.
  23:  *	Ray Essick
  24:  *
  25:  *	The routing table contains lines of the form:
  26:  *	site<space>path
  27:  *		site = destination site
  28:  *		path = a!b!c!d!site!	(not trailing !)
  29:  *
  30:  *	Must be in alphabetical order since the search gives up
  31:  *	after finding a site "after" the one we want!
  32:  */
  33: 
  34: FILE * fopen ();
  35: extern char *fgets ();
  36: 
  37: /*
  38:  *	This entire routine is only called when EXPANDPATH is defined
  39:  *	so we surround it with an ifdef to keep down the binary sizes
  40:  *	when EXPANDPATH is not defined.
  41:  */
  42: #ifdef  EXPANDPATH
  43: char   *getpath (dest)
  44: char   *dest;
  45: {
  46: 
  47:     static char line[BUFSIZ];
  48:     FILE * mapfile;
  49:     register char  *p,
  50:                    *path;
  51: 
  52: 
  53:     if ((mapfile = fopen (PATHMAP, "r")) == NULL)
  54:     return (NULL);                  /* no file */
  55: 
  56:     while (fgets (line, BUFSIZ, mapfile) != NULL)
  57:     {
  58:     p = line;
  59:     path = NULL;
  60:     do
  61:     {
  62:         switch (*p)
  63:         {
  64:         case ' ':
  65:         case '\t':              /* zap and mark path */
  66:             if (path == NULL)           /* only once */
  67:             {
  68:             *p++ = '\0';
  69:             path = p;
  70:             }
  71:             else
  72:             p++;                /* gotta move over it */
  73:             break;
  74: 
  75:         case '\n':
  76:             *p = '\0';              /* end of it all */
  77:             break;
  78: 
  79:         default:
  80:             p++;
  81:             break;
  82:         }
  83:     }
  84:     while (*p);                 /* terminates after newline */
  85:     if (strcmp (line, dest) == 0)           /* matches */
  86:     {
  87:         break;                  /* jump and return */
  88:     }
  89: 
  90:     if (strcmp (line, dest) > 0)            /* past it */
  91:     {
  92:         path = NULL;
  93:         break;
  94:     }
  95:     }
  96:     fclose (mapfile);                   /* don't litter */
  97:     return (path);                  /* and our answer */
  98: }
  99: #endif	EXPANDPATH

Defined functions

getpath defined in line 43; used 1 times

Defined variables

rcsid defined in line 5; never used
Last modified: 1985-01-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1926
Valid CSS Valid XHTML 1.0 Strict