[comp.unix.questions] Reading long lines from TTY

david@uhccux.uhcc.hawaii.edu (David Lassner) (02/03/89)

Any suggestions on using standard utilities to read VERY
long lines from the TTY using Unix (Ultrix 2.2).  The
intuitive:
	%cat > filename
and
	%cp /dev/ttyxx filename
both stop accepting characters after about 250 without a CR.

Our user basically wants to do the equivalent of a TOPS-20
	@copy tty: filename
to upload text that does not contain line breaks.  Yes, we
know about Kermit and other protocols, but they can't be
used in this case.

-- 
David Lassner, University of Hawaii Computing Center, 808/948-7351
INTERNET: david@uhccux.uhcc.hawaii.edu      BITNET: david@uhccux
UUCP:     ...!ucsd!nosc!uhccux!david        PLATO:  david/p/hawaii

gwyn@smoke.BRL.MIL (Doug Gwyn ) (02/03/89)

In article <3134@uhccux.uhcc.hawaii.edu> david@uhccux.uhcc.hawaii.edu (David Lassner) writes:
>Any suggestions on using standard utilities to read VERY
>long lines from the TTY using Unix (Ultrix 2.2).

So long as you're letting the terminal handler canonicalize input,
there will be an input line length limit imposed.  You have to turn
off input canonicalization (erase/kill processing).  Also be aware
that some characters (input byte values) may cause special actions,
and that probably needs to be disabled also.  Finally, the high-order
bit of each input byte may be automatically cleared by the handler.
Putting the handler into so-called "raw" mode solves most such
problems, but it leaves you with the new problem of how to terminate
the input (there is no longer an EOF character!).

You should really use a genuine protocol instead of a kludge.

dik@uva.UUCP (Casper H.S. Dik) (02/03/89)

In article <3134@uhccux.uhcc.hawaii.edu> david@uhccux.uhcc.hawaii.edu (David Lassner) writes:
>Any suggestions on using standard utilities to read VERY
>long lines from the TTY using Unix (Ultrix 2.2).  The
>intuitive:
>	%cat > filename
>and
>	%cp /dev/ttyxx filename
>both stop accepting characters after about 250 without a CR.
>
>Our user basically wants to do the equivalent of a TOPS-20
>	@copy tty: filename
>to upload text that does not contain line breaks.  Yes, we
>know about Kermit and other protocols, but they can't be
>used in this case.

Normally the terminal driver buffers all characters until it sees a
line terminator or special character (intr del, etc).
The buffer holds a maximum of 256 chars.

You can get around this. All you have to change is the terminal settings.
Put your tty in cbreak mode. This will cause each character typed
to be send to the reading process directly.

You can do this with:
		% stty cbreak
		% cat > file
		% stty -cbreak

But beware: If you use a shell that fiddles with the terminal settings this
won't work. (E.g. ksh, or csh with filec set)
So in csh do:
		% unset filec

Or use /bin/sh, to be on the save side.

>-- 
>David Lassner, University of Hawaii Computing Center, 808/948-7351
>INTERNET: david@uhccux.uhcc.hawaii.edu      BITNET: david@uhccux
>UUCP:     ...!ucsd!nosc!uhccux!david        PLATO:  david/p/hawaii


--cd
____________________________________________________________________________
Casper H.S. Dik
University of Amsterdam     |		      dik@uva.uucp
The Netherlands             |                 ...!uunet!mcvax!uva!dik