[comp.sys.mac.programmer] MPW-C stdio buffering, pontifications thereon

ldo@peace.waikato.ac.nz (Lawrence D'Oliveiro) (01/19/90)

In the referenced message, wrp@krebs.acc.Virginia.EDU (Bill Pearson) is
trying to port a Unix program to an MPW tool. The program is displaying
a prompt (without trailing newline), and the user types in a response
and presses Enter. The trouble is that the input line as read by
the program contains the prompt as well as the response!

Remember that MPW represents a unique, and somewhat quirky, merging
of the Unix concept of input and output byte streams with a windowing
system. The basic convention is that, to feed input to a tool (or a
command sequence to the Shell), you select the appropriate section of
input, and press Enter. To this is added a useful shortcut, namely,
if you don't have a selection, just a blinking insertion point, then
the entire line containing the insertion point as taken as the input.

This looks superficially like ordinary keyboard/screen input/output
on conventional character-oriented systems. Unfortunately, as you
have discovered, it is not. Once some text appears in a window, the
system forgets where it came from--whether it was output from a command,
or whether you typed it. It's all just part of the (possibly unsaved)
contents of the text file which is being displayed and edited in
that window.

In conclusion, the only way to get around this problem is to
select the part of the line that you typed (carefully omitting the
prompt at the start of the line) before pressing Enter.

The moral is, conventional character-oriented dialogs do not work
well in the MPW environment. The Mac offers its native alternatives;
though perhaps you might not be prepared to spend the time it takes
to use them.

Lawrence D'Oliveiro
Computer Services Dept
University of Waikato
Hamilton
New Zealand