コード例 #1
0
ファイル: test_np.c プロジェクト: doughunt/xmgr-resurrection
int
main (int argc, char* argv[])
{
    int i;

    /* Start xmgr with a buffer size of 2048 and open the pipe */
    if (ACEgrOpen(2048) == -1) {
        fprintf (stderr, "Can't run xmgr. \n");
        exit (EXIT_FAILURE);
    }
    
    /* Send some initialization commands to xmgr */
    ACEgrPrintf ("world xmax 100");
    ACEgrPrintf ("world ymax 10000");
    ACEgrPrintf ("xaxis tick major 20");
    ACEgrPrintf ("xaxis tick minor 10");
    ACEgrPrintf ("yaxis tick major 2000");
    ACEgrPrintf ("yaxis tick minor 1000");
    ACEgrPrintf ("sets symbol 2");
    ACEgrPrintf ("sets symbol fill 1");
    ACEgrPrintf ("sets symbol size 0.3");

    /* Display sample data */
    for (i = 1; i <= 100; i++) {
        ACEgrPrintf ("g0.s0 point %d, %d", i, i);
        ACEgrPrintf ("g0.s1 point %d, %d", i, i * i);
        /* Update the xmgr display after every ten steps */
        if (i % 10 == 0) {
            ACEgrPrintf ("redraw");
            /* Wait a second, just to simulate some time needed for
               calculations. Your real application shouldn't wait. */
            sleep (1);
        }
    }

    /* Tell xmgr to save the data */
    ACEgrPrintf ("saveall \"sample.gr\"");

    /* Flush the output buffer and close the pipe */
    ACEgrClose ();

    /* We are done */
    exit (EXIT_SUCCESS);
}
コード例 #2
0
ファイル: tclgr.c プロジェクト: syumprc/solar-eclipse
int TclgrCmd (ClientData clientData, Tcl_Interp *interp, int argc, 
	      const char *argv[])
{
    if (argc == 1 || (argc == 2 && (!strcmp (argv[1], "help") ||
	!strcmp (argv[1], "usage"))))
    {
	return Tcl_Eval (interp, "help tclgr");
    }

    if (!strcmp (argv[1], "syscommand"))
    {
	if (argc < 3)
	{
	    interp->result = gr_command;
	    return TCL_OK;
	}
	else
	{
	    strcpy (gr_command,argv[2]);
	    return TCL_OK;
	}
    }

    if (!strcmp (argv[1], "open"))
    {
	int status;
	int bufsize = 1000;
	int argindex;

	for (argindex = 2; argindex < argc; argindex++)
	{
	    if (!strcmp (argv[argindex], "-buffersize"))
	    {
		argindex++;
		if (argindex < argc)
		{
		    char dummy[512];
		    int count = sscanf (argv[argindex], 
					"%d %s", &bufsize, &dummy);
		    if (count == 1) 
		    {
			continue;
		    }
		}
		interp->result = "Ill-formed -buffersize argument";
		return TCL_ERROR;
	    }
	    else
	    {
		interp->result = "Invalid tclgr open arguments";
		return TCL_ERROR;
	    }
	}
	if (terminated_by_user)
	{
	    interp->result = 
    "ACE/gr session apparently terminated by user; use 'tclgr close' to reset";
	    return TCL_ERROR;
	}
	status = ACEgrOpen (bufsize, gr_command);
	if (status)
	{
	    if (status == -2)
	    {
		interp->result = 
		    "tclgr session already opened from this solar session";
	    }
	    else
	    {
		interp->result = "Error returned from ACEgrOpen";
	    }
	    return TCL_ERROR;
	}
	return TCL_OK;
    }
    if (!strcmp (argv[1], "close"))
    {
	int status = ACEgrClose (terminated_by_user);
	terminated_by_user = 0;
	if (status)
	{
	    interp->result = "Error returned from ACEgrClose";
	    return TCL_ERROR;
	}
	return TCL_OK;
    }
    if (terminated_by_user)
    {
	interp->result = 
    "ACE/gr session apparently terminated by user; use 'tclgr close' to reset";
	return TCL_ERROR;
    }
    if (!strcmp (argv[1], "buffer"))
    {
	char *command = Tcl_Concat (argc-2, &argv[2]);
	int status = ACEgrCommand (command);
	if (status)
	{
	    if (status == -2)
	    {
		terminated_by_user = 1;
		interp->result = 
    "ACE/gr session apparently terminated by user; use 'tclgr close' to reset";
		return TCL_ERROR;
	    }
	    interp->result = "Error returned from ACEgrCommand";
	    return TCL_ERROR;
	}
	return TCL_OK;
    }

    if (!strcmp (argv[1], "send"))
    {
	char *command = Tcl_Concat (argc-2, &argv[2]);
	int status = ACEgrCommand (command);
	if (status)
	{
	    interp->result = "Error returned from ACEgrCommand";
	    return TCL_ERROR;
	}
	status = ACEgrFlush ();
	if (status)
	{
	    if (status == -2)
	    {
		terminated_by_user = 1;
		interp->result = 
    "ACE/gr session apparently terminated by user; use 'tclgr close' to reset";
		return TCL_ERROR;
	    }
	    interp->result = "Error returned from ACEgrFlush";
	    return TCL_ERROR;
	}
	return TCL_OK;
    }
	
    if (!strcmp (argv[1], "flush"))
    {
	int status = ACEgrFlush ();
	if (status)
	{
	    if (status == -2)
	    {
		terminated_by_user = 1;
		interp->result = 
    "ACE/gr session apparently terminated by user; use 'tclgr close' to reset";
		return TCL_ERROR;
	    }
	    interp->result = "Error returned from ACEgrFlush";
	    return TCL_ERROR;
	}
	return TCL_OK;
    }

    interp->result = "Unrecognized tclgr command; see tclgr help";
    return TCL_ERROR;
}