home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / uuconf.subproj / hdnams.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-09  |  2.8 KB  |  110 lines

  1. /* hdnams.c
  2.    Get all known dialer names from the HDB configuration files.
  3.  
  4.    Copyright (C) 1992 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP uuconf library.
  7.  
  8.    This library is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU Library General Public License
  10.    as published by the Free Software Foundation; either version 2 of
  11.    the License, or (at your option) any later version.
  12.  
  13.    This library is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    Library General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU Library General Public
  19.    License along with this library; if not, write to the Free Software
  20.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
  24.    */
  25.  
  26. #include "uucnfi.h"
  27.  
  28. #if USE_RCS_ID
  29. const char _uuconf_hdnams_rcsid[] = "$Id: hdnams.c,v 1.6 1995/06/21 19:22:48 ian Rel $";
  30. #endif
  31.  
  32. #include <errno.h>
  33. #include <ctype.h>
  34.  
  35. /* Get all the dialer names from the HDB Dialers file.  */
  36.  
  37. int
  38. uuconf_hdb_dialer_names (pglobal, ppzdialers)
  39.      pointer pglobal;
  40.      char ***ppzdialers;
  41. {
  42.   struct sglobal *qglobal = (struct sglobal *) pglobal;
  43.   int iret;
  44.   char *zline;
  45.   size_t cline;
  46.   char **pz;
  47.  
  48.   *ppzdialers = NULL;
  49.  
  50.   iret = UUCONF_SUCCESS;
  51.  
  52.   zline = NULL;
  53.   cline = 0;
  54.  
  55.   for (pz = qglobal->qprocess->pzhdb_dialers; *pz != NULL; pz++)
  56.     {
  57.       FILE *e;
  58.  
  59.       e = fopen (*pz, "r");
  60.       if (e == NULL)
  61.     {
  62.       if (FNO_SUCH_FILE ())
  63.         continue;
  64.       qglobal->ierrno = errno;
  65.       iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
  66.       break;
  67.     }
  68.       
  69.       qglobal->ilineno = 0;
  70.  
  71.       while (_uuconf_getline (qglobal, &zline, &cline, e) > 0)
  72.     {
  73.       ++qglobal->ilineno;
  74.  
  75.       /* Lines beginning with whitespace are treated as comments.
  76.          No dialer name can contain a '#', which is another
  77.          comment character, so eliminating the first '#' does no
  78.          harm and catches comments.  */
  79.       zline[strcspn (zline, " \t#\n")] = '\0';
  80.       if (*zline == '\0')
  81.         continue;
  82.  
  83.       iret = _uuconf_iadd_string (qglobal, zline, TRUE, TRUE,
  84.                       ppzdialers, (pointer) NULL);
  85.       if (iret != UUCONF_SUCCESS)
  86.         {
  87.           iret |= UUCONF_ERROR_LINENO;
  88.           break;
  89.         }
  90.     }
  91.  
  92.       (void) fclose (e);
  93.     }
  94.  
  95.   if (zline != NULL)
  96.     free ((pointer) zline);
  97.  
  98.   if (iret != UUCONF_SUCCESS)
  99.     {
  100.       qglobal->zfilename = *pz;
  101.       return iret | UUCONF_ERROR_FILENAME;
  102.     }
  103.  
  104.   if (*ppzdialers == NULL)
  105.     iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
  106.                 ppzdialers, (pointer) NULL);
  107.  
  108.   return UUCONF_SUCCESS;
  109. }
  110.