Пример #1
0
int main(int argc, char *argv[])
{
	int ret = -1;
	global_output = start_gnuplot();

	/* int i;
	 * tortoise_pendown (); /
	 * for (i = 1; i <= 4; ++i)
	 * {
	 *	tortoise_move (3.0);
	 *	tortoise_turn (90.0);
	 * } */

	ret = tortoise_guile_main(argc, argv);
	return ret;
}
Пример #2
0
int
main( int argc, char *argv[] )
{
#if DEBUG_MXGNUPLT
	static const char fname[] = "mxgnuplt";
#endif

	struct update_struct_t update_struct;
	HWND hwnd_text, hwnd_top_level;
	DWORD process_id;
	LPARAM lParam;
	LRESULT status;
	char class_name[50];
	char buffer[200];
	char wgnuplot_name[200];
	int i, c, length, do_exit;
	int plotting_window_initialized;

#if DEBUG_MXGNUPLT
	/* plotgnu.pl redirects stderr to /dev/null in order to discard
	 * messages from wgnuplot, so we must open our own FILE to send
	 * debugging messages.
	 */

	FILE *con;

	con = fopen( "con", "w" );

	setvbuf( con, (char *)NULL, _IONBF, 0 );

	fprintf( con, "%s invoked.\n", fname );
#endif

	plotting_window_initialized = FALSE;
	global_hwnd_graph = NULL;

	/* Set standard input to be line buffered. */

	setvbuf( stdin, (char *)NULL, _IOLBF, 0 );

	/* Start the 'wgnuplot' program. */

	process_id = start_gnuplot( wgnuplot_name,
				sizeof(wgnuplot_name) );

	sprintf( buffer, "Process ID = %ld", process_id );

#if DEBUG_MXGNUPLT
	fprintf( con, "%s: wgnuplot PID = %ld\n", fname, process_id );
#endif

	/* Get a handle to the top level Gnuplot window.
	 * If we are lucky, it is the right one.
	 */

	for ( i = 0; i < 100; i++ ) {

		hwnd_top_level = find_window_by_processid(
				process_id, "wgnuplot_parent" );

		if ( hwnd_top_level != NULL ) {
			break;
		}

		Sleep(100);
	}

	if ( hwnd_top_level == NULL ) {
		MessageBox( NULL,
		(LPTSTR) "Unable to find 'wgnuplot' top level window.",
		    NULL, MB_OK );
		exit(1);
	}

#if DEBUG_MXGNUPLT
	fprintf( con, "%s: wgnuplot top level window = %p\n",
			fname, hwnd_top_level );
#endif

	/* Find the wgnuplot text window. */

	hwnd_text = FindWindowEx( hwnd_top_level, (HWND) NULL,
			(LPCTSTR) "wgnuplot_text", (LPCTSTR) "gnuplot" );

	if ( hwnd_text == NULL ) {
		MessageBox( NULL,
		(LPTSTR) "Unable to find 'wgnuplot' text input window.",
		    NULL, MB_OK );
		exit(1);
	}

#if DEBUG_MXGNUPLT
	fprintf( con, "%s: wgnuplot text window = %p\n",
			fname, hwnd_text );
#endif

	/* Start sending commands to the wgnuplot text window. */

	do_exit = FALSE;

	fgets( buffer, sizeof buffer, stdin );

	while ( !feof(stdin) && !ferror(stdin) ) {

#if DEBUG_MXGNUPLT
		fprintf( con, "%s: received '%s'\n", fname, buffer );
#endif

		if ( strcmp( buffer, "exit\n" ) == 0 ) {
			do_exit = TRUE;
		}

		if ( plotting_window_initialized == FALSE ) {
			if ( strncmp( buffer, "plot", 4 ) == 0 ) {

				update_struct.process_id = process_id;
				update_struct.hwnd_top_level
					= hwnd_top_level;

				_beginthread( update_plot_window,
					0, (void *) &update_struct );

				plotting_window_initialized = TRUE;
			}
		}

		length = strlen( buffer );

		for ( i = 0; i < length; i++ ) {
			c = buffer[i];

			status = SendMessage( hwnd_text, WM_CHAR, (long)c, 1L );

			if ( status != 0 ) {
				sprintf( buffer,
	"mxgnuplt: Error sending char '%c' to Gnuplot.  status = %ld\n",
					c, (long) status );
				MessageBox( NULL, (LPTSTR) buffer,
						NULL, MB_OK );
			}
		}

		if ( do_exit ) {
			/* If Gnuplot has been sent an 'exit' command,
			 * sending the graph window a mouse move message
			 * will cause Gnuplot to process the 'exit'
			 * command and terminate.
			 */

			if ( global_hwnd_graph != NULL ) {
				lParam = ( 5 << 16 ) | 5;

				PostMessage( global_hwnd_graph,
					WM_MOUSEMOVE,
					(WPARAM)0, lParam );
			}
			exit(0);
		}
		Sleep(10);

#if DEBUG_MXGNUPLT
		fprintf( con, "%s: waiting for next message...\n", fname );
#endif

		fgets( buffer, sizeof buffer, stdin );
	}

#if 0
	MessageBox( NULL, (LPTSTR) "mxgnuplt exiting abnormally.",
			NULL, MB_OK );
#else
	fprintf( stderr, "mxgnuplt exiting abnormally.\n" );
#endif

	exit(1);

	/* Suppress the Borland compiler's 'Function should return a value...'
	 * message.
	 */

	return 1;
}