xref: /csrg-svn/bin/stty/cchar.c (revision 60721)
148938Sbostic /*-
2*60721Sbostic  * Copyright (c) 1991, 1993
3*60721Sbostic  *	The Regents of the University of California.  All rights reserved.
448938Sbostic  *
548938Sbostic  * %sccs.include.redist.c%
648938Sbostic  */
748938Sbostic 
848938Sbostic #ifndef lint
9*60721Sbostic static char sccsid[] = "@(#)cchar.c	8.1 (Berkeley) 05/31/93";
1048938Sbostic #endif /* not lint */
1148938Sbostic 
1248938Sbostic #include <sys/types.h>
1359518Sbostic 
1459518Sbostic #include <err.h>
1548938Sbostic #include <stddef.h>
1650010Sbostic #include <stdlib.h>
1750010Sbostic #include <string.h>
1859518Sbostic 
1948938Sbostic #include "stty.h"
2050010Sbostic #include "extern.h"
2148938Sbostic 
2248938Sbostic /*
2348938Sbostic  * Special control characters.
2448938Sbostic  *
2548938Sbostic  * Cchars1 are the standard names, cchars2 are the old aliases.
2648938Sbostic  * The first are displayed, but both are recognized on the
2748938Sbostic  * command line.
2848938Sbostic  */
2948938Sbostic struct cchar cchars1[] = {
3059518Sbostic 	{ "discard",	VDISCARD, 	CDISCARD },
3159518Sbostic 	{ "dsusp", 	VDSUSP,		CDSUSP },
3259518Sbostic 	{ "eof",	VEOF,		CEOF },
3359518Sbostic 	{ "eol",	VEOL,		CEOL },
3459518Sbostic 	{ "eol2",	VEOL2,		CEOL },
3559518Sbostic 	{ "erase",	VERASE,		CERASE },
3659518Sbostic 	{ "intr",	VINTR,		CINTR },
3759518Sbostic 	{ "kill",	VKILL,		CKILL },
3859518Sbostic 	{ "lnext",	VLNEXT,		CLNEXT },
3959518Sbostic 	{ "quit",	VQUIT,		CQUIT },
4059518Sbostic 	{ "reprint",	VREPRINT, 	CREPRINT },
4159518Sbostic 	{ "start",	VSTART,		CSTART },
4259518Sbostic 	{ "status",	VSTATUS, 	CSTATUS },
4359518Sbostic 	{ "stop",	VSTOP,		CSTOP },
4459518Sbostic 	{ "susp",	VSUSP,		CSUSP },
4559518Sbostic 	{ "werase",	VWERASE,	CWERASE },
4659518Sbostic 	{ NULL },
4748938Sbostic };
4848938Sbostic 
4948938Sbostic struct cchar cchars2[] = {
5059518Sbostic 	{ "brk",	VEOL,		CEOL },
5159518Sbostic 	{ "flush",	VDISCARD, 	CDISCARD },
5259518Sbostic 	{ "rprnt",	VREPRINT, 	CREPRINT },
5359518Sbostic 	{ NULL },
5448938Sbostic };
5550010Sbostic 
5659518Sbostic int
5750010Sbostic csearch(argvp, ip)
5850010Sbostic 	char ***argvp;
5950010Sbostic 	struct info *ip;
6050010Sbostic {
6150010Sbostic 	register struct cchar *cp;
6250010Sbostic 	struct cchar tmp;
6350010Sbostic 	char *arg, *name;
6450010Sbostic 	static int c_cchar __P((const void *, const void *));
6550010Sbostic 
6650010Sbostic 	name = **argvp;
6750010Sbostic 
6850010Sbostic 	tmp.name = name;
6950010Sbostic 	if (!(cp = (struct cchar *)bsearch(&tmp, cchars1,
7050041Sbostic 	    sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
7150010Sbostic 	    c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars1,
7250041Sbostic 	    sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
7350010Sbostic 	    c_cchar)))
7459518Sbostic 		return (0);
7550010Sbostic 
7650010Sbostic 	arg = *++*argvp;
7759518Sbostic 	if (!arg) {
7859518Sbostic 		warnx("option requires an argument -- %s", name);
7959518Sbostic 		usage();
8059518Sbostic 	}
8150010Sbostic 
8250844Sbostic #define CHK(s)  (*arg == s[0] && !strcmp(arg, s))
8350010Sbostic 	if (CHK("undef") || CHK("<undef>"))
8450010Sbostic 		ip->t.c_cc[cp->sub] = _POSIX_VDISABLE;
8550010Sbostic 	else if (arg[0] == '^')
8650010Sbostic 		ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 :
8750010Sbostic 		    (arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037;
8850010Sbostic 	else
8950010Sbostic 		ip->t.c_cc[cp->sub] = arg[0];
9050010Sbostic 	ip->set = 1;
9159518Sbostic 	return (1);
9250010Sbostic }
9350010Sbostic 
9459518Sbostic static int
9550010Sbostic c_cchar(a, b)
9650010Sbostic         const void *a, *b;
9750010Sbostic {
9859518Sbostic         return (strcmp(((struct cchar *)a)->name, ((struct cchar *)b)->name));
9950010Sbostic }
100