1#!/bin/sh
2# Make sure stty can parse most of its options - in pairs [expensive].
3
4# Copyright (C) 1998-2023 Free Software Foundation, Inc.
5
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ stty
21
22expensive_
23
24# Make sure there's a tty on stdin.
25require_controlling_input_terminal_
26require_trap_signame_
27
28trap '' TTOU # Ignore SIGTTOU
29
30# Get the reversible settings from stty.c.
31stty_reversible_init_
32
33saved_state=.saved-state
34stty --save > $saved_state || fail=1
35stty $(cat $saved_state) || fail=1
36
37# Build a list of all boolean options stty accepts on this system.
38# Don't depend on terminal width.  Put each option on its own line,
39# remove all non-boolean ones, remove 'parenb' and 'cread' explicitly,
40# then remove any leading hyphens.
41sed_del='/^speed/d;/^rows/d;/^columns/d;/ = /d;s/parenb//;s/cread//'
42options=$(stty -a | tr -s ';' '\n' | sed "s/^ //;$sed_del;s/-//g")
43
44# Take them in pairs, with and without the leading '-'.
45for opt1 in $options; do
46  for opt2 in $options; do
47
48    stty $opt1 $opt2 || fail=1
49
50    if stty_reversible_query_ "$opt1" ; then
51      stty -$opt1 $opt2 || fail=1
52    fi
53    if stty_reversible_query_ "$opt2" ; then
54      stty $opt1 -$opt2 || fail=1
55    fi
56    if stty_reversible_query_ "$opt1" \
57        && stty_reversible_query_ "$opt2" ; then
58      stty -$opt1 -$opt2 || fail=1
59    fi
60  done
61done
62
63stty $(cat $saved_state)
64
65Exit $fail
66