1/* tdnams.c
2   Get all known dialer names from the Taylor UUCP configuration files.
3
4   Copyright (C) 1992, 2002 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_tdnams_rcsid[] = "$Id: tdnams.c,v 1.9 2002/03/05 19:10:43 ian Rel $";
29#endif
30
31#include <errno.h>
32
33static int indialer P((pointer pglobal, int argc, char **argv, pointer pvar,
34		       pointer pinfo));
35
36/* Get the names of all the dialers from the Taylor UUCP configuration
37   files.  */
38
39int
40uuconf_taylor_dialer_names (pglobal, ppzdialers)
41     pointer pglobal;
42     char ***ppzdialers;
43{
44  struct sglobal *qglobal = (struct sglobal *) pglobal;
45  struct uuconf_cmdtab as[2];
46  char **pz;
47  int iret;
48
49  *ppzdialers = NULL;
50
51  as[0].uuconf_zcmd = "dialer";
52  as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 2;
53  as[0].uuconf_pvar = (pointer) ppzdialers;
54  as[0].uuconf_pifn = indialer;
55
56  as[1].uuconf_zcmd = NULL;
57
58  iret = UUCONF_SUCCESS;
59
60  for (pz = qglobal->qprocess->pzdialfiles; *pz != NULL; pz++)
61    {
62      FILE *e;
63
64      e = fopen (*pz, "r");
65      if (e == NULL)
66	{
67	  if (FNO_SUCH_FILE ())
68	    continue;
69	  qglobal->ierrno = errno;
70	  iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
71	  break;
72	}
73
74      iret = uuconf_cmd_file (pglobal, e, as, (pointer) NULL,
75			      (uuconf_cmdtabfn) NULL,
76			      UUCONF_CMDTABFLAG_BACKSLASH,
77			      (pointer) NULL);
78
79      (void) fclose (e);
80
81      if (iret != UUCONF_SUCCESS)
82	break;
83    }
84
85  if (iret != UUCONF_SUCCESS)
86    {
87      qglobal->zfilename = *pz;
88      return iret | UUCONF_ERROR_FILENAME;
89    }
90
91  if (*ppzdialers == NULL)
92    iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
93				ppzdialers, (pointer) NULL);
94
95  return UUCONF_SUCCESS;
96}
97
98/* Add a dialer name to the list.  */
99
100/*ARGSUSED*/
101static int
102indialer (pglobal, argc, argv, pvar, pinfo)
103     pointer pglobal;
104     int argc ATTRIBUTE_UNUSED;
105     char **argv;
106     pointer pvar;
107     pointer pinfo ATTRIBUTE_UNUSED;
108{
109  struct sglobal *qglobal = (struct sglobal *) pglobal;
110  char ***ppzdialers = (char ***) pvar;
111  int iret;
112
113  iret = _uuconf_iadd_string (qglobal, argv[1], TRUE, TRUE, ppzdialers,
114			      (pointer) NULL);
115  if (iret != UUCONF_SUCCESS)
116    iret |= UUCONF_CMDTABRET_EXIT;
117  return iret;
118}
119