This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how do i simulate a null character from the keyboard?

Larry, Ethan,

It's not quite that simple.

CTRL-D is the (default) end-of-file generating character (more on what that 
means later). By a very long-standing convention in Unix that predates the 
existence of _any_ "visual" mode programs like Vi / Vim or (non-GUI) Emacs, 
an end-of-file causes virtually all non-interactive and almost all 
line-at-a-time interactive programs to terminate. This makes them generally 
well behaved when they're reading from pipes, files, network endpoints as 
well as TTY devices.

[ Irrelevant but interesting historical note: When TTYs really were 
clattering clunking mechanical TeleTYpe (brand) terminals, the erase 
character defaulted to # and the line kill was @! ]

What the (configurable) end-of-file character does is "activate" the input 
buffer without adding any characters to that buffer. Activating the TTY 
buffer means allowing accumulated input (up to one "line" worth) to be 
returned to the user-level process that's blocked reading from the TTY. 
This is similar to what the end-of-line characters do (both of which are 
also configurable, defaulting to CR and LF), except that they always add a 
character to the buffer before activating the buffer. Depending on other 
options, either the primary or secondary end-of-line activators may insert 
themselves or a converted version of themselves (cf. +/-inlcr +/-icrnl 
options) into the buffer.

Activating an input buffer into which no characters have been typed causes 
a read on the TTY to return a zero-length input, the Unix kernel API 
indication that end-of-file has been reached. If you type one or more 
characters and then hit CTRL-D, you will not get an "end-of-file," but 
rather an input "line" that does not end with a line termination character.

Lastly, note that programs that incorporate the readline library (such as 
BASH) are not using the terminal in the input canonicalizing mode (+icanon) 
mode I describe here. Rather they are receive each character as it's typed 
(-icanon), and perform backspace and other intra-line editing as well as 
all the other readline capabilities as configured by the input mappings.

Note, too, that I'm not sure exactly how fully of this description applies 
to Cygwin, but it's clearly pretty close. Some of it presumably varies 
depending on whether one includes "tty" in the CYGWIN environment variable.

That's terse, but I hope it clarifies somewhat the rather non-trivial 
treatment of TTY input in a Unix / POSIX environment.

Randall Schulz
Mountain View, CA USA

At 13:40 2002-02-20, Larry Hall (RFK Partners, Inc) wrote:
>At 04:37 PM 2/20/2002, Ethan Mallove wrote:
> >how do i simulate a null character from the keyboard within an a.exe?
>Sorry I don't know.  To be honest I don't understand enough about what 
>you're asking to even guess at a possible solution.
> >why is ctrl-d a logout command instead of NULL?
>You mean from sh/bash?  CTRL-D has always been logout in this context so I 
>don't know why you would expect it to be otherwise.
>Larry Hall                    

Unsubscribe info:
Bug reporting:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]