home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / uumail / getpath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.7 KB  |  112 lines

  1. /*
  2.  * Name: getpath -- return the full usenet path of the given name
  3.  *
  4.  * Paramaters: sysname (input) -- The system name to be expanded
  5.  *           pathname (output)  The usenet path of the given system name
  6.  *           pathfile (input) the file to search for the system name
  7.  *
  8.  * Returns: EX_OK     -- path found
  9.  *        EX_NOHOST -- path not found
  10.  *        EX_NOINPUT-- unable to open usemap
  11.  *
  12.  * Author: J. Donnelly   3/82
  13.  *
  14.  */
  15.  
  16. /* 22-jun-83 Sheppard
  17.  * modified to rewind path file (if open), rather than open again
  18.  *
  19.  * $Log:    getpath.c,v $
  20.  * Revision 1.9  85/11/14  20:21:49  sob
  21.  * Added #ifdef DEBUG to allow compilation without DEBUG
  22.  * 
  23.  * Revision 1.8  85/11/08  03:04:49  sob
  24.  * release version
  25.  * 
  26.  * Revision 1.7  85/09/30  02:47:40  sob
  27.  * Altered to use path filename from global variable.
  28.  * 
  29.  * Revision 1.6  85/08/03  00:48:57  UUCP
  30.  * Cleaned up with lint.
  31.  * Stan Barber
  32.  * 
  33.  * Revision 1.5  85/07/19  17:45:13  UUCP
  34.  * Added \t as a valid seperation character for the database
  35.  * in the non DBM case. This is what pathalias uses.
  36.  * 
  37.  * Revision 1.4  85/07/19  16:44:07  UUCP
  38.  * revised to return proper things in accordance with sysexits
  39.  * Stan
  40.  * 
  41.  * Revision 1.3  85/07/11  19:30:31  sob
  42.  * added "uuconf.h" include file and deleted duplicated information
  43.  * 
  44.  * Revision 1.2  85/07/10  18:30:59  sob
  45.  * updated to add DBM capabilities
  46.  * Stan Barber, Baylor College of Medicine
  47.  * 
  48.  * Revision 1.1  85/07/10  18:03:28  sob
  49.  * Initial revision
  50.  * 
  51.  */
  52.  
  53. #include    "uuconf.h"
  54.  
  55. static char rcsid[] = "$Header: getpath.c,v 1.9 85/11/14 20:21:49 sob Exp $";
  56.  
  57.  
  58.  
  59. FILE * fopen (), *in;
  60.  
  61. getpath (sysname, pathname)
  62. char   *sysname, *pathname;
  63. {
  64.     char    name[NAMESIZ],*p,t;
  65.  
  66. #ifdef DBM
  67.     datum lhs,rhs;
  68. #endif
  69. #ifdef DEBUG
  70. if (Debug>2)
  71.     printf("In getpath: Sysname = %s, Pathfile = %s\n",sysname,paths);
  72. #endif
  73. #ifdef DBM
  74.    if (dbminit(paths) <0) return(EX_NOINPUT);
  75.         lhs.dptr = sysname;
  76.     lhs.dsize = strlen(sysname)+1;
  77.     rhs = fetch(lhs);
  78.     if (rhs.dptr == NULL) return(EX_NOHOST); /* no name found */
  79.     strcpy(pathname,rhs.dptr);
  80.         return(EX_OK);            /* system name found */
  81.  
  82. #else
  83. if (in == NULL) {
  84.     if ((in = fopen(paths, "r")) == NULL)
  85.         return(EX_NOINPUT);
  86.     }
  87.     else
  88.     rewind(in);
  89.  
  90.     for (;;)
  91.     {
  92.     p = &name[0];
  93.     while ((t = getc(in)) != EOF && (*p++ = t) != ' ' && t != '\t'); /* read the system name */
  94.     if( t == EOF) return(EX_NOHOST);
  95.     *--p = '\0';                    /* set end of string */
  96.     p = &name[0];
  97. #ifdef DEBUG
  98.     if (Debug>4) printf("Found %s\n",p);
  99. #endif
  100.     if (strcmp (p,sysname) == 0)
  101.         break;
  102.     while ((getc (in) != '\n'));            /* skip this path */
  103.     }
  104.  
  105.     p = pathname;                    /* save start loc of pathname */
  106.     while ((*pathname++ = getc (in)) != '\n');
  107.     *--pathname = '\0';
  108.     pathname = p;
  109.     return(EX_OK);            /* system name found */
  110. #endif
  111. }
  112.