2 Find a dialer in the Taylor UUCP configuration files.
4 Copyright (C) 1992 Ian Lance Taylor
6 This file is part of the Taylor UUCP uuconf library.
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.
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.
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.
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.
29 const char _uuconf_tdial_rcsid[] = "$FreeBSD$";
34 static int iddialer P((pointer pglobal, int argc, char **argv, pointer pvar,
36 static int idunknown P((pointer pglobal, int argc, char **argv, pointer pvar,
39 /* Find a dialer in the Taylor UUCP configuration files by name. */
42 uuconf_taylor_dialer_info (pglobal, zname, qdialer)
45 struct uuconf_dialer *qdialer;
47 struct sglobal *qglobal = (struct sglobal *) pglobal;
55 iret = UUCONF_NOT_FOUND;
57 for (pz = qglobal->qprocess->pzdialfiles; *pz != NULL; pz++)
59 struct uuconf_cmdtab as[2];
61 struct uuconf_dialer sdefault;
69 qglobal->ierrno = errno;
70 iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
76 /* Gather the default information from the top of the file. We
77 do this by handling the "dialer" command ourselves and
78 passing every other command to _uuconf_idialer_cmd via
79 idunknown. The value of zdialer will be an malloc block. */
80 as[0].uuconf_zcmd = "dialer";
81 as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 2;
82 as[0].uuconf_pvar = (pointer) &zdialer;
83 as[0].uuconf_pifn = iddialer;
85 as[1].uuconf_zcmd = NULL;
87 pblock = uuconf_malloc_block ();
90 qglobal->ierrno = errno;
91 iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
95 _uuconf_uclear_dialer (&sdefault);
96 sdefault.uuconf_palloc = pblock;
98 iret = uuconf_cmd_file (pglobal, e, as, (pointer) &sdefault,
99 idunknown, UUCONF_CMDTABFLAG_BACKSLASH,
102 /* Now skip until we find a dialer with a matching name. */
103 while (iret == UUCONF_SUCCESS
105 && strcmp (zname, zdialer) != 0)
107 free ((pointer) zdialer);
109 ilineno = qglobal->ilineno;
110 iret = uuconf_cmd_file (pglobal, e, as, (pointer) NULL,
111 (uuconf_cmdtabfn) NULL,
112 UUCONF_CMDTABFLAG_BACKSLASH,
114 qglobal->ilineno += ilineno;
117 if (iret != UUCONF_SUCCESS)
120 free ((pointer) zdialer);
128 /* We've found the dialer we're looking for. Read the rest
129 of the commands for it. */
130 as[0].uuconf_pvar = NULL;
133 csize = strlen (zdialer) + 1;
134 qdialer->uuconf_zname = uuconf_malloc (pblock, csize);
135 if (qdialer->uuconf_zname == NULL)
137 qglobal->ierrno = errno;
138 free ((pointer) zdialer);
139 iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
142 memcpy ((pointer) qdialer->uuconf_zname, (pointer) zdialer,
144 free ((pointer) zdialer);
146 ilineno = qglobal->ilineno;
147 iret = uuconf_cmd_file (pglobal, e, as, qdialer, idunknown,
148 UUCONF_CMDTABFLAG_BACKSLASH, pblock);
149 qglobal->ilineno += ilineno;
155 uuconf_free_block (pblock);
158 iret = UUCONF_NOT_FOUND;
163 if (iret != UUCONF_SUCCESS && pblock != NULL)
164 uuconf_free_block (pblock);
166 if (iret != UUCONF_SUCCESS && iret != UUCONF_NOT_FOUND)
168 qglobal->zfilename = *pz;
169 iret |= UUCONF_ERROR_FILENAME;
175 /* Handle a "dialer" command. This copies the string onto the heap
176 and returns the pointer in *pvar, unless pvar is NULL. It returns
177 UUCONF_CMDTABRET_EXIT to force _uuconf_icmd_file_internal to stop
178 reading and return to the code above, which will then check the
179 dialer name just read to see if it matches. */
183 iddialer (pglobal, argc, argv, pvar, pinfo)
190 struct sglobal *qglobal = (struct sglobal *) pglobal;
191 char **pz = (char **) pvar;
197 csize = strlen (argv[1]) + 1;
198 *pz = malloc (csize);
201 qglobal->ierrno = errno;
202 return (UUCONF_MALLOC_FAILED
204 | UUCONF_CMDTABRET_EXIT);
206 memcpy ((pointer) *pz, (pointer) argv[1], csize);
208 return UUCONF_CMDTABRET_EXIT;
211 /* Handle an unknown command by passing it on to _uuconf_idialer_cmd,
212 which will parse it into the dialer structure. */
216 idunknown (pglobal, argc, argv, pvar, pinfo)
223 struct sglobal *qglobal = (struct sglobal *) pglobal;
224 struct uuconf_dialer *qdialer = (struct uuconf_dialer *) pinfo;
226 return _uuconf_idialer_cmd (qglobal, argc, argv, qdialer);