2 Find a port in the Taylor UUCP configuration files.
4 Copyright (C) 1992, 1993 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_tport_rcsid[] = "$FreeBSD$";
34 static int ipport P((pointer pglobal, int argc, char **argv, pointer pvar,
36 static int ipunknown P((pointer pglobal, int argc, char **argv,
37 pointer pvar, pointer pinfo));
39 /* Find a port in the Taylor UUCP configuration files by name, baud
40 rate, and special purpose function. */
43 uuconf_taylor_find_port (pglobal, zname, ibaud, ihighbaud, pifn, pinfo,
49 int (*pifn) P((struct uuconf_port *, pointer));
51 struct uuconf_port *qport;
53 struct sglobal *qglobal = (struct sglobal *) pglobal;
66 iret = UUCONF_NOT_FOUND;
68 for (pz = qglobal->qprocess->pzportfiles; *pz != NULL; pz++)
70 struct uuconf_cmdtab as[2];
72 struct uuconf_port sdefault;
80 qglobal->ierrno = errno;
81 iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
87 /* Gather the default information from the top of the file. We
88 do this by handling the "port" command ourselves and passing
89 every other command to _uuconf_iport_cmd via ipunknown. The
90 value of zport will be an malloc block. */
91 as[0].uuconf_zcmd = "port";
92 as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 2;
93 as[0].uuconf_pvar = (pointer) &zport;
94 as[0].uuconf_pifn = ipport;
96 as[1].uuconf_zcmd = NULL;
98 pblock = uuconf_malloc_block ();
101 qglobal->ierrno = errno;
102 iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
106 _uuconf_uclear_port (&sdefault);
107 sdefault.uuconf_palloc = pblock;
109 iret = uuconf_cmd_file (pglobal, e, as, (pointer) &sdefault,
110 ipunknown, UUCONF_CMDTABFLAG_BACKSLASH,
112 if (iret != UUCONF_SUCCESS)
118 /* Now skip until we find a port with a matching name. If the
119 zname argument is NULL, we will have to read every port. */
120 iret = UUCONF_NOT_FOUND;
121 while (zport != NULL)
123 uuconf_cmdtabfn piunknown;
126 if (zname == NULL || strcmp (zname, zport) == 0)
128 piunknown = ipunknown;
130 qport->uuconf_zname = zport;
137 free ((pointer) zport);
142 ilineno = qglobal->ilineno;
143 iret = uuconf_cmd_file (pglobal, e, as, (pointer) qport,
144 piunknown, UUCONF_CMDTABFLAG_BACKSLASH,
146 qglobal->ilineno += ilineno;
147 if (iret != UUCONF_SUCCESS)
149 iret = UUCONF_NOT_FOUND;
151 /* We may have just gathered information about a port. See
152 if it matches the name, the baud rate and the special
158 if (qport->uuconf_ttype == UUCONF_PORTTYPE_MODEM)
160 long imbaud, imhigh, imlow;
162 imbaud = qport->uuconf_u.uuconf_smodem.uuconf_ibaud;
163 imhigh = qport->uuconf_u.uuconf_smodem.uuconf_ihighbaud;
164 imlow = qport->uuconf_u.uuconf_smodem.uuconf_ilowbaud;
166 if (imbaud == 0 && imlow == 0)
168 else if (ibaud <= imbaud && imbaud <= ihighbaud)
171 && imlow <= ihighbaud
177 else if (qport->uuconf_ttype == UUCONF_PORTTYPE_DIRECT)
181 idbaud = qport->uuconf_u.uuconf_sdirect.uuconf_ibaud;
182 if (idbaud != 0 && idbaud != ibaud)
192 iret = (*pifn) (qport, pinfo);
193 if (iret == UUCONF_NOT_FOUND)
195 else if (iret != UUCONF_SUCCESS)
202 if (uuconf_add_block (pblock, zfree) == 0)
205 iret = UUCONF_SUCCESS;
209 qglobal->ierrno = errno;
210 iret = UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
217 free ((pointer) zfree);
225 if (iret != UUCONF_NOT_FOUND)
228 uuconf_free_block (pblock);
235 free ((pointer) zfree);
236 if (iret != UUCONF_SUCCESS && pblock != NULL)
237 uuconf_free_block (pblock);
239 if (iret != UUCONF_SUCCESS && iret != UUCONF_NOT_FOUND)
241 qglobal->zfilename = *pz;
242 iret |= UUCONF_ERROR_FILENAME;
248 /* Handle a "port" command. This copies the string onto the heap and
249 returns the pointer in *pvar. It returns UUCONF_CMDTABRET_EXIT to
250 force uuconf_cmd_file to stop reading and return to the code above,
251 which will then check the port just read to see if it matches. */
255 ipport (pglobal, argc, argv, pvar, pinfo)
262 struct sglobal *qglobal = (struct sglobal *) pglobal;
263 char **pz = (char **) pvar;
266 csize = strlen (argv[1]) + 1;
267 *pz = malloc (csize);
270 qglobal->ierrno = errno;
271 return (UUCONF_MALLOC_FAILED
273 | UUCONF_CMDTABRET_EXIT);
275 memcpy ((pointer) *pz, (pointer) argv[1], csize);
276 return UUCONF_CMDTABRET_EXIT;
279 /* Handle an unknown command by passing it on to _uuconf_iport_cmd,
280 which will parse it into the port structure. */
284 ipunknown (pglobal, argc, argv, pvar, pinfo)
291 struct sglobal *qglobal = (struct sglobal *) pglobal;
292 struct uuconf_port *qport = (struct uuconf_port *) pinfo;
295 iret = _uuconf_iport_cmd (qglobal, argc, argv, qport);
296 if (UUCONF_ERROR_VALUE (iret) != UUCONF_SUCCESS)
297 iret |= UUCONF_CMDTABRET_EXIT;