1 /*- 2 * Copyright (c) 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)cchar.c 5.6 (Berkeley) 07/10/92"; 10 #endif /* not lint */ 11 12 #include <sys/types.h> 13 #include <stddef.h> 14 #include <stdlib.h> 15 #include <string.h> 16 #include "stty.h" 17 #include "extern.h" 18 19 /* 20 * Special control characters. 21 * 22 * Cchars1 are the standard names, cchars2 are the old aliases. 23 * The first are displayed, but both are recognized on the 24 * command line. 25 */ 26 struct cchar cchars1[] = { 27 "discard", VDISCARD, CDISCARD, 28 "dsusp", VDSUSP, CDSUSP, 29 "eof", VEOF, CEOF, 30 "eol", VEOL, CEOL, 31 "eol2", VEOL2, CEOL, 32 "erase", VERASE, CERASE, 33 "intr", VINTR, CINTR, 34 "kill", VKILL, CKILL, 35 "lnext", VLNEXT, CLNEXT, 36 "quit", VQUIT, CQUIT, 37 "reprint", VREPRINT, CREPRINT, 38 "start", VSTART, CSTART, 39 "status", VSTATUS, CSTATUS, 40 "stop", VSTOP, CSTOP, 41 "susp", VSUSP, CSUSP, 42 "werase", VWERASE, CWERASE, 43 NULL, 44 }; 45 46 struct cchar cchars2[] = { 47 "brk", VEOL, CEOL, 48 "flush", VDISCARD, CDISCARD, 49 "rprnt", VREPRINT, CREPRINT, 50 NULL, 51 }; 52 53 csearch(argvp, ip) 54 char ***argvp; 55 struct info *ip; 56 { 57 extern char *usage; 58 register struct cchar *cp; 59 struct cchar tmp; 60 char *arg, *name; 61 static int c_cchar __P((const void *, const void *)); 62 63 name = **argvp; 64 65 tmp.name = name; 66 if (!(cp = (struct cchar *)bsearch(&tmp, cchars1, 67 sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar), 68 c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars1, 69 sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar), 70 c_cchar))) 71 return(0); 72 73 arg = *++*argvp; 74 if (!arg) 75 err("option requires an argument -- %s\n%s", name, usage); 76 77 #define CHK(s) (*arg == s[0] && !strcmp(arg, s)) 78 if (CHK("undef") || CHK("<undef>")) 79 ip->t.c_cc[cp->sub] = _POSIX_VDISABLE; 80 else if (arg[0] == '^') 81 ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 : 82 (arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037; 83 else 84 ip->t.c_cc[cp->sub] = arg[0]; 85 ip->set = 1; 86 return(1); 87 } 88 89 static 90 c_cchar(a, b) 91 const void *a, *b; 92 { 93 return(strcmp(((struct cchar *)a)->name, ((struct cchar *)b)->name)); 94 } 95