Exemple #1
0
void
main(int argc, char *argv[])
{
	int delay = 1000;

	setrules(".d.d..b..d.d.d.d.d");			/* regular rules */
	ARGBEGIN {
	case '3':
		setrules(".d.d.db.b..d.d.d.d");
		break;					/* 34-life */
	case 'o':
		setrules(".d.d.db.b.b..d.d.d");
		break;					/* lineosc? */
	case 'r':					/* rules from cmdline */
		setrules(EARGF(usage()));
		break;
	default:
		usage();
	} ARGEND
	if (argc != 1)
		usage();

	initdraw(g9err, 0, argv0);
	einit(Emouse|Ekeyboard);	/* implies rawon() */

	cen = divpt(subpt(addpt(screen->r.min, screen->r.max),
		Pt(NLIFE * PX, NLIFE * PX)), 2);
	box  = allocimage(display, Rect(0, 0, BX, BX), RGB24, 1, DBlack);
	assert(box != nil);

	redraw();
	readlife(argv[0]);
	do {
		flushimage(display, 1);
		idle();
		sleep(delay);
		idle();
	} while (generate());
	exits(nil);
}
Exemple #2
0
static void predictions(char **casev,
                        char **namesv,
                        char **treev,
                        char **rulesv,
                        char **costv,
                        int *predv,  /* XXX predictions are character */
			double *confidencev,
			int *trials,
                        char **outputv)
{
    int val;  /* Used by setjmp/longjmp for implementing rbm_exit */

    // Announce ourselves for testing
    // Rprintf("predictions called\n");

    // Initialize the globals
    initglobals();

    // Handles the strbufv data structure
    rbm_removeall();

    // XXX Should this be controlled via an option?
    // Rprintf("Calling setOf\n");
    setOf();

    STRBUF *sb_cases = strbuf_create_full(*casev, strlen(*casev));
	if (rbm_register(sb_cases, "undefined.cases", 0) < 0) {
		error("undefined.cases already exists");
	}

    STRBUF *sb_names = strbuf_create_full(*namesv, strlen(*namesv));
	if (rbm_register(sb_names, "undefined.names", 0) < 0) {
		error("undefined.names already exists");
	}

    if (strlen(*treev)) {
	STRBUF *sb_treev = strbuf_create_full(*treev, strlen(*treev));
	/* XXX should sb_treev be copied? */
	if (rbm_register(sb_treev, "undefined.tree", 0) < 0) {
	    error("undefined.tree already exists");
	}
    } else if (strlen(*rulesv))  {
	STRBUF *sb_rulesv = strbuf_create_full(*rulesv, strlen(*rulesv));
	/* XXX should sb_rulesv be copied? */
	if (rbm_register(sb_rulesv, "undefined.rules", 0) < 0) {
	    error("undefined.rules already exists");
	}
	setrules(1);
    } else {
	error("either a tree or rules must be provided");
    }

    // Create a strbuf using *costv and register it as "undefined.costs"
    if (strlen(*costv) > 0) {
        // Rprintf("registering cost matrix: %s", *costv);
        STRBUF *sb_costv = strbuf_create_full(*costv, strlen(*costv));
        // XXX should sb_costv be copied?
	    if (rbm_register(sb_costv, "undefined.costs", 0) < 0) {
		    error("undefined.cost already exists");
	    }
    } else {
        // Rprintf("no cost matrix to register\n");
    }

    /*
     * We need to initialize rbm_buf before calling any code that
     * might call exit/rbm_exit.
     */
    if ((val = setjmp(rbm_buf)) == 0) {
        // Real work is done here
        // Rprintf("\n\nCalling rpredictmain\n");
        rpredictmain(trials ,predv ,confidencev);

        // Rprintf("predict finished\n\n");
    } else {
        Rprintf("predict code called exit with value %d\n\n", val - JMP_OFFSET);
    }

    // Close file object "Of", and return its contents via argument outputv
    char *outputString = closeOf();
    char *output = R_alloc(strlen(outputString) + 1, 1);
    strcpy(output, outputString);
    *outputv = output;

    // We reinitialize the globals on exit out of general paranoia
    initglobals();
}