[comp.sys.mac.programmer] Buffering in MPW stdio

jcj@apexepa.UUCP (John Juback) (08/30/88)

I'm porting some UNIX utilities to the Mac as MPW tools.  Predictably,
there are sections of code that look something like this:

	char buf[256];
	printf("Prompt: ");
	gets(buf);

Unfortunately, "buf" contains the prompt string as well as the user's
response (unlike any UNIX or DOS implementation of stdio that I've seen).
I figured that the following lines would properly change the buffering mode:

	setvbuf(stdin, NULL, _IONBF | _IOSYNC, 0);
	setvbuf(stdout, NULL, _IONBF | _IOSYNC, 0);

That didn't work, so I tried an explicit "fflush" right before the "gets."
That didn't work either.  I suppose that a routine like the following would
do the trick,

	char *prompt(q, a)
	char *q, *a;
		{
		printf(q);
		gets(a);
	#ifdef ghs
		return a + strlen(q);
	#else
		return a;
		}

but it's annoying that MPW hasn't faithfully ported stdio, nonetheless.
Has anyone figured out a way to make stdio behave properly?
-- 
						             ____
"Omit needless words."				    /\   | )      \ /
						   /  \  |   ---   /
	- Strunk and White			  /    \ |   ____ / \

John C. Juback					  Apex Software Corporation
{allegra,bellcore,cadre}!pitt!darth!apexepa!jcj   Phone: (412) 681-4343

bob@eecs.nwu.edu (Bob Hablutzel) (08/31/88)

> Unfortunately, "buf" contains the prompt string as well as the user's
> response (unlike any UNIX or DOS implementation of stdio that I've seen).
>                                ...
> Has anyone figured out a way to make stdio behave properly?


From my understanding of what was said at MacWorld, this is not a bug, but
a feature. It has to do with the fact that you can edit command lines, 
and hit enter anywhere on the line for the line to take affect. To
change the behavior of stdio would require much work on the interface of
MPW itself, which is not deemed worthwhile.

Bob Hablutzel		BOB@NUACC.ACNS.NWU.EDU