Routines to read execute files.
Copyright (C) 1991, 1992 Ian Lance Taylor
This file is part of the Taylor UUCP package.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
The author of the program may be contacted at ian@airs.com or
c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
const char xqtfil_rcsid
[] = "$Id: xqtfil.c,v 1.1 1993/08/04 19:33:21 jtc Exp $";
#else /* ! HAVE_DIRENT_H */
#endif /* ! HAVE_DIRENT_H */
#endif /* HAVE_OPENDIR */
/* Under the V2 or BSD42 spool directory scheme, all execute files are
in the main spool directory. Under the BSD43 scheme, they are all
in the directory X.. Under the HDB or SVR4 scheme, they are in
directories named after systems. Under the ULTRIX scheme, they are
in X. subdirectories of subdirectories of sys. Under the TAYLOR
scheme, they are all in the subdirectory X. of a directory named
This means that for HDB, ULTRIX, SVR4 or TAYLOR, we have to search
directories of directories. */
#if SPOOLDIR_V2 || SPOOLDIR_BSD42
#if SPOOLDIR_HDB || SPOOLDIR_SVR4 || SPOOLDIR_TAYLOR
/* Static variables for the execute file scan. */
static DIR *qSxqt_topdir
;
static const char *zSdir
;
/* Initialize the scan for execute files. The function
usysdep_get_xqt_free will clear the data out when we are done with
the system. This returns FALSE on error. */
qSxqt_topdir
= opendir ((char *) ZDIR
);
if (qSxqt_topdir
== NULL
)
ulog (LOG_ERROR
, "opendir (%s): %s", ZDIR
, strerror (errno
));
/* Return the name of the next execute file to read and process. If
this returns NULL, *pferr must be checked. If will be TRUE on
error, FALSE if there are no more files. On a successful return
*pzsystem will be set to the system for which the execute file was
zsysdep_get_xqt (pzsystem
, pferr
)
if (qSxqt_topdir
== NULL
)
/* This loop continues until we find a file. */
/* This loop continues until we find a subdirectory to read. */
while (qSxqt_dir
== NULL
)
qtop
= readdir (qSxqt_topdir
);
(void) closedir (qSxqt_topdir
);
/* No system name may start with a dot (this is enforced by
tisystem in sysinf.c). This allows us to quickly skip
impossible directories. */
if (qtop
->d_name
[0] == '.')
DEBUG_MESSAGE1 (DEBUG_SPOOLDIR
,
"zsysdep_get_xqt: Found %s in top directory",
#if SPOOLDIR_HDB || SPOOLDIR_SVR4
zSdir
= zbufcpy (qtop
->d_name
);
zSdir
= zsappend3 ("sys", qtop
->d_name
, "X.");
zSdir
= zsysdep_in_dir (qtop
->d_name
, "X.");
zSsystem
= zbufcpy (qtop
->d_name
);
qSxqt_dir
= opendir (zSdir
);
ulog (LOG_ERROR
, "opendir (%s): %s", zSdir
, strerror (errno
));
DEBUG_MESSAGE2 (DEBUG_SPOOLDIR
,
"zsysdep_get_xqt: Found %s in subdirectory %s",
/* If we've found an execute file, return it. We have to get
the system name, which is easy for HDB or TAYLOR. For other
spool directory schemes, we have to pull it out of the X.
file name; this would be insecure, except that zsfind_file
clobbers the file name to include the real system name. */
#if SPOOLDIR_HDB || SPOOLDIR_SVR4 || SPOOLDIR_TAYLOR
*pzsystem
= zbufcpy (zSsystem
);
clen
= strlen (q
->d_name
) - 7;
*pzsystem
= zbufalc (clen
+ 1);
memcpy (*pzsystem
, q
->d_name
+ 2, clen
);
(*pzsystem
)[clen
] = '\0';
zret
= zsysdep_in_dir (zSdir
, q
->d_name
);
DEBUG_MESSAGE2 (DEBUG_SPOOLDIR
,
"zsysdep_get_xqt: Returning %s (system %s)",
/* If we've reached the end of the directory, then if we are
using subdirectories loop around to read the next one,
otherwise we are finished. */
/* Free up the results of an execute file scan, when we're done with
if (qSxqt_topdir
!= NULL
)
(void) closedir (qSxqt_topdir
);
(void) closedir (qSxqt_dir
);