Saving a file with a dialog box

Gavin A. Bell gavin at krypton.sgi.com
Tue Feb 6 06:13:03 AEST 1990


>In article <Feb.4.15.19.22.1990.11760 at topaz.rutgers.edu> elkins at topaz.rutgers.edu (George Elkins) writes:
>>How does one create such a dialog box with buttons and a text field in
>>4Sight using the GL/DGL interface?

Well, I thought up this little hack just two or three weeks ago, so I
can't guarantee that it is perfect yet.

However, it is a very good starting point.  Let me give you the code,
then explain what exactly it is doing:

---------   code follows  --------
/*
 * s      is the string the user's response will be put into
 * len_s  is the length of s (so we won't overflow it)
 * m      is the message prompt
 */
void
GetInputFromUser(char *s, int len_s, const char *m)
{
	char launchline[300];
	FILE *fp;

	sprintf(launchline, "launch -h echo -m \"%s\"", m);
	if ((fp = popen(launchline, "r")) != NULL)
	{
		fgets(s, len_s, fp);
		pclose(fp);
		/* Strip off trailing newline */
		if (s[0] != '\0' && s[strlen(s)-1] == '\n')
		{
			s[strlen(s)-1] = '\0';
		}
	}
	else s[0] = '\0';
}
----------- end of code ----------

This code uses the 'launch' command to do all of the dirty work.  It
launches an 'echo' command, which will just echo back whatever the
user types, which is sent back to the program through the magic of
popen().

Good things about this code:
	It is short and easy.
	The launch command allows you to edit the field in lots of ways,
		including using Copy/Paste and the mouse.

Bad things about this code:
	The program will ignore all events while the prompter is up; if
		the user moves either window, an ugly display is likely to
		result.
	This won't work unless the user is on the graphics console (an OK
		assumption if this is a graphics program that requires
		mouse/keyboard input).
	This won't work with the Distributed Graphics Library.

The 'launch' command is in version 3.2 of the OS; I don't know if it
was around before then.

You might also want to check out the 'confirm' and 'inform'
commands...

--gavin



More information about the Comp.sys.sgi mailing list