xref: /csrg-svn/bin/stty/cchar.c (revision 50010)
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*50010Sbostic static char sccsid[] = "@(#)cchar.c	5.3 (Berkeley) 06/05/91";
1048938Sbostic #endif /* not lint */
1148938Sbostic 
1248938Sbostic #include <sys/types.h>
1348938Sbostic #include <stddef.h>
14*50010Sbostic #include <stdlib.h>
15*50010Sbostic #include <string.h>
1648938Sbostic #include "stty.h"
17*50010Sbostic #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,
43*50010Sbostic 	"",						/* not 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,
52*50010Sbostic 	"",						/* not NULL */
5348938Sbostic };
54*50010Sbostic 
55*50010Sbostic csearch(argvp, ip)
56*50010Sbostic 	char ***argvp;
57*50010Sbostic 	struct info *ip;
58*50010Sbostic {
59*50010Sbostic 	extern char *usage;
60*50010Sbostic 	register struct cchar *cp;
61*50010Sbostic 	struct cchar tmp;
62*50010Sbostic 	char *arg, *name;
63*50010Sbostic 	static int c_cchar __P((const void *, const void *));
64*50010Sbostic 
65*50010Sbostic 	name = **argvp;
66*50010Sbostic 
67*50010Sbostic 	tmp.name = name;
68*50010Sbostic 	if (!(cp = (struct cchar *)bsearch(&tmp, cchars1,
69*50010Sbostic 	    sizeof(cchars1)/sizeof(struct cchar), sizeof(struct cchar),
70*50010Sbostic 	    c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars1,
71*50010Sbostic 	    sizeof(cchars1)/sizeof(struct cchar), sizeof(struct cchar),
72*50010Sbostic 	    c_cchar)))
73*50010Sbostic 		return(0);
74*50010Sbostic 
75*50010Sbostic 	arg = *++*argvp;
76*50010Sbostic 	if (!arg)
77*50010Sbostic 		err("option requires an argument -- %s\n%s", name, usage);
78*50010Sbostic 
79*50010Sbostic #define CHK(s)  (*name == s[0] && !strcmp(name, s))
80*50010Sbostic 	if (CHK("undef") || CHK("<undef>"))
81*50010Sbostic 		ip->t.c_cc[cp->sub] = _POSIX_VDISABLE;
82*50010Sbostic 	else if (arg[0] == '^')
83*50010Sbostic 		ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 :
84*50010Sbostic 		    (arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037;
85*50010Sbostic 	else
86*50010Sbostic 		ip->t.c_cc[cp->sub] = arg[0];
87*50010Sbostic 	ip->set = 1;
88*50010Sbostic 	return(1);
89*50010Sbostic }
90*50010Sbostic 
91*50010Sbostic static
92*50010Sbostic c_cchar(a, b)
93*50010Sbostic         const void *a, *b;
94*50010Sbostic {
95*50010Sbostic         return(strcmp(((struct cchar *)a)->name, ((struct cchar *)b)->name));
96*50010Sbostic }
97