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.
23   */
24
25#include "uucnfi.h"
26
27#if USE_RCS_ID
28const char _uuconf_hdnams_rcsid[] = "$Id: hdnams.c,v 1.7 2002/03/05 19:10:42 ian Rel $";
29#endif
30
31#include <errno.h>
32#include <ctype.h>
33
34/* Get all the dialer names from the HDB Dialers file.  */
35
36int
37uuconf_hdb_dialer_names (pglobal, ppzdialers)
38     pointer pglobal;
39     char ***ppzdialers;
40{
41  struct sglobal *qglobal = (struct sglobal *) pglobal;
42  int iret;
43  char *zline;
44  size_t cline;
45  char **pz;
46
47  *ppzdialers = NULL;
48
49  iret = UUCONF_SUCCESS;
50
51  zline = NULL;
52  cline = 0;
53
54  for (pz = qglobal->qprocess->pzhdb_dialers; *pz != NULL; pz++)
55    {
56      FILE *e;
57
58      e = fopen (*pz, "r");
59      if (e == NULL)
60	{
61	  if (FNO_SUCH_FILE ())
62	    continue;
63	  qglobal->ierrno = errno;
64	  iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
65	  break;
66	}
67
68      qglobal->ilineno = 0;
69
70      while (_uuconf_getline (qglobal, &zline, &cline, e) > 0)
71	{
72	  ++qglobal->ilineno;
73
74	  /* Lines beginning with whitespace are treated as comments.
75	     No dialer name can contain a '#', which is another
76	     comment character, so eliminating the first '#' does no
77	     harm and catches comments.  */
78	  zline[strcspn (zline, " \t#\n")] = '\0';
79	  if (*zline == '\0')
80	    continue;
81
82	  iret = _uuconf_iadd_string (qglobal, zline, TRUE, TRUE,
83				      ppzdialers, (pointer) NULL);
84	  if (iret != UUCONF_SUCCESS)
85	    {
86	      iret |= UUCONF_ERROR_LINENO;
87	      break;
88	    }
89	}
90
91      (void) fclose (e);
92    }
93
94  if (zline != NULL)
95    free ((pointer) zline);
96
97  if (iret != UUCONF_SUCCESS)
98    {
99      qglobal->zfilename = *pz;
100      return iret | UUCONF_ERROR_FILENAME;
101    }
102
103  if (*ppzdialers == NULL)
104    iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
105				ppzdialers, (pointer) NULL);
106
107  return UUCONF_SUCCESS;
108}
109