[net.sources.bugs] umodem source - System V compatible?

guy@rlgvax.UUCP (Guy Harris) (01/13/85)

A few comments on the configuration options:

> /* 4.2bsd unix */
> #ifdef V4.2
> #include <setjmp.h>
> #endif

This works on our system, to my great surprise, but (from K&R):

	2.2 Identifiers (Names)
		An identifier is a sequence of letters and digits;
	the first character must be a letter.  The underscore _ counts
	as a letter.

	12.3 Conditional compilation

		...A control line of the form

			#ifdef identifier

	checks whether the identifier is currently defined in the
	preprocessor...

Someday you may find a C compiler which objects to "V4.2" as a #define
identifier.  You might try "BSD4_2" instead (that seems to be what most
programs use).

> /*  UNIX SYSTEM III tty parameter file  */
> #ifdef SYS3
> #include <sgtty.h>
> #endif
> 
> /*  UNIX SYSTEM V tty parameter file	*/
> #ifdef SYS5
> #include <termio.h>
> #endif

Nope.  System III and System V both use "termio.h".  One or the other system
may *provide* "sgtty.h", but that's just for backward compatibility (and
backward compatibility with UNIX/TS 1.0 and PWB/UNIX 2.0, not with V7, to
boot).
> 
> /*  UNIX SYSTEM III structures  */
> #ifdef SYS3
> struct sgttyb  ttys, ttysnew, ttystemp;    /* for stty terminal mode calls */
> #endif
> 
> /*  UNIX SYSTEM V structures  */
> #ifdef SYS4
> struct termio  ttys, ttysnew, ttystemp;    /* for stty terminal mode calls */
> #endif

Again, same point; also, that "SYS4" should be "SYS5".

> /*  Device Characteristics for UNIX SYSTEM III  */
> #ifdef SYS5
	...

The comment is typoed (minor nit).

> 	/* transfer current modes to new structure */
> 	ttysnew.c_version = ttys.c_version;	/* termio structure version */
> 	ttysnew.c_iflag = ttys.c_iflag;		/* input flags	*/
	...

All System V systems should support structure assignment, if you want it.
"c_version" must have been something that Ridge (or somebody) added; it
is not present in standard System V.  Using structure assignment would
make this code work, whether or not there was a "c_version" field.

> 
> 	ttysnew.sg_flags |= RAW;    /* set for RAW Mode */
	...

This is completely wrong.  This is just the V7 code, which won't work
on a "termio" structure (as it doesn't have an "sg_flags" field.

Replace all the code that fiddles with the "sg_flags" field with:

	ttysnew.c_iflag = 0;	/* turn off all input mapping */
	ttysnew.c_oflag &= ~OPOST;	/* turn off all output mapping */
	ttysnew.c_cflag &= ~(CSIZE|PARENB|PARODD);	/* turn off parity, clear out character size */
	ttysnew.c_cflag |= CS8;	/* set character size to 8 bits */
	ttysnew.c_lflag = 0;	/* turn off all special processing */

> /* restore normal tty modes */
> restoremodes(errcall)
> int errcall;
> {
	...

This has no #define for System V.  The correct code for System III and
System V is:

> /*  Device characteristic restoration for UNIX SYSTEM III  */
> #ifdef SYS3
> 	if (wason)
> 		if (chmod(tty, statbuf.st_mode | 022) < 0)
> 			error("Can't change TTY mode", FALSE);
> 
> 	if (ioctl(0, TCSETAW, &ttys) < 0)  /* restore original tty modes */
	...

> /* print data on TTY setting */
> ttyparams()
> {
	...

This has no code for System V.  Code should be written for System V, and
the same code used for System III.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy