diff options
author | cvs2svn <cvs2svn@FreeBSD.org> | 2002-03-21 21:43:26 +0000 |
---|---|---|
committer | cvs2svn <cvs2svn@FreeBSD.org> | 2002-03-21 21:43:26 +0000 |
commit | d8e2db04f12ff68fffc2d72f69a4d10210d072fc (patch) | |
tree | 966ca3c90688bfed71b9ad3dde489fda5e1442b2 | |
parent | 8b04ebcbfe5c578370837cb8c5bb5f20d2c19467 (diff) |
This commit was manufactured by cvs2svn to create tag 'moduli_1_1'.vendor/OpenBSD/moduli_1_1
Notes
Notes:
svn path=/vendor/OpenBSD/dist/; revision=92894
svn path=/vendor/OpenBSD/moduli_1_1/; revision=92896; tag=vendor/OpenBSD/moduli_1_1
49 files changed, 0 insertions, 12817 deletions
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c deleted file mode 100644 index 26d67fff3f91..000000000000 --- a/lib/libc/gen/fts.c +++ /dev/null @@ -1,1104 +0,0 @@ -/* $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $ */ - -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; -#else -static char rcsid[] = "$OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $"; -#endif -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/stat.h> - -#include <dirent.h> -#include <errno.h> -#include <fcntl.h> -#include <fts.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -static FTSENT *fts_alloc __P((FTS *, char *, int)); -static FTSENT *fts_build __P((FTS *, int)); -static void fts_lfree __P((FTSENT *)); -static void fts_load __P((FTS *, FTSENT *)); -static size_t fts_maxarglen __P((char * const *)); -static void fts_padjust __P((FTS *, FTSENT *)); -static int fts_palloc __P((FTS *, size_t)); -static FTSENT *fts_sort __P((FTS *, FTSENT *, int)); -static u_short fts_stat __P((FTS *, FTSENT *, int)); -static int fts_safe_changedir __P((FTS *, FTSENT *, int)); - -#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) - -#define CLR(opt) (sp->fts_options &= ~(opt)) -#define ISSET(opt) (sp->fts_options & (opt)) -#define SET(opt) (sp->fts_options |= (opt)) - -#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path)) -#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) - -/* fts_build flags */ -#define BCHILD 1 /* fts_children */ -#define BNAMES 2 /* fts_children, names only */ -#define BREAD 3 /* fts_read */ - -FTS * -fts_open(argv, options, compar) - char * const *argv; - register int options; - int (*compar) __P((const FTSENT **, const FTSENT **)); -{ - register FTS *sp; - register FTSENT *p, *root; - register int nitems; - FTSENT *parent, *tmp; - int len; - - /* Options check. */ - if (options & ~FTS_OPTIONMASK) { - errno = EINVAL; - return (NULL); - } - - /* Allocate/initialize the stream */ - if ((sp = malloc((u_int)sizeof(FTS))) == NULL) - return (NULL); - memset(sp, 0, sizeof(FTS)); - sp->fts_compar = compar; - sp->fts_options = options; - - /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ - if (ISSET(FTS_LOGICAL)) - SET(FTS_NOCHDIR); - - /* - * Start out with 1K of path space, and enough, in any case, - * to hold the user's paths. - */ - if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) - goto mem1; - - /* Allocate/initialize root's parent. */ - if ((parent = fts_alloc(sp, "", 0)) == NULL) - goto mem2; - parent->fts_level = FTS_ROOTPARENTLEVEL; - - /* Allocate/initialize root(s). */ - for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { - /* Don't allow zero-length paths. */ - if ((len = strlen(*argv)) == 0) { - errno = ENOENT; - goto mem3; - } - - p = fts_alloc(sp, *argv, len); - p->fts_level = FTS_ROOTLEVEL; - p->fts_parent = parent; - p->fts_accpath = p->fts_name; - p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); - - /* Command-line "." and ".." are real directories. */ - if (p->fts_info == FTS_DOT) - p->fts_info = FTS_D; - - /* - * If comparison routine supplied, traverse in sorted - * order; otherwise traverse in the order specified. - */ - if (compar) { - p->fts_link = root; - root = p; - } else { - p->fts_link = NULL; - if (root == NULL) - tmp = root = p; - else { - tmp->fts_link = p; - tmp = p; - } - } - } - if (compar && nitems > 1) - root = fts_sort(sp, root, nitems); - - /* - * Allocate a dummy pointer and make fts_read think that we've just - * finished the node before the root(s); set p->fts_info to FTS_INIT - * so that everything about the "current" node is ignored. - */ - if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) - goto mem3; - sp->fts_cur->fts_link = root; - sp->fts_cur->fts_info = FTS_INIT; - - /* - * If using chdir(2), grab a file descriptor pointing to dot to ensure - * that we can get back here; this could be avoided for some paths, - * but almost certainly not worth the effort. Slashes, symbolic links, - * and ".." are all fairly nasty problems. Note, if we can't get the - * descriptor we run anyway, just more slowly. - */ - if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = open(".", O_RDONLY, 0)) < 0) - SET(FTS_NOCHDIR); - - return (sp); - -mem3: fts_lfree(root); - free(parent); -mem2: free(sp->fts_path); -mem1: free(sp); - return (NULL); -} - -static void -fts_load(sp, p) - FTS *sp; - register FTSENT *p; -{ - register int len; - register char *cp; - - /* - * Load the stream structure for the next traversal. Since we don't - * actually enter the directory until after the preorder visit, set - * the fts_accpath field specially so the chdir gets done to the right - * place and the user can access the first node. From fts_open it's - * known that the path will fit. - */ - len = p->fts_pathlen = p->fts_namelen; - memmove(sp->fts_path, p->fts_name, len + 1); - if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { - len = strlen(++cp); - memmove(p->fts_name, cp, len + 1); - p->fts_namelen = len; - } - p->fts_accpath = p->fts_path = sp->fts_path; - sp->fts_dev = p->fts_dev; -} - -int -fts_close(sp) - FTS *sp; -{ - register FTSENT *freep, *p; - int saved_errno; - - /* - * This still works if we haven't read anything -- the dummy structure - * points to the root list, so we step through to the end of the root - * list which has a valid parent pointer. - */ - if (sp->fts_cur) { - for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { - freep = p; - p = p->fts_link ? p->fts_link : p->fts_parent; - free(freep); - } - free(p); - } - - /* Free up child linked list, sort array, path buffer. */ - if (sp->fts_child) - fts_lfree(sp->fts_child); - if (sp->fts_array) - free(sp->fts_array); - free(sp->fts_path); - - /* Return to original directory, save errno if necessary. */ - if (!ISSET(FTS_NOCHDIR)) { - saved_errno = fchdir(sp->fts_rfd) ? errno : 0; - (void)close(sp->fts_rfd); - } - - /* Set errno and return. */ - if (!ISSET(FTS_NOCHDIR) && saved_errno) { - /* Free up the stream pointer. */ - free(sp); - errno = saved_errno; - return (-1); - } - - /* Free up the stream pointer. */ - free(sp); - return (0); -} - -/* - * Special case of "/" at the end of the path so that slashes aren't - * appended which would cause paths to be written as "....//foo". - */ -#define NAPPEND(p) \ - (p->fts_path[p->fts_pathlen - 1] == '/' \ - ? p->fts_pathlen - 1 : p->fts_pathlen) - -FTSENT * -fts_read(sp) - register FTS *sp; -{ - register FTSENT *p, *tmp; - register int instr; - register char *t; - int saved_errno; - - /* If finished or unrecoverable error, return NULL. */ - if (sp->fts_cur == NULL || ISSET(FTS_STOP)) - return (NULL); - - /* Set current node pointer. */ - p = sp->fts_cur; - - /* Save and zero out user instructions. */ - instr = p->fts_instr; - p->fts_instr = FTS_NOINSTR; - - /* Any type of file may be re-visited; re-stat and re-turn. */ - if (instr == FTS_AGAIN) { - p->fts_info = fts_stat(sp, p, 0); - return (p); - } - - /* - * Following a symlink -- SLNONE test allows application to see - * SLNONE and recover. If indirecting through a symlink, have - * keep a pointer to current location. If unable to get that - * pointer, follow fails. - */ - if (instr == FTS_FOLLOW && - (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { - p->fts_info = fts_stat(sp, p, 1); - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { - if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else - p->fts_flags |= FTS_SYMFOLLOW; - } - return (p); - } - - /* Directory in pre-order. */ - if (p->fts_info == FTS_D) { - /* If skipped or crossed mount point, do post-order visit. */ - if (instr == FTS_SKIP || - (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { - if (p->fts_flags & FTS_SYMFOLLOW) - (void)close(p->fts_symfd); - if (sp->fts_child) { - fts_lfree(sp->fts_child); - sp->fts_child = NULL; - } - p->fts_info = FTS_DP; - return (p); - } - - /* Rebuild if only read the names and now traversing. */ - if (sp->fts_child && ISSET(FTS_NAMEONLY)) { - CLR(FTS_NAMEONLY); - fts_lfree(sp->fts_child); - sp->fts_child = NULL; - } - - /* - * Cd to the subdirectory. - * - * If have already read and now fail to chdir, whack the list - * to make the names come out right, and set the parent errno - * so the application will eventually get an error condition. - * Set the FTS_DONTCHDIR flag so that when we logically change - * directories back to the parent we don't do a chdir. - * - * If haven't read do so. If the read fails, fts_build sets - * FTS_STOP or the fts_info field of the node. - */ - if (sp->fts_child) { - if (fts_safe_changedir(sp, p, -1)) { - p->fts_errno = errno; - p->fts_flags |= FTS_DONTCHDIR; - for (p = sp->fts_child; p; p = p->fts_link) - p->fts_accpath = - p->fts_parent->fts_accpath; - } - } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { - if (ISSET(FTS_STOP)) - return (NULL); - return (p); - } - p = sp->fts_child; - sp->fts_child = NULL; - goto name; - } - - /* Move to the next node on this level. */ -next: tmp = p; - if ((p = p->fts_link)) { - free(tmp); - - /* - * If reached the top, return to the original directory (or - * the root of the tree), and load the paths for the next root. - */ - if (p->fts_level == FTS_ROOTLEVEL) { - if (FCHDIR(sp, sp->fts_rfd)) { - SET(FTS_STOP); - return (NULL); - } - fts_load(sp, p); - return (sp->fts_cur = p); - } - - /* - * User may have called fts_set on the node. If skipped, - * ignore. If followed, get a file descriptor so we can - * get back if necessary. - */ - if (p->fts_instr == FTS_SKIP) - goto next; - if (p->fts_instr == FTS_FOLLOW) { - p->fts_info = fts_stat(sp, p, 1); - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { - if ((p->fts_symfd = - open(".", O_RDONLY, 0)) < 0) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else - p->fts_flags |= FTS_SYMFOLLOW; - } - p->fts_instr = FTS_NOINSTR; - } - -name: t = sp->fts_path + NAPPEND(p->fts_parent); - *t++ = '/'; - memmove(t, p->fts_name, p->fts_namelen + 1); - return (sp->fts_cur = p); - } - - /* Move up to the parent node. */ - p = tmp->fts_parent; - free(tmp); - - if (p->fts_level == FTS_ROOTPARENTLEVEL) { - /* - * Done; free everything up and set errno to 0 so the user - * can distinguish between error and EOF. - */ - free(p); - errno = 0; - return (sp->fts_cur = NULL); - } - - /* NUL terminate the pathname. */ - sp->fts_path[p->fts_pathlen] = '\0'; - - /* - * Return to the parent directory. If at a root node or came through - * a symlink, go back through the file descriptor. Otherwise, cd up - * one directory. - */ - if (p->fts_level == FTS_ROOTLEVEL) { - if (FCHDIR(sp, sp->fts_rfd)) { - SET(FTS_STOP); - return (NULL); - } - } else if (p->fts_flags & FTS_SYMFOLLOW) { - if (FCHDIR(sp, p->fts_symfd)) { - saved_errno = errno; - (void)close(p->fts_symfd); - errno = saved_errno; - SET(FTS_STOP); - return (NULL); - } - (void)close(p->fts_symfd); - } else if (!(p->fts_flags & FTS_DONTCHDIR)) { - if (CHDIR(sp, "..")) { - SET(FTS_STOP); - return (NULL); - } - } - p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; - return (sp->fts_cur = p); -} - -/* - * Fts_set takes the stream as an argument although it's not used in this - * implementation; it would be necessary if anyone wanted to add global - * semantics to fts using fts_set. An error return is allowed for similar - * reasons. - */ -/* ARGSUSED */ -int -fts_set(sp, p, instr) - FTS *sp; - FTSENT *p; - int instr; -{ - if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW && - instr != FTS_NOINSTR && instr != FTS_SKIP) { - errno = EINVAL; - return (1); - } - p->fts_instr = instr; - return (0); -} - -FTSENT * -fts_children(sp, instr) - register FTS *sp; - int instr; -{ - register FTSENT *p; - int fd; - - if (instr && instr != FTS_NAMEONLY) { - errno = EINVAL; - return (NULL); - } - - /* Set current node pointer. */ - p = sp->fts_cur; - - /* - * Errno set to 0 so user can distinguish empty directory from - * an error. - */ - errno = 0; - - /* Fatal errors stop here. */ - if (ISSET(FTS_STOP)) - return (NULL); - - /* Return logical hierarchy of user's arguments. */ - if (p->fts_info == FTS_INIT) - return (p->fts_link); - - /* - * If not a directory being visited in pre-order, stop here. Could - * allow FTS_DNR, assuming the user has fixed the problem, but the - * same effect is available with FTS_AGAIN. - */ - if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) - return (NULL); - - /* Free up any previous child list. */ - if (sp->fts_child) - fts_lfree(sp->fts_child); - - if (instr == FTS_NAMEONLY) { - SET(FTS_NAMEONLY); - instr = BNAMES; - } else - instr = BCHILD; - - /* - * If using chdir on a relative path and called BEFORE fts_read does - * its chdir to the root of a traversal, we can lose -- we need to - * chdir into the subdirectory, and we don't know where the current - * directory is, so we can't get back so that the upcoming chdir by - * fts_read will work. - */ - if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || - ISSET(FTS_NOCHDIR)) - return (sp->fts_child = fts_build(sp, instr)); - - if ((fd = open(".", O_RDONLY, 0)) < 0) - return (NULL); - sp->fts_child = fts_build(sp, instr); - if (fchdir(fd)) - return (NULL); - (void)close(fd); - return (sp->fts_child); -} - -/* - * This is the tricky part -- do not casually change *anything* in here. The - * idea is to build the linked list of entries that are used by fts_children - * and fts_read. There are lots of special cases. - * - * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is - * set and it's a physical walk (so that symbolic links can't be directories), - * we can do things quickly. First, if it's a 4.4BSD file system, the type - * of the file is in the directory entry. Otherwise, we assume that the number - * of subdirectories in a node is equal to the number of links to the parent. - * The former skips all stat calls. The latter skips stat calls in any leaf - * directories and for any files after the subdirectories in the directory have - * been found, cutting the stat calls by about 2/3. - */ -static FTSENT * -fts_build(sp, type) - register FTS *sp; - int type; -{ - register struct dirent *dp; - register FTSENT *p, *head; - register int nitems; - FTSENT *cur, *tail; - DIR *dirp; - void *oldaddr; - int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno, - nostat, doadjust; - char *cp; - - /* Set current node pointer. */ - cur = sp->fts_cur; - - /* - * Open the directory for reading. If this fails, we're done. - * If being called from fts_read, set the fts_info field. - */ -#ifdef FTS_WHITEOUT - if (ISSET(FTS_WHITEOUT)) - oflag = DTF_NODUP|DTF_REWIND; - else - oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; -#else -#define __opendir2(path, flag) opendir(path) -#endif - if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { - if (type == BREAD) { - cur->fts_info = FTS_DNR; - cur->fts_errno = errno; - } - return (NULL); - } - - /* - * Nlinks is the number of possible entries of type directory in the - * directory if we're cheating on stat calls, 0 if we're not doing - * any stat calls at all, -1 if we're doing stats on everything. - */ - if (type == BNAMES) - nlinks = 0; - else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) { - nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2); - nostat = 1; - } else { - nlinks = -1; - nostat = 0; - } - -#ifdef notdef - (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink); - (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n", - ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT)); -#endif - /* - * If we're going to need to stat anything or we want to descend - * and stay in the directory, chdir. If this fails we keep going, - * but set a flag so we don't chdir after the post-order visit. - * We won't be able to stat anything, but we can still return the - * names themselves. Note, that since fts_read won't be able to - * chdir into the directory, it will have to return different path - * names than before, i.e. "a/b" instead of "b". Since the node - * has already been visited in pre-order, have to wait until the - * post-order visit to return the error. There is a special case - * here, if there was nothing to stat then it's not an error to - * not be able to stat. This is all fairly nasty. If a program - * needed sorted entries or stat information, they had better be - * checking FTS_NS on the returned nodes. - */ - cderrno = 0; - if (nlinks || type == BREAD) { - if (fts_safe_changedir(sp, cur, dirfd(dirp))) { - if (nlinks && type == BREAD) - cur->fts_errno = errno; - cur->fts_flags |= FTS_DONTCHDIR; - descend = 0; - cderrno = errno; - (void)closedir(dirp); - dirp = NULL; - } else - descend = 1; - } else - descend = 0; - - /* - * Figure out the max file name length that can be stored in the - * current path -- the inner loop allocates more path as necessary. - * We really wouldn't have to do the maxlen calculations here, we - * could do them in fts_read before returning the path, but it's a - * lot easier here since the length is part of the dirent structure. - * - * If not changing directories set a pointer so that can just append - * each new name into the path. - */ - len = NAPPEND(cur); - if (ISSET(FTS_NOCHDIR)) { - cp = sp->fts_path + len; - *cp++ = '/'; - } - len++; - maxlen = sp->fts_pathlen - len; - - level = cur->fts_level + 1; - - /* Read the directory, attaching each entry to the `link' pointer. */ - doadjust = 0; - for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { - if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) - continue; - - if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL) - goto mem1; - if (dp->d_namlen >= maxlen) { /* include space for NUL */ - oldaddr = sp->fts_path; - if (fts_palloc(sp, dp->d_namlen +len + 1)) { - /* - * No more memory for path or structures. Save - * errno, free up the current structure and the - * structures already allocated. - */ -mem1: saved_errno = errno; - if (p) - free(p); - fts_lfree(head); - (void)closedir(dirp); - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - errno = saved_errno; - return (NULL); - } - /* Did realloc() change the pointer? */ - if (oldaddr != sp->fts_path) { - doadjust = 1; - if (ISSET(FTS_NOCHDIR)) - cp = sp->fts_path + len; - } - maxlen = sp->fts_pathlen - len; - } - - if (len + dp->d_namlen >= USHRT_MAX) { - /* - * In an FTSENT, fts_pathlen is a u_short so it is - * possible to wraparound here. If we do, free up - * the current structure and the structures already - * allocated, then error out with ENAMETOOLONG. - */ - free(p); - fts_lfree(head); - (void)closedir(dirp); - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - errno = ENAMETOOLONG; - return (NULL); - } - p->fts_level = level; - p->fts_parent = sp->fts_cur; - p->fts_pathlen = len + dp->d_namlen; - -#ifdef FTS_WHITEOUT - if (dp->d_type == DT_WHT) - p->fts_flags |= FTS_ISW; -#endif - - if (cderrno) { - if (nlinks) { - p->fts_info = FTS_NS; - p->fts_errno = cderrno; - } else - p->fts_info = FTS_NSOK; - p->fts_accpath = cur->fts_accpath; - } else if (nlinks == 0 -#ifdef DT_DIR - || (nostat && - dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN) -#endif - ) { - p->fts_accpath = - ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; - p->fts_info = FTS_NSOK; - } else { - /* Build a file name for fts_stat to stat. */ - if (ISSET(FTS_NOCHDIR)) { - p->fts_accpath = p->fts_path; - memmove(cp, p->fts_name, p->fts_namelen + 1); - } else - p->fts_accpath = p->fts_name; - /* Stat it. */ - p->fts_info = fts_stat(sp, p, 0); - - /* Decrement link count if applicable. */ - if (nlinks > 0 && (p->fts_info == FTS_D || - p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) - --nlinks; - } - - /* We walk in directory order so "ls -f" doesn't get upset. */ - p->fts_link = NULL; - if (head == NULL) - head = tail = p; - else { - tail->fts_link = p; - tail = p; - } - ++nitems; - } - if (dirp) - (void)closedir(dirp); - - /* - * If realloc() changed the address of the path, adjust the - * addresses for the rest of the tree and the dir list. - */ - if (doadjust) - fts_padjust(sp, head); - - /* - * If not changing directories, reset the path back to original - * state. - */ - if (ISSET(FTS_NOCHDIR)) { - if (len == sp->fts_pathlen || nitems == 0) - --cp; - *cp = '\0'; - } - - /* - * If descended after called from fts_children or after called from - * fts_read and nothing found, get back. At the root level we use - * the saved fd; if one of fts_open()'s arguments is a relative path - * to an empty directory, we wind up here with no other way back. If - * can't get back, we're done. - */ - if (descend && (type == BCHILD || !nitems) && - (cur->fts_level == FTS_ROOTLEVEL ? - FCHDIR(sp, sp->fts_rfd) : CHDIR(sp, ".."))) { - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - return (NULL); - } - - /* If didn't find anything, return NULL. */ - if (!nitems) { - if (type == BREAD) - cur->fts_info = FTS_DP; - return (NULL); - } - - /* Sort the entries. */ - if (sp->fts_compar && nitems > 1) - head = fts_sort(sp, head, nitems); - return (head); -} - -static u_short -fts_stat(sp, p, follow) - FTS *sp; - register FTSENT *p; - int follow; -{ - register FTSENT *t; - register dev_t dev; - register ino_t ino; - struct stat *sbp, sb; - int saved_errno; - - /* If user needs stat info, stat buffer already allocated. */ - sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp; - -#ifdef FTS_WHITEOUT - /* check for whiteout */ - if (p->fts_flags & FTS_ISW) { - if (sbp != &sb) { - memset(sbp, '\0', sizeof (*sbp)); - sbp->st_mode = S_IFWHT; - } - return (FTS_W); - } -#endif - - /* - * If doing a logical walk, or application requested FTS_FOLLOW, do - * a stat(2). If that fails, check for a non-existent symlink. If - * fail, set the errno from the stat call. - */ - if (ISSET(FTS_LOGICAL) || follow) { - if (stat(p->fts_accpath, sbp)) { - saved_errno = errno; - if (!lstat(p->fts_accpath, sbp)) { - errno = 0; - return (FTS_SLNONE); - } - p->fts_errno = saved_errno; - goto err; - } - } else if (lstat(p->fts_accpath, sbp)) { - p->fts_errno = errno; -err: memset(sbp, 0, sizeof(struct stat)); - return (FTS_NS); - } - - if (S_ISDIR(sbp->st_mode)) { - /* - * Set the device/inode. Used to find cycles and check for - * crossing mount points. Also remember the link count, used - * in fts_build to limit the number of stat calls. It is - * understood that these fields are only referenced if fts_info - * is set to FTS_D. - */ - dev = p->fts_dev = sbp->st_dev; - ino = p->fts_ino = sbp->st_ino; - p->fts_nlink = sbp->st_nlink; - - if (ISDOT(p->fts_name)) - return (FTS_DOT); - - /* - * Cycle detection is done by brute force when the directory - * is first encountered. If the tree gets deep enough or the - * number of symbolic links to directories is high enough, - * something faster might be worthwhile. - */ - for (t = p->fts_parent; - t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) - if (ino == t->fts_ino && dev == t->fts_dev) { - p->fts_cycle = t; - return (FTS_DC); - } - return (FTS_D); - } - if (S_ISLNK(sbp->st_mode)) - return (FTS_SL); - if (S_ISREG(sbp->st_mode)) - return (FTS_F); - return (FTS_DEFAULT); -} - -static FTSENT * -fts_sort(sp, head, nitems) - FTS *sp; - FTSENT *head; - register int nitems; -{ - register FTSENT **ap, *p; - - /* - * Construct an array of pointers to the structures and call qsort(3). - * Reassemble the array in the order returned by qsort. If unable to - * sort for memory reasons, return the directory entries in their - * current order. Allocate enough space for the current needs plus - * 40 so don't realloc one entry at a time. - */ - if (nitems > sp->fts_nitems) { - struct _ftsent **a; - - sp->fts_nitems = nitems + 40; - if ((a = realloc(sp->fts_array, - sp->fts_nitems * sizeof(FTSENT *))) == NULL) { - if (sp->fts_array) - free(sp->fts_array); - sp->fts_array = NULL; - sp->fts_nitems = 0; - return (head); - } - sp->fts_array = a; - } - for (ap = sp->fts_array, p = head; p; p = p->fts_link) - *ap++ = p; - qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar); - for (head = *(ap = sp->fts_array); --nitems; ++ap) - ap[0]->fts_link = ap[1]; - ap[0]->fts_link = NULL; - return (head); -} - -static FTSENT * -fts_alloc(sp, name, namelen) - FTS *sp; - char *name; - register int namelen; -{ - register FTSENT *p; - size_t len; - - /* - * The file name is a variable length array and no stat structure is - * necessary if the user has set the nostat bit. Allocate the FTSENT - * structure, the file name and the stat structure in one chunk, but - * be careful that the stat structure is reasonably aligned. Since the - * fts_name field is declared to be of size 1, the fts_name pointer is - * namelen + 2 before the first possible address of the stat structure. - */ - len = sizeof(FTSENT) + namelen; - if (!ISSET(FTS_NOSTAT)) - len += sizeof(struct stat) + ALIGNBYTES; - if ((p = malloc(len)) == NULL) - return (NULL); - - /* Copy the name and guarantee NUL termination. */ - memmove(p->fts_name, name, namelen); - p->fts_name[namelen] = '\0'; - - if (!ISSET(FTS_NOSTAT)) - p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2); - p->fts_namelen = namelen; - p->fts_path = sp->fts_path; - p->fts_errno = 0; - p->fts_flags = 0; - p->fts_instr = FTS_NOINSTR; - p->fts_number = 0; - p->fts_pointer = NULL; - return (p); -} - -static void -fts_lfree(head) - register FTSENT *head; -{ - register FTSENT *p; - - /* Free a linked list of structures. */ - while ((p = head)) { - head = head->fts_link; - free(p); - } -} - -/* - * Allow essentially unlimited paths; find, rm, ls should all work on any tree. - * Most systems will allow creation of paths much longer than MAXPATHLEN, even - * though the kernel won't resolve them. Add the size (not just what's needed) - * plus 256 bytes so don't realloc the path 2 bytes at a time. - */ -static int -fts_palloc(sp, more) - FTS *sp; - size_t more; -{ - char *p; - - sp->fts_pathlen += more + 256; - /* - * Check for possible wraparound. In an FTS, fts_pathlen is - * a signed int but in an FTSENT it is an unsigned short. - * We limit fts_pathlen to USHRT_MAX to be safe in both cases. - */ - if (sp->fts_pathlen < 0 || sp->fts_pathlen >= USHRT_MAX) { - if (sp->fts_path) - free(sp->fts_path); - sp->fts_path = NULL; - errno = ENAMETOOLONG; - return (1); - } - p = realloc(sp->fts_path, sp->fts_pathlen); - if (p == NULL) { - if (sp->fts_path) - free(sp->fts_path); - sp->fts_path = NULL; - return (1); - } - sp->fts_path = p; - return (0); -} - -/* - * When the path is realloc'd, have to fix all of the pointers in structures - * already returned. - */ -static void -fts_padjust(sp, head) - FTS *sp; - FTSENT *head; -{ - FTSENT *p; - char *addr = sp->fts_path; - -#define ADJUST(p) { \ - if ((p)->fts_accpath != (p)->fts_name) { \ - (p)->fts_accpath = \ - (char *)addr + ((p)->fts_accpath - (p)->fts_path); \ - } \ - (p)->fts_path = addr; \ -} - /* Adjust the current set of children. */ - for (p = sp->fts_child; p; p = p->fts_link) - ADJUST(p); - - /* Adjust the rest of the tree, including the current level. */ - for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { - ADJUST(p); - p = p->fts_link ? p->fts_link : p->fts_parent; - } -} - -static size_t -fts_maxarglen(argv) - char * const *argv; -{ - size_t len, max; - - for (max = 0; *argv; ++argv) - if ((len = strlen(*argv)) > max) - max = len; - return (max + 1); -} - -/* - * Change to dir specified by fd or p->fts_accpath without getting - * tricked by someone changing the world out from underneath us. - * Assumes p->fts_dev and p->fts_ino are filled in. - */ -static int -fts_safe_changedir(sp, p, fd) - FTS *sp; - FTSENT *p; - int fd; -{ - int ret, oerrno, newfd; - struct stat sb; - - newfd = fd; - if (ISSET(FTS_NOCHDIR)) - return (0); - if (fd < 0 && (newfd = open(p->fts_accpath, O_RDONLY, 0)) < 0) - return (-1); - if (fstat(newfd, &sb)) { - ret = -1; - goto bail; - } - if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) { - errno = ENOENT; /* disinformation */ - ret = -1; - goto bail; - } - ret = fchdir(newfd); -bail: - oerrno = errno; - if (fd < 0) - (void)close(newfd); - errno = oerrno; - return (ret); -} diff --git a/sbin/dhclient/Makefile b/sbin/dhclient/Makefile deleted file mode 100644 index 3148ea8f0bc5..000000000000 --- a/sbin/dhclient/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -# ex:ts=8 -# -# @(#)Makefile 1.0 (obrien) 2/6/99 -# $Id$ -# -# Copyright (c) 1999 by David O'Brien -# This file is under a "FreeBSD" copyright. See /usr/src/sys/sys/copyright.h -# for the terms of the copyright. -# - -.PATH: ${.CURDIR}/../../contrib/isc-dhcp/client ${.CURDIR}/../../contrib/isc-dhcp/common - -PROG= dhclient -MAN5= dhclient.conf.5 dhclient.leases.5 dhcp-options.5 -MAN8= dhclient.8 dhclient-script.8 - -SRCS= dhclient.c clparse.c -SRCS+= raw.c parse.c nit.c icmp.c dispatch.c conflex.c upf.c bpf.c \ - socket.c packet.c memory.c print.c options.c inet.c convert.c \ - tree.c tables.c hash.c alloc.c errwarn.c inet_addr.c - -CFLAGS+= -I${.CURDIR}/../../contrib/isc-dhcp/includes \ - -I${.CURDIR}/../../contrib/isc-dhcp - -afterinstall: - ${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ - ${.CURDIR}/../../contrib/isc-dhcp/client/scripts/freebsd \ - ${BINDIR}/dhclient-script - -.include <bsd.prog.mk> diff --git a/usr.bin/m4/Makefile b/usr.bin/m4/Makefile deleted file mode 100644 index 0d3c0f59b3aa..000000000000 --- a/usr.bin/m4/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# $OpenBSD: Makefile,v 1.8 2001/09/18 14:55:52 espie Exp $ - -# -DEXTENDED -# if you want the paste & spaste macros. - -PROG= m4 -CFLAGS+=-DEXTENDED -CDIAGFLAGS=-W -Wall -Wstrict-prototypes \ - -Wno-unused -Wno-char-subscripts -Wno-sign-compare -# No optimization for m88k -.if (${MACHINE_ARCH} == "m88k") -CFLAGS+=-O0 -.endif - -SRCS= eval.c expr.c look.c main.c misc.c gnum4.c trace.c -MAN= m4.1 - -.include <bsd.prog.mk> diff --git a/usr.bin/m4/PSD.doc/Makefile b/usr.bin/m4/PSD.doc/Makefile deleted file mode 100644 index c60c912e15c2..000000000000 --- a/usr.bin/m4/PSD.doc/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $OpenBSD: Makefile,v 1.2 1996/06/26 05:36:17 deraadt Exp $ - - -DIR= psd/17.m4 -SRCS= m4.ms -MACROS= -msU - -paper.ps: ${SRCS} - ${ROFF} ${SRCS} > ${.TARGET} - -.include <bsd.doc.mk> diff --git a/usr.bin/m4/TEST/ack.m4 b/usr.bin/m4/TEST/ack.m4 deleted file mode 100644 index ef0b5ef51593..000000000000 --- a/usr.bin/m4/TEST/ack.m4 +++ /dev/null @@ -1,42 +0,0 @@ -# $OpenBSD: ack.m4,v 1.2 1996/06/26 05:36:18 deraadt Exp $ -# $NetBSD: ack.m4,v 1.4 1995/09/28 05:37:54 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)ack.m4 8.1 (Berkeley) 6/6/93 -# - -define(ack, `ifelse($1,0,incr($2),$2,0,`ack(DECR($1),1)', -`ack(DECR($1), ack($1,DECR($2)))')') diff --git a/usr.bin/m4/TEST/hanoi.m4 b/usr.bin/m4/TEST/hanoi.m4 deleted file mode 100644 index d16f922ad0d2..000000000000 --- a/usr.bin/m4/TEST/hanoi.m4 +++ /dev/null @@ -1,47 +0,0 @@ -# $OpenBSD: hanoi.m4,v 1.2 1996/06/26 05:36:19 deraadt Exp $ -# $NetBSD: hanoi.m4,v 1.4 1995/09/28 05:37:56 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)hanoi.m4 8.1 (Berkeley) 6/6/93 -# - -define(hanoi, `trans(A, B, C, $1)') - -define(moved,`move disk from $1 to $2 -') - -define(trans, `ifelse($4,1,`moved($1,$2)', - `trans($1,$3,$2,DECR($4))moved($1,$2)trans($3,$2,$1,DECR($4))')') diff --git a/usr.bin/m4/TEST/hash.m4 b/usr.bin/m4/TEST/hash.m4 deleted file mode 100644 index 21b40e140c2f..000000000000 --- a/usr.bin/m4/TEST/hash.m4 +++ /dev/null @@ -1,57 +0,0 @@ -# $OpenBSD: hash.m4,v 1.2 1996/06/26 05:36:19 deraadt Exp $ -# $NetBSD: hash.m4,v 1.4 1995/09/28 05:37:58 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)hash.m4 8.1 (Berkeley) 6/6/93 -# - -dnl This probably will not run on any m4 that cannot -dnl handle char constants in eval. -dnl -changequote(<,>) define(HASHVAL,99) dnl -define(hash,<eval(str(substr($1,1),0)%HASHVAL)>) dnl -define(str, - <ifelse($1,",$2, - <str(substr(<$1>,1),<eval($2+'substr($1,0,1)')>)>) - >) dnl -define(KEYWORD,<$1,hash($1),>) dnl -define(TSTART, -<struct prehash { - char *keyword; - int hashval; -} keytab[] = {>) dnl -define(TEND,< "",0 -};>) dnl diff --git a/usr.bin/m4/TEST/sqroot.m4 b/usr.bin/m4/TEST/sqroot.m4 deleted file mode 100644 index d01789bb4d0d..000000000000 --- a/usr.bin/m4/TEST/sqroot.m4 +++ /dev/null @@ -1,47 +0,0 @@ -# $OpenBSD: sqroot.m4,v 1.2 1996/06/26 05:36:20 deraadt Exp $ -# $NetBSD: sqroot.m4,v 1.4 1995/09/28 05:38:01 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)sqroot.m4 8.1 (Berkeley) 6/6/93 -# - -define(square_root, - `ifelse(eval($1<0),1,negative-square-root, - `square_root_aux($1, 1, eval(($1+1)/2))')') -define(square_root_aux, - `ifelse($3, $2, $3, - $3, eval($1/$2), $3, - `square_root_aux($1, $3, eval(($3+($1/$3))/2))')') diff --git a/usr.bin/m4/TEST/string.m4 b/usr.bin/m4/TEST/string.m4 deleted file mode 100644 index bb0bba4d1b67..000000000000 --- a/usr.bin/m4/TEST/string.m4 +++ /dev/null @@ -1,47 +0,0 @@ -# $OpenBSD: string.m4,v 1.2 1996/06/26 05:36:20 deraadt Exp $ -# $NetBSD: string.m4,v 1.4 1995/09/28 05:38:03 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)string.m4 8.1 (Berkeley) 6/6/93 -# - -define(string,`integer $1(len(substr($2,1))) -str($1,substr($2,1),0) -data $1(len(substr($2,1)))/EOS/ -') - -define(str,`ifelse($2,",,data $1(incr($3))/`LET'substr($2,0,1)/ -`str($1,substr($2,1),incr($3))')') diff --git a/usr.bin/m4/TEST/test.m4 b/usr.bin/m4/TEST/test.m4 deleted file mode 100644 index 1c77b9bdef9d..000000000000 --- a/usr.bin/m4/TEST/test.m4 +++ /dev/null @@ -1,245 +0,0 @@ -# $OpenBSD: test.m4,v 1.2 1996/06/26 05:36:21 deraadt Exp $ -# $NetBSD: test.m4,v 1.4 1995/09/28 05:38:05 tls Exp $ -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# This code is derived from software contributed to Berkeley by -# Ozan Yigit. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)test.m4 8.1 (Berkeley) 6/6/93 -# - -# test file for mp (not comprehensive) -# -# v7 m4 does not have `decr'. -# -define(DECR,`eval($1-1)') -# -# include string macros -# -include(string.m4) -# -# create some fortrash strings for an even uglier language -# -string(TEXT, "text") -string(DATA, "data") -string(BEGIN, "begin") -string(END, "end") -string(IF, "if") -string(THEN, "then") -string(ELSE, "else") -string(CASE, "case") -string(REPEAT, "repeat") -string(WHILE, "while") -string(DEFAULT, "default") -string(UNTIL, "until") -string(FUNCTION, "function") -string(PROCEDURE, "procedure") -string(EXTERNAL, "external") -string(FORWARD, "forward") -string(TYPE, "type") -string(VAR, "var") -string(CONST, "const") -string(PROGRAM, "program") -string(INPUT, "input") -string(OUTPUT, "output") -# -divert(2) -diversion #1 -divert(3) -diversion #2 -divert(4) -diversion #3 -divert(5) -diversion #4 -divert(0) -define(abc,xxx) -ifdef(`abc',defined,undefined) -# -# v7 m4 does this wrong. The right output is -# this is A vEry lon sEntEnCE -# see m4 documentation for translit. -# -translit(`this is a very long sentence', abcdefg, ABCDEF) -# -# include towers-of-hanoi -# -include(hanoi.m4) -# -# some reasonable set of disks -# -hanoi(6) -# -# include ackermann's function -# -include(ack.m4) -# -# something like (3,3) will blow away un*x m4. -# -ack(2,3) -# -# include a square_root function for fixed nums -# -include(sqroot.m4) -# -# some square roots. -# -square_root(15) -square_root(100) -square_root(-4) -square_root(21372) -# -# some textual material for enjoyment. -# -[taken from the 'Clemson University Computer Newsletter', - September 1981, pp. 6-7] - -I am a wizard in the magical Kingdom of Transformation and I -slay dragons for a living. Actually, I am a systems programmer. -One of the problems with systems programming is explaining to -non-computer enthusiasts what that is. All of the terms I use to -describe my job are totally meaningless to them. Usually my response -to questions about my work is to say as little as possible. For -instance, if someone asks what happened at work this week, I say -"Nothing much" and then I change the subject. - -With the assistance of my brother, a mechanical engineer, I have devised -an analogy that everyone can understand. The analogy describes the -"Kingdom of Transformation" where travelers wander and are magically -transformed. This kingdom is the computer and the travelers are information. -The purpose of the computer is to change information to a more meaningful -forma. The law of conservation applies here: The computer never creates -and never intentionally destroys data. With no further ado, let us travel -to the Kingdom of Transformation: - -In a land far, far away, there is a magical kingdom called the Kingdom of -Transformation. A king rules over this land and employs a Council of -Wizardry. The main purpose of this kingdom is to provide a way for -neighboring kingdoms to transform citizens into more useful citizens. This -is done by allowing the citizens to enter the kingdom at one of its ports -and to travel any of the many routes in the kingdom. They are magically -transformed along the way. The income of the Kingdom of Transformation -comes from the many toll roads within its boundaries. - -The Kingdom of Transformation was created when several kingdoms got -together and discovered a mutual need for new talents and abilities for -citizens. They employed CTK, Inc. (Creators of Transformation, Inc.) to -create this kingdom. CTK designed the country, its transportation routes, -and its laws of transformation, and created the major highway system. - -Hazards -======= - -Because magic is not truly controllable, CTK invariably, but unknowingly, -creates dragons. Dragons are huge fire-breathing beasts which sometimes -injure or kill travelers. Fortunately, they do not travel, but always -remain near their den. - -Other hazards also exist which are potentially harmful. As the roads -become older and more weatherbeaten, pot-holes will develop, trees will -fall on travelers, etc. CTK maintenance men are called to fix these -problems. - -Wizards -======= - -The wizards play a major role in creating and maintaining the kingdom but -get little credit for their work because it is performed secretly. The -wizards do not wan the workers or travelers to learn their incantations -because many laws would be broken and chaos would result. - -CTK's grand design is always general enough to be applicable in many -different situations. As a result, it is often difficult to use. The -first duty of the wizards is to tailor the transformation laws so as to be -more beneficial and easier to use in their particular environment. - -After creation of the kingdom, a major duty of the wizards is to search for -and kill dragons. If travelers do not return on time or if they return -injured, the ruler of the country contacts the wizards. If the wizards -determine that the injury or death occurred due to the traveler's -negligence, they provide the traveler's country with additional warnings. -If not, they must determine if the cause was a road hazard or a dragon. If -the suspect a road hazard, they call in a CTK maintenance man to locate the -hazard and to eliminate it, as in repairing the pothole in the road. If -they think that cause was a dragon, then they must find and slay it. - -The most difficult part of eliminating a dragon is finding it. Sometimes -the wizard magically knows where the dragon's lair it, but often the wizard -must send another traveler along the same route and watch to see where he -disappears. This sounds like a failsafe method for finding dragons (and a -suicide mission for thr traveler) but the second traveler does not always -disappear. Some dragons eat any traveler who comes too close; others are -very picky. - -The wizards may call in CTK who designed the highway system and -transformation laws to help devise a way to locate the dragon. CTK also -helps provide the right spell or incantation to slay the dragon. (There is -no general spell to slay dragons; each dragon must be eliminated with a -different spell.) - -Because neither CTK nor wizards are perfect, spells to not always work -correctly. At best, nothing happens when the wrong spell is uttered. At -worst, the dragon becomes a much larger dragon or multiplies into several -smaller ones. In either case, new spells must be found. - -If all existing dragons are quiet (i.e. have eaten sufficiently), wizards -have time to do other things. They hide in castles and practice spells and -incatations. They also devise shortcuts for travelers and new laws of -transformation. - -Changes in the Kingdom -====================== - -As new transformation kingdoms are created and old ones are maintained, -CTK, Inc. is constantly learning new things. It learns ways to avoid -creating some of the dragons that they have previously created. It also -discovers new and better laws of transformation. As a result, CTK will -periodically create a new grand design which is far better than the old. -The wizards determine when is a good time to implement this new design. -This is when the tourist season is slow or when no important travelers -(VIPs) are to arrive. The kingdom must be closed for the actual -implementation and is leter reopened as a new and better place to go. - -A final question you might ask is what happens when the number of tourists -becomes too great for the kingdom to handle in a reasonable period of time -(i.e., the tourist lines at the ports are too long). The Kingdom of -Transformation has three options: (1) shorten the paths that a tourist must -travel, or (2) convince CTK to develop a faster breed of horses so that the -travelers can finish sooner, or (3) annex more territories so that the -kingdom can handle more travelers. - -Thus ends the story of the Kingdom of Transformation. I hope this has -explained my job to you: I slay dragons for a living. - -# -#should do an automatic undivert.. -# diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c deleted file mode 100644 index 870bffdeb89f..000000000000 --- a/usr.bin/m4/eval.c +++ /dev/null @@ -1,1094 +0,0 @@ -/* $OpenBSD: eval.c,v 1.43 2002/02/16 21:27:48 millert Exp $ */ -/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95"; -#else -static char rcsid[] = "$OpenBSD: eval.c,v 1.43 2002/02/16 21:27:48 millert Exp $"; -#endif -#endif /* not lint */ - -/* - * eval.c - * Facility: m4 macro processor - * by: oz - */ - -#include <sys/types.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <stddef.h> -#include <string.h> -#include <fcntl.h> -#include <err.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" -#include "pathnames.h" - -#define BUILTIN_MARKER "__builtin_" - -static void dodefn(const char *); -static void dopushdef(const char *, const char *); -static void dodump(const char *[], int); -static void dotrace(const char *[], int, int); -static void doifelse(const char *[], int); -static int doincl(const char *); -static int dopaste(const char *); -static void gnu_dochq(const char *[], int); -static void dochq(const char *[], int); -static void gnu_dochc(const char *[], int); -static void dochc(const char *[], int); -static void dodiv(int); -static void doundiv(const char *[], int); -static void dosub(const char *[], int); -static void map(char *, const char *, const char *, const char *); -static const char *handledash(char *, char *, const char *); -static void expand_builtin(const char *[], int, int); -static void expand_macro(const char *[], int); -static void dump_one_def(ndptr); - -unsigned long expansion_id; - -/* - * eval - eval all macros and builtins calls - * argc - number of elements in argv. - * argv - element vector : - * argv[0] = definition of a user - * macro or nil if built-in. - * argv[1] = name of the macro or - * built-in. - * argv[2] = parameters to user-defined - * . macro or built-in. - * . - * - * A call in the form of macro-or-builtin() will result in: - * argv[0] = nullstr - * argv[1] = macro-or-builtin - * argv[2] = nullstr - * - * argc is 3 for macro-or-builtin() and 2 for macro-or-builtin - */ -void -eval(argv, argc, td) - const char *argv[]; - int argc; - int td; -{ - ssize_t mark = -1; - - expansion_id++; - if (td & RECDEF) - errx(1, "%s at line %lu: expanding recursive definition for %s", - CURRENT_NAME, CURRENT_LINE, argv[1]); - if (traced_macros && is_traced(argv[1])) - mark = trace(argv, argc, infile+ilevel); - if (td == MACRTYPE) - expand_macro(argv, argc); - else - expand_builtin(argv, argc, td); - if (mark != -1) - finish_trace(mark); -} - -/* - * expand_builtin - evaluate built-in macros. - */ -void -expand_builtin(argv, argc, td) - const char *argv[]; - int argc; - int td; -{ - int c, n; - int ac; - static int sysval = 0; - -#ifdef DEBUG - printf("argc = %d\n", argc); - for (n = 0; n < argc; n++) - printf("argv[%d] = %s\n", n, argv[n]); - fflush(stdout); -#endif - - /* - * if argc == 3 and argv[2] is null, then we - * have macro-or-builtin() type call. We adjust - * argc to avoid further checking.. - */ - ac = argc; - - if (argc == 3 && !*(argv[2])) - argc--; - - switch (td & TYPEMASK) { - - case DEFITYPE: - if (argc > 2) - dodefine(argv[2], (argc > 3) ? argv[3] : null); - break; - - case PUSDTYPE: - if (argc > 2) - dopushdef(argv[2], (argc > 3) ? argv[3] : null); - break; - - case DUMPTYPE: - dodump(argv, argc); - break; - - case TRACEONTYPE: - dotrace(argv, argc, 1); - break; - - case TRACEOFFTYPE: - dotrace(argv, argc, 0); - break; - - case EXPRTYPE: - /* - * doexpr - evaluate arithmetic - * expression - */ - if (argc > 2) - pbnum(expr(argv[2])); - break; - - case IFELTYPE: - if (argc > 4) - doifelse(argv, argc); - break; - - case IFDFTYPE: - /* - * doifdef - select one of two - * alternatives based on the existence of - * another definition - */ - if (argc > 3) { - if (lookup(argv[2]) != nil) - pbstr(argv[3]); - else if (argc > 4) - pbstr(argv[4]); - } - break; - - case LENGTYPE: - /* - * dolen - find the length of the - * argument - */ - pbnum((argc > 2) ? strlen(argv[2]) : 0); - break; - - case INCRTYPE: - /* - * doincr - increment the value of the - * argument - */ - if (argc > 2) - pbnum(atoi(argv[2]) + 1); - break; - - case DECRTYPE: - /* - * dodecr - decrement the value of the - * argument - */ - if (argc > 2) - pbnum(atoi(argv[2]) - 1); - break; - - case SYSCTYPE: - /* - * dosys - execute system command - */ - if (argc > 2) - sysval = system(argv[2]); - break; - - case SYSVTYPE: - /* - * dosysval - return value of the last - * system call. - * - */ - pbnum(sysval); - break; - - case ESYSCMDTYPE: - if (argc > 2) - doesyscmd(argv[2]); - break; - case INCLTYPE: - if (argc > 2) - if (!doincl(argv[2])) - err(1, "%s at line %lu: include(%s)", - CURRENT_NAME, CURRENT_LINE, argv[2]); - break; - - case SINCTYPE: - if (argc > 2) - (void) doincl(argv[2]); - break; -#ifdef EXTENDED - case PASTTYPE: - if (argc > 2) - if (!dopaste(argv[2])) - err(1, "%s at line %lu: paste(%s)", - CURRENT_NAME, CURRENT_LINE, argv[2]); - break; - - case SPASTYPE: - if (argc > 2) - (void) dopaste(argv[2]); - break; -#endif - case CHNQTYPE: - if (mimic_gnu) - gnu_dochq(argv, ac); - else - dochq(argv, argc); - break; - - case CHNCTYPE: - if (mimic_gnu) - gnu_dochc(argv, ac); - else - dochc(argv, argc); - break; - - case SUBSTYPE: - /* - * dosub - select substring - * - */ - if (argc > 3) - dosub(argv, argc); - break; - - case SHIFTYPE: - /* - * doshift - push back all arguments - * except the first one (i.e. skip - * argv[2]) - */ - if (argc > 3) { - for (n = argc - 1; n > 3; n--) { - pbstr(rquote); - pbstr(argv[n]); - pbstr(lquote); - putback(COMMA); - } - pbstr(rquote); - pbstr(argv[3]); - pbstr(lquote); - } - break; - - case DIVRTYPE: - if (argc > 2 && (n = atoi(argv[2])) != 0) - dodiv(n); - else { - active = stdout; - oindex = 0; - } - break; - - case UNDVTYPE: - doundiv(argv, argc); - break; - - case DIVNTYPE: - /* - * dodivnum - return the number of - * current output diversion - */ - pbnum(oindex); - break; - - case UNDFTYPE: - /* - * doundefine - undefine a previously - * defined macro(s) or m4 keyword(s). - */ - if (argc > 2) - for (n = 2; n < argc; n++) - remhash(argv[n], ALL); - break; - - case POPDTYPE: - /* - * dopopdef - remove the topmost - * definitions of macro(s) or m4 - * keyword(s). - */ - if (argc > 2) - for (n = 2; n < argc; n++) - remhash(argv[n], TOP); - break; - - case MKTMTYPE: - /* - * dotemp - create a temporary file - */ - if (argc > 2) { - int fd; - char *temp; - - temp = xstrdup(argv[2]); - - fd = mkstemp(temp); - if (fd == -1) - err(1, - "%s at line %lu: couldn't make temp file %s", - CURRENT_NAME, CURRENT_LINE, argv[2]); - close(fd); - pbstr(temp); - free(temp); - } - break; - - case TRNLTYPE: - /* - * dotranslit - replace all characters in - * the source string that appears in the - * "from" string with the corresponding - * characters in the "to" string. - */ - if (argc > 3) { - char *temp; - - temp = xalloc(strlen(argv[2])+1); - if (argc > 4) - map(temp, argv[2], argv[3], argv[4]); - else - map(temp, argv[2], argv[3], null); - pbstr(temp); - free(temp); - } else if (argc > 2) - pbstr(argv[2]); - break; - - case INDXTYPE: - /* - * doindex - find the index of the second - * argument string in the first argument - * string. -1 if not present. - */ - pbnum((argc > 3) ? indx(argv[2], argv[3]) : -1); - break; - - case ERRPTYPE: - /* - * doerrp - print the arguments to stderr - * file - */ - if (argc > 2) { - for (n = 2; n < argc; n++) - fprintf(stderr, "%s ", argv[n]); - fprintf(stderr, "\n"); - } - break; - - case DNLNTYPE: - /* - * dodnl - eat-up-to and including - * newline - */ - while ((c = gpbc()) != '\n' && c != EOF) - ; - break; - - case M4WRTYPE: - /* - * dom4wrap - set up for - * wrap-up/wind-down activity - */ - m4wraps = (argc > 2) ? xstrdup(argv[2]) : null; - break; - - case EXITTYPE: - /* - * doexit - immediate exit from m4. - */ - killdiv(); - exit((argc > 2) ? atoi(argv[2]) : 0); - break; - - case DEFNTYPE: - if (argc > 2) - for (n = 2; n < argc; n++) - dodefn(argv[n]); - break; - - case INDIRTYPE: /* Indirect call */ - if (argc > 2) - doindir(argv, argc); - break; - - case BUILTINTYPE: /* Builtins only */ - if (argc > 2) - dobuiltin(argv, argc); - break; - - case PATSTYPE: - if (argc > 2) - dopatsubst(argv, argc); - break; - case REGEXPTYPE: - if (argc > 2) - doregexp(argv, argc); - break; - case LINETYPE: - doprintlineno(infile+ilevel); - break; - case FILENAMETYPE: - doprintfilename(infile+ilevel); - break; - case SELFTYPE: - pbstr(rquote); - pbstr(argv[1]); - pbstr(lquote); - break; - default: - errx(1, "%s at line %lu: eval: major botch.", - CURRENT_NAME, CURRENT_LINE); - break; - } -} - -/* - * expand_macro - user-defined macro expansion - */ -void -expand_macro(argv, argc) - const char *argv[]; - int argc; -{ - const char *t; - const char *p; - int n; - int argno; - - t = argv[0]; /* defn string as a whole */ - p = t; - while (*p) - p++; - p--; /* last character of defn */ - while (p > t) { - if (*(p - 1) != ARGFLAG) - PUTBACK(*p); - else { - switch (*p) { - - case '#': - pbnum(argc - 2); - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if ((argno = *p - '0') < argc - 1) - pbstr(argv[argno + 1]); - break; - case '*': - if (argc > 2) { - for (n = argc - 1; n > 2; n--) { - pbstr(argv[n]); - putback(COMMA); - } - pbstr(argv[2]); - } - break; - case '@': - if (argc > 2) { - for (n = argc - 1; n > 2; n--) { - pbstr(rquote); - pbstr(argv[n]); - pbstr(lquote); - putback(COMMA); - } - pbstr(rquote); - pbstr(argv[2]); - pbstr(lquote); - } - break; - default: - PUTBACK(*p); - PUTBACK('$'); - break; - } - p--; - } - p--; - } - if (p == t) /* do last character */ - PUTBACK(*p); -} - -/* - * dodefine - install definition in the table - */ -void -dodefine(name, defn) - const char *name; - const char *defn; -{ - ndptr p; - int n; - - if (!*name) - errx(1, "%s at line %lu: null definition.", CURRENT_NAME, - CURRENT_LINE); - if ((p = lookup(name)) == nil) - p = addent(name); - else if (p->defn != null) - free((char *) p->defn); - if (strncmp(defn, BUILTIN_MARKER, sizeof(BUILTIN_MARKER)-1) == 0) { - n = builtin_type(defn+sizeof(BUILTIN_MARKER)-1); - if (n != -1) { - p->type = n & TYPEMASK; - if ((n & NOARGS) == 0) - p->type |= NEEDARGS; - p->defn = null; - return; - } - } - if (!*defn) - p->defn = null; - else - p->defn = xstrdup(defn); - p->type = MACRTYPE; - if (STREQ(name, defn)) - p->type |= RECDEF; -} - -/* - * dodefn - push back a quoted definition of - * the given name. - */ -static void -dodefn(name) - const char *name; -{ - ndptr p; - char *real; - - if ((p = lookup(name)) != nil) { - if (p->defn != null) { - pbstr(rquote); - pbstr(p->defn); - pbstr(lquote); - } else if ((real = builtin_realname(p->type)) != NULL) { - pbstr(real); - pbstr(BUILTIN_MARKER); - } - } -} - -/* - * dopushdef - install a definition in the hash table - * without removing a previous definition. Since - * each new entry is entered in *front* of the - * hash bucket, it hides a previous definition from - * lookup. - */ -static void -dopushdef(name, defn) - const char *name; - const char *defn; -{ - ndptr p; - - if (!*name) - errx(1, "%s at line %lu: null definition", CURRENT_NAME, - CURRENT_LINE); - p = addent(name); - if (!*defn) - p->defn = null; - else - p->defn = xstrdup(defn); - p->type = MACRTYPE; - if (STREQ(name, defn)) - p->type |= RECDEF; -} - -/* - * dump_one_def - dump the specified definition. - */ -static void -dump_one_def(p) - ndptr p; -{ - char *real; - - if (mimic_gnu) { - if ((p->type & TYPEMASK) == MACRTYPE) - fprintf(traceout, "%s:\t%s\n", p->name, p->defn); - else { - real = builtin_realname(p->type); - if (real == NULL) - real = null; - fprintf(traceout, "%s:\t<%s>\n", p->name, real); - } - } else - fprintf(traceout, "`%s'\t`%s'\n", p->name, p->defn); -} - -/* - * dodumpdef - dump the specified definitions in the hash - * table to stderr. If nothing is specified, the entire - * hash table is dumped. - */ -static void -dodump(argv, argc) - const char *argv[]; - int argc; -{ - int n; - ndptr p; - - if (argc > 2) { - for (n = 2; n < argc; n++) - if ((p = lookup(argv[n])) != nil) - dump_one_def(p); - } else { - for (n = 0; n < HASHSIZE; n++) - for (p = hashtab[n]; p != nil; p = p->nxtptr) - dump_one_def(p); - } -} - -/* - * dotrace - mark some macros as traced/untraced depending upon on. - */ -static void -dotrace(argv, argc, on) - const char *argv[]; - int argc; - int on; -{ - int n; - - if (argc > 2) { - for (n = 2; n < argc; n++) - mark_traced(argv[n], on); - } else - mark_traced(NULL, on); -} - -/* - * doifelse - select one of two alternatives - loop. - */ -static void -doifelse(argv, argc) - const char *argv[]; - int argc; -{ - cycle { - if (STREQ(argv[2], argv[3])) - pbstr(argv[4]); - else if (argc == 6) - pbstr(argv[5]); - else if (argc > 6) { - argv += 3; - argc -= 3; - continue; - } - break; - } -} - -/* - * doinclude - include a given file. - */ -static int -doincl(ifile) - const char *ifile; -{ - if (ilevel + 1 == MAXINP) - errx(1, "%s at line %lu: too many include files.", - CURRENT_NAME, CURRENT_LINE); - if (fopen_trypath(infile+ilevel+1, ifile) != NULL) { - ilevel++; - bbase[ilevel] = bufbase = bp; - return (1); - } else - return (0); -} - -#ifdef EXTENDED -/* - * dopaste - include a given file without any - * macro processing. - */ -static int -dopaste(pfile) - const char *pfile; -{ - FILE *pf; - int c; - - if ((pf = fopen(pfile, "r")) != NULL) { - while ((c = getc(pf)) != EOF) - putc(c, active); - (void) fclose(pf); - return (1); - } else - return (0); -} -#endif - -static void -gnu_dochq(argv, ac) - const char *argv[]; - int ac; -{ - /* In gnu-m4 mode, the only way to restore quotes is to have no - * arguments at all. */ - if (ac == 2) { - lquote[0] = LQUOTE, lquote[1] = EOS; - rquote[0] = RQUOTE, rquote[1] = EOS; - } else { - strlcpy(lquote, argv[2], sizeof(lquote)); - if(ac > 3) - strlcpy(rquote, argv[3], sizeof(rquote)); - else - rquote[0] = EOS; - } -} - -/* - * dochq - change quote characters - */ -static void -dochq(argv, argc) - const char *argv[]; - int argc; -{ - if (argc > 2) { - if (*argv[2]) - strlcpy(lquote, argv[2], sizeof(lquote)); - else { - lquote[0] = LQUOTE; - lquote[1] = EOS; - } - if (argc > 3) { - if (*argv[3]) - strlcpy(rquote, argv[3], sizeof(rquote)); - } else - strcpy(rquote, lquote); - } else { - lquote[0] = LQUOTE, lquote[1] = EOS; - rquote[0] = RQUOTE, rquote[1] = EOS; - } -} - -static void -gnu_dochc(argv, ac) - const char *argv[]; - int ac; -{ - /* In gnu-m4 mode, no arguments mean no comment - * arguments at all. */ - if (ac == 2) { - scommt[0] = EOS; - ecommt[0] = EOS; - } else { - if (*argv[2]) - strlcpy(scommt, argv[2], sizeof(scommt)); - else - scommt[0] = SCOMMT, scommt[1] = EOS; - if(ac > 3 && *argv[3]) - strlcpy(ecommt, argv[3], sizeof(ecommt)); - else - ecommt[0] = ECOMMT, ecommt[1] = EOS; - } -} -/* - * dochc - change comment characters - */ -static void -dochc(argv, argc) - const char *argv[]; - int argc; -{ - if (argc > 2) { - if (*argv[2]) - strlcpy(scommt, argv[2], sizeof(scommt)); - if (argc > 3) { - if (*argv[3]) - strlcpy(ecommt, argv[3], sizeof(ecommt)); - } - else - ecommt[0] = ECOMMT, ecommt[1] = EOS; - } - else { - scommt[0] = SCOMMT, scommt[1] = EOS; - ecommt[0] = ECOMMT, ecommt[1] = EOS; - } -} - -/* - * dodivert - divert the output to a temporary file - */ -static void -dodiv(n) - int n; -{ - int fd; - - oindex = n; - if (n >= maxout) { - if (mimic_gnu) - resizedivs(n + 10); - else - n = 0; /* bitbucket */ - } - - if (n < 0) - n = 0; /* bitbucket */ - if (outfile[n] == NULL) { - char fname[] = _PATH_DIVNAME; - - if ((fd = mkstemp(fname)) < 0 || - (outfile[n] = fdopen(fd, "w+")) == NULL) - err(1, "%s: cannot divert", fname); - if (unlink(fname) == -1) - err(1, "%s: cannot unlink", fname); - } - active = outfile[n]; -} - -/* - * doundivert - undivert a specified output, or all - * other outputs, in numerical order. - */ -static void -doundiv(argv, argc) - const char *argv[]; - int argc; -{ - int ind; - int n; - - if (argc > 2) { - for (ind = 2; ind < argc; ind++) { - n = atoi(argv[ind]); - if (n > 0 && n < maxout && outfile[n] != NULL) - getdiv(n); - - } - } - else - for (n = 1; n < maxout; n++) - if (outfile[n] != NULL) - getdiv(n); -} - -/* - * dosub - select substring - */ -static void -dosub(argv, argc) - const char *argv[]; - int argc; -{ - const char *ap, *fc, *k; - int nc; - - ap = argv[2]; /* target string */ -#ifdef EXPR - fc = ap + expr(argv[3]); /* first char */ -#else - fc = ap + atoi(argv[3]); /* first char */ -#endif - nc = strlen(fc); - if (argc >= 5) -#ifdef EXPR - nc = min(nc, expr(argv[4])); -#else - nc = min(nc, atoi(argv[4])); -#endif - if (fc >= ap && fc < ap + strlen(ap)) - for (k = fc + nc - 1; k >= fc; k--) - putback(*k); -} - -/* - * map: - * map every character of s1 that is specified in from - * into s3 and replace in s. (source s1 remains untouched) - * - * This is a standard implementation of map(s,from,to) function of ICON - * language. Within mapvec, we replace every character of "from" with - * the corresponding character in "to". If "to" is shorter than "from", - * than the corresponding entries are null, which means that those - * characters dissapear altogether. Furthermore, imagine - * map(dest, "sourcestring", "srtin", "rn..*") type call. In this case, - * `s' maps to `r', `r' maps to `n' and `n' maps to `*'. Thus, `s' - * ultimately maps to `*'. In order to achieve this effect in an efficient - * manner (i.e. without multiple passes over the destination string), we - * loop over mapvec, starting with the initial source character. if the - * character value (dch) in this location is different than the source - * character (sch), sch becomes dch, once again to index into mapvec, until - * the character value stabilizes (i.e. sch = dch, in other words - * mapvec[n] == n). Even if the entry in the mapvec is null for an ordinary - * character, it will stabilize, since mapvec[0] == 0 at all times. At the - * end, we restore mapvec* back to normal where mapvec[n] == n for - * 0 <= n <= 127. This strategy, along with the restoration of mapvec, is - * about 5 times faster than any algorithm that makes multiple passes over - * destination string. - */ -static void -map(dest, src, from, to) - char *dest; - const char *src; - const char *from; - const char *to; -{ - const char *tmp; - unsigned char sch, dch; - static char frombis[257]; - static char tobis[257]; - static unsigned char mapvec[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, - 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, - 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, - 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, - 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, - 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, - 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, - 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 - }; - - if (*src) { - if (mimic_gnu) { - /* - * expand character ranges on the fly - */ - from = handledash(frombis, frombis + 256, from); - to = handledash(tobis, tobis + 256, to); - } - tmp = from; - /* - * create a mapping between "from" and - * "to" - */ - while (*from) - mapvec[(unsigned char)(*from++)] = (*to) ? - (unsigned char)(*to++) : 0; - - while (*src) { - sch = (unsigned char)(*src++); - dch = mapvec[sch]; - while (dch != sch) { - sch = dch; - dch = mapvec[sch]; - } - if ((*dest = (char)dch)) - dest++; - } - /* - * restore all the changed characters - */ - while (*tmp) { - mapvec[(unsigned char)(*tmp)] = (unsigned char)(*tmp); - tmp++; - } - } - *dest = '\0'; -} - - -/* - * handledash: - * use buffer to copy the src string, expanding character ranges - * on the way. - */ -static const char * -handledash(buffer, end, src) - char *buffer; - char *end; - const char *src; -{ - char *p; - - p = buffer; - while(*src) { - if (src[1] == '-' && src[2]) { - unsigned char i; - for (i = (unsigned char)src[0]; - i <= (unsigned char)src[2]; i++) { - *p++ = i; - if (p == end) { - *p = '\0'; - return buffer; - } - } - src += 3; - } else - *p++ = *src++; - if (p == end) - break; - } - *p = '\0'; - return buffer; -} - diff --git a/usr.bin/m4/expr.c b/usr.bin/m4/expr.c deleted file mode 100644 index d73e7123d8f3..000000000000 --- a/usr.bin/m4/expr.c +++ /dev/null @@ -1,623 +0,0 @@ -/* $OpenBSD: expr.c,v 1.12 2002/02/16 21:27:48 millert Exp $ */ -/* $NetBSD: expr.c,v 1.7 1995/09/28 05:37:31 tls Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)expr.c 8.2 (Berkeley) 4/29/95"; -#else -static char rcsid[] = "$OpenBSD: expr.c,v 1.12 2002/02/16 21:27:48 millert Exp $"; -#endif -#endif /* not lint */ - -#include <sys/cdefs.h> -#include <ctype.h> -#include <err.h> -#include <stddef.h> -#include <stdio.h> -#include "mdef.h" -#include "extern.h" - -/* - * expression evaluator: performs a standard recursive - * descent parse to evaluate any expression permissible - * within the following grammar: - * - * expr : query EOS - * query : lor - * | lor "?" query ":" query - * lor : land { "||" land } - * land : not { "&&" not } - * not : eqrel - * | '!' not - * eqrel : shift { eqrelop shift } - * shift : primary { shop primary } - * primary : term { addop term } - * term : exp { mulop exp } - * exp : unary { expop unary } - * unary : factor - * | unop unary - * factor : constant - * | "(" query ")" - * constant: num - * | "'" CHAR "'" - * num : DIGIT - * | DIGIT num - * shop : "<<" - * | ">>" - * eqrel : "=" - * | "==" - * | "!=" - * | "<" - * | ">" - * | "<=" - * | ">=" - * - * - * This expression evaluator is lifted from a public-domain - * C Pre-Processor included with the DECUS C Compiler distribution. - * It is hacked somewhat to be suitable for m4. - * - * Originally by: Mike Lutz - * Bob Harper - */ - -#define EQL 0 -#define NEQ 1 -#define LSS 2 -#define LEQ 3 -#define GTR 4 -#define GEQ 5 -#define OCTAL 8 -#define DECIMAL 10 -#define HEX 16 - -static const char *nxtch; /* Parser scan pointer */ -static const char *where; - -static int query(void); -static int lor(void); -static int land(void); -static int not(void); -static int eqrel(void); -static int shift(void); -static int primary(void); -static int term(void); -static int exp(void); -static int unary(void); -static int factor(void); -static int constant(void); -static int num(void); -static int geteqrel(void); -static int skipws(void); -static void experr(const char *); - -/* - * For longjmp - */ -#include <setjmp.h> -static jmp_buf expjump; - -/* - * macros: - * ungetch - Put back the last character examined. - * getch - return the next character from expr string. - */ -#define ungetch() nxtch-- -#define getch() *nxtch++ - -int -expr(expbuf) - const char *expbuf; -{ - int rval; - - nxtch = expbuf; - where = expbuf; - if (setjmp(expjump) != 0) - return FALSE; - - rval = query(); - if (skipws() == EOS) - return rval; - - printf("m4: ill-formed expression.\n"); - return FALSE; -} - -/* - * query : lor | lor '?' query ':' query - */ -static int -query() -{ - int bool, true_val, false_val; - - bool = lor(); - if (skipws() != '?') { - ungetch(); - return bool; - } - - true_val = query(); - if (skipws() != ':') - experr("bad query"); - - false_val = query(); - return bool ? true_val : false_val; -} - -/* - * lor : land { '||' land } - */ -static int -lor() -{ - int c, vl, vr; - - vl = land(); - while ((c = skipws()) == '|') { - if (getch() != '|') - ungetch(); - vr = land(); - vl = vl || vr; - } - - ungetch(); - return vl; -} - -/* - * land : not { '&&' not } - */ -static int -land() -{ - int c, vl, vr; - - vl = not(); - while ((c = skipws()) == '&') { - if (getch() != '&') - ungetch(); - vr = not(); - vl = vl && vr; - } - - ungetch(); - return vl; -} - -/* - * not : eqrel | '!' not - */ -static int -not() -{ - int val, c; - - if ((c = skipws()) == '!' && getch() != '=') { - ungetch(); - val = not(); - return !val; - } - - if (c == '!') - ungetch(); - ungetch(); - return eqrel(); -} - -/* - * eqrel : shift { eqrelop shift } - */ -static int -eqrel() -{ - int vl, vr, eqrel; - - vl = shift(); - while ((eqrel = geteqrel()) != -1) { - vr = shift(); - - switch (eqrel) { - - case EQL: - vl = (vl == vr); - break; - case NEQ: - vl = (vl != vr); - break; - - case LEQ: - vl = (vl <= vr); - break; - case LSS: - vl = (vl < vr); - break; - case GTR: - vl = (vl > vr); - break; - case GEQ: - vl = (vl >= vr); - break; - } - } - return vl; -} - -/* - * shift : primary { shop primary } - */ -static int -shift() -{ - int vl, vr, c; - - vl = primary(); - while (((c = skipws()) == '<' || c == '>') && getch() == c) { - vr = primary(); - - if (c == '<') - vl <<= vr; - else - vl >>= vr; - } - - if (c == '<' || c == '>') - ungetch(); - ungetch(); - return vl; -} - -/* - * primary : term { addop term } - */ -static int -primary() -{ - int c, vl, vr; - - vl = term(); - while ((c = skipws()) == '+' || c == '-') { - vr = term(); - - if (c == '+') - vl += vr; - else - vl -= vr; - } - - ungetch(); - return vl; -} - -/* - * <term> := <exp> { <mulop> <exp> } - */ -static int -term() -{ - int c, vl, vr; - - vl = exp(); - while ((c = skipws()) == '*' || c == '/' || c == '%') { - vr = exp(); - - switch (c) { - case '*': - vl *= vr; - break; - case '/': - if (vr == 0) - errx(1, "division by zero in eval."); - else - vl /= vr; - break; - case '%': - if (vr == 0) - errx(1, "modulo zero in eval."); - else - vl %= vr; - break; - } - } - ungetch(); - return vl; -} - -/* - * <term> := <unary> { <expop> <unary> } - */ -static int -exp() -{ - int c, vl, vr, n; - - vl = unary(); - switch (c = skipws()) { - - case '*': - if (getch() != '*') { - ungetch(); - break; - } - - case '^': - vr = exp(); - n = 1; - while (vr-- > 0) - n *= vl; - return n; - } - - ungetch(); - return vl; -} - -/* - * unary : factor | unop unary - */ -static int -unary() -{ - int val, c; - - if ((c = skipws()) == '+' || c == '-' || c == '~') { - val = unary(); - - switch (c) { - case '+': - return val; - case '-': - return -val; - case '~': - return ~val; - } - } - - ungetch(); - return factor(); -} - -/* - * factor : constant | '(' query ')' - */ -static int -factor() -{ - int val; - - if (skipws() == '(') { - val = query(); - if (skipws() != ')') - experr("bad factor"); - return val; - } - - ungetch(); - return constant(); -} - -/* - * constant: num | 'char' - * Note: constant() handles multi-byte constants - */ -static int -constant() -{ - int i; - int value; - int c; - int v[sizeof(int)]; - - if (skipws() != '\'') { - ungetch(); - return num(); - } - for (i = 0; i < sizeof(int); i++) { - if ((c = getch()) == '\'') { - ungetch(); - break; - } - if (c == '\\') { - switch (c = getch()) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - ungetch(); - c = num(); - break; - case 'n': - c = 012; - break; - case 'r': - c = 015; - break; - case 't': - c = 011; - break; - case 'b': - c = 010; - break; - case 'f': - c = 014; - break; - } - } - v[i] = c; - } - if (i == 0 || getch() != '\'') - experr("illegal character constant"); - for (value = 0; --i >= 0;) { - value <<= 8; - value += v[i]; - } - return value; -} - -/* - * num : digit | num digit - */ -static int -num() -{ - int rval, c, base; - int ndig; - - rval = 0; - ndig = 0; - c = skipws(); - if (c == '0') { - c = skipws(); - if (c == 'x' || c == 'X') { - base = HEX; - c = skipws(); - } else { - base = OCTAL; - ndig++; - } - } else - base = DECIMAL; - for(;;) { - switch(c) { - case '8': case '9': - if (base == OCTAL) - goto bad_digit; - /*FALLTHRU*/ - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - rval *= base; - rval += c - '0'; - break; - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - c = tolower(c); - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - if (base == HEX) { - rval *= base; - rval += c - 'a' + 10; - break; - } - /*FALLTHRU*/ - default: - goto bad_digit; - } - c = getch(); - ndig++; - } -bad_digit: - ungetch(); - - if (ndig == 0) - experr("bad constant"); - - return rval; -} - -/* - * eqrel : '=' | '==' | '!=' | '<' | '>' | '<=' | '>=' - */ -static int -geteqrel() -{ - int c1, c2; - - c1 = skipws(); - c2 = getch(); - - switch (c1) { - - case '=': - if (c2 != '=') - ungetch(); - return EQL; - - case '!': - if (c2 == '=') - return NEQ; - ungetch(); - ungetch(); - return -1; - - case '<': - if (c2 == '=') - return LEQ; - ungetch(); - return LSS; - - case '>': - if (c2 == '=') - return GEQ; - ungetch(); - return GTR; - - default: - ungetch(); - ungetch(); - return -1; - } -} - -/* - * Skip over any white space and return terminating char. - */ -static int -skipws() -{ - int c; - - while ((c = getch()) <= ' ' && c > EOS) - ; - return c; -} - -/* - * resets environment to eval(), prints an error - * and forces eval to return FALSE. - */ -static void -experr(msg) - const char *msg; -{ - printf("m4: %s in expr %s.\n", msg, where); - longjmp(expjump, -1); -} diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h deleted file mode 100644 index 9170fa89c046..000000000000 --- a/usr.bin/m4/extern.h +++ /dev/null @@ -1,152 +0,0 @@ -/* $OpenBSD: extern.h,v 1.29 2002/02/16 21:27:48 millert Exp $ */ -/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */ - -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)extern.h 8.1 (Berkeley) 6/6/93 - */ - -/* eval.c */ -extern void eval(const char *[], int, int); -extern void dodefine(const char *, const char *); -extern unsigned long expansion_id; - -/* expr.c */ -extern int expr(const char *); - -/* gnum4.c */ -extern void addtoincludepath(const char *); -extern struct input_file *fopen_trypath(struct input_file *, const char *); -extern void doindir(const char *[], int); -extern void dobuiltin(const char *[], int); -extern void dopatsubst(const char *[], int); -extern void doregexp(const char *[], int); - -extern void doprintlineno(struct input_file *); -extern void doprintfilename(struct input_file *); - -extern void doesyscmd(const char *); - - -/* look.c */ -extern ndptr addent(const char *); -extern unsigned hash(const char *); -extern ndptr lookup(const char *); -extern void remhash(const char *, int); - -/* main.c */ -extern void outputstr(const char *); -extern int builtin_type(const char *); -extern char *builtin_realname(int); - -/* misc.c */ -extern void chrsave(int); -extern char *compute_prevep(void); -extern void getdiv(int); -extern ptrdiff_t indx(const char *, const char *); -extern void initspaces(void); -extern void killdiv(void); -extern void onintr(int); -extern void pbnum(int); -extern void pbunsigned(unsigned long); -extern void pbstr(const char *); -extern void putback(int); -extern void *xalloc(size_t); -extern char *xstrdup(const char *); -extern void usage(void); -extern void resizedivs(int); -extern size_t buffer_mark(void); -extern void dump_buffer(FILE *, size_t); - -extern int obtain_char(struct input_file *); -extern void set_input(struct input_file *, FILE *, const char *); -extern void release_input(struct input_file *); - -/* speeded-up versions of chrsave/putback */ -#define PUTBACK(c) \ - do { \ - if (bp >= endpbb) \ - enlarge_bufspace(); \ - *bp++ = (c); \ - } while(0) - -#define CHRSAVE(c) \ - do { \ - if (ep >= endest) \ - enlarge_strspace(); \ - *ep++ = (c); \ - } while(0) - -/* and corresponding exposure for local symbols */ -extern void enlarge_bufspace(void); -extern void enlarge_strspace(void); -extern char *endpbb; -extern char *endest; - -/* trace.c */ -extern void mark_traced(const char *, int); -extern int is_traced(const char *); -extern void trace_file(const char *); -extern ssize_t trace(const char **, int, struct input_file *); -extern void finish_trace(size_t); -extern int traced_macros; -extern void set_trace_flags(const char *); -extern FILE *traceout; - -extern ndptr hashtab[]; /* hash table for macros etc. */ -extern stae *mstack; /* stack of m4 machine */ -extern char *sstack; /* shadow stack, for string space extension */ -extern FILE *active; /* active output file pointer */ -extern struct input_file infile[];/* input file stack (0=stdin) */ -extern FILE **outfile; /* diversion array(0=bitbucket) */ -extern int maxout; /* maximum number of diversions */ -extern int fp; /* m4 call frame pointer */ -extern int ilevel; /* input file stack pointer */ -extern int oindex; /* diversion index. */ -extern int sp; /* current m4 stack pointer */ -extern char *bp; /* first available character */ -extern char *buf; /* push-back buffer */ -extern char *bufbase; /* buffer base for this ilevel */ -extern char *bbase[]; /* buffer base per ilevel */ -extern char ecommt[MAXCCHARS+1];/* end character for comment */ -extern char *ep; /* first free char in strspace */ -extern char lquote[MAXCCHARS+1];/* left quote character (`) */ -extern char *m4wraps; /* m4wrap string default. */ -extern char *null; /* as it says.. just a null. */ -extern char rquote[MAXCCHARS+1];/* right quote character (') */ -extern char scommt[MAXCCHARS+1];/* start character for comment */ - -extern int mimic_gnu; /* behaves like gnu-m4 */ diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c deleted file mode 100644 index 782090d3a0ed..000000000000 --- a/usr.bin/m4/gnum4.c +++ /dev/null @@ -1,563 +0,0 @@ -/* $OpenBSD: gnum4.c,v 1.16 2002/02/16 21:27:48 millert Exp $ */ - -/* - * Copyright (c) 1999 Marc Espie - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * functions needed to support gnu-m4 extensions, including a fake freezing - */ - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <ctype.h> -#include <paths.h> -#include <regex.h> -#include <stddef.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <err.h> -#include <errno.h> -#include <unistd.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" - - -int mimic_gnu = 0; - -/* - * Support for include path search - * First search in the the current directory. - * If not found, and the path is not absolute, include path kicks in. - * First, -I options, in the order found on the command line. - * Then M4PATH env variable - */ - -struct path_entry { - char *name; - struct path_entry *next; -} *first, *last; - -static struct path_entry *new_path_entry(const char *); -static void ensure_m4path(void); -static struct input_file *dopath(struct input_file *, const char *); - -static struct path_entry * -new_path_entry(dirname) - const char *dirname; -{ - struct path_entry *n; - - n = malloc(sizeof(struct path_entry)); - if (!n) - errx(1, "out of memory"); - n->name = strdup(dirname); - if (!n->name) - errx(1, "out of memory"); - n->next = 0; - return n; -} - -void -addtoincludepath(dirname) - const char *dirname; -{ - struct path_entry *n; - - n = new_path_entry(dirname); - - if (last) { - last->next = n; - last = n; - } - else - last = first = n; -} - -static void -ensure_m4path() -{ - static int envpathdone = 0; - char *envpath; - char *sweep; - char *path; - - if (envpathdone) - return; - envpathdone = TRUE; - envpath = getenv("M4PATH"); - if (!envpath) - return; - /* for portability: getenv result is read-only */ - envpath = strdup(envpath); - if (!envpath) - errx(1, "out of memory"); - for (sweep = envpath; - (path = strsep(&sweep, ":")) != NULL;) - addtoincludepath(path); - free(envpath); -} - -static -struct input_file * -dopath(i, filename) - struct input_file *i; - const char *filename; -{ - char path[MAXPATHLEN]; - struct path_entry *pe; - FILE *f; - - for (pe = first; pe; pe = pe->next) { - snprintf(path, sizeof(path), "%s/%s", pe->name, filename); - if ((f = fopen(path, "r")) != 0) { - set_input(i, f, path); - return i; - } - } - return NULL; -} - -struct input_file * -fopen_trypath(i, filename) - struct input_file *i; - const char *filename; -{ - FILE *f; - - f = fopen(filename, "r"); - if (f != NULL) { - set_input(i, f, filename); - return i; - } - if (filename[0] == '/') - return NULL; - - ensure_m4path(); - - return dopath(i, filename); -} - -void -doindir(argv, argc) - const char *argv[]; - int argc; -{ - ndptr p; - - p = lookup(argv[2]); - if (p == NULL) - errx(1, "undefined macro %s", argv[2]); - argv[1] = p->defn; - eval(argv+1, argc-1, p->type); -} - -void -dobuiltin(argv, argc) - const char *argv[]; - int argc; -{ - int n; - argv[1] = NULL; - n = builtin_type(argv[2]); - if (n != -1) - eval(argv+1, argc-1, n); - else - errx(1, "unknown builtin %s", argv[2]); -} - - -/* We need some temporary buffer space, as pb pushes BACK and substitution - * proceeds forward... */ -static char *buffer; -static size_t bufsize = 0; -static size_t current = 0; - -static void addchars(const char *, size_t); -static void addchar(char); -static char *twiddle(const char *); -static char *getstring(void); -static void exit_regerror(int, regex_t *); -static void do_subst(const char *, regex_t *, const char *, regmatch_t *); -static void do_regexpindex(const char *, regex_t *, regmatch_t *); -static void do_regexp(const char *, regex_t *, const char *, regmatch_t *); -static void add_sub(int, const char *, regex_t *, regmatch_t *); -static void add_replace(const char *, regex_t *, const char *, regmatch_t *); -#define addconstantstring(s) addchars((s), sizeof(s)-1) - -static void -addchars(c, n) - const char *c; - size_t n; -{ - if (n == 0) - return; - while (current + n > bufsize) { - if (bufsize == 0) - bufsize = 1024; - else - bufsize *= 2; - buffer = realloc(buffer, bufsize); - if (buffer == NULL) - errx(1, "out of memory"); - } - memcpy(buffer+current, c, n); - current += n; -} - -static void -addchar(c) - char c; -{ - if (current +1 > bufsize) { - if (bufsize == 0) - bufsize = 1024; - else - bufsize *= 2; - buffer = realloc(buffer, bufsize); - if (buffer == NULL) - errx(1, "out of memory"); - } - buffer[current++] = c; -} - -static char * -getstring() -{ - addchar('\0'); - current = 0; - return buffer; -} - - -static void -exit_regerror(er, re) - int er; - regex_t *re; -{ - size_t errlen; - char *errbuf; - - errlen = regerror(er, re, NULL, 0); - errbuf = xalloc(errlen); - regerror(er, re, errbuf, errlen); - errx(1, "regular expression error: %s", errbuf); -} - -static void -add_sub(n, string, re, pm) - int n; - const char *string; - regex_t *re; - regmatch_t *pm; -{ - if (n > re->re_nsub) - warnx("No subexpression %d", n); - /* Subexpressions that did not match are - * not an error. */ - else if (pm[n].rm_so != -1 && - pm[n].rm_eo != -1) { - addchars(string + pm[n].rm_so, - pm[n].rm_eo - pm[n].rm_so); - } -} - -/* Add replacement string to the output buffer, recognizing special - * constructs and replacing them with substrings of the original string. - */ -static void -add_replace(string, re, replace, pm) - const char *string; - regex_t *re; - const char *replace; - regmatch_t *pm; -{ - const char *p; - - for (p = replace; *p != '\0'; p++) { - if (*p == '&' && !mimic_gnu) { - add_sub(0, string, re, pm); - continue; - } - if (*p == '\\') { - if (p[1] == '\\') { - addchar(p[1]); - p++; - continue; - } - if (p[1] == '&') { - if (mimic_gnu) - add_sub(0, string, re, pm); - else - addchar(p[1]); - p++; - continue; - } - if (isdigit(p[1])) { - add_sub(*(++p) - '0', string, re, pm); - continue; - } - } - addchar(*p); - } -} - -static void -do_subst(string, re, replace, pm) - const char *string; - regex_t *re; - const char *replace; - regmatch_t *pm; -{ - int error; - int flags = 0; - const char *last_match = NULL; - - while ((error = regexec(re, string, re->re_nsub+1, pm, flags)) == 0) { - if (pm[0].rm_eo != 0) { - if (string[pm[0].rm_eo-1] == '\n') - flags = 0; - else - flags = REG_NOTBOL; - } - - /* NULL length matches are special... We use the `vi-mode' - * rule: don't allow a NULL-match at the last match - * position. - */ - if (pm[0].rm_so == pm[0].rm_eo && - string + pm[0].rm_so == last_match) { - if (*string == '\0') - return; - addchar(*string); - if (*string++ == '\n') - flags = 0; - else - flags = REG_NOTBOL; - continue; - } - last_match = string + pm[0].rm_so; - addchars(string, pm[0].rm_so); - add_replace(string, re, replace, pm); - string += pm[0].rm_eo; - } - if (error != REG_NOMATCH) - exit_regerror(error, re); - pbstr(string); -} - -static void -do_regexp(string, re, replace, pm) - const char *string; - regex_t *re; - const char *replace; - regmatch_t *pm; -{ - int error; - - switch(error = regexec(re, string, re->re_nsub+1, pm, 0)) { - case 0: - add_replace(string, re, replace, pm); - pbstr(getstring()); - break; - case REG_NOMATCH: - break; - default: - exit_regerror(error, re); - } -} - -static void -do_regexpindex(string, re, pm) - const char *string; - regex_t *re; - regmatch_t *pm; -{ - int error; - - switch(error = regexec(re, string, re->re_nsub+1, pm, 0)) { - case 0: - pbunsigned(pm[0].rm_so); - break; - case REG_NOMATCH: - pbnum(-1); - break; - default: - exit_regerror(error, re); - } -} - -/* In Gnu m4 mode, parentheses for backmatch don't work like POSIX 1003.2 - * says. So we twiddle with the regexp before passing it to regcomp. - */ -static char * -twiddle(p) - const char *p; -{ - /* This could use strcspn for speed... */ - while (*p != '\0') { - if (*p == '\\') { - switch(p[1]) { - case '(': - case ')': - case '|': - addchar(p[1]); - break; - case 'w': - addconstantstring("[_a-zA-Z0-9]"); - break; - case 'W': - addconstantstring("[^_a-zA-Z0-9]"); - break; - case '<': - addconstantstring("[[:<:]]"); - break; - case '>': - addconstantstring("[[:>:]]"); - break; - default: - addchars(p, 2); - break; - } - p+=2; - continue; - } - if (*p == '(' || *p == ')' || *p == '|') - addchar('\\'); - - addchar(*p); - p++; - } - return getstring(); -} - -/* patsubst(string, regexp, opt replacement) */ -/* argv[2]: string - * argv[3]: regexp - * argv[4]: opt rep - */ -void -dopatsubst(argv, argc) - const char *argv[]; - int argc; -{ - int error; - regex_t re; - regmatch_t *pmatch; - - if (argc <= 3) { - warnx("Too few arguments to patsubst"); - return; - } - error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], - REG_NEWLINE | REG_EXTENDED); - if (error != 0) - exit_regerror(error, &re); - - pmatch = xalloc(sizeof(regmatch_t) * (re.re_nsub+1)); - do_subst(argv[2], &re, - argc != 4 && argv[4] != NULL ? argv[4] : "", pmatch); - pbstr(getstring()); - free(pmatch); - regfree(&re); -} - -void -doregexp(argv, argc) - const char *argv[]; - int argc; -{ - int error; - regex_t re; - regmatch_t *pmatch; - - if (argc <= 3) { - warnx("Too few arguments to regexp"); - return; - } - error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], - REG_EXTENDED); - if (error != 0) - exit_regerror(error, &re); - - pmatch = xalloc(sizeof(regmatch_t) * (re.re_nsub+1)); - if (argv[4] == NULL || argc == 4) - do_regexpindex(argv[2], &re, pmatch); - else - do_regexp(argv[2], &re, argv[4], pmatch); - free(pmatch); - regfree(&re); -} - -void -doesyscmd(cmd) - const char *cmd; -{ - int p[2]; - pid_t pid, cpid; - char *argv[4]; - int cc; - int status; - - /* Follow gnu m4 documentation: first flush buffers. */ - fflush(NULL); - - argv[0] = "sh"; - argv[1] = "-c"; - argv[2] = (char *)cmd; - argv[3] = NULL; - - /* Just set up standard output, share stderr and stdin with m4 */ - if (pipe(p) == -1) - err(1, "bad pipe"); - switch(cpid = fork()) { - case -1: - err(1, "bad fork"); - /* NOTREACHED */ - case 0: - (void) close(p[0]); - (void) dup2(p[1], 1); - (void) close(p[1]); - execv(_PATH_BSHELL, argv); - exit(1); - default: - /* Read result in two stages, since m4's buffer is - * pushback-only. */ - (void) close(p[1]); - do { - char result[BUFSIZE]; - cc = read(p[0], result, sizeof result); - if (cc > 0) - addchars(result, cc); - } while (cc > 0 || (cc == -1 && errno == EINTR)); - - (void) close(p[0]); - while ((pid = wait(&status)) != cpid && pid >= 0) - continue; - pbstr(getstring()); - } -} diff --git a/usr.bin/m4/look.c b/usr.bin/m4/look.c deleted file mode 100644 index ffb58e05167c..000000000000 --- a/usr.bin/m4/look.c +++ /dev/null @@ -1,151 +0,0 @@ -/* $OpenBSD: look.c,v 1.9 2002/02/16 21:27:48 millert Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/6/93"; -#endif /* not lint */ - -/* - * look.c - * Facility: m4 macro processor - * by: oz - */ - -#include <sys/types.h> -#include <stdio.h> -#include <stdlib.h> -#include <stddef.h> -#include <string.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" - -static void freent(ndptr); - -unsigned -hash(name) - const char *name; -{ - unsigned int h = 0; - while (*name) - h = (h << 5) + h + *name++; - return (h); -} - -/* - * find name in the hash table - */ -ndptr -lookup(name) - const char *name; -{ - ndptr p; - unsigned int h; - - h = hash(name); - for (p = hashtab[h % HASHSIZE]; p != nil; p = p->nxtptr) - if (h == p->hv && STREQ(name, p->name)) - break; - return (p); -} - -/* - * hash and create an entry in the hash table. - * The new entry is added in front of a hash bucket. - */ -ndptr -addent(name) - const char *name; -{ - unsigned int h; - ndptr p; - - h = hash(name); - p = (ndptr) xalloc(sizeof(struct ndblock)); - p->nxtptr = hashtab[h % HASHSIZE]; - hashtab[h % HASHSIZE] = p; - p->name = xstrdup(name); - p->hv = h; - return p; -} - -static void -freent(p) - ndptr p; -{ - free((char *) p->name); - if (p->defn != null) - free((char *) p->defn); - free((char *) p); -} - -/* - * remove an entry from the hashtable - */ -void -remhash(name, all) - const char *name; - int all; -{ - unsigned int h; - ndptr xp, tp, mp; - - h = hash(name); - mp = hashtab[h % HASHSIZE]; - tp = nil; - while (mp != nil) { - if (mp->hv == h && STREQ(mp->name, name)) { - mp = mp->nxtptr; - if (tp == nil) { - freent(hashtab[h % HASHSIZE]); - hashtab[h % HASHSIZE] = mp; - } - else { - xp = tp->nxtptr; - tp->nxtptr = mp; - freent(xp); - } - if (!all) - break; - } - else { - tp = mp; - mp = mp->nxtptr; - } - } -} diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c deleted file mode 100644 index 644b8978844b..000000000000 --- a/usr.bin/m4/main.c +++ /dev/null @@ -1,636 +0,0 @@ -/* $OpenBSD: main.c,v 1.52 2002/02/16 21:27:48 millert Exp $ */ -/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ - -/*- - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1989, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; -#else -static char rcsid[] = "$OpenBSD: main.c,v 1.52 2002/02/16 21:27:48 millert Exp $"; -#endif -#endif /* not lint */ - -/* - * main.c - * Facility: m4 macro processor - * by: oz - */ - -#include <sys/types.h> -#include <assert.h> -#include <signal.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <stddef.h> -#include <stdlib.h> -#include <err.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" -#include "pathnames.h" - -ndptr hashtab[HASHSIZE]; /* hash table for macros etc. */ -stae *mstack; /* stack of m4 machine */ -char *sstack; /* shadow stack, for string space extension */ -static size_t STACKMAX; /* current maximum size of stack */ -int sp; /* current m4 stack pointer */ -int fp; /* m4 call frame pointer */ -struct input_file infile[MAXINP];/* input file stack (0=stdin) */ -FILE **outfile; /* diversion array(0=bitbucket)*/ -int maxout; -FILE *active; /* active output file pointer */ -int ilevel = 0; /* input file stack pointer */ -int oindex = 0; /* diversion index.. */ -char *null = ""; /* as it says.. just a null.. */ -char *m4wraps = ""; /* m4wrap string default.. */ -char lquote[MAXCCHARS+1] = {LQUOTE}; /* left quote character (`) */ -char rquote[MAXCCHARS+1] = {RQUOTE}; /* right quote character (') */ -char scommt[MAXCCHARS+1] = {SCOMMT}; /* start character for comment */ -char ecommt[MAXCCHARS+1] = {ECOMMT}; /* end character for comment */ - -struct keyblk keywrds[] = { /* m4 keywords to be installed */ - { "include", INCLTYPE }, - { "sinclude", SINCTYPE }, - { "define", DEFITYPE }, - { "defn", DEFNTYPE }, - { "divert", DIVRTYPE | NOARGS }, - { "expr", EXPRTYPE }, - { "eval", EXPRTYPE }, - { "substr", SUBSTYPE }, - { "ifelse", IFELTYPE }, - { "ifdef", IFDFTYPE }, - { "len", LENGTYPE }, - { "incr", INCRTYPE }, - { "decr", DECRTYPE }, - { "dnl", DNLNTYPE | NOARGS }, - { "changequote", CHNQTYPE | NOARGS }, - { "changecom", CHNCTYPE | NOARGS }, - { "index", INDXTYPE }, -#ifdef EXTENDED - { "paste", PASTTYPE }, - { "spaste", SPASTYPE }, - /* Newer extensions, needed to handle gnu-m4 scripts */ - { "indir", INDIRTYPE}, - { "builtin", BUILTINTYPE}, - { "patsubst", PATSTYPE}, - { "regexp", REGEXPTYPE}, - { "esyscmd", ESYSCMDTYPE}, - { "__file__", FILENAMETYPE | NOARGS}, - { "__line__", LINETYPE | NOARGS}, -#endif - { "popdef", POPDTYPE }, - { "pushdef", PUSDTYPE }, - { "dumpdef", DUMPTYPE | NOARGS }, - { "shift", SHIFTYPE | NOARGS }, - { "translit", TRNLTYPE }, - { "undefine", UNDFTYPE }, - { "undivert", UNDVTYPE | NOARGS }, - { "divnum", DIVNTYPE | NOARGS }, - { "maketemp", MKTMTYPE }, - { "errprint", ERRPTYPE | NOARGS }, - { "m4wrap", M4WRTYPE | NOARGS }, - { "m4exit", EXITTYPE | NOARGS }, - { "syscmd", SYSCTYPE }, - { "sysval", SYSVTYPE | NOARGS }, - { "traceon", TRACEONTYPE | NOARGS }, - { "traceoff", TRACEOFFTYPE | NOARGS }, - -#if defined(unix) || defined(__unix__) - { "unix", SELFTYPE | NOARGS }, -#else -#ifdef vms - { "vms", SELFTYPE | NOARGS }, -#endif -#endif -}; - -#define MAXKEYS (sizeof(keywrds)/sizeof(struct keyblk)) - -extern int optind; -extern char *optarg; - -#define MAXRECORD 50 -static struct position { - char *name; - unsigned long line; -} quotes[MAXRECORD], paren[MAXRECORD]; - -static void record(struct position *, int); -static void dump_stack(struct position *, int); - -static void macro(void); -static void initkwds(void); -static ndptr inspect(int, char *); -static int do_look_ahead(int, const char *); - -static void enlarge_stack(void); - -int main(int, char *[]); - -int -main(argc,argv) - int argc; - char *argv[]; -{ - int c; - int n; - char *p; - - if (signal(SIGINT, SIG_IGN) != SIG_IGN) - signal(SIGINT, onintr); - - initkwds(); - initspaces(); - STACKMAX = INITSTACKMAX; - - mstack = (stae *)xalloc(sizeof(stae) * STACKMAX); - sstack = (char *)xalloc(STACKMAX); - - maxout = 0; - outfile = NULL; - resizedivs(MAXOUT); - - while ((c = getopt(argc, argv, "gt:d:D:U:o:I:")) != -1) - switch(c) { - - case 'D': /* define something..*/ - for (p = optarg; *p; p++) - if (*p == '=') - break; - if (*p) - *p++ = EOS; - dodefine(optarg, p); - break; - case 'I': - addtoincludepath(optarg); - break; - case 'U': /* undefine... */ - remhash(optarg, TOP); - break; - case 'g': - mimic_gnu = 1; - break; - case 'd': - set_trace_flags(optarg); - break; - case 't': - mark_traced(optarg, 1); - break; - case 'o': - trace_file(optarg); - break; - case '?': - usage(); - } - - argc -= optind; - argv += optind; - - active = stdout; /* default active output */ - bbase[0] = bufbase; - if (!argc) { - sp = -1; /* stack pointer initialized */ - fp = 0; /* frame pointer initialized */ - set_input(infile+0, stdin, "stdin"); - /* default input (naturally) */ - macro(); - } else - for (; argc--; ++argv) { - p = *argv; - if (p[0] == '-' && p[1] == EOS) - set_input(infile, stdin, "stdin"); - else if (fopen_trypath(infile, p) == NULL) - err(1, "%s", p); - sp = -1; - fp = 0; - macro(); - release_input(infile); - } - - if (*m4wraps) { /* anything for rundown ?? */ - ilevel = 0; /* in case m4wrap includes.. */ - bufbase = bp = buf; /* use the entire buffer */ - pbstr(m4wraps); /* user-defined wrapup act */ - macro(); /* last will and testament */ - } - - if (active != stdout) - active = stdout; /* reset output just in case */ - for (n = 1; n < maxout; n++) /* default wrap-up: undivert */ - if (outfile[n] != NULL) - getdiv(n); - /* remove bitbucket if used */ - if (outfile[0] != NULL) { - (void) fclose(outfile[0]); - } - - return 0; -} - -/* - * Look ahead for `token'. - * (on input `t == token[0]') - * Used for comment and quoting delimiters. - * Returns 1 if `token' present; copied to output. - * 0 if `token' not found; all characters pushed back - */ -static int -do_look_ahead(t, token) - int t; - const char *token; -{ - int i; - - assert((unsigned char)t == (unsigned char)token[0]); - - for (i = 1; *++token; i++) { - t = gpbc(); - if (t == EOF || (unsigned char)t != (unsigned char)*token) { - putback(t); - while (--i) - putback(*--token); - return 0; - } - } - return 1; -} - -#define LOOK_AHEAD(t, token) (t != EOF && \ - (unsigned char)(t)==(unsigned char)(token)[0] && \ - do_look_ahead(t,token)) - -/* - * macro - the work horse.. - */ -static void -macro() -{ - char token[MAXTOK+1]; - int t, l; - ndptr p; - int nlpar; - - cycle { - t = gpbc(); - if (t == '_' || isalpha(t)) { - p = inspect(t, token); - if (p != nil) - putback(l = gpbc()); - if (p == nil || (l != LPAREN && - (p->type & NEEDARGS) != 0)) - outputstr(token); - else { - /* - * real thing.. First build a call frame: - */ - pushf(fp); /* previous call frm */ - pushf(p->type); /* type of the call */ - pushf(0); /* parenthesis level */ - fp = sp; /* new frame pointer */ - /* - * now push the string arguments: - */ - pushs1(p->defn); /* defn string */ - pushs1(p->name); /* macro name */ - pushs(ep); /* start next..*/ - - if (l != LPAREN && PARLEV == 0) { - /* no bracks */ - chrsave(EOS); - - if (sp == STACKMAX) - errx(1, "internal stack overflow"); - eval((const char **) mstack+fp+1, 2, - CALTYP); - - ep = PREVEP; /* flush strspace */ - sp = PREVSP; /* previous sp.. */ - fp = PREVFP; /* rewind stack...*/ - } - } - } else if (t == EOF) { - if (sp > -1) { - warnx( "unexpected end of input, unclosed parenthesis:"); - dump_stack(paren, PARLEV); - exit(1); - } - if (ilevel <= 0) - break; /* all done thanks.. */ - release_input(infile+ilevel--); - bufbase = bbase[ilevel]; - continue; - } - /* - * non-alpha token possibly seen.. - * [the order of else if .. stmts is important.] - */ - else if (LOOK_AHEAD(t,lquote)) { /* strip quotes */ - nlpar = 0; - record(quotes, nlpar++); - /* - * Opening quote: scan forward until matching - * closing quote has been found. - */ - do { - - l = gpbc(); - if (LOOK_AHEAD(l,rquote)) { - if (--nlpar > 0) - outputstr(rquote); - } else if (LOOK_AHEAD(l,lquote)) { - record(quotes, nlpar++); - outputstr(lquote); - } else if (l == EOF) { - if (nlpar == 1) - warnx("unclosed quote:"); - else - warnx("%d unclosed quotes:", nlpar); - dump_stack(quotes, nlpar); - exit(1); - } else { - if (nlpar > 0) { - if (sp < 0) - putc(l, active); - else - CHRSAVE(l); - } - } - } - while (nlpar != 0); - } - - else if (sp < 0 && LOOK_AHEAD(t, scommt)) { - fputs(scommt, active); - - for(;;) { - t = gpbc(); - if (LOOK_AHEAD(t, ecommt)) { - fputs(ecommt, active); - break; - } - if (t == EOF) - break; - putc(t, active); - } - } - - else if (sp < 0) { /* not in a macro at all */ - putc(t, active); /* output directly.. */ - } - - else switch(t) { - - case LPAREN: - if (PARLEV > 0) - chrsave(t); - while (isspace(l = gpbc())) - ; /* skip blank, tab, nl.. */ - putback(l); - record(paren, PARLEV++); - break; - - case RPAREN: - if (--PARLEV > 0) - chrsave(t); - else { /* end of argument list */ - chrsave(EOS); - - if (sp == STACKMAX) - errx(1, "internal stack overflow"); - - eval((const char **) mstack+fp+1, sp-fp, - CALTYP); - - ep = PREVEP; /* flush strspace */ - sp = PREVSP; /* previous sp.. */ - fp = PREVFP; /* rewind stack...*/ - } - break; - - case COMMA: - if (PARLEV == 1) { - chrsave(EOS); /* new argument */ - while (isspace(l = gpbc())) - ; - putback(l); - pushs(ep); - } else - chrsave(t); - break; - - default: - if (LOOK_AHEAD(t, scommt)) { - char *p; - for (p = scommt; *p; p++) - chrsave(*p); - for(;;) { - t = gpbc(); - if (LOOK_AHEAD(t, ecommt)) { - for (p = ecommt; *p; p++) - chrsave(*p); - break; - } - if (t == EOF) - break; - CHRSAVE(t); - } - } else - CHRSAVE(t); /* stack the char */ - break; - } - } -} - -/* - * output string directly, without pushing it for reparses. - */ -void -outputstr(s) - const char *s; -{ - if (sp < 0) - while (*s) - putc(*s++, active); - else - while (*s) - CHRSAVE(*s++); -} - -/* - * build an input token.. - * consider only those starting with _ or A-Za-z. This is a - * combo with lookup to speed things up. - */ -static ndptr -inspect(c, tp) - int c; - char *tp; -{ - char *name = tp; - char *etp = tp+MAXTOK; - ndptr p; - unsigned int h; - - h = *tp++ = c; - - while ((isalnum(c = gpbc()) || c == '_') && tp < etp) - h = (h << 5) + h + (*tp++ = c); - if (c != EOF) - PUTBACK(c); - *tp = EOS; - /* token is too long, it won't match anything, but it can still - * be output. */ - if (tp == ep) { - outputstr(name); - while (isalnum(c = gpbc()) || c == '_') { - if (sp < 0) - putc(c, active); - else - CHRSAVE(c); - } - *name = EOS; - return nil; - } - - for (p = hashtab[h % HASHSIZE]; p != nil; p = p->nxtptr) - if (h == p->hv && STREQ(name, p->name)) - break; - return p; -} - -/* - * initkwds - initialise m4 keywords as fast as possible. - * This very similar to install, but without certain overheads, - * such as calling lookup. Malloc is not used for storing the - * keyword strings, since we simply use the static pointers - * within keywrds block. - */ -static void -initkwds() -{ - size_t i; - unsigned int h; - ndptr p; - - for (i = 0; i < MAXKEYS; i++) { - h = hash(keywrds[i].knam); - p = (ndptr) xalloc(sizeof(struct ndblock)); - p->nxtptr = hashtab[h % HASHSIZE]; - hashtab[h % HASHSIZE] = p; - p->name = xstrdup(keywrds[i].knam); - p->defn = null; - p->hv = h; - p->type = keywrds[i].ktyp & TYPEMASK; - if ((keywrds[i].ktyp & NOARGS) == 0) - p->type |= NEEDARGS; - } -} - -/* Look up a builtin type, even if overridden by the user */ -int -builtin_type(key) - const char *key; -{ - int i; - - for (i = 0; i != MAXKEYS; i++) - if (STREQ(keywrds[i].knam, key)) - return keywrds[i].ktyp; - return -1; -} - -char * -builtin_realname(n) - int n; -{ - int i; - - for (i = 0; i != MAXKEYS; i++) - if (((keywrds[i].ktyp ^ n) & TYPEMASK) == 0) - return keywrds[i].knam; - return NULL; -} - -static void -record(t, lev) - struct position *t; - int lev; -{ - if (lev < MAXRECORD) { - t[lev].name = CURRENT_NAME; - t[lev].line = CURRENT_LINE; - } -} - -static void -dump_stack(t, lev) - struct position *t; - int lev; -{ - int i; - - for (i = 0; i < lev; i++) { - if (i == MAXRECORD) { - fprintf(stderr, " ...\n"); - break; - } - fprintf(stderr, " %s at line %lu\n", - t[i].name, t[i].line); - } -} - - -static void -enlarge_stack() -{ - STACKMAX *= 2; - mstack = realloc(mstack, sizeof(stae) * STACKMAX); - sstack = realloc(sstack, STACKMAX); - if (mstack == NULL || sstack == NULL) - errx(1, "Evaluation stack overflow (%lu)", - (unsigned long)STACKMAX); -} diff --git a/usr.bin/m4/mdef.h b/usr.bin/m4/mdef.h deleted file mode 100644 index 4a10500be28e..000000000000 --- a/usr.bin/m4/mdef.h +++ /dev/null @@ -1,224 +0,0 @@ -/* $OpenBSD: mdef.h,v 1.21 2001/09/27 11:40:33 espie Exp $ */ -/* $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mdef.h 8.1 (Berkeley) 6/6/93 - */ - -#define MACRTYPE 1 -#define DEFITYPE 2 -#define EXPRTYPE 3 -#define SUBSTYPE 4 -#define IFELTYPE 5 -#define LENGTYPE 6 -#define CHNQTYPE 7 -#define SYSCTYPE 8 -#define UNDFTYPE 9 -#define INCLTYPE 10 -#define SINCTYPE 11 -#define PASTTYPE 12 -#define SPASTYPE 13 -#define INCRTYPE 14 -#define IFDFTYPE 15 -#define PUSDTYPE 16 -#define POPDTYPE 17 -#define SHIFTYPE 18 -#define DECRTYPE 19 -#define DIVRTYPE 20 -#define UNDVTYPE 21 -#define DIVNTYPE 22 -#define MKTMTYPE 23 -#define ERRPTYPE 24 -#define M4WRTYPE 25 -#define TRNLTYPE 26 -#define DNLNTYPE 27 -#define DUMPTYPE 28 -#define CHNCTYPE 29 -#define INDXTYPE 30 -#define SYSVTYPE 31 -#define EXITTYPE 32 -#define DEFNTYPE 33 -#define SELFTYPE 34 -#define INDIRTYPE 35 -#define BUILTINTYPE 36 -#define PATSTYPE 37 -#define FILENAMETYPE 38 -#define LINETYPE 39 -#define REGEXPTYPE 40 -#define ESYSCMDTYPE 41 -#define TRACEONTYPE 42 -#define TRACEOFFTYPE 43 - - -#define TYPEMASK 63 /* Keep bits really corresponding to a type. */ -#define RECDEF 256 /* Pure recursive def, don't expand it */ -#define NOARGS 512 /* builtin needs no args */ -#define NEEDARGS 1024 /* mark builtin that need args with this */ - -/* - * m4 special characters - */ - -#define ARGFLAG '$' -#define LPAREN '(' -#define RPAREN ')' -#define LQUOTE '`' -#define RQUOTE '\'' -#define COMMA ',' -#define SCOMMT '#' -#define ECOMMT '\n' - -#ifdef msdos -#define system(str) (-1) -#endif - -/* - * other important constants - */ - -#define EOS '\0' -#define MAXINP 10 /* maximum include files */ -#define MAXOUT 10 /* maximum # of diversions */ -#define BUFSIZE 4096 /* starting size of pushback buffer */ -#define INITSTACKMAX 4096 /* starting size of call stack */ -#define STRSPMAX 4096 /* starting size of string space */ -#define MAXTOK 512 /* maximum chars in a tokn */ -#define HASHSIZE 199 /* maximum size of hashtab */ -#define MAXCCHARS 5 /* max size of comment/quote delim */ - -#define ALL 1 -#define TOP 0 - -#define TRUE 1 -#define FALSE 0 -#define cycle for(;;) - -/* - * m4 data structures - */ - -typedef struct ndblock *ndptr; - -struct ndblock { /* hastable structure */ - char *name; /* entry name.. */ - char *defn; /* definition.. */ - unsigned int type; /* type of the entry.. */ - unsigned int hv; /* hash function value.. */ - ndptr nxtptr; /* link to next entry.. */ -}; - -#define nil ((ndptr) 0) - -struct keyblk { - char *knam; /* keyword name */ - int ktyp; /* keyword type */ -}; - -typedef union { /* stack structure */ - int sfra; /* frame entry */ - char *sstr; /* string entry */ -} stae; - -struct input_file { - FILE *file; - char *name; - unsigned long lineno; - int c; -}; - -#define CURRENT_NAME (infile[ilevel].name) -#define CURRENT_LINE (infile[ilevel].lineno) -/* - * macros for readibility and/or speed - * - * gpbc() - get a possibly pushed-back character - * pushf() - push a call frame entry onto stack - * pushs() - push a string pointer onto stack - */ -#define gpbc() (bp > bufbase) ? *--bp : obtain_char(infile+ilevel) -#define pushf(x) \ - do { \ - if (++sp == STACKMAX) \ - enlarge_stack();\ - mstack[sp].sfra = (x); \ - sstack[sp] = 0; \ - } while (0) - -#define pushs(x) \ - do { \ - if (++sp == STACKMAX) \ - enlarge_stack();\ - mstack[sp].sstr = (x); \ - sstack[sp] = 1; \ - } while (0) - -#define pushs1(x) \ - do { \ - if (++sp == STACKMAX) \ - enlarge_stack();\ - mstack[sp].sstr = (x); \ - sstack[sp] = 0; \ - } while (0) - -/* - * . . - * | . | <-- sp | . | - * +-------+ +-----+ - * | arg 3 ----------------------->| str | - * +-------+ | . | - * | arg 2 ---PREVEP-----+ . - * +-------+ | - * . | | | - * +-------+ | +-----+ - * | plev | PARLEV +-------->| str | - * +-------+ | . | - * | type | CALTYP . - * +-------+ - * | prcf ---PREVFP--+ - * +-------+ | - * | . | PREVSP | - * . | - * +-------+ | - * | <----------+ - * +-------+ - * - */ -#define PARLEV (mstack[fp].sfra) -#define CALTYP (mstack[fp-1].sfra) -#define PREVEP (mstack[fp+3].sstr) -#define PREVSP (fp-3) -#define PREVFP (mstack[fp-2].sfra) diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c deleted file mode 100644 index e4bfa7ef1a8b..000000000000 --- a/usr.bin/m4/misc.c +++ /dev/null @@ -1,381 +0,0 @@ -/* $OpenBSD: misc.c,v 1.26 2001/11/16 23:50:40 deraadt Exp $ */ -/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; -#else -static char rcsid[] = "$OpenBSD: misc.c,v 1.26 2001/11/16 23:50:40 deraadt Exp $"; -#endif -#endif /* not lint */ - -#include <sys/types.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <stddef.h> -#include <string.h> -#include <err.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" -#include "pathnames.h" - - -char *ep; /* first free char in strspace */ -static char *strspace; /* string space for evaluation */ -char *endest; /* end of string space */ -static size_t strsize = STRSPMAX; -static size_t bufsize = BUFSIZE; - -char *buf; /* push-back buffer */ -char *bufbase; /* the base for current ilevel */ -char *bbase[MAXINP]; /* the base for each ilevel */ -char *bp; /* first available character */ -char *endpbb; /* end of push-back buffer */ - - -/* - * find the index of second str in the first str. - */ -ptrdiff_t -indx(s1, s2) - const char *s1; - const char *s2; -{ - char *t; - - t = strstr(s1, s2); - if (t == NULL) - return (-1); - else - return (t - s1); -} -/* - * putback - push character back onto input - */ -void -putback(c) - int c; -{ - if (c == EOF) - return; - if (bp >= endpbb) - enlarge_bufspace(); - *bp++ = c; -} - -/* - * pbstr - push string back onto input - * putback is replicated to improve - * performance. - */ -void -pbstr(s) - const char *s; -{ - size_t n; - - n = strlen(s); - while (endpbb - bp <= n) - enlarge_bufspace(); - while (n > 0) - *bp++ = s[--n]; -} - -/* - * pbnum - convert number to string, push back on input. - */ -void -pbnum(n) - int n; -{ - int num; - - num = (n < 0) ? -n : n; - do { - putback(num % 10 + '0'); - } - while ((num /= 10) > 0); - - if (n < 0) - putback('-'); -} - -/* - * pbunsigned - convert unsigned long to string, push back on input. - */ -void -pbunsigned(n) - unsigned long n; -{ - do { - putback(n % 10 + '0'); - } - while ((n /= 10) > 0); -} - -void -initspaces() -{ - int i; - - strspace = xalloc(strsize+1); - ep = strspace; - endest = strspace+strsize; - buf = (char *)xalloc(bufsize); - bufbase = buf; - bp = buf; - endpbb = buf + bufsize; - for (i = 0; i < MAXINP; i++) - bbase[i] = buf; -} - -void -enlarge_strspace() -{ - char *newstrspace; - int i; - - strsize *= 2; - newstrspace = malloc(strsize + 1); - if (!newstrspace) - errx(1, "string space overflow"); - memcpy(newstrspace, strspace, strsize/2); - for (i = 0; i <= sp; i++) - if (sstack[i]) - mstack[i].sstr = (mstack[i].sstr - strspace) - + newstrspace; - ep = (ep-strspace) + newstrspace; - free(strspace); - strspace = newstrspace; - endest = strspace + strsize; -} - -void -enlarge_bufspace() -{ - char *newbuf; - int i; - - bufsize *= 2; - newbuf = realloc(buf, bufsize); - if (!newbuf) - errx(1, "too many characters pushed back"); - for (i = 0; i < MAXINP; i++) - bbase[i] = (bbase[i]-buf)+newbuf; - bp = (bp-buf)+newbuf; - bufbase = (bufbase-buf)+newbuf; - buf = newbuf; - endpbb = buf+bufsize; -} - -/* - * chrsave - put single char on string space - */ -void -chrsave(c) - int c; -{ - if (ep >= endest) - enlarge_strspace(); - *ep++ = c; -} - -/* - * read in a diversion file, and dispose it. - */ -void -getdiv(n) - int n; -{ - int c; - - if (active == outfile[n]) - errx(1, "undivert: diversion still active"); - rewind(outfile[n]); - while ((c = getc(outfile[n])) != EOF) - putc(c, active); - (void) fclose(outfile[n]); - outfile[n] = NULL; -} - -void -onintr(signo) - int signo; -{ -#define intrmessage "m4: interrupted.\n" - write(STDERR_FILENO, intrmessage, sizeof(intrmessage)-1); - _exit(1); -} - -/* - * killdiv - get rid of the diversion files - */ -void -killdiv() -{ - int n; - - for (n = 0; n < maxout; n++) - if (outfile[n] != NULL) { - (void) fclose(outfile[n]); - } -} - -/* - * resizedivs: allocate more diversion files */ -void -resizedivs(n) - int n; -{ - int i; - - outfile = (FILE **)realloc(outfile, sizeof(FILE *) * n); - if (outfile == NULL) - errx(1, "too many diverts %d", n); - for (i = maxout; i < n; i++) - outfile[i] = NULL; - maxout = n; -} - -void * -xalloc(n) - size_t n; -{ - char *p = malloc(n); - - if (p == NULL) - err(1, "malloc"); - return p; -} - -char * -xstrdup(s) - const char *s; -{ - char *p = strdup(s); - if (p == NULL) - err(1, "strdup"); - return p; -} - -void -usage() -{ - fprintf(stderr, "usage: m4 [-Dname[=val]] [-Uname] [-I dirname...]\n"); - exit(1); -} - -int -obtain_char(f) - struct input_file *f; -{ - if (f->c == EOF) - return EOF; - else if (f->c == '\n') - f->lineno++; - - f->c = fgetc(f->file); - return f->c; -} - -void -set_input(f, real, name) - struct input_file *f; - FILE *real; - const char *name; -{ - f->file = real; - f->lineno = 1; - f->c = 0; - f->name = xstrdup(name); -} - -void -release_input(f) - struct input_file *f; -{ - if (f->file != stdin) - fclose(f->file); - f->c = EOF; - /* - * XXX can't free filename, as there might still be - * error information pointing to it. - */ -} - -void -doprintlineno(f) - struct input_file *f; -{ - pbunsigned(f->lineno); -} - -void -doprintfilename(f) - struct input_file *f; -{ - pbstr(rquote); - pbstr(f->name); - pbstr(lquote); -} - -/* - * buffer_mark/dump_buffer: allows one to save a mark in a buffer, - * and later dump everything that was added since then to a file. - */ -size_t -buffer_mark() -{ - return bp - buf; -} - - -void -dump_buffer(f, m) - FILE *f; - size_t m; -{ - char *s; - - for (s = bp; s-buf > m;) - fputc(*--s, f); -} diff --git a/usr.bin/m4/pathnames.h b/usr.bin/m4/pathnames.h deleted file mode 100644 index dc7f0d3dff54..000000000000 --- a/usr.bin/m4/pathnames.h +++ /dev/null @@ -1,60 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.4 1997/04/04 18:41:29 deraadt Exp $ */ -/* $NetBSD: pathnames.h,v 1.6 1995/09/29 00:27:55 cgd Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 - */ - -/* - * Definitions of diversion files. If the name of the file is changed, - * adjust UNIQUE to point to the wildcard (*) character in the filename. - */ - -#ifdef msdos -#define _PATH_DIVNAME "\\M4*XXXXXX" /* msdos diversion files */ -#define UNIQUE 3 /* unique char location */ -#endif - -#if defined(unix) || defined(__NetBSD__) || defined(__OpenBSD__) -#define _PATH_DIVNAME "/tmp/m4.0XXXXXXXXXX" /* unix diversion files */ -#define UNIQUE 8 /* unique char location */ -#endif - -#ifdef vms -#define _PATH_DIVNAME "sys$login:m4*XXXXXX" /* vms diversion files */ -#define UNIQUE 12 /* unique char location */ -#endif diff --git a/usr.bin/m4/stdd.h b/usr.bin/m4/stdd.h deleted file mode 100644 index 5c869b7f77d3..000000000000 --- a/usr.bin/m4/stdd.h +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: stdd.h,v 1.4 1999/11/09 18:16:18 deraadt Exp $ */ -/* $NetBSD: stdd.h,v 1.2 1995/09/28 05:37:50 tls Exp $ */ - -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Ozan Yigit at York University. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)stdd.h 8.1 (Berkeley) 6/6/93 - */ - -/* - * standard defines - */ - -#define max(a,b) ((a) > (b)? (a): (b)) -#define min(a,b) ((a) < (b)? (a): (b)) - -#define iswhite(c) ((c) == ' ' || (c) == '\t') - -/* - * STREQ is an optimised strcmp(a,b)==0 - * STREQN is an optimised strncmp(a,b,n)==0; assumes n > 0 - */ -#define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0) -#define STREQN(a, b, n) ((a)[0] == (b)[0] && strncmp(a, b, n) == 0) - -#define YES 1 -#define NO 0 diff --git a/usr.bin/m4/trace.c b/usr.bin/m4/trace.c deleted file mode 100644 index 231667edd360..000000000000 --- a/usr.bin/m4/trace.c +++ /dev/null @@ -1,272 +0,0 @@ -/* $OpenBSD: trace.c,v 1.4 2002/02/16 21:27:48 millert Exp $ */ -/* - * Copyright (c) 2001 Marc Espie. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD - * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <stddef.h> -#include <stdio.h> -#include <err.h> -#include <stdlib.h> -#include "mdef.h" -#include "stdd.h" -#include "extern.h" - -FILE *traceout = stderr; - -int traced_macros = 0; - -#define TRACE_ARGS 1 -#define TRACE_EXPANSION 2 -#define TRACE_QUOTE 4 -#define TRACE_FILENAME 8 -#define TRACE_LINENO 16 -#define TRACE_CONT 32 -#define TRACE_ID 64 -#define TRACE_NEWFILE 128 /* not implemented yet */ -#define TRACE_INPUT 256 /* not implemented yet */ -#define TRACE_ALL 512 - -static struct t { - struct t *next; - char *name; - int on; -} *l; - -static unsigned int letter_to_flag(int); -static void print_header(struct input_file *); -static struct t *find_trace_entry(const char *); -static int frame_level(void); - -static unsigned int flags = TRACE_QUOTE | TRACE_EXPANSION; - -static struct t * -find_trace_entry(name) - const char *name; -{ - struct t *n; - - for (n = l; n != NULL; n = n->next) - if (STREQ(n->name, name)) - return n; - return NULL; -} - - -void -mark_traced(name, on) - const char *name; - int on; -{ - struct t *n, *n2; - - traced_macros = 1; - - if (name == NULL) { - if (on) - flags |= TRACE_ALL; - else { - flags &= ~TRACE_ALL; - traced_macros = 0; - } - for (n = l; n != NULL; n = n2) { - n2 = n->next; - free(n->name); - free(n); - } - l = NULL; - } else { - n = find_trace_entry(name); - if (n == NULL) { - n = xalloc(sizeof(struct t)); - n->name = xstrdup(name); - n->next = l; - l = n; - } - n->on = on; - } -} - -int -is_traced(name) - const char *name; -{ - struct t *n; - - for (n = l; n != NULL; n = n->next) - if (STREQ(n->name, name)) - return n->on; - return (flags & TRACE_ALL) ? 1 : 0; -} - -void -trace_file(name) - const char *name; -{ - - if (traceout != stderr) - fclose(traceout); - traceout = fopen(name, "w"); - if (!traceout) - err(1, "can't open %s", name); -} - -static unsigned int -letter_to_flag(c) - int c; -{ - switch(c) { - case 'a': - return TRACE_ARGS; - case 'e': - return TRACE_EXPANSION; - case 'q': - return TRACE_QUOTE; - case 'c': - return TRACE_CONT; - case 'x': - return TRACE_ID; - case 'f': - return TRACE_FILENAME; - case 'l': - return TRACE_LINENO; - case 'p': - return TRACE_NEWFILE; - case 'i': - return TRACE_INPUT; - case 't': - return TRACE_ALL; - case 'V': - return ~0; - default: - return 0; - } -} - -void -set_trace_flags(s) - const char *s; -{ - char mode = 0; - unsigned int f = 0; - - traced_macros = 1; - - if (*s == '+' || *s == '-') - mode = *s++; - while (*s) - f |= letter_to_flag(*s++); - switch(mode) { - case 0: - flags = f; - break; - case '+': - flags |= f; - break; - case '-': - flags &= ~f; - break; - } -} - -static int -frame_level() -{ - int level; - int framep; - - for (framep = fp, level = 0; framep != 0; - level++,framep = mstack[framep-2].sfra) - ; - return level; -} - -static void -print_header(inp) - struct input_file *inp; -{ - fprintf(traceout, "m4trace:"); - if (flags & TRACE_FILENAME) - fprintf(traceout, "%s:", inp->name); - if (flags & TRACE_LINENO) - fprintf(traceout, "%lu:", inp->lineno); - fprintf(traceout, " -%d- ", frame_level()); - if (flags & TRACE_ID) - fprintf(traceout, "id %lu: ", expansion_id); -} - -ssize_t -trace(argv, argc, inp) - const char **argv; - int argc; - struct input_file *inp; -{ - print_header(inp); - if (flags & TRACE_CONT) { - fprintf(traceout, "%s ...\n", argv[1]); - print_header(inp); - } - fprintf(traceout, "%s", argv[1]); - if ((flags & TRACE_ARGS) && argc > 2) { - char delim[3]; - int i; - - delim[0] = LPAREN; - delim[1] = EOS; - for (i = 2; i < argc; i++) { - fprintf(traceout, "%s%s%s%s", delim, - (flags & TRACE_QUOTE) ? lquote : "", - argv[i], - (flags & TRACE_QUOTE) ? rquote : ""); - delim[0] = COMMA; - delim[1] = ' '; - delim[2] = EOS; - } - fprintf(traceout, "%c", RPAREN); - } - if (flags & TRACE_CONT) { - fprintf(traceout, " -> ???\n"); - print_header(inp); - fprintf(traceout, argc > 2 ? "%s(...)" : "%s", argv[1]); - } - if (flags & TRACE_EXPANSION) - return buffer_mark(); - else { - fprintf(traceout, "\n"); - return -1; - } -} - -void -finish_trace(mark) -size_t mark; -{ - fprintf(traceout, " -> "); - if (flags & TRACE_QUOTE) - fprintf(traceout, "%s", lquote); - dump_buffer(traceout, mark); - if (flags & TRACE_QUOTE) - fprintf(traceout, "%s", rquote); - fprintf(traceout, "\n"); -} diff --git a/usr.bin/tip/libacu/biz22.c b/usr.bin/tip/libacu/biz22.c deleted file mode 100644 index cd5ca4acfcc8..000000000000 --- a/usr.bin/tip/libacu/biz22.c +++ /dev/null @@ -1,195 +0,0 @@ -/* $OpenBSD: biz22.c,v 1.7 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: biz22.c,v 1.6 1997/02/11 09:24:11 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)biz22.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: biz22.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -#define DISCONNECT_CMD "\20\04" /* disconnection string */ - -static void sigALRM(); -static int timeout = 0; -static jmp_buf timeoutbuf; - -static int cmd(), detect(); -void biz22_disconnect(); - -/* - * Dial up on a BIZCOMP Model 1022 with either - * tone dialing (mod = "V") - * pulse dialing (mod = "W") - */ -static int -biz_dialer(num, mod) - char *num, *mod; -{ - int connected = 0; - char cbuf[40]; - - if (boolean(value(VERBOSE))) - printf("\nstarting call..."); - /* - * Disable auto-answer and configure for tone/pulse - * dialing - */ - if (cmd("\02K\r")) { - printf("can't initialize bizcomp..."); - return (0); - } - (void)strcpy(cbuf, "\02.\r"); - cbuf[1] = *mod; - if (cmd(cbuf)) { - printf("can't set dialing mode..."); - return (0); - } - (void)snprintf(cbuf, sizeof(cbuf), "\02D%s\r", num); - write(FD, cbuf, strlen(cbuf)); - if (!detect("7\r")) { - printf("can't get dial tone..."); - return (0); - } - if (boolean(value(VERBOSE))) - printf("ringing..."); - /* - * The reply from the BIZCOMP should be: - * 2 \r or 7 \r failure - * 1 \r success - */ - connected = detect("1\r"); -#ifdef ACULOG - if (timeout) { - char line[80]; - - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "biz1022", line); - } -#endif - if (timeout) - biz22_disconnect(); /* insurance */ - return (connected); -} - -int -biz22w_dialer(num, acu) - char *num, *acu; -{ - - return (biz_dialer(num, "W")); -} - -int -biz22f_dialer(num, acu) - char *num, *acu; -{ - - return (biz_dialer(num, "V")); -} - -void -biz22_disconnect() -{ - write(FD, DISCONNECT_CMD, 4); - sleep(2); - tcflush(FD, TCIOFLUSH); -} - -void -biz22_abort() -{ - - write(FD, "\02", 1); -} - -static void -sigALRM() -{ - - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int -cmd(s) - char *s; -{ - sig_t f; - char c; - - write(FD, s, strlen(s)); - f = signal(SIGALRM, sigALRM); - if (setjmp(timeoutbuf)) { - biz22_abort(); - signal(SIGALRM, f); - return (1); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - signal(SIGALRM, f); - c &= 0177; - return (c != '\r'); -} - -static int -detect(s) - char *s; -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - while (*s) { - if (setjmp(timeoutbuf)) { - biz22_abort(); - break; - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - c &= 0177; - if (c != *s++) - return (0); - } - signal(SIGALRM, f); - return (timeout == 0); -} diff --git a/usr.bin/tip/libacu/biz31.c b/usr.bin/tip/libacu/biz31.c deleted file mode 100644 index 5522d652aed0..000000000000 --- a/usr.bin/tip/libacu/biz31.c +++ /dev/null @@ -1,254 +0,0 @@ -/* $OpenBSD: biz31.c,v 1.6 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: biz31.c,v 1.5 1997/02/11 09:24:14 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)biz31.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: biz31.c,v 1.6 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -#define MAXRETRY 3 /* sync up retry count */ -#define DISCONNECT_CMD "\21\25\11\24" /* disconnection string */ - -static void sigALRM(); -static int timeout = 0; -static jmp_buf timeoutbuf; - -/* - * Dial up on a BIZCOMP Model 1031 with either - * tone dialing (mod = "f") - * pulse dialing (mod = "w") - */ -static int -biz_dialer(num, mod) - char *num, *mod; -{ - int connected = 0; - - if (!bizsync(FD)) { - logent(value(HOST), "", "biz", "out of sync"); - printf("bizcomp out of sync\n"); - delock(uucplock); - exit(0); - } - if (boolean(value(VERBOSE))) - printf("\nstarting call..."); - echo("#\rk$\r$\n"); /* disable auto-answer */ - echo("$>$.$ #\r"); /* tone/pulse dialing */ - echo(mod); - echo("$\r$\n"); - echo("$>$.$ #\re$ "); /* disconnection sequence */ - echo(DISCONNECT_CMD); - echo("\r$\n$\r$\n"); - echo("$>$.$ #\rr$ "); /* repeat dial */ - echo(num); - echo("\r$\n"); - if (boolean(value(VERBOSE))) - printf("ringing..."); - /* - * The reply from the BIZCOMP should be: - * `^G NO CONNECTION\r\n^G\r\n' failure - * ` CONNECTION\r\n^G' success - */ - connected = detect(" "); -#ifdef ACULOG - if (timeout) { - char line[80]; - - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "biz", line); - } -#endif - if (!connected) - flush(" NO CONNECTION\r\n\07\r\n"); - else - flush("CONNECTION\r\n\07"); - if (timeout) - biz31_disconnect(); /* insurance */ - return (connected); -} - -biz31w_dialer(num, acu) - char *num, *acu; -{ - - return (biz_dialer(num, "w")); -} - -biz31f_dialer(num, acu) - char *num, *acu; -{ - - return (biz_dialer(num, "f")); -} - -biz31_disconnect() -{ - - write(FD, DISCONNECT_CMD, 4); - sleep(2); - tcflush(FD, TCIOFLUSH); -} - -biz31_abort() -{ - - write(FD, "\33", 1); -} - -static int -echo(s) - char *s; -{ - char c; - - while (c = *s++) switch (c) { - - case '$': - read(FD, &c, 1); - s++; - break; - - case '#': - c = *s++; - write(FD, &c, 1); - break; - - default: - write(FD, &c, 1); - read(FD, &c, 1); - } -} - -static void -sigALRM() -{ - - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int -detect(s) - char *s; -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - while (*s) { - if (setjmp(timeoutbuf)) { - printf("\07timeout waiting for reply\n"); - biz31_abort(); - break; - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - if (c != *s++) - break; - } - signal(SIGALRM, f); - return (timeout == 0); -} - -static int -flush(s) - char *s; -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - while (*s++) { - if (setjmp(timeoutbuf)) - break; - alarm(10); - read(FD, &c, 1); - alarm(0); - } - signal(SIGALRM, f); - timeout = 0; /* guard against disconnection */ -} - -/* - * This convoluted piece of code attempts to get - * the bizcomp in sync. If you don't have the capacity or nread - * call there are gory ways to simulate this. - */ -static int -bizsync(fd) -{ -#ifdef FIOCAPACITY - struct capacity b; -# define chars(b) ((b).cp_nbytes) -# define IOCTL FIOCAPACITY -#endif -#ifdef FIONREAD - long b; -# define chars(b) (b) -# define IOCTL FIONREAD -#endif - int already = 0; - char buf[10]; - -retry: - if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0 && chars(b) > 0) - tcflush(FD, TCIOFLUSH); - write(fd, "\rp>\r", 4); - sleep(1); - if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0) { - if (chars(b) != 10) { - nono: - if (already > MAXRETRY) - return (0); - write(fd, DISCONNECT_CMD, 4); - sleep(2); - already++; - goto retry; - } else { - read(fd, buf, 10); - if (strncmp(buf, "p >\r\n\r\n>", 8)) - goto nono; - } - } - return (1); -} diff --git a/usr.bin/tip/libacu/courier.c b/usr.bin/tip/libacu/courier.c deleted file mode 100644 index 728ccc9f4377..000000000000 --- a/usr.bin/tip/libacu/courier.c +++ /dev/null @@ -1,354 +0,0 @@ -/* $OpenBSD: courier.c,v 1.9 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: courier.c,v 1.7 1997/02/11 09:24:16 mrg Exp $ */ - -/* - * Copyright (c) 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)courier.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: courier.c,v 1.9 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * Routines for calling up on a Courier modem. - * Derived from Hayes driver. - */ -#include "tip.h" -#include <sys/ioctl.h> -#include <stdio.h> - -#define MAXRETRY 5 - -static void sigALRM(); -static int timeout = 0; -static int connected = 0; -static jmp_buf timeoutbuf, intbuf; -static int coursync(), cour_connect(), cour_swallow(); -void cour_nap(); - -void cour_disconnect __P((void)); - -int -cour_dialer(num, acu) - char *num; - char *acu; -{ - char *cp; -#ifdef ACULOG - char line[80]; -#endif - struct termios cntrl; - - if (boolean(value(VERBOSE))) - printf("Using \"%s\"\n", acu); - - tcgetattr(FD, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(FD, TCSAFLUSH, &cntrl); - /* - * Get in synch. - */ - if (!coursync()) { -badsynch: - printf("can't synchronize with courier\n"); -#ifdef ACULOG - logent(value(HOST), num, "courier", "can't synch up"); -#endif - return (0); - } - cour_write(FD, "AT E0\r", 6); /* turn off echoing */ - sleep(1); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - cour_verbose_read(); -#endif - tcflush(FD, TCIOFLUSH); - cour_write(FD, "AT C1 E0 H0 Q0 X6 V1\r", 21); - if (!cour_swallow("\r\nOK\r\n")) - goto badsynch; - fflush(stdout); - cour_write(FD, "AT D", 4); - for (cp = num; *cp; cp++) - if (*cp == '=') - *cp = ','; - cour_write(FD, num, strlen(num)); - cour_write(FD, "\r", 1); - connected = cour_connect(); -#ifdef ACULOG - if (timeout) { - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "cour", line); - } -#endif - if (timeout) - cour_disconnect(); - return (connected); -} - -void -cour_disconnect() -{ - /* first hang up the modem*/ - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - coursync(); /* reset */ - close(FD); -} - -void -cour_abort() -{ - cour_write(FD, "\r", 1); /* send anything to abort the call */ - cour_disconnect(); -} - -static void -sigALRM() -{ - printf("\07timeout waiting for reply\n"); - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int -cour_swallow(match) - char *match; -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - do { - if (*match =='\0') { - signal(SIGALRM, f); - return (1); - } - if (setjmp(timeoutbuf)) { - signal(SIGALRM, f); - return (0); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - c &= 0177; -#ifdef DEBUG - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } while (c == *match++); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - fflush(stdout); -#endif - signal(SIGALRM, SIG_DFL); - return (0); -} - -struct baud_msg { - char *msg; - int baud; -} baud_msg[] = { - "", B300, - " 1200", B1200, - " 2400", B2400, - " 9600", B9600, - " 9600/ARQ", B9600, - 0, 0, -}; - -static int -cour_connect() -{ - char c; - int nc, nl, n; - char dialer_buf[64]; - struct baud_msg *bm; - sig_t f; - - if (cour_swallow("\r\n") == 0) - return (0); - f = signal(SIGALRM, sigALRM); -again: - nc = 0; nl = sizeof(dialer_buf)-1; - bzero(dialer_buf, sizeof(dialer_buf)); - timeout = 0; - for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) { - if (setjmp(timeoutbuf)) - break; - alarm(number(value(DIALTIMEOUT))); - n = read(FD, &c, 1); - alarm(0); - if (n <= 0) - break; - c &= 0x7f; - if (c == '\r') { - if (cour_swallow("\n") == 0) - break; - if (!dialer_buf[0]) - goto again; - if (strcmp(dialer_buf, "RINGING") == 0 && - boolean(value(VERBOSE))) { -#ifdef DEBUG - printf("%s\r\n", dialer_buf); -#endif - goto again; - } - if (strncmp(dialer_buf, "CONNECT", - sizeof("CONNECT")-1) != 0) - break; - for (bm = baud_msg ; bm->msg ; bm++) - if (strcmp(bm->msg, - dialer_buf+sizeof("CONNECT")-1) == 0) { - struct termios cntrl; - - tcgetattr(FD, &cntrl); - cfsetospeed(&cntrl, bm->baud); - cfsetispeed(&cntrl, bm->baud); - tcsetattr(FD, TCSAFLUSH, &cntrl); - signal(SIGALRM, f); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - printf("%s\r\n", dialer_buf); -#endif - return (1); - } - break; - } - dialer_buf[nc] = c; -#ifdef notdef - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } - printf("%s\r\n", dialer_buf); - signal(SIGALRM, f); - return (0); -} - -/* - * This convoluted piece of code attempts to get - * the courier in sync. - */ -static int -coursync() -{ - int already = 0; - int len; - char buf[40]; - - while (already++ < MAXRETRY) { - tcflush(FD, TCIOFLUSH); - cour_write(FD, "\rAT Z\r", 6); /* reset modem */ - bzero(buf, sizeof(buf)); - sleep(1); - ioctl(FD, FIONREAD, &len); - if (len) { - len = read(FD, buf, sizeof(buf)); -#ifdef DEBUG - buf[len] = '\0'; - printf("coursync: (\"%s\")\n\r", buf); -#endif - if (strchr(buf, '0') || - (strchr(buf, 'O') && strchr(buf, 'K'))) - return(1); - } - /* - * If not strapped for DTR control, - * try to get command mode. - */ - sleep(1); - cour_write(FD, "+++", 3); - sleep(1); - /* - * Toggle DTR to force anyone off that might have left - * the modem connected. - */ - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - } - cour_write(FD, "\rAT Z\r", 6); - return (0); -} - -static void -cour_write(fd, cp, n) -int fd; -char *cp; -int n; -{ -#ifdef notdef - if (boolean(value(VERBOSE))) - write(1, cp, n); -#endif - tcdrain(fd); - cour_nap(); - for ( ; n-- ; cp++) { - write(fd, cp, 1); - tcdrain(fd); - cour_nap(); - } -} - -#ifdef DEBUG -cour_verbose_read() -{ - int n = 0; - char buf[BUFSIZ]; - - if (ioctl(FD, FIONREAD, &n) < 0) - return; - if (n <= 0) - return; - if (read(FD, buf, n) != n) - return; - write(1, buf, n); -} -#endif - -/* Give the courier 50 milliseconds between characters */ -void -cour_nap() -{ - struct timespec ts; - - ts.tv_sec = 0; - ts.tv_nsec = 50 * 1000000; - - nanosleep(&ts, NULL); -} diff --git a/usr.bin/tip/libacu/df.c b/usr.bin/tip/libacu/df.c deleted file mode 100644 index 2fa0a0b320a1..000000000000 --- a/usr.bin/tip/libacu/df.c +++ /dev/null @@ -1,145 +0,0 @@ -/* $OpenBSD: df.c,v 1.5 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: df.c,v 1.4 1995/10/29 00:49:51 pk Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)df.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: df.c,v 1.5 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * Dial the DF02-AC or DF03-AC - */ - -#include "tip.h" - -static jmp_buf Sjbuf; -static void timeout(); - -int -df02_dialer(num, acu) - char *num, *acu; -{ - - return (df_dialer(num, acu, 0)); -} - -int -df03_dialer(num, acu) - char *num, *acu; -{ - - return (df_dialer(num, acu, 1)); -} - -int -df_dialer(num, acu, df03) - char *num, *acu; - int df03; -{ - int f = FD; - struct termios cntrl; - int speed = 0; - char c = '\0'; - - tcgetattr(f, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(f, TCSANOW, &cntrl); - if (setjmp(Sjbuf)) { - printf("connection timed out\r\n"); - df_disconnect(); - return (0); - } - if (boolean(value(VERBOSE))) - printf("\ndialing..."); - fflush(stdout); -#ifdef TIOCMSET - if (df03) { - int st = TIOCM_ST; /* secondary Transmit flag */ - - tcgetattr(f, &cntrl); - speed = cfgetospeed(&cntrl); - if (speed != B1200) { /* must dial at 1200 baud */ - cfsetospeed(&cntrl, B1200); - cfsetispeed(&cntrl, B1200); - tcsetattr(f, TCSAFLUSH, &cntrl); - ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */ - } else - ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */ - } -#endif - signal(SIGALRM, timeout); - alarm(5 * strlen(num) + 10); - tcflush(f, TCIOFLUSH); - write(f, "\001", 1); - sleep(1); - write(f, "\002", 1); - write(f, num, strlen(num)); - read(f, &c, 1); -#ifdef TIOCMSET - if (df03 && speed != B1200) { - cfsetospeed(&cntrl, speed); - cfsetispeed(&cntrl, speed); - tcsetattr(f, TCSAFLUSH, &cntrl); - } -#endif - return (c == 'A'); -} - -void -df_disconnect() -{ - write(FD, "\001", 1); - sleep(1); - tcflush(FD, TCIOFLUSH); -} - - -void -df_abort() -{ - - df_disconnect(); -} - - -static void -timeout() -{ - - longjmp(Sjbuf, 1); -} diff --git a/usr.bin/tip/libacu/dn11.c b/usr.bin/tip/libacu/dn11.c deleted file mode 100644 index 3f3461594296..000000000000 --- a/usr.bin/tip/libacu/dn11.c +++ /dev/null @@ -1,152 +0,0 @@ -/* $OpenBSD: dn11.c,v 1.5 2001/11/19 19:02:16 mpech Exp $ */ -/* $NetBSD: dn11.c,v 1.4 1995/10/29 00:49:53 pk Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)dn11.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: dn11.c,v 1.5 2001/11/19 19:02:16 mpech Exp $"; -#endif /* not lint */ - -/* - * Routines for dialing up on DN-11 - */ -#include "tip.h" - -void dn_abort(); -void alarmtr(); -static jmp_buf jmpbuf; -static int child = -1, dn; - -int -dn_dialer(num, acu) - char *num, *acu; -{ - int lt, nw; - int timelim; - struct termios cntrl; - - if (boolean(value(VERBOSE))) - printf("\nstarting call..."); - if ((dn = open(acu, 1)) < 0) { - if (errno == EBUSY) - printf("line busy..."); - else - printf("acu open error..."); - return (0); - } - if (setjmp(jmpbuf)) { - kill(child, SIGKILL); - close(dn); - return (0); - } - signal(SIGALRM, alarmtr); - timelim = 5 * strlen(num); - alarm(timelim < 30 ? 30 : timelim); - if ((child = fork()) == 0) { - /* - * ignore this stuff for aborts - */ - signal(SIGALRM, SIG_IGN); - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - sleep(2); - nw = write(dn, num, lt = strlen(num)); - exit(nw != lt); - } - /* - * open line - will return on carrier - */ - if ((FD = open(DV, 2)) < 0) { - if (errno == EIO) - printf("lost carrier..."); - else - printf("dialup line open failed..."); - alarm(0); - kill(child, SIGKILL); - close(dn); - return (0); - } - alarm(0); - tcgetattr(dn, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(dn, TCSANOW, &cntrl); - signal(SIGALRM, SIG_DFL); - while ((nw = wait(<)) != child && nw != -1) - ; - fflush(stdout); - close(dn); - if (lt != 0) { - close(FD); - return (0); - } - return (1); -} - -void -alarmtr() -{ - alarm(0); - longjmp(jmpbuf, 1); -} - -/* - * Insurance, for some reason we don't seem to be - * hanging up... - */ -void -dn_disconnect() -{ - - sleep(2); - if (FD > 0) - ioctl(FD, TIOCCDTR, 0); - close(FD); -} - -void -dn_abort() -{ - - sleep(2); - if (child > 0) - kill(child, SIGKILL); - if (dn > 0) - close(dn); - if (FD > 0) - ioctl(FD, TIOCCDTR, 0); - close(FD); -} diff --git a/usr.bin/tip/libacu/hayes.c b/usr.bin/tip/libacu/hayes.c deleted file mode 100644 index 19ee8f80abe6..000000000000 --- a/usr.bin/tip/libacu/hayes.c +++ /dev/null @@ -1,321 +0,0 @@ -/* $OpenBSD: hayes.c,v 1.8 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: hayes.c,v 1.6 1997/02/11 09:24:17 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)hayes.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: hayes.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * Routines for calling up on a Hayes Modem - * (based on the old VenTel driver). - * The modem is expected to be strapped for "echo". - * Also, the switches enabling the DTR and CD lines - * must be set correctly. - * NOTICE: - * The easy way to hang up a modem is always simply to - * clear the DTR signal. However, if the +++ sequence - * (which switches the modem back to local mode) is sent - * before modem is hung up, removal of the DTR signal - * has no effect (except that it prevents the modem from - * recognizing commands). - * (by Helge Skrivervik, Calma Company, Sunnyvale, CA. 1984) - */ -/* - * TODO: - * It is probably not a good idea to switch the modem - * state between 'verbose' and terse (status messages). - * This should be kicked out and we should use verbose - * mode only. This would make it consistent with normal - * interactive use thru the command 'tip dialer'. - */ -#include "tip.h" - -#include <termios.h> -#include <sys/ioctl.h> - -#define min(a,b) ((a < b) ? a : b) - -static void sigALRM(); -static int timeout = 0; -static jmp_buf timeoutbuf; -static char gobble(); -#define DUMBUFLEN 40 -static char dumbuf[DUMBUFLEN]; - -#define DIALING 1 -#define IDLE 2 -#define CONNECTED 3 -#define FAILED 4 -static int state = IDLE; - -int -hay_dialer(num, acu) - char *num; - char *acu; -{ - char *cp; - int connected = 0; - char dummy; - struct termios cntrl; -#ifdef ACULOG - char line[80]; -#endif - if (hay_sync() == 0) /* make sure we can talk to the modem */ - return(0); - if (boolean(value(VERBOSE))) - printf("\ndialing..."); - fflush(stdout); - tcgetattr(FD, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(FD, TCSANOW, &cntrl); - tcflush(FD, TCIOFLUSH); - write(FD, "ATv0\r", 5); /* tell modem to use short status codes */ - gobble("\r"); - gobble("\r"); - write(FD, "ATTD", 4); /* send dial command */ - for (cp = num; *cp; cp++) - if (*cp == '=') - *cp = ','; - write(FD, num, strlen(num)); - state = DIALING; - write(FD, "\r", 1); - connected = 0; - if (gobble("\r")) { - if ((dummy = gobble("01234")) != '1') - error_rep(dummy); - else - connected = 1; - } - if (connected) - state = CONNECTED; - else { - state = FAILED; - return (connected); /* lets get out of here.. */ - } - tcflush(FD, TCIOFLUSH); -#ifdef ACULOG - if (timeout) { - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "hayes", line); - } -#endif - if (timeout) - hay_disconnect(); /* insurance */ - return (connected); -} - - -void -hay_disconnect() -{ - /* first hang up the modem*/ -#ifdef DEBUG - printf("\rdisconnecting modem....\n\r"); -#endif - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - goodbye(); -} - -void -hay_abort() -{ - - write(FD, "\r", 1); /* send anything to abort the call */ - hay_disconnect(); -} - -static void -sigALRM() -{ - - printf("\07timeout waiting for reply\n\r"); - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static char -gobble(match) - char *match; -{ - char c; - sig_t f; - int i, status = 0; - - f = signal(SIGALRM, sigALRM); - timeout = 0; -#ifdef DEBUG - printf("\ngobble: waiting for %s\n", match); -#endif - do { - if (setjmp(timeoutbuf)) { - signal(SIGALRM, f); - return (0); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - c &= 0177; -#ifdef DEBUG - printf("%c 0x%x ", c, c); -#endif - for (i = 0; i < strlen(match); i++) - if (c == match[i]) - status = c; - } while (status == 0); - signal(SIGALRM, SIG_DFL); -#ifdef DEBUG - printf("\n"); -#endif - return (status); -} - -static void -error_rep(c) - char c; -{ - printf("\n\r"); - switch (c) { - - case '0': - printf("OK"); - break; - - case '1': - printf("CONNECT"); - break; - - case '2': - printf("RING"); - break; - - case '3': - printf("NO CARRIER"); - break; - - case '4': - printf("ERROR in input"); - break; - - case '5': - printf("CONNECT 1200"); - break; - - default: - printf("Unknown Modem error: %c (0x%x)", c, c); - } - printf("\n\r"); - return; -} - -/* - * set modem back to normal verbose status codes. - */ -void -goodbye() -{ - int len; - char c; - - tcflush(FD, TCIOFLUSH); - if (hay_sync()) { - sleep(1); -#ifndef DEBUG - tcflush(FD, TCIOFLUSH); -#endif - write(FD, "ATH0\r", 5); /* insurance */ -#ifndef DEBUG - c = gobble("03"); - if (c != '0' && c != '3') { - printf("cannot hang up modem\n\r"); - printf("please use 'tip dialer' to make sure the line is hung up\n\r"); - } -#endif - sleep(1); - ioctl(FD, FIONREAD, &len); -#ifdef DEBUG - printf("goodbye1: len=%d -- ", len); - rlen = read(FD, dumbuf, min(len, DUMBUFLEN)); - dumbuf[rlen] = '\0'; - printf("read (%d): %s\r\n", rlen, dumbuf); -#endif - write(FD, "ATv1\r", 5); - sleep(1); -#ifdef DEBUG - ioctl(FD, FIONREAD, &len); - printf("goodbye2: len=%d -- ", len); - rlen = read(FD, dumbuf, min(len, DUMBUFLEN)); - dumbuf[rlen] = '\0'; - printf("read (%d): %s\r\n", rlen, dumbuf); -#endif - } - tcflush(FD, TCIOFLUSH); - ioctl(FD, TIOCCDTR, 0); /* clear DTR (insurance) */ - close(FD); -} - -#define MAXRETRY 5 - -int -hay_sync() -{ - int len, retry = 0; - - while (retry++ <= MAXRETRY) { - write(FD, "AT\r", 3); - sleep(1); - ioctl(FD, FIONREAD, &len); - if (len) { - len = read(FD, dumbuf, min(len, DUMBUFLEN)); - if (strchr(dumbuf, '0') || - (strchr(dumbuf, 'O') && strchr(dumbuf, 'K'))) - return(1); -#ifdef DEBUG - dumbuf[len] = '\0'; - printf("hay_sync: (\"%s\") %d\n\r", dumbuf, retry); -#endif - } - ioctl(FD, TIOCCDTR, 0); - ioctl(FD, TIOCSDTR, 0); - } - printf("Cannot synchronize with hayes...\n\r"); - return(0); -} diff --git a/usr.bin/tip/libacu/t3000.c b/usr.bin/tip/libacu/t3000.c deleted file mode 100644 index 1f0509104475..000000000000 --- a/usr.bin/tip/libacu/t3000.c +++ /dev/null @@ -1,370 +0,0 @@ -/* $OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: t3000.c,v 1.5 1997/02/11 09:24:18 mrg Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)t3000.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: t3000.c,v 1.9 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * Routines for calling up on a Telebit T3000 modem. - * Derived from Courier driver. - */ -#include "tip.h" - -#include <sys/ioctl.h> -#include <stdio.h> - -#define MAXRETRY 5 - -static void sigALRM(); -static int timeout = 0; -static int connected = 0; -static jmp_buf timeoutbuf, intbuf; -static int t3000_sync(), t3000_connect(), t3000_swallow(); -static void t3000_nap(); - -int -t3000_dialer(num, acu) - char *num; - char *acu; -{ - char *cp; - struct termios cntrl; -#ifdef ACULOG - char line[80]; -#endif - - if (boolean(value(VERBOSE))) - printf("Using \"%s\"\n", acu); - - tcgetattr(FD, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(FD, TCSANOW, &cntrl); - /* - * Get in synch. - */ - if (!t3000_sync()) { -badsynch: - printf("can't synchronize with t3000\n"); -#ifdef ACULOG - logent(value(HOST), num, "t3000", "can't synch up"); -#endif - return (0); - } - t3000_write(FD, "AT E0\r", 6); /* turn off echoing */ - sleep(1); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - t3000_verbose_read(); -#endif - tcflush(FD, TCIOFLUSH); - t3000_write(FD, "AT E0 H0 Q0 X4 V1\r", 18); - if (!t3000_swallow("\r\nOK\r\n")) - goto badsynch; - fflush(stdout); - t3000_write(FD, "AT D", 4); - for (cp = num; *cp; cp++) - if (*cp == '=') - *cp = ','; - t3000_write(FD, num, strlen(num)); - t3000_write(FD, "\r", 1); - connected = t3000_connect(); -#ifdef ACULOG - if (timeout) { - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "t3000", line); - } -#endif - if (timeout) - t3000_disconnect(); - return (connected); -} - -void -t3000_disconnect() -{ - /* first hang up the modem*/ - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - t3000_sync(); /* reset */ - close(FD); -} - -void -t3000_abort() -{ - t3000_write(FD, "\r", 1); /* send anything to abort the call */ - t3000_disconnect(); -} - -static void -sigALRM() -{ - printf("\07timeout waiting for reply\n"); - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int -t3000_swallow(match) - char *match; -{ - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - do { - if (*match =='\0') { - signal(SIGALRM, f); - return (1); - } - if (setjmp(timeoutbuf)) { - signal(SIGALRM, f); - return (0); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, &c, 1); - alarm(0); - c &= 0177; -#ifdef DEBUG - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } while (c == *match++); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - fflush(stdout); -#endif - signal(SIGALRM, SIG_DFL); - return (0); -} - -#ifndef B19200 /* XXX */ -#define B19200 EXTA -#define B38400 EXTB -#endif - -struct tbaud_msg { - char *msg; - int baud; - int baud2; -} tbaud_msg[] = { - "", B300, 0, - " 1200", B1200, 0, - " 2400", B2400, 0, - " 4800", B4800, 0, - " 9600", B9600, 0, - " 14400", B19200, B9600, - " 19200", B19200, B9600, - " 38400", B38400, B9600, - " 57600", B38400, B9600, - " 7512", B9600, 0, - " 1275", B2400, 0, - " 7200", B9600, 0, - " 12000", B19200, B9600, - 0, 0, 0, -}; - -static int -t3000_connect() -{ - char c; - int nc, nl, n; - char dialer_buf[64]; - struct tbaud_msg *bm; - sig_t f; - - if (t3000_swallow("\r\n") == 0) - return (0); - f = signal(SIGALRM, sigALRM); -again: - nc = 0; nl = sizeof(dialer_buf)-1; - bzero(dialer_buf, sizeof(dialer_buf)); - timeout = 0; - for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) { - if (setjmp(timeoutbuf)) - break; - alarm(number(value(DIALTIMEOUT))); - n = read(FD, &c, 1); - alarm(0); - if (n <= 0) - break; - c &= 0x7f; - if (c == '\r') { - if (t3000_swallow("\n") == 0) - break; - if (!dialer_buf[0]) - goto again; - if (strcmp(dialer_buf, "RINGING") == 0 && - boolean(value(VERBOSE))) { -#ifdef DEBUG - printf("%s\r\n", dialer_buf); -#endif - goto again; - } - if (strncmp(dialer_buf, "CONNECT", - sizeof("CONNECT")-1) != 0) - break; - for (bm = tbaud_msg ; bm->msg ; bm++) - if (strcmp(bm->msg, - dialer_buf+sizeof("CONNECT")-1) == 0) { - struct termios cntrl; - - tcgetattr(FD, &cntrl); - cfsetospeed(&cntrl, bm->baud); - cfsetispeed(&cntrl, bm->baud); - tcsetattr(FD, TCSAFLUSH, &cntrl); - signal(SIGALRM, f); -#ifdef DEBUG - if (boolean(value(VERBOSE))) - printf("%s\r\n", dialer_buf); -#endif - return (1); - } - break; - } - dialer_buf[nc] = c; -#ifdef notdef - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } - printf("%s\r\n", dialer_buf); - signal(SIGALRM, f); - return (0); -} - -/* - * This convoluted piece of code attempts to get - * the t3000 in sync. - */ -static int -t3000_sync() -{ - int already = 0; - int len; - char buf[40]; - - while (already++ < MAXRETRY) { - tcflush(FD, TCIOFLUSH); - t3000_write(FD, "\rAT Z\r", 6); /* reset modem */ - bzero(buf, sizeof(buf)); - sleep(2); - ioctl(FD, FIONREAD, &len); -#if 1 -if (len == 0) len = 1; -#endif - if (len) { - len = read(FD, buf, sizeof(buf)); -#ifdef DEBUG - buf[len] = '\0'; - printf("t3000_sync: (\"%s\")\n\r", buf); -#endif - if (strchr(buf, '0') || - (strchr(buf, 'O') && strchr(buf, 'K'))) - return(1); - } - /* - * If not strapped for DTR control, - * try to get command mode. - */ - sleep(1); - t3000_write(FD, "+++", 3); - sleep(1); - /* - * Toggle DTR to force anyone off that might have left - * the modem connected. - */ - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - } - t3000_write(FD, "\rAT Z\r", 6); - return (0); -} - -static int -t3000_write(fd, cp, n) -int fd; -char *cp; -int n; -{ -#ifdef notdef - if (boolean(value(VERBOSE))) - write(1, cp, n); -#endif - tcdrain(fd); - t3000_nap(); - for ( ; n-- ; cp++) { - write(fd, cp, 1); - tcdrain(fd); - t3000_nap(); - } -} - -#ifdef DEBUG -t3000_verbose_read() -{ - int n = 0; - char buf[BUFSIZ]; - - if (ioctl(FD, FIONREAD, &n) < 0) - return; - if (n <= 0) - return; - if (read(FD, buf, n) != n) - return; - write(1, buf, n); -} -#endif - -/* Give the t3000 50 milliseconds between characters */ -void -t3000_nap() -{ - struct timespec ts; - - ts.tv_sec = 0; - ts.tv_nsec = 50 * 1000000; - - nanosleep(&ts, NULL); -} diff --git a/usr.bin/tip/libacu/v3451.c b/usr.bin/tip/libacu/v3451.c deleted file mode 100644 index 1440c551e0e0..000000000000 --- a/usr.bin/tip/libacu/v3451.c +++ /dev/null @@ -1,220 +0,0 @@ -/* $OpenBSD: v3451.c,v 1.6 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: v3451.c,v 1.6 1997/02/11 09:24:20 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)v3451.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: v3451.c,v 1.6 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * Routines for calling up on a Vadic 3451 Modem - */ -#include "tip.h" - -static jmp_buf Sjbuf; - -static int expect(), notin(), prefix(); -static void vawrite(), alarmtr(); - -int -v3451_dialer(num, acu) - char *num; - char *acu; -{ - sig_t func; - int ok; - int slow = number(value(BAUDRATE)) < 1200; - char phone[50]; - struct termios cntrl; - - /* - * Get in synch - */ - vawrite("I\r", 1 + slow); - vawrite("I\r", 1 + slow); - vawrite("I\r", 1 + slow); - vawrite("\005\r", 2 + slow); - if (!expect("READY")) { - printf("can't synchronize with vadic 3451\n"); -#ifdef ACULOG - logent(value(HOST), num, "vadic", "can't synch up"); -#endif - return (0); - } - tcgetattr(FD, &cntrl); - term.c_cflag |= HUPCL; - tcsetattr(FD, TCSANOW, &cntrl); - sleep(1); - vawrite("D\r", 2 + slow); - if (!expect("NUMBER?")) { - printf("Vadic will not accept dial command\n"); -#ifdef ACULOG - logent(value(HOST), num, "vadic", "will not accept dial"); -#endif - return (0); - } - (void)snprintf(phone, sizeof phone, "%s\r", num); - vawrite(phone, 1 + slow); - if (!expect(phone)) { - printf("Vadic will not accept phone number\n"); -#ifdef ACULOG - logent(value(HOST), num, "vadic", "will not accept number"); -#endif - return (0); - } - func = signal(SIGINT,SIG_IGN); - /* - * You cannot interrupt the Vadic when its dialing; - * even dropping DTR does not work (definitely a - * brain damaged design). - */ - vawrite("\r", 1 + slow); - vawrite("\r", 1 + slow); - if (!expect("DIALING:")) { - printf("Vadic failed to dial\n"); -#ifdef ACULOG - logent(value(HOST), num, "vadic", "failed to dial"); -#endif - return (0); - } - if (boolean(value(VERBOSE))) - printf("\ndialing..."); - ok = expect("ON LINE"); - signal(SIGINT, func); - if (!ok) { - printf("call failed\n"); -#ifdef ACULOG - logent(value(HOST), num, "vadic", "call failed"); -#endif - return (0); - } - tcflush(FD, TCIOFLUSH); - return (1); -} - -void -v3451_disconnect() -{ - - close(FD); -} - -void -v3451_abort() -{ - - close(FD); -} - -static void -vawrite(cp, delay) - char *cp; - int delay; -{ - - for (; *cp; sleep(delay), cp++) - write(FD, cp, 1); -} - -static int -expect(cp) - char *cp; -{ - char buf[300]; - char *rp = buf; - int timeout = 30, online = 0; - - if (strcmp(cp, "\"\"") == 0) - return (1); - *rp = 0; - /* - * If we are waiting for the Vadic to complete - * dialing and get a connection, allow more time - * Unfortunately, the Vadic times out 24 seconds after - * the last digit is dialed - */ - online = strcmp(cp, "ON LINE") == 0; - if (online) - timeout = number(value(DIALTIMEOUT)); - signal(SIGALRM, alarmtr); - if (setjmp(Sjbuf)) - return (0); - alarm(timeout); - while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { - if (online && notin("FAILED CALL", buf) == 0) - return (0); - if (read(FD, rp, 1) < 0) { - alarm(0); - return (0); - } - if (*rp &= 0177) - rp++; - *rp = '\0'; - } - alarm(0); - return (1); -} - -static void -alarmtr() -{ - longjmp(Sjbuf, 1); -} - -static int -notin(sh, lg) - char *sh, *lg; -{ - - for (; *lg; lg++) - if (prefix(sh, lg)) - return (0); - return (1); -} - -static int -prefix(s1, s2) - char *s1, *s2; -{ - char c; - - while ((c = *s1++) == *s2++) - if (c == '\0') - return (1); - return (c == '\0'); -} diff --git a/usr.bin/tip/libacu/v831.c b/usr.bin/tip/libacu/v831.c deleted file mode 100644 index 005e5d931e52..000000000000 --- a/usr.bin/tip/libacu/v831.c +++ /dev/null @@ -1,268 +0,0 @@ -/* $OpenBSD: v831.c,v 1.6 2001/11/19 19:02:16 mpech Exp $ */ -/* $NetBSD: v831.c,v 1.5 1996/12/29 10:42:01 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)v831.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: v831.c,v 1.6 2001/11/19 19:02:16 mpech Exp $"; -#endif /* not lint */ - -/* - * Routines for dialing up on Vadic 831 - */ -#include "tip.h" -#include <termios.h> - -void v831_abort(); -static void alarmtr(); -static int dialit(); -static char *sanitize(); - -static jmp_buf jmpbuf; -static int child = -1; - -int -v831_dialer(num, acu) - char *num, *acu; -{ - int status, pid; - int timelim; - - if (boolean(value(VERBOSE))) - printf("\nstarting call..."); -#ifdef DEBUG - printf ("(acu=%s)\n", acu); -#endif - if ((AC = open(acu, O_RDWR)) < 0) { - if (errno == EBUSY) - printf("line busy..."); - else - printf("acu open error..."); - return (0); - } - if (setjmp(jmpbuf)) { - kill(child, SIGKILL); - close(AC); - return (0); - } - signal(SIGALRM, alarmtr); - timelim = 5 * strlen(num); - alarm(timelim < 30 ? 30 : timelim); - if ((child = fork()) == 0) { - /* - * ignore this stuff for aborts - */ - signal(SIGALRM, SIG_IGN); - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - sleep(2); - exit(dialit(num, acu) != 'A'); - } - /* - * open line - will return on carrier - */ - if ((FD = open(DV, O_RDWR)) < 0) { -#ifdef DEBUG - printf("(after open, errno=%d)\n", errno); -#endif - if (errno == EIO) - printf("lost carrier..."); - else - printf("dialup line open failed..."); - alarm(0); - kill(child, SIGKILL); - close(AC); - return (0); - } - alarm(0); - signal(SIGALRM, SIG_DFL); - while ((pid = wait(&status)) != child && pid != -1) - ; - if (status) { - close(AC); - return (0); - } - return (1); -} - -static void -alarmtr() -{ - alarm(0); - longjmp(jmpbuf, 1); -} - -/* - * Insurance, for some reason we don't seem to be - * hanging up... - */ -void -v831_disconnect() -{ - struct termios cntrl; - - sleep(2); -#ifdef DEBUG - printf("[disconnect: FD=%d]\n", FD); -#endif - if (FD > 0) { - ioctl(FD, TIOCCDTR, 0); - tcgetattr(FD, &cntrl); - cfsetospeed(&cntrl, 0); - cfsetispeed(&cntrl, 0); - tcsetattr(FD, TCSAFLUSH, &cntrl); - ioctl(FD, TIOCNXCL, NULL); - } - close(FD); -} - -void -v831_abort() -{ - -#ifdef DEBUG - printf("[abort: AC=%d]\n", AC); -#endif - sleep(2); - if (child > 0) - kill(child, SIGKILL); - if (AC > 0) - ioctl(FD, TIOCNXCL, NULL); - close(AC); - if (FD > 0) - ioctl(FD, TIOCCDTR, 0); - close(FD); -} - -/* - * Sigh, this probably must be changed at each site. - */ -struct vaconfig { - char *vc_name; - char vc_rack; - char vc_modem; -} vaconfig[] = { - { "/dev/cua0",'4','0' }, - { "/dev/cua1",'4','1' }, - { 0 } -}; - -#define pc(x) (c = x, write(AC,&c,1)) -#define ABORT 01 -#define SI 017 -#define STX 02 -#define ETX 03 - -static int -dialit(phonenum, acu) - char *phonenum; - char *acu; -{ - struct vaconfig *vp; - struct termios cntrl; - char c; - int i; - - phonenum = sanitize(phonenum); -#ifdef DEBUG - printf ("(dial phonenum=%s)\n", phonenum); -#endif - if (*phonenum == '<' && phonenum[1] == 0) - return ('Z'); - for (vp = vaconfig; vp->vc_name; vp++) - if (strcmp(vp->vc_name, acu) == 0) - break; - if (vp->vc_name == 0) { - printf("Unable to locate dialer (%s)\n", acu); - return ('K'); - } - tcgetattr(AC, &cntrl); - cfsetospeed(&cntrl, B2400); - cfsetispeed(&cntrl, B2400); - cntrl.c_cflag |= PARODD | PARENB; - cntrl.c_lflag &= ~(ISIG | ICANON); - tcsetattr(AC, TCSANOW, &cntrl); - tcflush(AC, TCIOFLUSH); - pc(STX); - pc(vp->vc_rack); - pc(vp->vc_modem); - while (*phonenum && *phonenum != '<') - pc(*phonenum++); - pc(SI); - pc(ETX); - sleep(1); - i = read(AC, &c, 1); -#ifdef DEBUG - printf("read %d chars, char=%c, errno %d\n", i, c, errno); -#endif - if (i != 1) - c = 'M'; - if (c == 'B' || c == 'G') { - char cc, oc = c; - - pc(ABORT); - read(AC, &cc, 1); -#ifdef DEBUG - printf("abort response=%c\n", cc); -#endif - c = oc; - v831_disconnect(); - } - close(AC); -#ifdef DEBUG - printf("dialit: returns %c\n", c); -#endif - return (c); -} - -static char * -sanitize(s) - char *s; -{ - static char buf[128]; - char *cp; - - for (cp = buf; *s; s++) { - if (!isdigit(*s) && *s == '<' && *s != '_') - continue; - if (*s == '_') - *s = '='; - *cp++ = *s; - } - *cp++ = 0; - return (buf); -} diff --git a/usr.bin/tip/libacu/ventel.c b/usr.bin/tip/libacu/ventel.c deleted file mode 100644 index 48035c177d2d..000000000000 --- a/usr.bin/tip/libacu/ventel.c +++ /dev/null @@ -1,266 +0,0 @@ -/* $OpenBSD: ventel.c,v 1.7 2001/11/19 19:02:16 mpech Exp $ */ -/* $NetBSD: ventel.c,v 1.6 1997/02/11 09:24:21 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)ventel.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: ventel.c,v 1.7 2001/11/19 19:02:16 mpech Exp $"; -#endif /* not lint */ - -/* - * Routines for calling up on a Ventel Modem - * The Ventel is expected to be strapped for local echo (just like uucp) - */ -#include "tip.h" -#include <termios.h> -#include <sys/ioctl.h> - -#define MAXRETRY 5 - -static void sigALRM(); -static int timeout = 0; -static jmp_buf timeoutbuf; - -static int gobble(), vensync(); -static void echo(); - -/* - * some sleep calls have been replaced by this macro - * because some ventel modems require two <cr>s in less than - * a second in order to 'wake up'... yes, it is dirty... - */ -#define delay(num,denom) busyloop(CPUSPEED*num/denom) -#define CPUSPEED 1000000 /* VAX 780 is 1MIPS */ -#define DELAY(n) do { long N = (n); while (--N > 0); } while (0) -#define busyloop(n) do { DELAY(n); } while (0) - -int -ven_dialer(num, acu) - char *num; - char *acu; -{ - char *cp; - int connected = 0; - char *msg, line[80]; - struct termios cntrl; - - /* - * Get in synch with a couple of carriage returns - */ - if (!vensync(FD)) { - printf("can't synchronize with ventel\n"); -#ifdef ACULOG - logent(value(HOST), num, "ventel", "can't synch up"); -#endif - return (0); - } - if (boolean(value(VERBOSE))) - printf("\ndialing..."); - fflush(stdout); - tcgetattr(FD, &cntrl); - cntrl.c_cflag |= HUPCL; - tcsetattr(FD, TCSANOW, &cntrl); - echo("#k$\r$\n$D$I$A$L$:$ "); - for (cp = num; *cp; cp++) { - delay(1, 10); - write(FD, cp, 1); - } - delay(1, 10); - write(FD, "\r", 1); - gobble('\n', line); - if (gobble('\n', line)) - connected = gobble('!', line); - tcflush(FD, TCIOFLUSH); -#ifdef ACULOG - if (timeout) { - (void)sprintf(line, "%ld second dial timeout", - number(value(DIALTIMEOUT))); - logent(value(HOST), num, "ventel", line); - } -#endif - if (timeout) - ven_disconnect(); /* insurance */ - if (connected || timeout || !boolean(value(VERBOSE))) - return (connected); - /* call failed, parse response for user */ - cp = strchr(line, '\r'); - if (cp) - *cp = '\0'; - for (cp = line; cp = strchr(cp, ' '); cp++) - if (cp[1] == ' ') - break; - if (cp) { - while (*cp == ' ') - cp++; - msg = cp; - while (*cp) { - if (isupper(*cp)) - *cp = tolower(*cp); - cp++; - } - printf("%s...", msg); - } - return (connected); -} - -void -ven_disconnect() -{ - - close(FD); -} - -void -ven_abort() -{ - - write(FD, "\03", 1); - close(FD); -} - -static void -echo(s) - char *s; -{ - char c; - - while (c = *s++) switch (c) { - - case '$': - read(FD, &c, 1); - s++; - break; - - case '#': - c = *s++; - write(FD, &c, 1); - break; - - default: - write(FD, &c, 1); - read(FD, &c, 1); - } -} - -static void -sigALRM() -{ - printf("\07timeout waiting for reply\n"); - timeout = 1; - longjmp(timeoutbuf, 1); -} - -static int -gobble(match, response) - char match; - char response[]; -{ - char *cp = response; - sig_t f; - char c; - - f = signal(SIGALRM, sigALRM); - timeout = 0; - do { - if (setjmp(timeoutbuf)) { - signal(SIGALRM, f); - *cp = '\0'; - return (0); - } - alarm(number(value(DIALTIMEOUT))); - read(FD, cp, 1); - alarm(0); - c = (*cp++ &= 0177); -#ifdef notdef - if (boolean(value(VERBOSE))) - putchar(c); -#endif - } while (c != '\n' && c != match); - signal(SIGALRM, SIG_DFL); - *cp = '\0'; - return (c == match); -} - -#define min(a,b) ((a)>(b)?(b):(a)) -/* - * This convoluted piece of code attempts to get - * the ventel in sync. If you don't have FIONREAD - * there are gory ways to simulate this. - */ -static int -vensync(fd) -{ - int already = 0, nread; - char buf[60]; - - /* - * Toggle DTR to force anyone off that might have left - * the modem connected, and insure a consistent state - * to start from. - * - * If you don't have the ioctl calls to diddle directly - * with DTR, you can always try setting the baud rate to 0. - */ - ioctl(FD, TIOCCDTR, 0); - sleep(1); - ioctl(FD, TIOCSDTR, 0); - while (already < MAXRETRY) { - /* - * After reseting the modem, send it two \r's to - * autobaud on. Make sure to delay between them - * so the modem can frame the incoming characters. - */ - write(fd, "\r", 1); - delay(1,10); - write(fd, "\r", 1); - sleep(2); - if (ioctl(fd, FIONREAD, (caddr_t)&nread) < 0) { - perror("tip: ioctl"); - continue; - } - while (nread > 0) { - read(fd, buf, min(nread, 60)); - if ((buf[nread - 1] & 0177) == '$') - return (1); - nread -= min(nread, 60); - } - sleep(1); - already++; - } - return (0); -} - diff --git a/usr.bin/tip/tip/Makefile b/usr.bin/tip/tip/Makefile deleted file mode 100644 index 8d269d65cbd3..000000000000 --- a/usr.bin/tip/tip/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# $OpenBSD: Makefile,v 1.9 2001/09/23 06:15:30 pvalchev Exp $ -# -# Files are: -# /etc/remote remote host description file -# /etc/phones phone number file, owned by ${OWNER} and -# mode 6?? -# /var/log/aculog ACU accounting file, owned by ${OWNER} and -# mode 6?? {if ACULOG defined} -# Presently supports: -# BIZCOMP -# DEC DF02-AC, DF03-AC -# DEC DN-11/Able Quadracall -# HAYES and Hayes emulators -# USR COURIER (2400 baud) -# VENTEL 212+ -# VADIC 831 RS232 adaptor -# VADIC 3451 -# TELEBIT T3000 -# -# Configuration defines: -# DF02, DF03, DN11 ACU's supported -# BIZ1031, BIZ1022, VENTEL, V831, V3451, HAYES, COURIER, T3000 -# ACULOG turn on tip logging of ACU use -# PRISTINE no phone #'s put in ACU log file -# CONNECT worthless command -# DEFBR default baud rate to make connection at -# DEFFS default frame size for FTP buffering of -# writes on local side -# BUFSIZ buffer sizing from stdio, must be fed -# explicitly to remcap.c if not 1024 -# CONNECT enable ~C command (connect pgm to remote) - -PROG= tip -LINKS= ${BINDIR}/tip ${BINDIR}/cu -MLINKS= tip.1 cu.1 -CFLAGS+=-I${.CURDIR} -ansi -pedantic \ - -DDEFBR=9600 -DDEFFS=BUFSIZ -DACULOG -DPRISTINE -DCONNECT \ - -DV831 -DVENTEL -DHAYES -DCOURIER -DT3000 -.PATH: ${.CURDIR}/aculib -SRCS= acu.c acutab.c cmds.c cmdtab.c cu.c hunt.c log.c partab.c \ - remote.c tip.c tipout.c uucplock.c value.c vars.c \ - biz22.c courier.c df.c dn11.c hayes.c t3000.c v3451.c v831.c ventel.c - -# -- acutab is configuration dependent, and so depends on the Makefile -# -- remote.o depends on the Makefile because of DEFBR and DEFFS -# -- log.o depends on the Makefile because of ACULOG -acutab.o log.o remote.o: Makefile - -.include <bsd.prog.mk> diff --git a/usr.bin/tip/tip/acu.c b/usr.bin/tip/tip/acu.c deleted file mode 100644 index 91549e917417..000000000000 --- a/usr.bin/tip/tip/acu.c +++ /dev/null @@ -1,198 +0,0 @@ -/* $OpenBSD: acu.c,v 1.7 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: acu.c,v 1.4 1996/12/29 10:34:03 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)acu.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: acu.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -static acu_t *acu = NOACU; -static int conflag; -static void acuabort(); -static acu_t *acutype(); -static jmp_buf jmpbuf; -/* - * Establish connection for tip - * - * If DU is true, we should dial an ACU whose type is AT. - * The phone numbers are in PN, and the call unit is in CU. - * - * If the PN is an '@', then we consult the PHONES file for - * the phone numbers. This file is /etc/phones, unless overriden - * by an exported shell variable. - * - * The data base files must be in the format: - * host-name[ \t]*phone-number - * with the possibility of multiple phone numbers - * for a single host acting as a rotary (in the order - * found in the file). - */ -char * -connect() -{ - char *cp = PN; - char *phnum, string[256]; - FILE *fd; - volatile int tried = 0; - - if (!DU) { /* regular connect message */ - if (CM != NOSTR) - parwrite(FD, CM, size(CM)); - logent(value(HOST), "", DV, "call completed"); - return (NOSTR); - } - /* - * @ =>'s use data base in PHONES environment variable - * otherwise, use /etc/phones - */ - signal(SIGINT, acuabort); - signal(SIGQUIT, acuabort); - if (setjmp(jmpbuf)) { - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - printf("\ncall aborted\n"); - logent(value(HOST), "", "", "call aborted"); - if (acu != NOACU) { - setboolean(value(VERBOSE), FALSE); - if (conflag) - disconnect(NOSTR); - else - (*acu->acu_abort)(); - } - return ("interrupt"); - } - if ((acu = acutype(AT)) == NOACU) - return ("unknown ACU type"); - if (*cp != '@') { - while (*cp) { - phnum = cp; - cp = strpbrk(cp, ","); - if (*cp != '\0') - *cp++ = '\0'; - - if (strlen(phnum) == 0) - continue; - - conflag = (*acu->acu_dialer)(phnum, CU); - if (conflag) - break; - - logent(value(HOST), phnum, acu->acu_name, "call failed"); - tried++; - } - } else { - if ((fd = fopen(PH, "r")) == NOFILE) { - printf("%s: ", PH); - return ("can't open phone number file"); - } - while (fgets(string, sizeof(string), fd) != NOSTR) { - cp = &string[strcspn(string, " \t\n")]; - if (*cp != '\0') - *cp++ = '\0'; - - if (strcmp(string, value(HOST)) != 0) - continue; - - cp += strspn(cp, " \t\n"); - phnum = cp; - *(cp + strcspn(cp, ",\n")) = '\0'; - - if (strlen(phnum) == 0) - continue; - - conflag = (*acu->acu_dialer)(phnum, CU); - if (conflag) - break; - - logent(value(HOST), phnum, acu->acu_name, "call failed"); - tried++; - } - fclose(fd); - } - if (conflag) { - if (CM != NOSTR) - parwrite(FD, CM, size(CM)); - logent(value(HOST), phnum, acu->acu_name, "call completed"); - return (NOSTR); - } else if (!tried) { - logent(value(HOST), "", acu->acu_name, "missing phone number"); - return ("missing phone number"); - } else { - (*acu->acu_abort)(); - return ("call failed"); - } -} - -void -disconnect(reason) - char *reason; -{ - if (!conflag) { - logent(value(HOST), "", DV, "call terminated"); - return; - } - if (reason == NOSTR) { - logent(value(HOST), "", acu->acu_name, "call terminated"); - if (boolean(value(VERBOSE))) - printf("\r\ndisconnecting..."); - } else - logent(value(HOST), "", acu->acu_name, reason); - (*acu->acu_disconnect)(); -} - -static void -acuabort(s) -{ - signal(s, SIG_IGN); - longjmp(jmpbuf, 1); -} - -static acu_t * -acutype(s) - char *s; -{ - acu_t *p; - extern acu_t acutable[]; - - for (p = acutable; p->acu_name != '\0'; p++) - if (!strcmp(s, p->acu_name)) - return (p); - return (NOACU); -} diff --git a/usr.bin/tip/tip/acutab.c b/usr.bin/tip/tip/acutab.c deleted file mode 100644 index 193b8cc70cac..000000000000 --- a/usr.bin/tip/tip/acutab.c +++ /dev/null @@ -1,103 +0,0 @@ -/* $OpenBSD: acutab.c,v 1.2 1996/06/26 05:40:41 deraadt Exp $ */ -/* $NetBSD: acutab.c,v 1.3 1994/12/08 09:30:41 jtc Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)acutab.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: acutab.c,v 1.2 1996/06/26 05:40:41 deraadt Exp $"; -#endif /* not lint */ - -#include "tip.h" - -extern int df02_dialer(), df03_dialer(), df_disconnect(), df_abort(), - biz31f_dialer(), biz31_disconnect(), biz31_abort(), - biz31w_dialer(), - biz22f_dialer(), biz22_disconnect(), biz22_abort(), - biz22w_dialer(), - ven_dialer(), ven_disconnect(), ven_abort(), - hay_dialer(), hay_disconnect(), hay_abort(), - cour_dialer(), cour_disconnect(), cour_abort(), - t3000_dialer(), t3000_disconnect(), t3000_abort(), - v3451_dialer(), v3451_disconnect(), v3451_abort(), - v831_dialer(), v831_disconnect(), v831_abort(), - dn_dialer(), dn_disconnect(), dn_abort(); - -acu_t acutable[] = { -#if BIZ1031 - "biz31f", biz31f_dialer, biz31_disconnect, biz31_abort, - "biz31w", biz31w_dialer, biz31_disconnect, biz31_abort, -#endif -#if BIZ1022 - "biz22f", biz22f_dialer, biz22_disconnect, biz22_abort, - "biz22w", biz22w_dialer, biz22_disconnect, biz22_abort, -#endif -#if DF02 - "df02", df02_dialer, df_disconnect, df_abort, -#endif -#if DF03 - "df03", df03_dialer, df_disconnect, df_abort, -#endif -#if DN11 - "dn11", dn_dialer, dn_disconnect, dn_abort, -#endif -#ifdef VENTEL - "ventel",ven_dialer, ven_disconnect, ven_abort, -#endif -#ifdef HAYES - "hayes",hay_dialer, hay_disconnect, hay_abort, -#endif -#ifdef COURIER - "courier",cour_dialer, cour_disconnect, cour_abort, -#endif -#ifdef T3000 - "t3000",t3000_dialer, t3000_disconnect, t3000_abort, -#endif -#ifdef V3451 -#ifndef V831 - "vadic",v3451_dialer, v3451_disconnect, v3451_abort, -#endif - "v3451",v3451_dialer, v3451_disconnect, v3451_abort, -#endif -#ifdef V831 -#ifndef V3451 - "vadic",v831_dialer, v831_disconnect, v831_abort, -#endif - "v831",v831_dialer, v831_disconnect, v831_abort, -#endif - 0, 0, 0, 0 -}; - diff --git a/usr.bin/tip/tip/cmds.c b/usr.bin/tip/tip/cmds.c deleted file mode 100644 index 07d7f51f08d0..000000000000 --- a/usr.bin/tip/tip/cmds.c +++ /dev/null @@ -1,952 +0,0 @@ -/* $OpenBSD: cmds.c,v 1.13 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: cmds.c,v 1.7 1997/02/11 09:24:03 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: cmds.c,v 1.13 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" -#include "pathnames.h" - -#include <vis.h> - -/* - * tip - * - * miscellaneous commands - */ - -int quant[] = { 60, 60, 24 }; - -char null = '\0'; -char *sep[] = { "second", "minute", "hour" }; -static char *argv[10]; /* argument vector for take and put */ - -void timeout(); /* timeout function called on alarm */ -void stopsnd(); /* SIGINT handler during file transfers */ -void intcopy(); /* interrupt routine for file transfers */ - -/* - * FTP - remote ==> local - * get a file from the remote host - */ -void -getfl(c) - char c; -{ - char buf[256], *cp, *expand(); - - putchar(c); - /* - * get the UNIX receiving file's name - */ - if (prompt("Local file name? ", copyname, sizeof(copyname))) - return; - cp = expand(copyname); - if ((sfd = creat(cp, 0666)) < 0) { - printf("\r\n%s: cannot creat\r\n", copyname); - return; - } - - /* - * collect parameters - */ - if (prompt("List command for remote system? ", buf, sizeof(buf))) { - unlink(copyname); - return; - } - transfer(buf, sfd, value(EOFREAD)); -} - -/* - * Cu-like take command - */ -void -cu_take(cc) - char cc; -{ - int fd, argc; - char line[BUFSIZ], *expand(), *cp; - - if (prompt("[take] ", copyname, sizeof(copyname))) - return; - if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || - argc > 2) { - printf("usage: <take> from [to]\r\n"); - return; - } - if (argc == 1) - argv[1] = argv[0]; - cp = expand(argv[1]); - if ((fd = creat(cp, 0666)) < 0) { - printf("\r\n%s: cannot create\r\n", argv[1]); - return; - } - (void)snprintf(line, sizeof(line), "cat %s;echo \01", argv[0]); - transfer(line, fd, "\01"); -} - -static jmp_buf intbuf; - -/* - * Bulk transfer routine -- - * used by getfl(), cu_take(), and pipefile() - */ -void -transfer(buf, fd, eofchars) - char *buf, *eofchars; - int fd; -{ - int ct; - char c, buffer[BUFSIZ]; - char *p = buffer; - int cnt, eof; - time_t start; - sig_t f; - char r; - - parwrite(FD, buf, size(buf)); - quit = 0; - kill(pid, SIGIOT); - read(repdes[0], (char *)&ccc, 1); /* Wait until read process stops */ - - /* - * finish command - */ - r = '\r'; - parwrite(FD, &r, 1); - do - read(FD, &c, 1); - while ((c&STRIP_PAR) != '\n'); - tcsetattr(0, TCSAFLUSH, &defchars); - - (void) setjmp(intbuf); - f = signal(SIGINT, intcopy); - start = time(0); - for (ct = 0; !quit;) { - eof = read(FD, &c, 1) <= 0; - c &= STRIP_PAR; - if (quit) - continue; - if (eof || any(c, eofchars)) - break; - if (c == 0) - continue; /* ignore nulls */ - if (c == '\r') - continue; - *p++ = c; - - if (c == '\n' && boolean(value(VERBOSE))) - printf("\r%d", ++ct); - if ((cnt = (p-buffer)) == number(value(FRAMESIZE))) { - if (write(fd, buffer, cnt) != cnt) { - printf("\r\nwrite error\r\n"); - quit = 1; - } - p = buffer; - } - } - if ((cnt = (p-buffer))) - if (write(fd, buffer, cnt) != cnt) - printf("\r\nwrite error\r\n"); - - if (boolean(value(VERBOSE))) - prtime(" lines transferred in ", time(0)-start); - tcsetattr(0, TCSAFLUSH, &term); - write(fildes[1], (char *)&ccc, 1); - signal(SIGINT, f); - close(fd); -} - -/* - * FTP - remote ==> local process - * send remote input to local process via pipe - */ -void -pipefile() -{ - int cpid, pdes[2]; - char buf[256]; - int status, p; - - if (prompt("Local command? ", buf, sizeof(buf))) - return; - - if (pipe(pdes)) { - printf("can't establish pipe\r\n"); - return; - } - - if ((cpid = fork()) < 0) { - printf("can't fork!\r\n"); - return; - } else if (cpid) { - if (prompt("List command for remote system? ", buf, sizeof(buf))) { - close(pdes[0]), close(pdes[1]); - kill (cpid, SIGKILL); - } else { - close(pdes[0]); - signal(SIGPIPE, intcopy); - transfer(buf, pdes[1], value(EOFREAD)); - signal(SIGPIPE, SIG_DFL); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } - } else { - int f; - - dup2(pdes[0], 0); - close(pdes[0]); - for (f = 3; f < 20; f++) - close(f); - execute(buf); - printf("can't execl!\r\n"); - exit(0); - } -} - -/* - * Interrupt service routine for FTP - */ -void -stopsnd() -{ - - stop = 1; - signal(SIGINT, SIG_IGN); -} - -/* - * FTP - local ==> remote - * send local file to remote host - * terminate transmission with pseudo EOF sequence - */ -void -sendfile(cc) - char cc; -{ - FILE *fd; - char *fnamex; - char *expand(); - - putchar(cc); - /* - * get file name - */ - if (prompt("Local file name? ", fname, sizeof(fname))) - return; - - /* - * look up file - */ - fnamex = expand(fname); - if ((fd = fopen(fnamex, "r")) == NULL) { - printf("%s: cannot open\r\n", fname); - return; - } - transmit(fd, value(EOFWRITE), NULL); - if (!boolean(value(ECHOCHECK))) - tcdrain(FD); -} - -/* - * Bulk transfer routine to remote host -- - * used by sendfile() and cu_put() - */ -void -transmit(fd, eofchars, command) - FILE *fd; - char *eofchars, *command; -{ - char *pc, lastc; - int c, ccount, lcount; - time_t start_t, stop_t; - sig_t f; - - kill(pid, SIGIOT); /* put TIPOUT into a wait state */ - stop = 0; - f = signal(SIGINT, stopsnd); - tcsetattr(0, TCSAFLUSH, &defchars); - read(repdes[0], (char *)&ccc, 1); - if (command != NULL) { - for (pc = command; *pc; pc++) - send(*pc); - if (boolean(value(ECHOCHECK))) - read(FD, (char *)&c, 1); /* trailing \n */ - else { - tcdrain(FD); - sleep(5); /* wait for remote stty to take effect */ - } - } - lcount = 0; - lastc = '\0'; - start_t = time(0); - while (1) { - ccount = 0; - do { - c = getc(fd); - if (stop) - goto out; - if (c == EOF) - goto out; - if (c == 0177 && !boolean(value(RAWFTP))) - continue; - lastc = c; - if (c < 040) { - if (c == '\n') { - if (!boolean(value(RAWFTP))) - c = '\r'; - } - else if (c == '\t') { - if (!boolean(value(RAWFTP))) { - if (boolean(value(TABEXPAND))) { - send(' '); - while ((++ccount % 8) != 0) - send(' '); - continue; - } - } - } else - if (!boolean(value(RAWFTP))) - continue; - } - send(c); - } while (c != '\r' && !boolean(value(RAWFTP))); - if (boolean(value(VERBOSE))) - printf("\r%d", ++lcount); - if (boolean(value(ECHOCHECK))) { - timedout = 0; - alarm((long)value(ETIMEOUT)); - do { /* wait for prompt */ - read(FD, (char *)&c, 1); - if (timedout || stop) { - if (timedout) - printf("\r\ntimed out at eol\r\n"); - alarm(0); - goto out; - } - } while ((c&STRIP_PAR) != character(value(PROMPT))); - alarm(0); - } - } -out: - if (lastc != '\n' && !boolean(value(RAWFTP))) - send('\r'); - if (eofchars) { - for (pc = eofchars; *pc; pc++) - send(*pc); - } - stop_t = time(0); - fclose(fd); - signal(SIGINT, f); - if (boolean(value(VERBOSE))) { - if (boolean(value(RAWFTP))) - prtime(" chars transferred in ", stop_t-start_t); - else - prtime(" lines transferred in ", stop_t-start_t); - } - write(fildes[1], (char *)&ccc, 1); - tcsetattr(0, TCSAFLUSH, &term); -} - -/* - * Cu-like put command - */ -void -cu_put(cc) - char cc; -{ - FILE *fd; - char line[BUFSIZ]; - int argc; - char *expand(); - char *copynamex; - - if (prompt("[put] ", copyname, sizeof(copyname))) - return; - if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || - argc > 2) { - printf("usage: <put> from [to]\r\n"); - return; - } - if (argc == 1) - argv[1] = argv[0]; - copynamex = expand(argv[0]); - if ((fd = fopen(copynamex, "r")) == NULL) { - printf("%s: cannot open\r\n", copynamex); - return; - } - if (boolean(value(ECHOCHECK))) - (void)snprintf(line, sizeof(line), "cat>%s\r", argv[1]); - else - (void)snprintf(line, sizeof(line), - "stty -echo;cat>%s;stty echo\r", argv[1]); - transmit(fd, "\04", line); -} - -/* - * FTP - send single character - * wait for echo & handle timeout - */ -void -send(c) - int c; -{ - char cc; - int retry = 0; - - cc = c; - parwrite(FD, &cc, 1); -#ifdef notdef - if (number(value(CDELAY)) > 0 && c != '\r') - nap(number(value(CDELAY))); -#endif - if (!boolean(value(ECHOCHECK))) { -#ifdef notdef - if (number(value(LDELAY)) > 0 && c == '\r') - nap(number(value(LDELAY))); -#endif - return; - } -tryagain: - timedout = 0; - alarm((long)value(ETIMEOUT)); - read(FD, &cc, 1); - alarm(0); - if (timedout) { - printf("\r\ntimeout error (%s)\r\n", ctrl(c)); - if (retry++ > 3) - return; - parwrite(FD, &null, 1); /* poke it */ - goto tryagain; - } -} - -void -timeout() -{ - signal(SIGALRM, timeout); - timedout = 1; -} - -/* - * Stolen from consh() -- puts a remote file on the output of a local command. - * Identical to consh() except for where stdout goes. - */ -void -pipeout(c) -{ - char buf[256]; - int cpid, status, p; - time_t start = time(NULL); - - putchar(c); - if (prompt("Local command? ", buf, sizeof(buf))) - return; - kill(pid, SIGIOT); /* put TIPOUT into a wait state */ - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - tcsetattr(0, TCSAFLUSH, &defchars); - read(repdes[0], (char *)&ccc, 1); - /* - * Set up file descriptors in the child and - * let it go... - */ - if ((cpid = fork()) < 0) - printf("can't fork!\r\n"); - else if (cpid) { - start = time(NULL); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } else { - int i; - - dup2(FD, 1); - for (i = 3; i < 20; i++) - close(i); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - execute(buf); - printf("can't find `%s'\r\n", buf); - exit(0); - } - if (boolean(value(VERBOSE))) - prtime("away for ", time(0)-start); - write(fildes[1], (char *)&ccc, 1); - tcsetattr(0, TCSAFLUSH, &term); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); -} - -#ifdef CONNECT -/* - * Fork a program with: - * 0 <-> remote tty in - * 1 <-> remote tty out - * 2 <-> local tty out - */ -void -consh(c) -{ - char buf[256]; - int cpid, status, p; - time_t start = time(NULL); - - putchar(c); - if (prompt("Local command? ", buf, sizeof(buf))) - return; - kill(pid, SIGIOT); /* put TIPOUT into a wait state */ - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - tcsetattr(0, TCSAFLUSH, &defchars); - read(repdes[0], (char *)&ccc, 1); - /* - * Set up file descriptors in the child and - * let it go... - */ - if ((cpid = fork()) < 0) - printf("can't fork!\r\n"); - else if (cpid) { - start = time(0); - while ((p = wait(&status)) > 0 && p != cpid) - ; - } else { - int i; - - dup2(FD, 0); - dup2(3, 1); - for (i = 3; i < 20; i++) - close(i); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - execute(buf); - printf("can't find `%s'\r\n", buf); - exit(0); - } - if (boolean(value(VERBOSE))) - prtime("away for ", time(0)-start); - write(fildes[1], (char *)&ccc, 1); - tcsetattr(0, TCSAFLUSH, &term); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); -} -#endif - -/* - * Escape to local shell - */ -void -shell() -{ - int shpid, status; - char *cp; - - printf("[sh]\r\n"); - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - unraw(); - if ((shpid = fork())) { - while (shpid != wait(&status)); - raw(); - printf("\r\n!\r\n"); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - return; - } else { - signal(SIGQUIT, SIG_DFL); - signal(SIGINT, SIG_DFL); - if ((cp = strrchr(value(SHELL), '/')) == NULL) - cp = value(SHELL); - else - cp++; - shell_uid(); - execl(value(SHELL), cp, (char *)NULL); - printf("\r\ncan't execl!\r\n"); - exit(1); - } -} - -/* - * TIPIN portion of scripting - * initiate the conversation with TIPOUT - */ -void -setscript() -{ - char c; - /* - * enable TIPOUT side for dialogue - */ - kill(pid, SIGEMT); - if (boolean(value(SCRIPT))) - write(fildes[1], value(RECORD), size(value(RECORD))); - write(fildes[1], "\n", 1); - /* - * wait for TIPOUT to finish - */ - read(repdes[0], &c, 1); - if (c == 'n') - printf("can't create %s\r\n", value(RECORD)); -} - -/* - * Change current working directory of - * local portion of tip - */ -void -chdirectory() -{ - char dirname[PATH_MAX]; - char *cp = dirname; - - if (prompt("[cd] ", dirname, sizeof(dirname))) { - if (stoprompt) - return; - cp = value(HOME); - } - if (chdir(cp) < 0) - printf("%s: bad directory\r\n", cp); - printf("!\r\n"); -} - -void -tipabort(msg) - char *msg; -{ - - kill(pid, SIGTERM); - disconnect(msg); - if (msg != NOSTR) - printf("\r\n%s", msg); - printf("\r\n[EOT]\r\n"); - daemon_uid(); - (void)uu_unlock(uucplock); - unraw(); - exit(0); -} - -void -finish() -{ - char *dismsg; - - if ((dismsg = value(DISCONNECT)) != NOSTR) { - write(FD, dismsg, strlen(dismsg)); - sleep(5); - } - tipabort(NOSTR); -} - -void -intcopy() -{ - raw(); - quit = 1; - longjmp(intbuf, 1); -} - -void -execute(s) - char *s; -{ - char *cp; - - if ((cp = strrchr(value(SHELL), '/')) == NULL) - cp = value(SHELL); - else - cp++; - shell_uid(); - execl(value(SHELL), cp, "-c", s, (char *)NULL); -} - -int -args(buf, a, num) - char *buf, *a[]; - int num; -{ - char *p = buf, *start; - char **parg = a; - int n = 0; - - do { - while (*p && (*p == ' ' || *p == '\t')) - p++; - start = p; - if (*p) - *parg = p; - while (*p && (*p != ' ' && *p != '\t')) - p++; - if (p != start) - parg++, n++; - if (*p) - *p++ = '\0'; - } while (*p && n < num); - - return(n); -} - -void -prtime(s, a) - char *s; - time_t a; -{ - int i; - int nums[3]; - - for (i = 0; i < 3; i++) { - nums[i] = (int)(a % quant[i]); - a /= quant[i]; - } - printf("%s", s); - while (--i >= 0) - if (nums[i] || i == 0 && nums[1] == 0 && nums[2] == 0) - printf("%d %s%c ", nums[i], sep[i], - nums[i] == 1 ? '\0' : 's'); - printf("\r\n!\r\n"); -} - -void -variable() -{ - char buf[256]; - - if (prompt("[set] ", buf, sizeof(buf))) - return; - vlex(buf); - if (vtable[BEAUTIFY].v_access&CHANGED) { - vtable[BEAUTIFY].v_access &= ~CHANGED; - kill(pid, SIGSYS); - } - if (vtable[SCRIPT].v_access&CHANGED) { - vtable[SCRIPT].v_access &= ~CHANGED; - setscript(); - /* - * So that "set record=blah script" doesn't - * cause two transactions to occur. - */ - if (vtable[RECORD].v_access&CHANGED) - vtable[RECORD].v_access &= ~CHANGED; - } - if (vtable[RECORD].v_access&CHANGED) { - vtable[RECORD].v_access &= ~CHANGED; - if (boolean(value(SCRIPT))) - setscript(); - } - if (vtable[TAND].v_access&CHANGED) { - vtable[TAND].v_access &= ~CHANGED; - if (boolean(value(TAND))) - tandem("on"); - else - tandem("off"); - } - if (vtable[LECHO].v_access&CHANGED) { - vtable[LECHO].v_access &= ~CHANGED; - HD = boolean(value(LECHO)); - } - if (vtable[PARITY].v_access&CHANGED) { - vtable[PARITY].v_access &= ~CHANGED; - setparity(NOSTR); - } -} - -void -listvariables() -{ - value_t *p; - char buf[BUFSIZ]; - - puts("v\r"); - for (p = vtable; p->v_name; p++) { - fputs(p->v_name, stdout); - switch (p->v_type&TMASK) { - case STRING: - if (p->v_value) { - strnvis(buf, p->v_value, sizeof(buf), - VIS_WHITE|VIS_OCTAL); - printf(" %s", buf); - } - putchar('\r'); - putchar('\n'); - break; - case NUMBER: - printf(" %ld\r\n", number(p->v_value)); - break; - case BOOL: - printf(" %s\r\n", - boolean(p->v_value) == '!' ? "false" : "true"); - break; - case CHAR: - vis(buf, character(p->v_value), VIS_WHITE|VIS_OCTAL, 0); - printf(" %s\r\n", buf); - break; - } - } -} - -/* - * Turn tandem mode on or off for remote tty. - */ -void -tandem(option) - char *option; -{ - struct termios rmtty; - - tcgetattr(FD, &rmtty); - if (strcmp(option, "on") == 0) { - rmtty.c_iflag |= IXOFF; - term.c_iflag |= IXOFF; - } else { - rmtty.c_iflag &= ~IXOFF; - term.c_iflag &= ~IXOFF; - } - tcsetattr(FD, TCSADRAIN, &rmtty); - tcsetattr(0, TCSADRAIN, &term); -} - -/* - * Send a break. - */ -void -genbrk() -{ - - ioctl(FD, TIOCSBRK, NULL); - sleep(1); - ioctl(FD, TIOCCBRK, NULL); -} - -/* - * Suspend tip - */ -void -suspend(c) - char c; -{ - - unraw(); - kill(c == CTRL('y') ? getpid() : 0, SIGTSTP); - raw(); -} - -/* - * expand a file name if it includes shell meta characters - */ - -char * -expand(name) - char name[]; -{ - static char xname[BUFSIZ]; - char cmdbuf[BUFSIZ]; - int pid, l; - char *cp, *Shell; - int s, pivec[2]; - - if (!anyof(name, "~{[*?$`'\"\\")) - return(name); - /* sigint = signal(SIGINT, SIG_IGN); */ - if (pipe(pivec) < 0) { - perror("pipe"); - /* signal(SIGINT, sigint) */ - return(name); - } - (void)snprintf(cmdbuf, sizeof(cmdbuf), "echo %s", name); - if ((pid = vfork()) == 0) { - Shell = value(SHELL); - if (Shell == NOSTR) - Shell = _PATH_BSHELL; - close(pivec[0]); - close(1); - dup(pivec[1]); - close(pivec[1]); - close(2); - shell_uid(); - execl(Shell, Shell, "-c", cmdbuf, (char *)NULL); - _exit(1); - } - if (pid == -1) { - perror("fork"); - close(pivec[0]); - close(pivec[1]); - return(NOSTR); - } - close(pivec[1]); - l = read(pivec[0], xname, BUFSIZ); - close(pivec[0]); - while (wait(&s) != pid); - ; - s &= 0377; - if (s != 0 && s != SIGPIPE) { - fprintf(stderr, "\"Echo\" failed\n"); - return(NOSTR); - } - if (l < 0) { - perror("read"); - return(NOSTR); - } - if (l == 0) { - fprintf(stderr, "\"%s\": No match\n", name); - return(NOSTR); - } - if (l == BUFSIZ) { - fprintf(stderr, "Buffer overflow expanding \"%s\"\n", name); - return(NOSTR); - } - xname[l] = 0; - for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--) - ; - *++cp = '\0'; - return(xname); -} - -/* - * Are any of the characters in the two strings the same? - */ -int -anyof(s1, s2) - char *s1, *s2; -{ - int c; - - while ((c = *s1++)) - if (any(c, s2)) - return(1); - return(0); -} diff --git a/usr.bin/tip/tip/cmdtab.c b/usr.bin/tip/tip/cmdtab.c deleted file mode 100644 index 7f77e2777749..000000000000 --- a/usr.bin/tip/tip/cmdtab.c +++ /dev/null @@ -1,71 +0,0 @@ -/* $OpenBSD: cmdtab.c,v 1.3 2001/09/09 17:58:41 millert Exp $ */ -/* $NetBSD: cmdtab.c,v 1.3 1994/12/08 09:30:46 jtc Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.3 2001/09/09 17:58:41 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -extern int shell(), getfl(), sendfile(), chdirectory(); -extern int finish(), help(), pipefile(), pipeout(), consh(), variable(); -extern int cu_take(), cu_put(), dollar(), genbrk(), suspend(), listvariables(); - -esctable_t etable[] = { - { '!', NORM, "shell", shell }, - { '<', NORM, "receive file from remote host", getfl }, - { '>', NORM, "send file to remote host", sendfile }, - { 't', NORM, "take file from remote UNIX", cu_take }, - { 'p', NORM, "put file to remote UNIX", cu_put }, - { '|', NORM, "pipe remote file", pipefile }, - { '$', NORM, "pipe local command to remote host", pipeout }, -#ifdef CONNECT - { 'C', NORM, "connect program to remote host",consh }, -#endif - { 'c', NORM, "change directory", chdirectory }, - { '.', NORM, "exit from tip", finish }, - {CTRL('d'),NORM,"exit from tip", finish }, - {CTRL('y'),NORM,"suspend tip (local+remote)", suspend }, - {CTRL('z'),NORM,"suspend tip (local only)", suspend }, - { 's', NORM, "set variable", variable }, - { 'v', NORM, "list variables", listvariables }, - { '?', NORM, "get this summary", help }, - { '#', NORM, "send break", genbrk }, - { 0, 0, 0 } -}; diff --git a/usr.bin/tip/tip/cu.c b/usr.bin/tip/tip/cu.c deleted file mode 100644 index 8a44845b4269..000000000000 --- a/usr.bin/tip/tip/cu.c +++ /dev/null @@ -1,175 +0,0 @@ -/* $OpenBSD: cu.c,v 1.10 2001/09/26 06:07:28 pvalchev Exp $ */ -/* $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: cu.c,v 1.10 2001/09/26 06:07:28 pvalchev Exp $"; -#endif /* not lint */ - -#include "tip.h" - -void cleanup(); -void cuusage(); - -/* - * Botch the interface to look like cu's - */ -void -cumain(argc, argv) - int argc; - char *argv[]; -{ - int ch, i; - long l; - char *cp; - static char sbuf[12]; - - if (argc < 2) - cuusage(); - CU = DV = NOSTR; - BR = DEFBR; - while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) { - switch(ch) { - case 'a': - CU = optarg; - break; - case 'l': - if (DV != NULL) { - fprintf(stderr, - "%s: cannot specificy multiple -l options\n", - __progname); - exit(3); - } - if (strchr(optarg, '/')) - DV = optarg; - else - asprintf(&DV, "/dev/%s", optarg); - break; - case 's': - l = strtol(optarg, &cp, 10); - if (*cp != '\0' || l < 0 || l >= INT_MAX || - speed((int)l) == 0) { - fprintf(stderr, "%s: unsupported speed %s\n", - __progname, optarg); - exit(3); - } - BR = (int)l; - break; - case 'h': - setboolean(value(LECHO), TRUE); - HD = TRUE; - break; - case 't': - HW = 1, DU = -1; - break; - case 'o': - setparity("odd"); - break; - case 'e': - setparity("even"); - break; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - if (CU) - CU[strlen(CU)-1] = ch; - if (DV) - DV[strlen(DV)-1] = ch; - break; - default: - cuusage(); - break; - } - } - argc -= optind; - argv += optind; - - switch (argc) { - case 1: - PN = argv[0]; - break; - case 0: - break; - default: - cuusage(); - break; - } - - signal(SIGINT, cleanup); - signal(SIGQUIT, cleanup); - signal(SIGHUP, cleanup); - signal(SIGTERM, cleanup); - - /* - * The "cu" host name is used to define the - * attributes of the generic dialer. - */ - (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR); - if ((i = hunt(sbuf)) == 0) { - printf("all ports busy\n"); - exit(3); - } - if (i == -1) { - printf("link down\n"); - (void)uu_unlock(uucplock); - exit(3); - } - setbuf(stdout, NULL); - loginit(); - user_uid(); - vinit(); - setparity("none"); - setboolean(value(VERBOSE), FALSE); - if (HW) - ttysetup(speed(BR)); - if (connect()) { - printf("Connect failed\n"); - daemon_uid(); - (void)uu_unlock(uucplock); - exit(1); - } - if (!HW) - ttysetup(speed(BR)); -} - -void -cuusage() -{ - fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] [-s speed] [-#] " - "[phone-number]\n"); - exit(8); -} diff --git a/usr.bin/tip/tip/hunt.c b/usr.bin/tip/tip/hunt.c deleted file mode 100644 index 60aaa2350957..000000000000 --- a/usr.bin/tip/tip/hunt.c +++ /dev/null @@ -1,110 +0,0 @@ -/* $OpenBSD: hunt.c,v 1.8 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: hunt.c,v 1.6 1997/04/20 00:02:10 mellon Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)hunt.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: hunt.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -extern char *getremote(); - -static jmp_buf deadline; -static int deadfl; - -void -dead() -{ - deadfl = 1; - longjmp(deadline, 1); -} - -long -hunt(name) - char *name; -{ - char *cp; - sig_t f; - - f = signal(SIGALRM, dead); - while ((cp = getremote(name))) { - deadfl = 0; - uucplock = strrchr(cp, '/'); - if (uucplock == NULL) - uucplock = cp; - else - uucplock++; - - if (uu_lock(uucplock) < 0) - continue; - /* - * Straight through call units, such as the BIZCOMP, - * VADIC and the DF, must indicate they're hardwired in - * order to get an open file descriptor placed in FD. - * Otherwise, as for a DN-11, the open will have to - * be done in the "open" routine. - */ - if (!HW) - break; - if (setjmp(deadline) == 0) { - alarm(10); - FD = open(cp, (O_RDWR | - (boolean(value(DC)) ? O_NONBLOCK : 0))); - } - alarm(0); - if (FD < 0) { - perror(cp); - deadfl = 1; - } - if (!deadfl) { - struct termios cntrl; - - tcgetattr(FD, &cntrl); - if (!boolean(value(DC))) - cntrl.c_cflag |= HUPCL; - tcsetattr(FD, TCSAFLUSH, &cntrl); - ioctl(FD, TIOCEXCL, 0); - signal(SIGALRM, SIG_DFL); - return ((long)cp); - } - (void)uu_unlock(uucplock); - } - signal(SIGALRM, f); - return (deadfl ? -1 : (long)cp); -} diff --git a/usr.bin/tip/tip/log.c b/usr.bin/tip/tip/log.c deleted file mode 100644 index 1a715c0d5f52..000000000000 --- a/usr.bin/tip/tip/log.c +++ /dev/null @@ -1,94 +0,0 @@ -/* $OpenBSD: log.c,v 1.5 2001/09/09 19:30:49 millert Exp $ */ -/* $NetBSD: log.c,v 1.4 1994/12/24 17:56:28 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: log.c,v 1.5 2001/09/09 19:30:49 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -#ifdef ACULOG -static FILE *flog = NULL; - -/* - * Log file maintenance routines - */ -void -logent(group, num, acu, message) - char *group, *num, *acu, *message; -{ - char *user, *timestamp; - struct passwd *pwd; - time_t t; - - if (flog == NULL) - return; - if (flock(fileno(flog), LOCK_EX) < 0) { - perror("flock"); - return; - } - if ((user = getlogin()) == NOSTR) { - if ((pwd = getpwuid(getuid())) == NOPWD) - user = "???"; - else - user = pwd->pw_name; - } - t = time(0); - timestamp = ctime(&t); - timestamp[24] = '\0'; - fprintf(flog, "%s (%s) <%s, %s, %s> %s\n", - user, timestamp, group, -#ifdef PRISTINE - "", -#else - num, -#endif - acu, message); - (void) fflush(flog); - (void) flock(fileno(flog), LOCK_UN); -} - -void -loginit() -{ - flog = fopen(value(LOG), "a"); - if (flog == NULL) - fprintf(stderr, "can't open log file %s.\r\n", value(LOG)); -} -#endif diff --git a/usr.bin/tip/tip/partab.c b/usr.bin/tip/tip/partab.c deleted file mode 100644 index b0e4dc2f732e..000000000000 --- a/usr.bin/tip/tip/partab.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: partab.c,v 1.3 1997/04/02 01:47:02 millert Exp $ */ -/* $NetBSD: partab.c,v 1.4 1996/12/29 10:38:21 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)partab.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: partab.c,v 1.3 1997/04/02 01:47:02 millert Exp $"; -#endif /* not lint */ - -/* - * Even parity table for 0-0177 - */ -const unsigned char evenpartab[] = { - 0000,0201,0202,0003,0204,0005,0006,0207, - 0210,0011,0012,0213,0014,0215,0216,0017, - 0220,0021,0022,0223,0024,0225,0226,0027, - 0030,0231,0232,0033,0234,0035,0036,0237, - 0240,0041,0042,0243,0044,0245,0246,0047, - 0050,0251,0252,0053,0254,0055,0056,0257, - 0060,0261,0262,0063,0264,0065,0066,0267, - 0270,0071,0072,0273,0074,0275,0276,0077, - 0300,0101,0102,0303,0104,0305,0306,0107, - 0110,0311,0312,0113,0314,0115,0116,0317, - 0120,0321,0322,0123,0324,0125,0126,0327, - 0330,0131,0132,0333,0134,0335,0336,0137, - 0140,0341,0342,0143,0344,0145,0146,0347, - 0350,0151,0152,0353,0154,0355,0356,0157, - 0360,0161,0162,0363,0164,0365,0366,0167, - 0170,0371,0372,0173,0374,0175,0176,0377, -}; diff --git a/usr.bin/tip/tip/pathnames.h b/usr.bin/tip/tip/pathnames.h deleted file mode 100644 index cc7cbf4a7a2a..000000000000 --- a/usr.bin/tip/tip/pathnames.h +++ /dev/null @@ -1,44 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.2 1996/06/26 05:40:45 deraadt Exp $ */ -/* $NetBSD: pathnames.h,v 1.3 1994/12/08 09:30:59 jtc Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 - */ - -#include <paths.h> - -#define _PATH_ACULOG "/var/log/aculog" -#define _PATH_LOCKDIRNAME "/var/spool/lock/LCK..%s" -#define _PATH_PHONES "/etc/phones" -#define _PATH_REMOTE "/etc/remote" diff --git a/usr.bin/tip/tip/remote.c b/usr.bin/tip/tip/remote.c deleted file mode 100644 index f2aaeb243523..000000000000 --- a/usr.bin/tip/tip/remote.c +++ /dev/null @@ -1,241 +0,0 @@ -/* $OpenBSD: remote.c,v 1.10 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: remote.c,v 1.5 1997/04/20 00:02:45 mellon Exp $ */ - -/* - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1992, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: remote.c,v 1.10 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include <stdio.h> -#include <stdlib.h> - -#include "pathnames.h" -#include "tip.h" - -/* - * Attributes to be gleened from remote host description - * data base. - */ -static char **caps[] = { - &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI, - &ES, &EX, &FO, &RC, &RE, &PA -}; - -static char *capstrings[] = { - "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr", - "di", "es", "ex", "fo", "rc", "re", "pa", 0 -}; - -static char *db_array[3] = { _PATH_REMOTE, 0, 0 }; - -#define cgetflag(f) (cgetcap(bp, f, ':') != NULL) - -static void -getremcap(host) - char *host; -{ - char **p, ***q; - char *bp; - char *rempath; - int stat; - - rempath = getenv("REMOTE"); - if (rempath != NULL) { - if (*rempath != '/') - /* we have an entry */ - cgetset(rempath); - else { /* we have a path */ - db_array[1] = rempath; - db_array[2] = _PATH_REMOTE; - } - } - - if ((stat = cgetent(&bp, db_array, host)) < 0) { - if (DV || - host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) { - CU = DV; - HO = host; - HW = 1; - DU = 0; - if (!BR) - BR = DEFBR; - FS = DEFFS; - return; - } - switch(stat) { - case -1: - fprintf(stderr, "%s: unknown host %s\n", __progname, - host); - break; - case -2: - fprintf(stderr, - "%s: can't open host description file\n", - __progname); - break; - case -3: - fprintf(stderr, - "%s: possible reference loop in host description file\n", __progname); - break; - } - exit(3); - } - - for (p = capstrings, q = caps; *p != NULL; p++, q++) - if (**q == NULL) - cgetstr(bp, *p, *q); - if (!BR && (cgetnum(bp, "br", &BR) == -1)) - BR = DEFBR; - if (cgetnum(bp, "fs", &FS) == -1) - FS = DEFFS; - if (DU < 0) - DU = 0; - else - DU = cgetflag("du"); - if (DV == NOSTR) { - fprintf(stderr, "%s: missing device spec\n", host); - exit(3); - } - if (DU && CU == NOSTR) - CU = DV; - if (DU && PN == NOSTR) { - fprintf(stderr, "%s: missing phone number\n", host); - exit(3); - } - if (DU && AT == NOSTR) { - fprintf(stderr, "%s: missing acu type\n", host); - exit(3); - } - - HD = cgetflag("hd"); - - /* - * This effectively eliminates the "hw" attribute - * from the description file - */ - if (!HW) - HW = (CU == NOSTR) || (DU && equal(DV, CU)); - HO = host; - /* - * see if uppercase mode should be turned on initially - */ - if (cgetflag("ra")) - setboolean(value(RAISE), 1); - if (cgetflag("ec")) - setboolean(value(ECHOCHECK), 1); - if (cgetflag("be")) - setboolean(value(BEAUTIFY), 1); - if (cgetflag("nb")) - setboolean(value(BEAUTIFY), 0); - if (cgetflag("sc")) - setboolean(value(SCRIPT), 1); - if (cgetflag("tb")) - setboolean(value(TABEXPAND), 1); - if (cgetflag("vb")) - setboolean(value(VERBOSE), 1); - if (cgetflag("nv")) - setboolean(value(VERBOSE), 0); - if (cgetflag("ta")) - setboolean(value(TAND), 1); - if (cgetflag("nt")) - setboolean(value(TAND), 0); - if (cgetflag("rw")) - setboolean(value(RAWFTP), 1); - if (cgetflag("hd")) - setboolean(value(HALFDUPLEX), 1); - if (cgetflag("dc")) - setboolean(value(DC), 1); - if (RE == NOSTR) - RE = (char *)"tip.record"; - if (EX == NOSTR) - EX = (char *)"\t\n\b\f"; - if (ES != NOSTR) - vstring("es", ES); - if (FO != NOSTR) - vstring("fo", FO); - if (PR != NOSTR) - vstring("pr", PR); - if (RC != NOSTR) - vstring("rc", RC); - if (cgetnum(bp, "dl", &DL) == -1) - DL = 0; - if (cgetnum(bp, "cl", &CL) == -1) - CL = 0; - if (cgetnum(bp, "et", &ET) == -1) - ET = 10; -} - -char * -getremote(host) - char *host; -{ - char *cp; - static char *next; - static int lookedup = 0; - - if (!lookedup) { - if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { - fprintf(stderr, "%s: no host specified\n", __progname); - exit(3); - } - getremcap(host); - next = DV; - lookedup++; - } - /* - * We return a new device each time we're called (to allow - * a rotary action to be simulated) - */ - if (next == NOSTR) - return (NOSTR); - if ((cp = strchr(next, ',')) == NULL) { - DV = next; - next = NOSTR; - } else { - *cp++ = '\0'; - DV = next; - next = cp; - } - return (DV); -} diff --git a/usr.bin/tip/tip/tip.1 b/usr.bin/tip/tip/tip.1 deleted file mode 100644 index 805d77c4151c..000000000000 --- a/usr.bin/tip/tip/tip.1 +++ /dev/null @@ -1,580 +0,0 @@ -.\" $OpenBSD: tip.1,v 1.19 2001/09/23 06:15:30 pvalchev Exp $ -.\" $NetBSD: tip.1,v 1.7 1994/12/08 09:31:05 jtc Exp $ -.\" -.\" Copyright (c) 1980, 1990, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)tip.1 8.4 (Berkeley) 4/18/94 -.\" -.Dd September 9, 2001 -.Dt TIP 1 -.Os -.Sh NAME -.Nm tip , -.Nm cu -.Nd connect to a remote system -.Sh SYNOPSIS -.Nm tip -.Op Fl nv -.Op Fl Ar speed -.Op Ar system\-name -.Nm cu -.Op Fl ehot -.Op Fl a Ar acu -.Op Fl l Ar line -.Op Fl s Ar speed -.Op Fl # -.Op Ar phone\-number -.Sh DESCRIPTION -.Nm -and -.Nm cu -establish a full-duplex connection to another machine, giving the -appearance of being logged in directly on the remote CPU. -It goes without saying that you must have a login on the machine (or -equivalent) to which you wish to connect. -The preferred interface is -.Nm tip . -The -.Nm cu -interface is included for those people attached to the -``call -.Ux Ns '' -command of -.At v7 . -This manual page -describes only -.Nm tip . -.Pp -The options are as follows: -.Bl -tag -width 4n -.It Fl a Ar acu -Set the acu. -.It Fl l Ar line -For -.Nm cu , -specify the line to use. Either of the forms like -.Pa tty00 -or -.Pa /dev/tty00 -are permitted. -.It Fl n -No escape (disable tilde). -.It Fl s Ar speed -For -.Nm cu , -set the speed of the connection. Defaults to 9600. -.It Fl v -Set verbose mode. -.El -.Pp -If -.Ar speed -is specified it will override any baudrate specified in the system -description being used. -.Pp -If neither -.Ar speed -nor -.Ar system-name -are specified, -.Ar system-name -will be set to the value of the -.Ev HOST -environment variable. -.Pp -If -.Ar speed -is specified but -.Ar system-name -is not, -.Ar system-name -will be set to a value of 'tip' with -.Ar speed -appended. -e.g. -.Ic tip -1200 -will set -.Ar system-name -to 'tip1200'. -.Pp -Typed characters are normally transmitted directly to the remote -machine (which does the echoing as well). -A tilde -.Pq Ql ~ -appearing as the first character of a line is an escape signal; the -following are recognized: -.Bl -tag -offset indent -width Fl -.It Ic \&~^D No or Ic \&~ . -Drop the connection and exit (you may still be logged in on the remote -machine). -.It Ic \&~c Op Ar name -Change directory to -.Ar name -(no argument implies change to your home directory). -.It Ic \&~! -Escape to a shell (exiting the shell will return you to -.Nm tip Ns ). -.It Ic \&~> -Copy file from local to remote. -.Nm -prompts for the name of a local file to transmit. -.It Ic \&~< -Copy file from remote to local. -.Nm -prompts first for the name of the file to be sent, then for a command -to be executed on the remote machine. -.It Ic \&~p Ar from Op Ar to -Send a file to a remote -.Ux -host. -The put command causes the remote -.Ux -system to run the command string -.Dq cat > 'to' , -while -.Nm -sends it the -.Dq from -file. -If the -.Dq to -file isn't specified the -.Dq from -file name is used. -this command is actually a -.Ux -specific version of the -.Ic ~> -command. -.It Ic \&~t Ar from Op Ar to -Take a file from a remote -.Ux -host. -As in the put command the -.Dq to -file defaults to the -.Dq from -file name if it isn't specified. -The remote host executes the command string -.Dq cat 'from';echo ^A -to send the file to -.Nm tip . -.It Ic \&~| -Pipe the output from a remote command to a local -.Ux -process. -The command string sent to the local -.Ux -system is processed by the shell. -.It Ic \&~$ -Pipe the output from a local -.Ux -process to the remote host. -The command string sent to the local -.Ux -system is processed by the shell. -.It Ic \&~C -Fork a child process on the local system to perform special protocols -such as \s-1XMODEM\s+1. -The child program will be run with the following somewhat unusual -arrangement of file descriptors: -.Bd -literal -offset indent -0 <-> local tty in -1 <-> local tty out -2 <-> local tty out -3 <-> remote tty in -4 <-> remote tty out -.Ed -.It Ic \&~# -Send a -.Dv BREAK -to the remote system. -For systems which don't support the necessary -.Fn ioctl -call the break is simulated by a sequence of line speed changes and -DEL characters. -.It Ic \&~s -Set a variable (see the discussion below). -.It Ic \&~v -List all variables and their values (if set). -.It Ic \&~^Z -Stop -.Nm -(only available with job control). -.It Ic \&~^Y -Stop only the -.Dq local side -of -.Nm -(only available with job control); the -.Dq remote side -of -.Nm tip , -the side that displays output from the remote host, is left running. -.It Ic \&~? -Get a summary of the tilde escapes. -.El -.Pp -To find the system description and thus the operating characteristics -of -.Ar system-name , -.Nm -searches for a system description with a name identical to -.Ar system-name . -The search order is -.Bl -enum -offset indent -.It -If the environment variable -.Ev REMOTE -does not start with a -.Ql \&/ -it is assumed to be a system description, and is considered first. -.It -If the environment variable -.Ev REMOTE -begins with a -.Ql \&/ -it is assumed to be a path to a -.Xr remote 5 -database, and the specified database is searched. -.It -The default -.Xr remote 5 -database, -.Pa /etc/remote , -is searched. -.El -.Pp -See -.Xr remote 5 -for full documentation on system descriptions. -.Pp -The -.Ar ba -capability is used in system descriptions to specify the baud rate -with which to establish a connection. -If the value specified is not suitable, the baud rate to be used may -be given on the command line, e.g., -.Ql "tip -300 mds" . -.Pp -When -.Nm -establishes a connection it sends out the connection message -specified in the -.Ar cm -capability of the system description being used. -.Pp -When -.Nm -prompts for an argument (e.g., during setup of a file transfer) the -line typed may be edited with the standard erase and kill characters. -A null line in response to a prompt, or an interrupt, will abort the -dialogue and return you to the remote machine. -.Pp -.Nm -guards against multiple users connecting to a remote system by opening -modems and terminal lines with exclusive access, and by honoring the -locking protocol used by -.Xr uucico 8 . -.Pp -During file transfers -.Nm -provides a running count of the number of lines transferred. -When using the -.Ic ~> -and -.Ic ~< -commands, the -.Dq eofread -and -.Dq eofwrite -variables are used to recognize end-of-file when reading, and specify -end-of-file when writing (see below). -File transfers normally depend on tandem mode for flow control. -If the remote system does not support tandem mode, -.Dq echocheck -may be set to indicate -.Nm -should synchronize with the remote system on the echo of each -transmitted character. -.Pp -When -.Nm -must dial a phone number to connect to a system it will print various -messages indicating its actions. -.Nm -supports a variety of auto-call units and modems with the -.Ar at -capability in system descriptions. -.Pp -Support for Ventel 212+ (ventel), Hayes AT-style (hayes), -USRobotics Courier (courier), Telebit T3000 (t3000) and -Racal-Vadic 831 (vadic) units is enabled by default. -.Pp -Support for Bizcomp 1031[fw] (biz31[fw]), Bizcomp 1022[fw] -(biz22[fw]), DEC DF0[23]-AC (df0[23]), DEC DN-11 (dn11) and -Racal-Vadic 3451 (v3451) units can be added by recompiling -.Xr tip 1 -with the appropriate defines. -.Pp -Note that if support for both the Racal-Vadic 831 and 3451 is enabled -they are referred to as the v831 and v3451 respectively. -If only one of the two is supported, it is referred to as vadic. -.Ss VARIABLES -.Nm -maintains a set of variables which control its operation. -Some of these variables are read-only to normal users (root is allowed -to change anything of interest). -Variables may be displayed and set through the -.Sq s -escape. -The syntax for variables is patterned after -.Xr vi 1 -and -.Xr Mail 1 . -Supplying -.Dq all -as an argument to the set command displays all variables readable by -the user. -Alternatively, the user may request display of a particular variable -by attaching a -.Ql ? -to the end. -For example, -.Dq escape? -displays the current escape character. -.Pp -Variables are numeric, string, character, or boolean values. -Boolean variables are set merely by specifying their name; they may be -reset by prepending a -.Ql ! -to the name. -Other variable types are set by concatenating an -.Ql = -and the value. -The entire assignment must not have any blanks in it. -A single set command may be used to interrogate as well as set a -number of variables. -Variables may be initialized at run time by placing set commands -(without the -.Ql ~s -prefix in a file -.Pa .tiprc -in one's home directory). -The -.Fl v -option causes -.Nm -to display the sets as they are made. -Certain common variables have abbreviations. -The following is a list of common variables, their abbreviations, and -their default values: -.Bl -tag -width Ar -.It Ar beautify -(bool) Discard unprintable characters when a session is being -scripted; abbreviated -.Ar be . -.It Ar baudrate -(num) The baud rate at which the connection was established; -abbreviated -.Ar ba . -.It Ar dialtimeout -(num) When dialing a phone number, the time (in seconds) to wait for a -connection to be established; abbreviated -.Ar dial . -.It Ar echocheck -(bool) Synchronize with the remote host during file transfer by -waiting for the echo of the last character transmitted; default is -.Ar off . -.It Ar eofread -(str) The set of characters which signify an end-of-transmission -during a -.Ic ~< -file transfer command; abbreviated -.Ar eofr . -.It Ar eofwrite -(str) The string sent to indicate end-of-transmission during a -.Ic ~> -file transfer command; abbreviated -.Ar eofw . -.It Ar eol -(str) The set of characters which indicate an end-of-line. -.Nm -will recognize escape characters only after an end-of-line. -.It Ar escape -(char) The command prefix (escape) character; abbreviated -.Ar es ; -default value is -.Ql ~ . -.It Ar exceptions -(str) The set of characters which should not be discarded due to the -beautification switch; abbreviated -.Ar ex ; -default value is -.Dq \et\en\ef\eb . -.It Ar force -(char) The character used to force literal data transmission; -abbreviated -.Ar fo ; -default value is -.Ql ^P . -.It Ar framesize -(num) The amount of data (in bytes) to buffer between filesystem -writes when receiving files; abbreviated -.Ar fr . -.It Ar host -(str) The name of the host to which you are connected; abbreviated -.Ar ho . -.It Ar prompt -(char) The character which indicates an end-of-line on the remote -host; abbreviated -.Ar pr ; -default value is -.Ql \en . -This value is used to synchronize during data transfers. -The count of lines transferred during a file transfer command is based -on receipt of this character. -.It Ar raise -(bool) Upper case mapping mode; abbreviated -.Ar ra ; -default value is -.Ar off . -When this mode is enabled, all lowercase letters will be mapped to -uppercase by -.Nm -for transmission to the remote machine. -.It Ar raisechar -(char) The input character used to toggle uppercase mapping mode; -abbreviated -.Ar rc ; -default value is -.Ql ^A . -.It Ar record -(str) The name of the file in which a session script is recorded; -abbreviated -.Ar rec ; -default value is -.Dq tip.record . -.It Ar script -(bool) Session scripting mode; abbreviated -.Ar sc ; -default is -.Ar off . -When -.Ar script -is -.Li true , -.Nm -will record everything transmitted by the remote machine in the script -record file specified in -.Ar record . -If the -.Ar beautify -switch is on, only printable -.Tn ASCII -characters will be included in the script file (those characters -between 040 and 0177). -The variable -.Ar exceptions -is used to indicate characters which are an exception to the normal -beautification rules. -.It Ar tabexpand -(bool) Expand tabs to spaces during file transfers; abbreviated -.Ar tab ; -default value is -.Ar false . -Each tab is expanded to 8 spaces. -.It Ar verbose -(bool) Verbose mode; abbreviated -.Ar verb ; -default is -.Ar true . -When verbose mode is enabled, -.Nm -prints messages while dialing, shows the current number of lines -transferred during a file transfer operations, and more. -.El -.Sh ENVIRONMENT -.Bl -tag -width Fl -.It Ev SHELL -The name of the shell to use for the -.Ic ~! -command; default value is -.Dq /bin/sh . -.It Ev HOME -The home directory to use for the -.Ic ~c -command. -.It Ev HOST -The default value for -.Ar system-name -if none is specified via the command line. -.It Ev REMOTE -A system description, or an absolute path to a -.Xr remote 5 -system description database. -.It Ev PHONES -A path to a -.Xr phones 5 -database. -.El -.Sh FILES -.Bl -tag -width "/var/spool/lock/LCK..*" -compact -.It Pa /etc/remote -global -.Xr remote 5 -database -.It Pa /etc/phones -default -.Xr phones 5 -file -.It Pa ~/.tiprc -initialization file -.It Pa tip.record -record file -.It Pa /var/log/aculog -line access log -.It Pa /var/spool/lock/LCK..* -lock file to avoid conflicts with -.Xr uucp -.El -.Sh SEE ALSO -.Xr phones 5 , -.Xr remote 5 -.Sh HISTORY -The -.Nm -appeared command in -.Bx 4.2 . -.Sh BUGS -The full set of variables is undocumented and should, probably, be -pared down. diff --git a/usr.bin/tip/tip/tip.c b/usr.bin/tip/tip/tip.c deleted file mode 100644 index 64cd76021531..000000000000 --- a/usr.bin/tip/tip/tip.c +++ /dev/null @@ -1,629 +0,0 @@ -/* $OpenBSD: tip.c,v 1.15 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: tip.c,v 1.13 1997/04/20 00:03:05 mellon Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1983, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: tip.c,v 1.15 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -/* - * tip - UNIX link to other systems - * tip [-v] [-speed] system-name - * or - * cu phone-number [-s speed] [-l line] [-a acu] - */ -#include "tip.h" -#include "pathnames.h" - -/* - * Baud rate mapping table - */ -int rates[] = { - 0, 50, 75, 110, 134, 150, 200, 300, 600, - 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, -1 -}; - -int disc = TTYDISC; /* tip normally runs this way */ -void intprompt(); -void timeout(); -void cleanup(); -char PNbuf[256]; /* This limits the size of a number */ - -int -main(argc, argv) - int argc; - char *argv[]; -{ - char *system = NOSTR; - int i; - char *p; - char sbuf[12]; - - gid = getgid(); - egid = getegid(); - uid = getuid(); - euid = geteuid(); - if (equal(__progname, "cu")) { - cumode = 1; - cumain(argc, argv); - goto cucommon; - } - - if (argc > 4) { - fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n"); - exit(1); - } - if (!isatty(0)) { - fprintf(stderr, "%s: must be interactive\n", __progname); - exit(1); - } - - for (; argc > 1; argv++, argc--) { - if (argv[1][0] != '-') - system = argv[1]; - else switch (argv[1][1]) { - - case 'v': - vflag++; - break; - - case 'n': - noesc++; - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - BR = atoi(&argv[1][1]); - break; - - default: - fprintf(stderr, "%s: %s, unknown option\n", __progname, - argv[1]); - break; - } - } - - if (system == NOSTR) - goto notnumber; - if (isalpha(*system)) - goto notnumber; - /* - * System name is really a phone number... - * Copy the number then stomp on the original (in case the number - * is private, we don't want 'ps' or 'w' to find it). - */ - if (strlen(system) > sizeof PNbuf - 1) { - fprintf(stderr, "%s: phone number too long (max = %d bytes)\n", - __progname, (int)sizeof(PNbuf) - 1); - exit(1); - } - strncpy( PNbuf, system, sizeof PNbuf - 1 ); - for (p = system; *p; p++) - *p = '\0'; - PN = PNbuf; - (void)snprintf(sbuf, sizeof(sbuf), "tip%ld", BR); - system = sbuf; - -notnumber: - (void)signal(SIGINT, cleanup); - (void)signal(SIGQUIT, cleanup); - (void)signal(SIGHUP, cleanup); - (void)signal(SIGTERM, cleanup); - - if ((i = hunt(system)) == 0) { - printf("all ports busy\n"); - exit(3); - } - if (i == -1) { - printf("link down\n"); - (void)uu_unlock(uucplock); - exit(3); - } - setbuf(stdout, NULL); - loginit(); - - /* - * Now that we have the logfile and the ACU open - * return to the real uid and gid. These things will - * be closed on exit. Swap real and effective uid's - * so we can get the original permissions back - * for removing the uucp lock. - */ - user_uid(); - - /* - * Kludge, their's no easy way to get the initialization - * in the right order, so force it here - */ - if ((PH = getenv("PHONES")) == NOSTR) - PH = _PATH_PHONES; - vinit(); /* init variables */ - setparity("none"); /* set the parity table */ - if ((i = speed(number(value(BAUDRATE)))) == 0) { - printf("%s: bad baud rate %ld\n", __progname, - number(value(BAUDRATE))); - daemon_uid(); - (void)uu_unlock(uucplock); - exit(3); - } - - /* - * Hardwired connections require the - * line speed set before they make any transmissions - * (this is particularly true of things like a DF03-AC) - */ - if (HW) - ttysetup(i); - if ((p = connect())) { - printf("\07%s\n[EOT]\n", p); - daemon_uid(); - (void)uu_unlock(uucplock); - exit(1); - } - if (!HW) - ttysetup(i); -cucommon: - /* - * From here down the code is shared with - * the "cu" version of tip. - */ - - i = fcntl(FD, F_GETFL); - if (i == -1) { - perror("fcntl"); - cleanup(); - } - i = fcntl(FD, F_SETFL, i & ~O_NONBLOCK); - if (i == -1) { - perror("fcntl"); - cleanup(); - } - - tcgetattr(0, &defterm); - term = defterm; - term.c_lflag &= ~(ICANON|IEXTEN|ECHO); - term.c_iflag &= ~(INPCK|ICRNL); - term.c_oflag &= ~OPOST; - term.c_cc[VMIN] = 1; - term.c_cc[VTIME] = 0; - defchars = term; - term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] = - term.c_cc[VDSUSP] = term.c_cc[VDISCARD] = - term.c_cc[VLNEXT] = _POSIX_VDISABLE; - raw(); - - pipe(fildes); pipe(repdes); - (void)signal(SIGALRM, timeout); - - /* - * Everything's set up now: - * connection established (hardwired or dialup) - * line conditioned (baud rate, mode, etc.) - * internal data structures (variables) - * so, fork one process for local side and one for remote. - */ - printf(cumode ? "Connected\r\n" : "\07connected\r\n"); - if ((pid = fork())) - tipin(); - else - tipout(); - /*NOTREACHED*/ - exit(0); -} - -void -cleanup() -{ - - daemon_uid(); - (void)uu_unlock(uucplock); - if (odisc) - ioctl(0, TIOCSETD, (char *)&odisc); - exit(0); -} - -/* - * Muck with user ID's. We are setuid to the owner of the lock - * directory when we start. user_uid() reverses real and effective - * ID's after startup, to run with the user's permissions. - * daemon_uid() switches back to the privileged uid for unlocking. - * Finally, to avoid running a shell with the wrong real uid, - * shell_uid() sets real and effective uid's to the user's real ID. - */ -static int uidswapped; - -void -user_uid() -{ - if (uidswapped == 0) { - seteuid(uid); - uidswapped = 1; - } -} - -void -daemon_uid() -{ - - if (uidswapped) { - seteuid(euid); - uidswapped = 0; - } -} - -void -shell_uid() -{ - setegid(gid); - seteuid(uid); -} - -/* - * put the controlling keyboard into raw mode - */ -void -raw() -{ - tcsetattr(0, TCSADRAIN, &term); -} - - -/* - * return keyboard to normal mode - */ -void -unraw() -{ - tcsetattr(0, TCSADRAIN, &defterm); -} - -static jmp_buf promptbuf; - -/* - * Print string ``s'', then read a string - * in from the terminal. Handles signals & allows use of - * normal erase and kill characters. - */ -int -prompt(s, p, sz) - char *s; - char *p; - size_t sz; -{ - int c; - char *b = p; - sig_t oint, oquit; - - stoprompt = 0; - oint = signal(SIGINT, intprompt); - oquit = signal(SIGQUIT, SIG_IGN); - unraw(); - printf("%s", s); - if (setjmp(promptbuf) == 0) - while ((c = getchar()) != EOF && (*p = c) != '\n' && --sz > 0) - p++; - *p = '\0'; - - raw(); - (void)signal(SIGINT, oint); - (void)signal(SIGQUIT, oquit); - return (stoprompt || p == b); -} - -/* - * Interrupt service routine during prompting - */ -void -intprompt() -{ - - (void)signal(SIGINT, SIG_IGN); - stoprompt = 1; - printf("\r\n"); - longjmp(promptbuf, 1); -} - -/* - * ****TIPIN TIPIN**** - */ -void -tipin() -{ - char gch, bol = 1; - - /* - * Kinda klugey here... - * check for scripting being turned on from the .tiprc file, - * but be careful about just using setscript(), as we may - * send a SIGEMT before tipout has a chance to set up catching - * it; so wait a second, then setscript() - */ - if (boolean(value(SCRIPT))) { - sleep(1); - setscript(); - } - - while (1) { - gch = getchar()&STRIP_PAR; - if ((gch == character(value(ESCAPE))) && bol) { - if (!noesc) { - if (!(gch = escape())) - continue; - } - } else if (!cumode && gch == character(value(RAISECHAR))) { - setboolean(value(RAISE), !boolean(value(RAISE))); - continue; - } else if (gch == '\r') { - bol = 1; - parwrite(FD, &gch, 1); - if (boolean(value(HALFDUPLEX))) - printf("\r\n"); - continue; - } else if (!cumode && gch == character(value(FORCE))) - gch = getchar()&STRIP_PAR; - bol = any(gch, value(EOL)); - if (boolean(value(RAISE)) && islower(gch)) - gch = toupper(gch); - parwrite(FD, &gch, 1); - if (boolean(value(HALFDUPLEX))) - printf("%c", gch); - } -} - -extern esctable_t etable[]; - -/* - * Escape handler -- - * called on recognition of ``escapec'' at the beginning of a line - */ -int -escape() -{ - char gch; - esctable_t *p; - char c = character(value(ESCAPE)); - - gch = (getchar()&STRIP_PAR); - for (p = etable; p->e_char; p++) - if (p->e_char == gch) { - if ((p->e_flags&PRIV) && uid) - continue; - printf("%s", ctrl(c)); - (*p->e_func)(gch); - return (0); - } - /* ESCAPE ESCAPE forces ESCAPE */ - if (c != gch) - parwrite(FD, &c, 1); - return (gch); -} - -int -speed(n) - int n; -{ - int *p; - - for (p = rates; *p != -1; p++) - if (*p == n) - return n; - return 0; -} - -int -any(cc, p) - int cc; - char *p; -{ - char c = cc; - while (p && *p) - if (*p++ == c) - return (1); - return (0); -} - -int -size(s) - char *s; -{ - int i = 0; - - while (s && *s++) - i++; - return (i); -} - -char * -interp(s) - char *s; -{ - static char buf[256]; - char *p = buf, c, *q; - - while ((c = *s++)) { - for (q = "\nn\rr\tt\ff\033E\bb"; *q; q++) - if (*q++ == c) { - *p++ = '\\'; *p++ = *q; - goto next; - } - if (c < 040) { - *p++ = '^'; *p++ = c + 'A'-1; - } else if (c == 0177) { - *p++ = '^'; *p++ = '?'; - } else - *p++ = c; - next: - ; - } - *p = '\0'; - return (buf); -} - -char * -ctrl(c) - char c; -{ - static char s[3]; - - if (c < 040 || c == 0177) { - s[0] = '^'; - s[1] = c == 0177 ? '?' : c+'A'-1; - s[2] = '\0'; - } else { - s[0] = c; - s[1] = '\0'; - } - return (s); -} - -/* - * Help command - */ -void -help(c) - char c; -{ - esctable_t *p; - - printf("%c\r\n", c); - for (p = etable; p->e_char; p++) { - if ((p->e_flags&PRIV) && uid) - continue; - printf("%2s", ctrl(character(value(ESCAPE)))); - printf("%-2s %c %s\r\n", ctrl(p->e_char), - p->e_flags&EXP ? '*': ' ', p->e_help); - } -} - -/* - * Set up the "remote" tty's state - */ -void -ttysetup(speed) - int speed; -{ - struct termios cntrl; - - tcgetattr(FD, &cntrl); - cfsetospeed(&cntrl, speed); - cfsetispeed(&cntrl, speed); - cntrl.c_cflag &= ~(CSIZE|PARENB); - cntrl.c_cflag |= CS8; - if (boolean(value(DC))) - cntrl.c_cflag |= CLOCAL; - cntrl.c_iflag &= ~(ISTRIP|ICRNL); - cntrl.c_oflag &= ~OPOST; - cntrl.c_lflag &= ~(ICANON|ISIG|IEXTEN|ECHO); - cntrl.c_cc[VMIN] = 1; - cntrl.c_cc[VTIME] = 0; - if (boolean(value(TAND))) - cntrl.c_iflag |= IXOFF; - tcsetattr(FD, TCSAFLUSH, &cntrl); -} - -static char partab[0200]; - -/* - * Do a write to the remote machine with the correct parity. - * We are doing 8 bit wide output, so we just generate a character - * with the right parity and output it. - */ -void -parwrite(fd, buf, n) - int fd; - char *buf; - int n; -{ - int i; - char *bp; - - bp = buf; - if (bits8 == 0) - for (i = 0; i < n; i++) { - *bp = partab[(*bp) & 0177]; - bp++; - } - if (write(fd, buf, n) < 0) { - if (errno == EIO) - tipabort("Lost carrier."); - /* this is questionable */ - perror("write"); - } -} - -/* - * Build a parity table with appropriate high-order bit. - */ -void -setparity(defparity) - char *defparity; -{ - int i, flip, clr, set; - char *parity; - extern const unsigned char evenpartab[]; - - if (value(PARITY) == NOSTR) - value(PARITY) = defparity; - parity = value(PARITY); - if (equal(parity, "none")) { - bits8 = 1; - return; - } - bits8 = 0; - flip = 0; - clr = 0377; - set = 0; - if (equal(parity, "odd")) - flip = 0200; /* reverse bit 7 */ - else if (equal(parity, "zero")) - clr = 0177; /* turn off bit 7 */ - else if (equal(parity, "one")) - set = 0200; /* turn on bit 7 */ - else if (!equal(parity, "even")) { - (void) fprintf(stderr, "%s: unknown parity value\r\n", parity); - (void) fflush(stderr); - } - for (i = 0; i < 0200; i++) - partab[i] = (evenpartab[i] ^ flip | set) & clr; -} diff --git a/usr.bin/tip/tip/tip.h b/usr.bin/tip/tip/tip.h deleted file mode 100644 index 4c5ab2064eec..000000000000 --- a/usr.bin/tip/tip/tip.h +++ /dev/null @@ -1,312 +0,0 @@ -/* $OpenBSD: tip.h,v 1.11 2001/09/09 19:30:49 millert Exp $ */ -/* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tip.h 8.1 (Berkeley) 6/6/93 - */ - -/* - * tip - terminal interface program - */ - -#include <sys/types.h> -#include <sys/file.h> -#include <sys/time.h> -#include <sys/wait.h> -#include <sys/ioctl.h> - -#include <termios.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <pwd.h> -#include <ctype.h> -#include <setjmp.h> -#include <unistd.h> -#include <errno.h> -#include <limits.h> - -/* - * Remote host attributes - */ -char *DV; /* UNIX device(s) to open */ -char *EL; /* chars marking an EOL */ -char *CM; /* initial connection message */ -char *IE; /* EOT to expect on input */ -char *OE; /* EOT to send to complete FT */ -char *CU; /* call unit if making a phone call */ -char *AT; /* acu type */ -char *PN; /* phone number(s) */ -char *DI; /* disconnect string */ -char *PA; /* parity to be generated */ - -char *PH; /* phone number file */ -char *RM; /* remote file name */ -char *HO; /* host name */ - -long BR; /* line speed for conversation */ -long FS; /* frame size for transfers */ - -short DU; /* this host is dialed up */ -short HW; /* this device is hardwired, see hunt.c */ -char *ES; /* escape character */ -char *EX; /* exceptions */ -char *FO; /* force (literal next) char*/ -char *RC; /* raise character */ -char *RE; /* script record file */ -char *PR; /* remote prompt */ -long DL; /* line delay for file transfers to remote */ -long CL; /* char delay for file transfers to remote */ -long ET; /* echocheck timeout */ -short HD; /* this host is half duplex - do local echo */ -short DC; /* this host is directly connected. */ - -/* - * String value table - */ -typedef - struct { - char *v_name; /* whose name is it */ - char v_type; /* for interpreting set's */ - char v_access; /* protection of touchy ones */ - char *v_abrev; /* possible abreviation */ - char *v_value; /* casted to a union later */ - } - value_t; - -#define STRING 01 /* string valued */ -#define BOOL 02 /* true-false value */ -#define NUMBER 04 /* numeric value */ -#define CHAR 010 /* character value */ - -#define WRITE 01 /* write access to variable */ -#define READ 02 /* read access */ - -#define CHANGED 01 /* low bit is used to show modification */ -#define PUBLIC 1 /* public access rights */ -#define PRIVATE 03 /* private to definer */ -#define ROOT 05 /* root defined */ - -#define TRUE 1 -#define FALSE 0 - -#define ENVIRON 020 /* initialize out of the environment */ -#define IREMOTE 040 /* initialize out of remote structure */ -#define INIT 0100 /* static data space used for initialization */ -#define TMASK 017 - -/* - * Definition of ACU line description - */ -typedef - struct { - char *acu_name; - int (*acu_dialer)(); - int (*acu_disconnect)(); - int (*acu_abort)(); - } - acu_t; - -#define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */ - -/* - * variable manipulation stuff -- - * if we defined the value entry in value_t, then we couldn't - * initialize it in vars.c, so we cast it as needed to keep lint - * happy. - */ - -#define value(v) vtable[v].v_value - -#define number(v) ((long)(v)) -#define boolean(v) ((short)(long)(v)) -#define character(v) ((char)(long)(v)) -#define address(v) ((long *)(v)) - -#define setnumber(v,n) do { (v) = (char *)(long)(n); } while (0) -#define setboolean(v,n) do { (v) = (char *)(long)(n); } while (0) -#define setcharacter(v,n) do { (v) = (char *)(long)(n); } while (0) -#define setaddress(v,n) do { (v) = (char *)(n); } while (0) - -/* - * Escape command table definitions -- - * lookup in this table is performed when ``escapec'' is recognized - * at the begining of a line (as defined by the eolmarks variable). -*/ - -typedef - struct { - char e_char; /* char to match on */ - char e_flags; /* experimental, priviledged */ - char *e_help; /* help string */ - int (*e_func)(); /* command */ - } - esctable_t; - -#define NORM 00 /* normal protection, execute anyone */ -#define EXP 01 /* experimental, mark it with a `*' on help */ -#define PRIV 02 /* priviledged, root execute only */ - -extern int vflag; /* verbose during reading of .tiprc file */ -extern int noesc; /* no escape `~' char */ -extern value_t vtable[]; /* variable table */ - -#ifndef ACULOG -#define logent(a, b, c, d) -#define loginit() -#endif - -/* - * Definition of indices into variable table so - * value(DEFINE) turns into a static address. - */ - -#define BEAUTIFY 0 -#define BAUDRATE 1 -#define DIALTIMEOUT 2 -#define EOFREAD 3 -#define EOFWRITE 4 -#define EOL 5 -#define ESCAPE 6 -#define EXCEPTIONS 7 -#define FORCE 8 -#define FRAMESIZE 9 -#define HOST 10 -#define LOG 11 -#define PHONES 12 -#define PROMPT 13 -#define RAISE 14 -#define RAISECHAR 15 -#define RECORD 16 -#define REMOTE 17 -#define SCRIPT 18 -#define TABEXPAND 19 -#define VERBOSE 20 -#define SHELL 21 -#define HOME 22 -#define ECHOCHECK 23 -#define DISCONNECT 24 -#define TAND 25 -#define LDELAY 26 -#define CDELAY 27 -#define ETIMEOUT 28 -#define RAWFTP 29 -#define HALFDUPLEX 30 -#define LECHO 31 -#define PARITY 32 - -#define NOVAL ((value_t *)NULL) -#define NOACU ((acu_t *)NULL) -#define NOSTR ((char *)NULL) -#define NOFILE ((FILE *)NULL) -#define NOPWD ((struct passwd *)0) - -struct termios term; /* current mode of terminal */ -struct termios defterm; /* initial mode of terminal */ -struct termios defchars; /* current mode with initial chars */ - -FILE *fscript; /* FILE for scripting */ - -int fildes[2]; /* file transfer synchronization channel */ -int repdes[2]; /* read process sychronization channel */ -int FD; /* open file descriptor to remote host */ -int AC; /* open file descriptor to dialer (v831 only) */ -int vflag; /* print .tiprc initialization sequence */ -int noesc; /* no `~' escape char */ -int sfd; /* for ~< operation */ -int pid; /* pid of tipout */ -uid_t uid, euid; /* real and effective user id's */ -gid_t gid, egid; /* real and effective group id's */ -int stop; /* stop transfer session flag */ -int quit; /* same; but on other end */ -int intflag; /* recognized interrupt */ -int stoprompt; /* for interrupting a prompt session */ -int timedout; /* ~> transfer timedout */ -int cumode; /* simulating the "cu" program */ -int bits8; /* terminal is is 8-bit mode */ -#define STRIP_PAR (bits8 ? 0377 : 0177) - -char fname[PATH_MAX]; /* file name buffer for ~< */ -char copyname[PATH_MAX]; /* file name buffer for ~> */ -char ccc; /* synchronization character */ -char ch; /* for tipout */ -char *uucplock; /* name of lock file for uucp's */ - -int odisc; /* initial tty line discipline */ -extern int disc; /* current tty discpline */ - -extern char *__progname; /* program name */ - -extern char *ctrl(); -extern char *vinterp(); -extern char *connect(); - -char *sname __P((char *s)); -int any __P((int cc, char *p)); -int anyof __P((char *s1, char *s2)); -int args __P((char *buf, char *a[], int num)); -int escape __P((void)); -int prompt __P((char *s, char *p, size_t sz)); -int size __P((char *s)); -int speed __P((int n)); -int uu_lock __P((char *ttyname)); -int uu_unlock __P((char *ttyname)); -int vstring __P((char *s, char *v)); -long hunt __P((char *name)); -void cumain __P((int argc, char *argv[])); -void daemon_uid __P((void)); -void disconnect __P((char *reason)); -void execute __P((char *s)); -void logent __P((char *group, char *num, char *acu, char *message)); -void loginit __P((void)); -void prtime __P((char *s, time_t a)); -void parwrite __P((int fd, char *buf, int n)); -void raw __P((void)); -void send __P((int c)); -void setparity __P((char *defparity)); -void setscript __P((void)); -void shell_uid __P((void)); -void tandem __P((char *option)); -void tipabort __P((char *msg)); -void tipin __P((void)); -void tipout __P((void)); -void transfer __P((char *buf, int fd, char *eofchars)); -void transmit __P((FILE *fd, char *eofchars, char *command)); -void ttysetup __P((int speed)); -void unraw __P((void)); -void user_uid __P((void)); -void vinit __P((void)); -void vlex __P((char *s)); diff --git a/usr.bin/tip/tip/tipout.c b/usr.bin/tip/tip/tipout.c deleted file mode 100644 index d1ff53cdc0bb..000000000000 --- a/usr.bin/tip/tip/tipout.c +++ /dev/null @@ -1,172 +0,0 @@ -/* $OpenBSD: tipout.c,v 1.8 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: tipout.c,v 1.5 1996/12/29 10:34:12 cgd Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)tipout.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: tipout.c,v 1.8 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" -/* - * tip - * - * lower fork of tip -- handles passive side - * reading from the remote host - */ - -static jmp_buf sigbuf; - -/* - * TIPOUT wait state routine -- - * sent by TIPIN when it wants to posses the remote host - */ -void -intIOT() -{ - - write(repdes[1],&ccc,1); - read(fildes[0], &ccc,1); - longjmp(sigbuf, 1); -} - -/* - * Scripting command interpreter -- - * accepts script file name over the pipe and acts accordingly - */ -void -intEMT() -{ - char c, line[256]; - char *pline = line; - char reply; - - read(fildes[0], &c, 1); - while (c != '\n' && pline - line < sizeof(line)) { - *pline++ = c; - read(fildes[0], &c, 1); - } - *pline = '\0'; - if (boolean(value(SCRIPT)) && fscript != NULL) - fclose(fscript); - if (pline == line) { - setboolean(value(SCRIPT), FALSE); - reply = 'y'; - } else { - if ((fscript = fopen(line, "a")) == NULL) - reply = 'n'; - else { - reply = 'y'; - setboolean(value(SCRIPT), TRUE); - } - } - write(repdes[1], &reply, 1); - longjmp(sigbuf, 1); -} - -void -intTERM() -{ - - if (boolean(value(SCRIPT)) && fscript != NULL) - fclose(fscript); - exit(0); -} - -void -intSYS() -{ - - setboolean(value(BEAUTIFY), !boolean(value(BEAUTIFY))); - longjmp(sigbuf, 1); -} - -/* - * ****TIPOUT TIPOUT**** - */ -void -tipout() -{ - char buf[BUFSIZ]; - char *cp; - int cnt; - sigset_t mask, omask; - - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - signal(SIGEMT, intEMT); /* attention from TIPIN */ - signal(SIGTERM, intTERM); /* time to go signal */ - signal(SIGIOT, intIOT); /* scripting going on signal */ - signal(SIGHUP, intTERM); /* for dial-ups */ - signal(SIGSYS, intSYS); /* beautify toggle */ - (void) setjmp(sigbuf); - sigprocmask(SIG_BLOCK, NULL, &omask); - for (;;) { - sigprocmask(SIG_SETMASK, &omask, NULL); - cnt = read(FD, buf, BUFSIZ); - if (cnt <= 0) { - /* lost carrier */ - if (cnt < 0 && errno == EIO) { - sigemptyset(&mask); - sigaddset(&mask, SIGTERM); - sigprocmask(SIG_BLOCK, &mask, NULL); - intTERM(); - /*NOTREACHED*/ - } - continue; - } - sigemptyset(&mask); - sigaddset(&mask, SIGEMT); - sigaddset(&mask, SIGTERM); - sigaddset(&mask, SIGIOT); - sigaddset(&mask, SIGSYS); - sigprocmask(SIG_BLOCK, &mask, NULL); - for (cp = buf; cp < buf + cnt; cp++) - *cp &= STRIP_PAR; - write(1, buf, cnt); - if (boolean(value(SCRIPT)) && fscript != NULL) { - if (!boolean(value(BEAUTIFY))) { - fwrite(buf, 1, cnt, fscript); - continue; - } - for (cp = buf; cp < buf + cnt; cp++) - if ((*cp >= ' ' && *cp <= '~') || - any(*cp, value(EXCEPTIONS))) - putc(*cp, fscript); - } - } -} diff --git a/usr.bin/tip/tip/uucplock.c b/usr.bin/tip/tip/uucplock.c deleted file mode 100644 index a2a703b9edbe..000000000000 --- a/usr.bin/tip/tip/uucplock.c +++ /dev/null @@ -1,132 +0,0 @@ -/* $OpenBSD: uucplock.c,v 1.6 1998/07/13 02:11:44 millert Exp $ */ -/* $NetBSD: uucplock.c,v 1.7 1997/02/11 09:24:08 mrg Exp $ */ - -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: uucplock.c,v 1.6 1998/07/13 02:11:44 millert Exp $"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/file.h> -#include <sys/dir.h> -#include <stdio.h> -#include <string.h> -#include <signal.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include "pathnames.h" - -/* - * uucp style locking routines - * return: 0 - success - * -1 - failure - */ - -int -uu_lock(ttyname) - char *ttyname; -{ - int fd, pid; - char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN]; - char text_pid[81]; - int len; - - (void)snprintf(tbuf, sizeof tbuf, _PATH_LOCKDIRNAME, ttyname); - fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660); - if (fd < 0) { - /* - * file is already locked - * check to see if the process holding the lock still exists - */ - fd = open(tbuf, O_RDWR, 0); - if (fd < 0) { - perror(tbuf); - fprintf(stderr, "Can't open lock file.\n"); - return(-1); - } - len = read(fd, text_pid, sizeof(text_pid)-1); - if(len<=0) { - perror(tbuf); - (void)close(fd); - fprintf(stderr, "Can't read lock file.\n"); - return(-1); - } - text_pid[len] = 0; - pid = atol(text_pid); - - if (kill(pid, 0) == 0 || errno != ESRCH) { - (void)close(fd); /* process is still running */ - return(-1); - } - /* - * The process that locked the file isn't running, so - * we'll lock it ourselves - */ - fprintf(stderr, "Stale lock on %s PID=%d... overriding.\n", - ttyname, pid); - if (lseek(fd, (off_t)0, SEEK_SET) < 0) { - perror(tbuf); - (void)close(fd); - fprintf(stderr, "Can't seek lock file.\n"); - return(-1); - } - /* fall out and finish the locking process */ - } - pid = getpid(); - (void)sprintf(text_pid, "%10d\n", pid); - len = strlen(text_pid); - if (write(fd, text_pid, len) != len) { - (void)close(fd); - (void)unlink(tbuf); - perror("lock write"); - return(-1); - } - (void)close(fd); - return(0); -} - -int -uu_unlock(ttyname) - char *ttyname; -{ - char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN]; - - (void)snprintf(tbuf, sizeof tbuf, _PATH_LOCKDIRNAME, ttyname); - return(unlink(tbuf)); -} diff --git a/usr.bin/tip/tip/value.c b/usr.bin/tip/tip/value.c deleted file mode 100644 index 20817e9cdffc..000000000000 --- a/usr.bin/tip/tip/value.c +++ /dev/null @@ -1,365 +0,0 @@ -/* $OpenBSD: value.c,v 1.7 2001/10/24 18:38:58 millert Exp $ */ -/* $NetBSD: value.c,v 1.6 1997/02/11 09:24:09 mrg Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)value.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: value.c,v 1.7 2001/10/24 18:38:58 millert Exp $"; -#endif /* not lint */ - -#include "tip.h" - -#define MIDDLE 35 - -static value_t *vlookup(); -static int col = 0; - -/* - * Variable manipulation - */ -void -vinit() -{ - value_t *p; - char *cp; - FILE *f; - char file[FILENAME_MAX]; - - for (p = vtable; p->v_name != NULL; p++) { - if (p->v_type&ENVIRON) - if ((cp = getenv(p->v_name))) - p->v_value = cp; - if (p->v_type&IREMOTE) - setnumber(p->v_value, *address(p->v_value)); - } - /* - * Read the .tiprc file in the HOME directory - * for sets - */ - if (strlen(value(HOME)) + sizeof("/.tiprc") > sizeof(file)) { - (void)fprintf(stderr, "Home directory path too long: %s\n", - value(HOME)); - } else { - snprintf(file, sizeof file, "%s/.tiprc", value(HOME)); - if ((f = fopen(file, "r")) != NULL) { - char *tp; - - while (fgets(file, sizeof(file)-1, f) != NULL) { - if (vflag) - printf("set %s", file); - if ((tp = strrchr(file, '\n'))) - *tp = '\0'; - vlex(file); - } - fclose(f); - } - } - /* - * To allow definition of exception prior to fork - */ - vtable[EXCEPTIONS].v_access &= ~(WRITE<<PUBLIC); -} - -static int vaccess(); - -/*VARARGS1*/ -void -vassign(p, v) - value_t *p; - char *v; -{ - - if (!vaccess(p->v_access, WRITE)) { - printf("access denied\r\n"); - return; - } - switch (p->v_type&TMASK) { - - case STRING: - if (p->v_value && equal(p->v_value, v)) - return; - if (!(p->v_type&(ENVIRON|INIT))) - free(p->v_value); - if ((p->v_value = strdup(v)) == NOSTR) { - printf("out of core\r\n"); - return; - } - p->v_type &= ~(ENVIRON|INIT); - break; - - case NUMBER: - if (number(p->v_value) == number(v)) - return; - setnumber(p->v_value, number(v)); - break; - - case BOOL: - if (boolean(p->v_value) == (*v != '!')) - return; - setboolean(p->v_value, (*v != '!')); - break; - - case CHAR: - if (character(p->v_value) == *v) - return; - setcharacter(p->v_value, *v); - } - p->v_access |= CHANGED; -} - -static void vprint(); -static void vtoken(); - -void -vlex(s) - char *s; -{ - value_t *p; - - if (equal(s, "all")) { - for (p = vtable; p->v_name; p++) - if (vaccess(p->v_access, READ)) - vprint(p); - } else { - char *cp; - - do { - if ((cp = vinterp(s, ' '))) - cp++; - vtoken(s); - s = cp; - } while (s); - } - if (col > 0) { - printf("\r\n"); - col = 0; - } -} - -static void -vtoken(s) - char *s; -{ - value_t *p; - char *cp; - char *expand(); - - if ((cp = strchr(s, '='))) { - *cp = '\0'; - if ((p = vlookup(s))) { - cp++; - if (p->v_type&NUMBER) - vassign(p, atoi(cp)); - else { - if (strcmp(s, "record") == 0) - cp = expand(cp); - vassign(p, cp); - } - return; - } - } else if ((cp = strchr(s, '?'))) { - *cp = '\0'; - if ((p = vlookup(s)) && vaccess(p->v_access, READ)) { - vprint(p); - return; - } - } else { - if (*s != '!') - p = vlookup(s); - else - p = vlookup(s+1); - if (p != NOVAL) { - vassign(p, s); - return; - } - } - printf("%s: unknown variable\r\n", s); -} - -static void -vprint(p) - value_t *p; -{ - char *cp; - extern char *interp(), *ctrl(); - - if (col > 0 && col < MIDDLE) - while (col++ < MIDDLE) - putchar(' '); - col += size(p->v_name); - switch (p->v_type&TMASK) { - - case BOOL: - if (boolean(p->v_value) == FALSE) { - col++; - putchar('!'); - } - printf("%s", p->v_name); - break; - - case STRING: - printf("%s=", p->v_name); - col++; - if (p->v_value) { - cp = interp(p->v_value, NULL); - col += size(cp); - printf("%s", cp); - } - break; - - case NUMBER: - col += 6; - printf("%s=%-5ld", p->v_name, number(p->v_value)); - break; - - case CHAR: - printf("%s=", p->v_name); - col++; - if (p->v_value) { - cp = ctrl(character(p->v_value)); - col += size(cp); - printf("%s", cp); - } - break; - } - if (col >= MIDDLE) { - col = 0; - printf("\r\n"); - return; - } -} - - -static int -vaccess(mode, rw) - unsigned mode, rw; -{ - if (mode & (rw<<PUBLIC)) - return (1); - if (mode & (rw<<PRIVATE)) - return (1); - return ((mode & (rw<<ROOT)) && getuid() == 0); -} - -static value_t * -vlookup(s) - char *s; -{ - value_t *p; - - for (p = vtable; p->v_name; p++) - if (equal(p->v_name, s) || (p->v_abrev && equal(p->v_abrev, s))) - return (p); - return (NULL); -} - -char * -vinterp(s, stop) - char *s; - char stop; -{ - char *p = s, c; - int num; - - while ((c = *s++) && c != stop) - switch (c) { - - case '^': - if (*s) - *p++ = *s++ - 0100; - else - *p++ = c; - break; - - case '\\': - num = 0; - c = *s++; - if (c >= '0' && c <= '7') - num = (num<<3)+(c-'0'); - else { - char *q = "n\nr\rt\tb\bf\f"; - - for (; *q; q++) - if (c == *q++) { - *p++ = *q; - goto cont; - } - *p++ = c; - cont: - break; - } - if ((c = *s++) >= '0' && c <= '7') { - num = (num<<3)+(c-'0'); - if ((c = *s++) >= '0' && c <= '7') - num = (num<<3)+(c-'0'); - else - s--; - } else - s--; - *p++ = num; - break; - - default: - *p++ = c; - } - *p = '\0'; - return (c == stop ? s-1 : NULL); -} - -/* - * assign variable s with value v (for NUMBER or STRING or CHAR types) - */ -int -vstring(s,v) - char *s; - char *v; -{ - value_t *p; - char *expand(); - - p = vlookup(s); - if (p == 0) - return (1); - if (p->v_type&NUMBER) - vassign(p, atoi(v)); - else { - if (strcmp(s, "record") == 0) - v = expand(v); - vassign(p, v); - } - return (0); -} diff --git a/usr.bin/tip/tip/vars.c b/usr.bin/tip/tip/vars.c deleted file mode 100644 index 6131dd29f97d..000000000000 --- a/usr.bin/tip/tip/vars.c +++ /dev/null @@ -1,118 +0,0 @@ -/* $OpenBSD: vars.c,v 1.2 1996/06/26 05:40:50 deraadt Exp $ */ -/* $NetBSD: vars.c,v 1.3 1994/12/08 09:31:19 jtc Exp $ */ - -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)vars.c 8.1 (Berkeley) 6/6/93"; -#endif -static char rcsid[] = "$OpenBSD: vars.c,v 1.2 1996/06/26 05:40:50 deraadt Exp $"; -#endif /* not lint */ - -#include "tip.h" -#include "pathnames.h" - -/* - * Definition of variables - */ -value_t vtable[] = { - { "beautify", BOOL, (READ|WRITE)<<PUBLIC, - "be", (char *)TRUE }, - { "baudrate", NUMBER|IREMOTE|INIT, (READ<<PUBLIC)|(WRITE<<ROOT), - "ba", (char *)&BR }, - { "dialtimeout",NUMBER, (READ<<PUBLIC)|(WRITE<<ROOT), - "dial", (char *)60 }, - { "eofread", STRING|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "eofr", (char *)&IE }, - { "eofwrite", STRING|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "eofw", (char *)&OE }, - { "eol", STRING|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - NOSTR, (char *)&EL }, - { "escape", CHAR, (READ|WRITE)<<PUBLIC, - "es", (char *)'~' }, - { "exceptions", STRING|INIT|IREMOTE, (READ|WRITE)<<PUBLIC, - "ex", (char *)&EX }, - { "force", CHAR, (READ|WRITE)<<PUBLIC, - "fo", (char *)CTRL('p') }, - { "framesize", NUMBER|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "fr", (char *)&FS }, - { "host", STRING|IREMOTE|INIT, READ<<PUBLIC, - "ho", (char *)&HO }, - { "log", STRING|INIT, (READ|WRITE)<<ROOT, - NOSTR, _PATH_ACULOG }, - { "phones", STRING|INIT|IREMOTE, READ<<PUBLIC, - NOSTR, (char *)&PH }, - { "prompt", CHAR, (READ|WRITE)<<PUBLIC, - "pr", (char *)'\n' }, - { "raise", BOOL, (READ|WRITE)<<PUBLIC, - "ra", (char *)FALSE }, - { "raisechar", CHAR, (READ|WRITE)<<PUBLIC, - "rc", (char *)CTRL('a') }, - { "record", STRING|INIT|IREMOTE, (READ|WRITE)<<PUBLIC, - "rec", (char *)&RE }, - { "remote", STRING|INIT|IREMOTE, READ<<PUBLIC, - NOSTR, (char *)&RM }, - { "script", BOOL, (READ|WRITE)<<PUBLIC, - "sc", (char *)FALSE }, - { "tabexpand", BOOL, (READ|WRITE)<<PUBLIC, - "tab", (char *)FALSE }, - { "verbose", BOOL, (READ|WRITE)<<PUBLIC, - "verb", (char *)TRUE }, - { "SHELL", STRING|ENVIRON|INIT, (READ|WRITE)<<PUBLIC, - NULL, _PATH_BSHELL }, - { "HOME", STRING|ENVIRON, (READ|WRITE)<<PUBLIC, - NOSTR, NOSTR }, - { "echocheck", BOOL, (READ|WRITE)<<PUBLIC, - "ec", (char *)FALSE }, - { "disconnect", STRING|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "di", (char *)&DI }, - { "tandem", BOOL, (READ|WRITE)<<PUBLIC, - "ta", (char *)TRUE }, - { "linedelay", NUMBER|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "ldelay", (char *)&DL }, - { "chardelay", NUMBER|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "cdelay", (char *)&CL }, - { "etimeout", NUMBER|IREMOTE|INIT, (READ|WRITE)<<PUBLIC, - "et", (char *)&ET }, - { "rawftp", BOOL, (READ|WRITE)<<PUBLIC, - "raw", (char *)FALSE }, - { "halfduplex", BOOL, (READ|WRITE)<<PUBLIC, - "hdx", (char *)FALSE }, - { "localecho", BOOL, (READ|WRITE)<<PUBLIC, - "le", (char *)FALSE }, - { "parity", STRING|INIT|IREMOTE, (READ|WRITE)<<PUBLIC, - "par", (char *)&PA }, - { NOSTR, NULL, NULL, NOSTR, NOSTR } -}; |