/*-1* Copyright (c) 1991, 1993, 19942* The Regents of the University of California. All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#include <sys/types.h>3031#include <err.h>32#include <limits.h>33#include <stdlib.h>34#include <string.h>3536#include "stty.h"37#include "extern.h"3839static int c_cchar(const void *, const void *);4041/*42* Special control characters.43*44* Cchars1 are the standard names, cchars2 are the old aliases.45* The first are displayed, but both are recognized on the46* command line.47*/48struct cchar cchars1[] = {49{ "discard", VDISCARD, CDISCARD },50{ "dsusp", VDSUSP, CDSUSP },51{ "eof", VEOF, CEOF },52{ "eol", VEOL, CEOL },53{ "eol2", VEOL2, CEOL },54{ "erase", VERASE, CERASE },55{ "erase2", VERASE2, CERASE2 },56{ "intr", VINTR, CINTR },57{ "kill", VKILL, CKILL },58{ "lnext", VLNEXT, CLNEXT },59{ "min", VMIN, CMIN },60{ "quit", VQUIT, CQUIT },61{ "reprint", VREPRINT, CREPRINT },62{ "start", VSTART, CSTART },63{ "status", VSTATUS, CSTATUS },64{ "stop", VSTOP, CSTOP },65{ "susp", VSUSP, CSUSP },66{ "time", VTIME, CTIME },67{ "werase", VWERASE, CWERASE },68{ NULL, 0, 0},69};7071struct cchar cchars2[] = {72{ "brk", VEOL, CEOL },73{ "flush", VDISCARD, CDISCARD },74{ "rprnt", VREPRINT, CREPRINT },75{ NULL, 0, 0 },76};7778static int79c_cchar(const void *a, const void *b)80{8182return (strcmp(((const struct cchar *)a)->name, ((const struct cchar *)b)->name));83}8485int86csearch(char ***argvp, struct info *ip)87{88struct cchar *cp, tmp;89long val;90char *arg, *ep, *name;9192name = **argvp;9394tmp.name = name;95if (!(cp = (struct cchar *)bsearch(&tmp, cchars1,96sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),97c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars2,98sizeof(cchars2)/sizeof(struct cchar) - 1, sizeof(struct cchar),99c_cchar)))100return (0);101102arg = *++*argvp;103if (!arg) {104warnx("option requires an argument -- %s", name);105usage();106}107108#define CHK(s) (*arg == s[0] && !strcmp(arg, s))109if (CHK("undef") || CHK("<undef>"))110ip->t.c_cc[cp->sub] = _POSIX_VDISABLE;111else if (cp->sub == VMIN || cp->sub == VTIME) {112val = strtol(arg, &ep, 10);113if (val > UCHAR_MAX) {114warnx("maximum option value is %d -- %s",115UCHAR_MAX, name);116usage();117}118if (*ep != '\0') {119warnx("option requires a numeric argument -- %s", name);120usage();121}122ip->t.c_cc[cp->sub] = val;123} else if (arg[0] == '^')124ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 :125(arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037;126else127ip->t.c_cc[cp->sub] = arg[0];128ip->set = 1;129return (1);130}131132133