14b88c807SRodney W. Grimes /*-
24b88c807SRodney W. Grimes * Copyright (c) 1991, 1993, 1994
34b88c807SRodney W. Grimes * The Regents of the University of California. All rights reserved.
44b88c807SRodney W. Grimes *
54b88c807SRodney W. Grimes * Redistribution and use in source and binary forms, with or without
64b88c807SRodney W. Grimes * modification, are permitted provided that the following conditions
74b88c807SRodney W. Grimes * are met:
84b88c807SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright
94b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer.
104b88c807SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright
114b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the
124b88c807SRodney W. Grimes * documentation and/or other materials provided with the distribution.
13fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors
144b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software
154b88c807SRodney W. Grimes * without specific prior written permission.
164b88c807SRodney W. Grimes *
174b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
184b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
194b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
204b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
214b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
224b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
234b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
244b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
254b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
264b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
274b88c807SRodney W. Grimes * SUCH DAMAGE.
284b88c807SRodney W. Grimes */
294b88c807SRodney W. Grimes
304b88c807SRodney W. Grimes #include <sys/types.h>
314b88c807SRodney W. Grimes
324b88c807SRodney W. Grimes #include <err.h>
334b88c807SRodney W. Grimes #include <stdio.h>
34*50fcb4eeSStefan Eßer #include <stdlib.h>
354b88c807SRodney W. Grimes #include <string.h>
364b88c807SRodney W. Grimes
374b88c807SRodney W. Grimes #include "stty.h"
384b88c807SRodney W. Grimes #include "extern.h"
394b88c807SRodney W. Grimes
40f9bcf9caSColin Percival static void gerr(const char *s) __dead2;
415e5a5667SKris Kennaway
424b88c807SRodney W. Grimes static void
gerr(const char * s)435134c3f7SWarner Losh gerr(const char *s)
444b88c807SRodney W. Grimes {
454b88c807SRodney W. Grimes if (s)
464b88c807SRodney W. Grimes errx(1, "illegal gfmt1 option -- %s", s);
474b88c807SRodney W. Grimes else
484b88c807SRodney W. Grimes errx(1, "illegal gfmt1 option");
494b88c807SRodney W. Grimes }
504b88c807SRodney W. Grimes
514b88c807SRodney W. Grimes void
gprint(struct termios * tp,struct winsize * wp __unused,int ldisc __unused)525134c3f7SWarner Losh gprint(struct termios *tp, struct winsize *wp __unused, int ldisc __unused)
534b88c807SRodney W. Grimes {
544b88c807SRodney W. Grimes struct cchar *cp;
554b88c807SRodney W. Grimes
560fd510b7SJoerg Wunsch (void)printf("gfmt1:cflag=%lx:iflag=%lx:lflag=%lx:oflag=%lx:",
570eb7b1caSBruce Evans (u_long)tp->c_cflag, (u_long)tp->c_iflag, (u_long)tp->c_lflag,
580eb7b1caSBruce Evans (u_long)tp->c_oflag);
594b88c807SRodney W. Grimes for (cp = cchars1; cp->name; ++cp)
604b88c807SRodney W. Grimes (void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
61df41cfeeSAndrey A. Chernov (void)printf("ispeed=%lu:ospeed=%lu\n",
62df41cfeeSAndrey A. Chernov (u_long)cfgetispeed(tp), (u_long)cfgetospeed(tp));
634b88c807SRodney W. Grimes }
644b88c807SRodney W. Grimes
654b88c807SRodney W. Grimes void
gread(struct termios * tp,char * s)665134c3f7SWarner Losh gread(struct termios *tp, char *s)
674b88c807SRodney W. Grimes {
684b88c807SRodney W. Grimes struct cchar *cp;
694b88c807SRodney W. Grimes char *ep, *p;
704b88c807SRodney W. Grimes long tmp;
714b88c807SRodney W. Grimes
724b88c807SRodney W. Grimes if ((s = strchr(s, ':')) == NULL)
734b88c807SRodney W. Grimes gerr(NULL);
744b88c807SRodney W. Grimes for (++s; s != NULL;) {
754b88c807SRodney W. Grimes p = strsep(&s, ":\0");
764b88c807SRodney W. Grimes if (!p || !*p)
774b88c807SRodney W. Grimes break;
784b88c807SRodney W. Grimes if (!(ep = strchr(p, '=')))
794b88c807SRodney W. Grimes gerr(p);
804b88c807SRodney W. Grimes *ep++ = '\0';
81*50fcb4eeSStefan Eßer tmp = strtoul(ep, NULL, 0x10);
824b88c807SRodney W. Grimes
834b88c807SRodney W. Grimes #define CHK(s) (*p == s[0] && !strcmp(p, s))
844b88c807SRodney W. Grimes if (CHK("cflag")) {
854b88c807SRodney W. Grimes tp->c_cflag = tmp;
864b88c807SRodney W. Grimes continue;
874b88c807SRodney W. Grimes }
884b88c807SRodney W. Grimes if (CHK("iflag")) {
894b88c807SRodney W. Grimes tp->c_iflag = tmp;
904b88c807SRodney W. Grimes continue;
914b88c807SRodney W. Grimes }
924b88c807SRodney W. Grimes if (CHK("ispeed")) {
93*50fcb4eeSStefan Eßer tmp = strtoul(ep, NULL, 10);
944b88c807SRodney W. Grimes tp->c_ispeed = tmp;
954b88c807SRodney W. Grimes continue;
964b88c807SRodney W. Grimes }
974b88c807SRodney W. Grimes if (CHK("lflag")) {
984b88c807SRodney W. Grimes tp->c_lflag = tmp;
994b88c807SRodney W. Grimes continue;
1004b88c807SRodney W. Grimes }
1014b88c807SRodney W. Grimes if (CHK("oflag")) {
1024b88c807SRodney W. Grimes tp->c_oflag = tmp;
1034b88c807SRodney W. Grimes continue;
1044b88c807SRodney W. Grimes }
1054b88c807SRodney W. Grimes if (CHK("ospeed")) {
106*50fcb4eeSStefan Eßer tmp = strtoul(ep, NULL, 10);
1074b88c807SRodney W. Grimes tp->c_ospeed = tmp;
108d0834e7fSAndrey A. Chernov continue;
109d0834e7fSAndrey A. Chernov }
1104b88c807SRodney W. Grimes for (cp = cchars1; cp->name != NULL; ++cp)
1114b88c807SRodney W. Grimes if (CHK(cp->name)) {
1124b88c807SRodney W. Grimes if (cp->sub == VMIN || cp->sub == VTIME)
113*50fcb4eeSStefan Eßer tmp = strtoul(ep, NULL, 10);
1144b88c807SRodney W. Grimes tp->c_cc[cp->sub] = tmp;
1154b88c807SRodney W. Grimes break;
1164b88c807SRodney W. Grimes }
1174b88c807SRodney W. Grimes if (cp->name == NULL)
1184b88c807SRodney W. Grimes gerr(p);
1194b88c807SRodney W. Grimes }
1204b88c807SRodney W. Grimes }
121