home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / bin / stty / cchar.c next >
Encoding:
C/C++ Source or Header  |  1991-06-09  |  3.8 KB  |  123 lines

  1. /*-
  2.  * Copyright (c) 1991 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)cchar.c    5.4 (Berkeley) 6/10/91";
  36. #endif /* not lint */
  37.  
  38. #include <sys/types.h>
  39. #include <stddef.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include "stty.h"
  43. #include "extern.h"
  44.  
  45. /*
  46.  * Special control characters.
  47.  *
  48.  * Cchars1 are the standard names, cchars2 are the old aliases.
  49.  * The first are displayed, but both are recognized on the
  50.  * command line.
  51.  */
  52. struct cchar cchars1[] = {
  53.     "discard",    VDISCARD,     CDISCARD,
  54.     "dsusp",     VDSUSP,        CDSUSP,
  55.     "eof",        VEOF,        CEOF,
  56.     "eol",        VEOL,        CEOL,
  57.     "eol2",        VEOL2,        CEOL,
  58.     "erase",    VERASE,        CERASE,
  59.     "intr",        VINTR,        CINTR,
  60.     "kill",        VKILL,        CKILL,
  61.     "lnext",    VLNEXT,        CLNEXT,
  62.     "quit",        VQUIT,        CQUIT,
  63.     "reprint",    VREPRINT,     CREPRINT,
  64.     "start",    VSTART,        CSTART,
  65.     "status",    VSTATUS,     CSTATUS,
  66.     "stop",        VSTOP,        CSTOP,
  67.     "susp",        VSUSP,        CSUSP,
  68.     "werase",    VWERASE,    CWERASE,
  69.     NULL,
  70. };
  71.  
  72. struct cchar cchars2[] = {
  73.     "brk",        VEOL,        CEOL,
  74.     "flush",    VDISCARD,     CDISCARD,
  75.     "rprnt",    VREPRINT,     CREPRINT,
  76.     "xoff",        VSTOP,        CSTOP,
  77.     "xon",        VSTART,        CSTART,
  78.     NULL,
  79. };
  80.  
  81. csearch(argvp, ip)
  82.     char ***argvp;
  83.     struct info *ip;
  84. {
  85.     extern char *usage;
  86.     register struct cchar *cp;
  87.     struct cchar tmp;
  88.     char *arg, *name;
  89.     static int c_cchar __P((const void *, const void *));
  90.         
  91.     name = **argvp;
  92.  
  93.     tmp.name = name;
  94.     if (!(cp = (struct cchar *)bsearch(&tmp, cchars1,
  95.         sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
  96.         c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars1,
  97.         sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar),
  98.         c_cchar)))
  99.         return(0);
  100.  
  101.     arg = *++*argvp;
  102.     if (!arg)
  103.         err("option requires an argument -- %s\n%s", name, usage);
  104.  
  105. #define CHK(s)  (*name == s[0] && !strcmp(name, s))
  106.     if (CHK("undef") || CHK("<undef>"))
  107.         ip->t.c_cc[cp->sub] = _POSIX_VDISABLE;
  108.     else if (arg[0] == '^')
  109.         ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 :
  110.             (arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037;
  111.     else
  112.         ip->t.c_cc[cp->sub] = arg[0];
  113.     ip->set = 1;
  114.     return(1);
  115. }
  116.  
  117. static
  118. c_cchar(a, b)
  119.         const void *a, *b;
  120. {
  121.         return(strcmp(((struct cchar *)a)->name, ((struct cchar *)b)->name));
  122. }
  123.