]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - gnu/libexec/uucp/libuuconf/diacod.c
This commit was generated by cvs2svn to compensate for changes in r54820,
[FreeBSD/FreeBSD.git] / gnu / libexec / uucp / libuuconf / diacod.c
1 /* diacod.c
2    Translate a dialcode.
3
4    Copyright (C) 1992, 1993 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_diacod_rcsid[] = "$FreeBSD$";
30 #endif
31
32 #include <errno.h>
33 \f
34 static int idcode P((pointer pglobal, int argc, char **argv,
35                      pointer pinfo, pointer pvar));
36 \f
37 /* Get the name of the UUCP log file.  */
38
39 int
40 uuconf_dialcode (pglobal, zdial, pznum)
41      pointer pglobal;
42      const char *zdial;
43      char **pznum;
44 {
45   struct sglobal *qglobal = (struct sglobal *) pglobal;
46   struct uuconf_cmdtab as[2];
47   char **pz;
48   int iret;
49
50   as[0].uuconf_zcmd = zdial;
51   as[0].uuconf_itype = UUCONF_CMDTABTYPE_FN | 0;
52   as[0].uuconf_pvar = (pointer) pznum;
53   as[0].uuconf_pifn = idcode;
54
55   as[1].uuconf_zcmd = NULL;
56
57   *pznum = NULL;
58
59   iret = UUCONF_SUCCESS;
60
61   for (pz = qglobal->qprocess->pzdialcodefiles; *pz != NULL; pz++)
62     {
63       FILE *e;
64
65       e = fopen (*pz, "r");
66       if (e == NULL)
67         {
68           if (FNO_SUCH_FILE ())
69             continue;
70           qglobal->ierrno = errno;
71           iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
72           break;
73         }
74
75       iret = uuconf_cmd_file (pglobal, e, as, (pointer) NULL,
76                               (uuconf_cmdtabfn) NULL, 0, (pointer) NULL);
77       (void) fclose (e);
78
79       if (iret != UUCONF_SUCCESS || *pznum != NULL)
80         break;
81     }
82
83   if (iret != UUCONF_SUCCESS)
84     {
85       qglobal->zfilename = *pz;
86       iret |= UUCONF_ERROR_FILENAME;
87     }
88   else if (*pznum == NULL)
89     iret = UUCONF_NOT_FOUND;
90
91   return iret;
92 }
93
94 /* This is called if the dialcode is found.  It copies the number into
95    the heap and gets out of reading the file.  */
96
97 /*ARGSUSED*/
98 static int
99 idcode (pglobal, argc, argv, pvar, pinfo)
100      pointer pglobal;
101      int argc;
102      char **argv;
103      pointer pvar;
104      pointer pinfo;
105 {
106   struct sglobal *qglobal = (struct sglobal *) pglobal;
107   char **pznum = (char **) pvar;
108
109   if (argc == 1)
110     {
111       *pznum = malloc (1);
112       if (*pznum != NULL)
113         **pznum = '\0';
114     }
115   else if (argc == 2)
116     *pznum = strdup (argv[1]);
117   else
118     return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
119
120   if (*pznum == NULL)
121     {
122       qglobal->ierrno = errno;
123       return (UUCONF_MALLOC_FAILED
124               | UUCONF_ERROR_ERRNO
125               | UUCONF_CMDTABRET_EXIT);
126     }
127
128   return UUCONF_CMDTABRET_EXIT;
129 }