The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] V6 Console IO
@ 2020-07-24  0:18 Paul Riley
  2020-07-24  2:57 ` Larry McVoy
  0 siblings, 1 reply; 21+ messages in thread
From: Paul Riley @ 2020-07-24  0:18 UTC (permalink / raw)
  To: tuhs

[-- Attachment #1: Type: text/plain, Size: 1398 bytes --]

I am using C in V6 to create a Forth compiler. I don;t have any interest in
Forth as a general purpose language, however I do like it. It's satisfying
to create a language from the ground up. I'm interested in it a simple and
extensible interpreted language for toying with my PDP-11s, so I'll have
some with it in the future.

I have a very basic problem. I am simply using getchar and putchar for
console IO, which is convenient indeed. I'm struggling however with how C
processes the IO. It seems that when I type at the console, my typing is
immediately echoed to my terminal window. When I press backspace the system
responds with the character that was deleted, which is fine, as I assume it
was from the paper teletype days. However, my code is receiving input and
also echoing the output, but nothing appears on the terminal until I press
enter, when the system displays the whole line of input, which is
essentially a duplicate of what the terminal originally displayed, but with
the consolidated edits. My code is reading and echoing the input character
by character.

Here's my question. How can I suppress the original C/Unix echo, and get my
output to appear immediately? This simple sample code form the C
programming manual behaves the same.

int main() {
int c;
while ((c = getchar()) != EOF) {
putchar(c);
}
}

Paul



*Paul Riley*

Mo: +86 186 8227 8332
Email: paul@rileyriot.com

[-- Attachment #2: Type: text/html, Size: 1975 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: [TUHS] V6 Console IO
@ 2020-07-24  2:28 Noel Chiappa
  2020-07-24  4:54 ` Paul Riley
  2020-07-24 14:34 ` Clem Cole
  0 siblings, 2 replies; 21+ messages in thread
From: Noel Chiappa @ 2020-07-24  2:28 UTC (permalink / raw)
  To: tuhs; +Cc: jnc

    > From: Paul Riley

    > I'm struggling however with how C processes the IO. It seems that when I
    > type at the console, my typing is immediately echoed to my terminal
    > window. ...  nothing appears on the terminal until I press enter, when
    > the system displays the whole line of input ... How
    > can I suppress the original C/Unix echo, and get my output to appear
    > immediately?

This is not a C issue; it's the Unix I/O system (and specifically, terminal I/O).

Normally, Unix terminal input is done line-at-a-time: i.e. the read() call to
the OS (whether for 1 character, or a large number) doesn't return until an
enire line has been typed, and [Retrurn] has been hit; then the entire line is
available. While it's being buffered by the OS, echoing is done, and rubout
processing is also performed.

One can suppress all this; there's a mode call 'raw' (the normal mode is
sometime labelled 'cooked') which suppresses all that, and just gives one the
characters actually typed, as they are typed. The stty() system call can be
used to turn this on.

See the V6 tty(IV) manual entry for more. stty() is in stty(II).

    Noel

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: [TUHS] V6 Console IO
@ 2020-07-24 14:33 Noel Chiappa
  2020-07-24 14:36 ` Clem Cole
  0 siblings, 1 reply; 21+ messages in thread
From: Noel Chiappa @ 2020-07-24 14:33 UTC (permalink / raw)
  To: tuhs; +Cc: jnc

    > From: Larry McVoy

    > Yeah, write is unbuffered though I think Noel is correct, it's going to
    > a tty and the tty will buffer until \n

The 'wait until newline' is on the input side.

Output is buffered (in the sense that characters are held in the kernel until
the output device can take them); but normally output will start to happen as
soon as the device is able to take them. Only a certain amount can be
buffered though, after that (the 'high water', I think it's called), the
process is blocked if it tries to do output, and awakened when the buffered
output level goes past the 'low water' mark.

Note that getchar() and putchar() are subroutines in a library; looking
at the source:

  https://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/source/s4/getchr.s

you can see how they relate to the actual read/write calls to the OS.

    > So you probably have to set the tty in raw mode

Probably best to run such programs from something other than the main console,
because if there's a bug in the program, and the terminal is in raw mode, if
you're on the console, you may have to reboot the system to regain control of
the system. (Interrupt characters, ^D etc won't work.)

    > (sorry that I'm vague, I never ran V6).

Tnat's OK, I pretty much have the V6 kernel memorized, from working with
it back in the day... :-)

	Noel

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: [TUHS] V6 Console IO
@ 2020-07-25 17:45 Noel Chiappa
  0 siblings, 0 replies; 21+ messages in thread
From: Noel Chiappa @ 2020-07-25 17:45 UTC (permalink / raw)
  To: tuhs; +Cc: jnc

    > From: Clem Cole <clemc@ccc.com>

    > another old V6 trick is the use file redirection from the different
    > terminal to unlock a hosed tty. 

'stty {mumble} > /dev/ttyX', in case that wasn't clear.

Note that this only works if you have a working shell on _another_ terminal,
so if you're e.g. working with an emulation which has only one working
terminal, and your raw-mode program on it has gone berserk, 'See Figure 1'.
It really is advised to have another working terminal if you want to play
with raw-mode programs.

	Noel

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2020-07-27  9:13 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24  0:18 [TUHS] V6 Console IO Paul Riley
2020-07-24  2:57 ` Larry McVoy
2020-07-24  4:41   ` Paul Riley
2020-07-24  4:54     ` Paul Riley
2020-07-24 14:01       ` Larry McVoy
2020-07-24  2:28 Noel Chiappa
2020-07-24  4:54 ` Paul Riley
2020-07-24 16:37   ` Random832
2020-07-24 17:15     ` Clem Cole
2020-07-25  2:45       ` Random832
2020-07-24 14:34 ` Clem Cole
2020-07-25  2:48   ` Paul Riley
2020-07-25  4:02     ` John Cowan
2020-07-25 15:09       ` Clem Cole
2020-07-25 15:31         ` Richard Salz
2020-07-26  1:08           ` Random832
2020-07-27  9:11             ` Paul Riley
2020-07-24 14:33 Noel Chiappa
2020-07-24 14:36 ` Clem Cole
2020-07-25  1:53   ` Dave Horsfall
2020-07-25 17:45 Noel Chiappa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).