[comp.unix.questions] stty -g output ...

Michael Panosh - Unix Education@relay.cs.net, (06/19/91)

Guy Harris replies to a comment about stty -g:

>>I can do a {mv my-new-and-improved-stty /bin/stty} any time,
>>and thereby change the implementation of stty instantaneously.

>You could also do "rm /bin/*", given that you have permission to write
>in "/bin" (or whatever "/bin" is a link to, if it is such), and change a
>hell of a lot more than just the implementation of "stty"; the system
>shouldn't necessarily be prepared for *everything* a
>sufficiently-privileged user can do.

Nobody expects Unix to be able to preempt usrs, but there is no *good* reason
the stty command should not output a recognisable, STANDARD format (which was
described in the manual pages).  Then it would not matter that the stty
command was replaced by the new, improved version while the system was
running.  And there would be no need to rely on word-of-mouth, "second guess"
opinions that may or may not work with your version of Unix.

Don't deliberately make Unix any more obscure than it already is...

++++++++  Michael Panosh           Q. What is a user?
++++++++  Unix Education           A. A person who does not have to
++++++++  Prime Computer              write documentation.

torek@elf.ee.lbl.gov (Chris Torek) (06/20/91)

In article <27243@adm.brl.mil> Michael Panosh - Unix Education@relay.cs.net
writes:
>... there is no *good* reason the stty command should not output a
>recognisable, STANDARD format ...

For -g, there *is* such a reason; for others, the format should be
described in the manuals, so that you can read it.

Remember, -g is, in effect, `save the current state'.  In
implementation A, the current state is `erase, kill, and mode'; in
implementation B, it is `ispeed, ospeed, lflags, iflags, oflags,
cflags, discard, dsusp, eof, eol, eol2, erase, intr, kill, lnext, quit,
reprint, start, status, stop, susp, werase'.  Tomorrow, implementation
C will add `swtch', implementation D will add 42 incompatible options,
and implementation E will do something completely different.  When they
change, -g output will change to encode the new state.

Incidentally, the `g format of the day' on implementation B is:
gfmt1:cflag=5a00:iflag=2b22:lflag=5cb:oflag=7:discard=f:dsusp=19:eof=4:\
eol=ff:eol2=ff:erase=8:intr=3:kill=18:lnext=16:quit=1c:reprint=12:start=11:\
status=14:stop=13:susp=1a:werase=17:ispeed=9600:ospeed=9600
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA		Domain:	torek@ee.lbl.gov

boyd@prl.dec.com (Boyd Roberts) (06/20/91)

The `-g' format is just wrong.  I should be able to go:

   ; stty -a > x		# sane stty's should work on stdin

   ...

   ; stty `cat x`

What did Pike say about `program[ming] the inputs'?


Boyd Roberts			boyd@prl.dec.com

``When the going gets wierd, the weird turn pro...''

guy@auspex.auspex.com (Guy Harris) (06/21/91)

>Nobody expects Unix to be able to preempt usrs, but there is no *good* reason
>the stty command should not output a recognisable, STANDARD format (which was
>described in the manual pages).  Then it would not matter that the stty
>command was replaced by the new, improved version while the system was
>running.  And there would be no need to rely on word-of-mouth, "second guess"
>opinions that may or may not work with your version of Unix.

Umm, do you mean that *all* versions should use the same format?  If so,
it'd better be a format that:

	1) works on systems with

		#define	NCC	8

		struct termio {
			unsigned short	c_iflag;	/* input modes */
			unsigned short	c_oflag;	/* output modes */
			unsigned short	c_cflag;	/* control modes */
			unsigned short	c_lflag;	/* line discipline modes */
			char	c_line;			/* line discipline */
			unsigned char	c_cc[NCC];	/* control chars */
		};

	   (pre-SVR4 S5);

	2) works, *without change*, on systems with:

		#define	NCCS	17

		struct termios {
			unsigned long	c_iflag;	/* input modes */
			unsigned long	c_oflag;	/* output modes */
			unsigned long	c_cflag;	/* control modes */
			unsigned long	c_lflag;	/* line discipline modes */
			char		c_line;		/* line discipline XXX */
			unsigned char	c_cc[NCCS];	/* control chars */
		};

	   (i.e., uses the *exact same format* as the previous one, and
	   *without* losing information);

	   (SunOS 4.1; S5R4 is similar, if not identical)

	3) *also* works on systems with:

		#define	NCCS		20
		typedef unsigned long	tcflag_t;
		typedef unsigned char	cc_t;

		struct termios {
			tcflag_t	c_iflag;	/* input flags */
			tcflag_t	c_oflag;	/* output flags */
			tcflag_t	c_cflag;	/* control flags */
			tcflag_t	c_lflag;	/* local flags */
			cc_t		c_cc[NCCS];	/* control chars */
			long		c_ispeed;	/* input speed */
			long		c_ospeed;	/* output speed */
		};

	    (4.3-reno and probably 4.4BSD).

If no such format is possible, that kills the idea of making it
universal to all UNIX systems (or POSIX systems, if you've decided to
consider some or all of the above "not UNIX systems").

If you didn't mean "one universal format", bear in mind that once you've
put something in writing, it could be Very Hard to undo it; for example,
if S5R3 had Put It In Writing, it might have been difficult to change
for S5R4 (I'm assuming here that they *did* change it for S5R4).

The other question then is "under what circumstances would some program
or script care about the format?"  If the script wants to know whether
"echo" is on, for example, it should do a *normal* "stty" and see if the
right string appears in the output (it's more than a simple "grep", as
you have to worry about "echoe" and the like).