1/* vsnams.c
2   Get all known system names from the V2 configuration files.
3
4   Copyright (C) 1992, 1995, 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_vsnams_rcsid[] = "$Id: vsnams.c,v 1.11 2002/03/05 19:10:43 ian Rel $";
29#endif
30
31#include <errno.h>
32
33/* Get all the system names from the V2 L.sys file.  This code does
34   not support aliases, although some V2 versions do have an L-aliases
35   file.  */
36
37/*ARGSUSED*/
38int
39uuconf_v2_system_names (pglobal, ppzsystems, falias)
40     pointer pglobal;
41     char ***ppzsystems;
42     int falias ATTRIBUTE_UNUSED;
43{
44  struct sglobal *qglobal = (struct sglobal *) pglobal;
45  FILE *e;
46  int iret;
47  char *zline;
48  size_t cline;
49
50  *ppzsystems = NULL;
51
52  e = fopen (qglobal->qprocess->zv2systems, "r");
53  if (e == NULL)
54    {
55      if (FNO_SUCH_FILE ())
56	return _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
57				    ppzsystems, (pointer) NULL);
58      qglobal->ierrno = errno;
59      qglobal->zfilename = qglobal->qprocess->zv2systems;
60      return (UUCONF_FOPEN_FAILED
61	      | UUCONF_ERROR_ERRNO
62	      | UUCONF_ERROR_FILENAME);
63    }
64
65  qglobal->ilineno = 0;
66  iret = UUCONF_SUCCESS;
67
68  zline = NULL;
69  cline = 0;
70  while (_uuconf_getline (qglobal, &zline, &cline, e) > 0)
71    {
72      char *zname;
73
74      ++qglobal->ilineno;
75
76      /* Skip leading whitespace to get to the system name.  Then cut
77	 the system name off at the first whitespace, comment, or
78	 newline.  */
79      zname = zline + strspn (zline, " \t");
80      zname[strcspn (zname, " \t#\n")] = '\0';
81      if (*zname == '\0')
82	continue;
83
84      iret = _uuconf_iadd_string (qglobal, zname, TRUE, TRUE, ppzsystems,
85				  (pointer) NULL);
86      if (iret != UUCONF_SUCCESS)
87	break;
88    }
89
90  (void) fclose (e);
91  if (zline != NULL)
92    free ((pointer) zline);
93
94  if (iret != UUCONF_SUCCESS)
95    {
96      qglobal->zfilename = qglobal->qprocess->zv2systems;
97      return iret | UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
98    }
99
100  if (*ppzsystems == NULL)
101    iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
102				ppzsystems, (pointer) NULL);
103
104  return iret;
105}
106