xref: /csrg-svn/bin/stty/cchar.c (revision 50844)
148938Sbostic /*-
248938Sbostic  * Copyright (c) 1991 The Regents of the University of California.
348938Sbostic  * All rights reserved.
448938Sbostic  *
548938Sbostic  * %sccs.include.redist.c%
648938Sbostic  */
748938Sbostic 
848938Sbostic #ifndef lint
9*50844Sbostic static char sccsid[] = "@(#)cchar.c	5.5 (Berkeley) 08/12/91";
1048938Sbostic #endif /* not lint */
1148938Sbostic 
1248938Sbostic #include <sys/types.h>
1348938Sbostic #include <stddef.h>
1450010Sbostic #include <stdlib.h>
1550010Sbostic #include <string.h>
1648938Sbostic #include "stty.h"
1750010Sbostic #include "extern.h"
1848938Sbostic 
1948938Sbostic /*
2048938Sbostic  * Special control characters.
2148938Sbostic  *
2248938Sbostic  * Cchars1 are the standard names, cchars2 are the old aliases.
2348938Sbostic  * The first are displayed, but both are recognized on the
2448938Sbostic  * command line.
2548938Sbostic  */
2648938Sbostic struct cchar cchars1[] = {
2748938Sbostic 	"discard",	VDISCARD, 	CDISCARD,
2848938Sbostic 	"dsusp", 	VDSUSP,		CDSUSP,
2948938Sbostic 	"eof",		VEOF,		CEOF,
3048938Sbostic 	"eol",		VEOL,		CEOL,
3148938Sbostic 	"eol2",		VEOL2,		CEOL,
3248938Sbostic 	"erase",	VERASE,		CERASE,
3348938Sbostic 	"intr",		VINTR,		CINTR,
3448938Sbostic 	"kill",		VKILL,		CKILL,
3548938Sbostic 	"lnext",	VLNEXT,		CLNEXT,
3648938Sbostic 	"quit",		VQUIT,		CQUIT,
3748938Sbostic 	"reprint",	VREPRINT, 	CREPRINT,
3848938Sbostic 	"start",	VSTART,		CSTART,
3948938Sbostic 	"status",	VSTATUS, 	CSTATUS,
4048938Sbostic 	"stop",		VSTOP,		CSTOP,
4148938Sbostic 	"susp",		VSUSP,		CSUSP,
4248938Sbostic 	"werase",	VWERASE,	CWERASE,
4350041Sbostic 	NULL,
4448938Sbostic };
4548938Sbostic 
4648938Sbostic struct cchar cchars2[] = {
4748938Sbostic 	"brk",		VEOL,		CEOL,
4848938Sbostic 	"flush",	VDISCARD, 	CDISCARD,
4948938Sbostic 	"rprnt",	VREPRINT, 	CREPRINT,
5048938Sbostic 	"xoff",		VSTOP,		CSTOP,
5148938Sbostic 	"xon",		VSTART,		CSTART,
5250041Sbostic 	NULL,
5348938Sbostic };
5450010Sbostic 
5550010Sbostic csearch(argvp, ip)
5650010Sbostic 	char ***argvp;
5750010Sbostic 	struct info *ip;
5850010Sbostic {
5950010Sbostic 	extern char *usage;
6050010Sbostic 	register struct cchar *cp;
6150010Sbostic 	struct cchar tmp;
6250010Sbostic 	char *arg, *name;
6350010Sbostic 	static int c_cchar __P((const void *, const void *));
6450010Sbostic 
6550010Sbostic 	name = **argvp;
6650010Sbostic 
6750010Sbostic 	tmp.name = name;
6850010Sbostic 	if (!(cp = (struct cchar *)bsearch(&tmp, cchars1,
6950041Sbostic 	    sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
7050010Sbostic 	    c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars1,
7150041Sbostic 	    sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
7250010Sbostic 	    c_cchar)))
7350010Sbostic 		return(0);
7450010Sbostic 
7550010Sbostic 	arg = *++*argvp;
7650010Sbostic 	if (!arg)
7750010Sbostic 		err("option requires an argument -- %s\n%s", name, usage);
7850010Sbostic 
79*50844Sbostic #define CHK(s)  (*arg == s[0] && !strcmp(arg, s))
8050010Sbostic 	if (CHK("undef") || CHK("<undef>"))
8150010Sbostic 		ip->t.c_cc[cp->sub] = _POSIX_VDISABLE;
8250010Sbostic 	else if (arg[0] == '^')
8350010Sbostic 		ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 :
8450010Sbostic 		    (arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037;
8550010Sbostic 	else
8650010Sbostic 		ip->t.c_cc[cp->sub] = arg[0];
8750010Sbostic 	ip->set = 1;
8850010Sbostic 	return(1);
8950010Sbostic }
9050010Sbostic 
9150010Sbostic static
9250010Sbostic c_cchar(a, b)
9350010Sbostic         const void *a, *b;
9450010Sbostic {
9550010Sbostic         return(strcmp(((struct cchar *)a)->name, ((struct cchar *)b)->name));
9650010Sbostic }
97