From 3c534fdc78e1d9d7914017bfcd5ff579bb754c70 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 23 Sep 2020 06:41:59 -0500 Subject: Cleanup pass on stty.c --- toys/pending/stty.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'toys/pending/stty.c') diff --git a/toys/pending/stty.c b/toys/pending/stty.c index 8c937696..4168b9ba 100644 --- a/toys/pending/stty.c +++ b/toys/pending/stty.c @@ -41,7 +41,7 @@ config STTY #include GLOBALS( - char *device; + char *F; int fd, col; unsigned output_cols; @@ -120,12 +120,15 @@ static const struct synonym { char *from; char *to; } synonyms[] = { - { "cbreak", "-icanon" }, { "-cbreak", "icanon" }, { "-cooked", "raw" }, - { "crterase", "echoe" }, { "-crterase", "-echoe" }, { "crtkill", "echoke" }, - { "-crtkill", "-echoke" }, { "ctlecho", "echoctl" }, { "-tandem", "-ixoff" }, - { "-ctlecho", "-echoctl" }, { "hup", "hupcl" }, { "-hup", "-hupcl" }, - { "prterase", "echoprt" }, { "-prterase", "-echoprt" }, { "-raw", "cooked" }, - { "tabs", "tab0" }, { "-tabs", "tab3" }, { "tandem", "ixoff" }, + { "cbreak", "-icanon" }, { "-cbreak", "icanon" }, + { "-cooked", "raw" }, { "-raw", "cooked" }, + { "crterase", "echoe" }, { "-crterase", "-echoe" }, + { "crtkill", "echoke" }, { "-crtkill", "-echoke" }, + { "ctlecho", "echoctl" }, { "-ctlecho", "-echoctl" }, + { "-tandem", "-ixoff" }, { "tandem", "ixoff" }, + { "hup", "hupcl" }, { "-hup", "-hupcl" }, + { "prterase", "echoprt" }, { "-prterase", "-echoprt" }, + { "tabs", "tab0" }, { "-tabs", "tab3" }, }; static void out(const char *fmt, ...) @@ -160,9 +163,9 @@ static void show_flags(tcflag_t actual, tcflag_t sane, int i, j, value, mask; // Implement -a by ensuring that sane != actual so we'll show everything. - if (toys.optflags&FLAG_a) sane = ~actual; + if (FLAG(a)) sane = ~actual; - for (i=j=0;ic_cc[chars[j].value] = ch; return 1; } @@ -311,7 +313,7 @@ static void make_sane(struct termios *t) static void xtcgetattr(struct termios *t) { - if (tcgetattr(TT.fd, t)) perror_exit("tcgetattr %s", TT.device); + if (tcgetattr(TT.fd, t)) perror_exit("tcgetattr %s", TT.F); } void stty_main(void) @@ -322,8 +324,8 @@ void stty_main(void) if (toys.optflags&(FLAG_a|FLAG_g) && *toys.optargs) error_exit("no settings with -a/-g"); - if (!TT.device) TT.device = "standard input"; - else TT.fd = xopen(TT.device, (O_RDWR*!!*toys.optargs)|O_NOCTTY|O_NONBLOCK); + if (!TT.F) TT.F = "standard input"; + else TT.fd = xopen(TT.F, (O_RDWR*!!*toys.optargs)|O_NOCTTY|O_NONBLOCK); xtcgetattr(&old); @@ -390,7 +392,7 @@ void stty_main(void) } else if (!strcmp(arg, "sane")) make_sane(&new); else { // Translate historical cruft into canonical forms. - for (j=0;j