コード例 #1
0
ファイル: golf.c プロジェクト: alandipert/cgolf
int
cgiMain()
{ 
	cgiHeaderContentType("text/html");
	
	int serverside = 0;
	cgiFormInteger("serverside", &serverside, 0);
	
	char function_call[50];
	int callback = 0;
	if (cgiFormString("function_call", &function_call[0], 50) == cgiFormSuccess)
		callback = 1;
	
	if(serverside) {
		/* Initialise the SEE library */
		SEE_init();
		
		/* Initialise an interpreter */
		SEE_interpreter_init(&g_interp_storage);
		g_interp = &g_interp_storage;
	
		/* Bring our native functions into the interpreter */
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "println", g_println, 1, 0);
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "include", g_include, 1, 0);
		SEE_CFUNCTION_PUTA(g_interp, g_interp->Global, "version", g_version, 1, 0);
		
		/* evaluate bootstrapping code, and then script, then transform events */
		evaluate_file(g_interp, &g_result, "/Users/alan/working/golf/boot/serverside.js");
		evaluate_file(g_interp, &g_result, cgiPathTranslated);
		
		/* this is dangerous lol.  should check to make sure the callback is a function */
		if(callback)
			evaluate_string(g_interp, &g_result, function_call);
		
		/* this converts elements with onclick event attributes into links */
		evaluate_file(g_interp, &g_result, "/Users/alan/working/golf/boot/transform.js");
		evaluate_string(g_interp, &g_result, "document.render();");
		
	} else {
		
		fprintf(cgiOut, "<html>\n<head>\n");
		fprintf(cgiOut, "<script type = \"text/javascript\">\n");
		fprintf(cgiOut, "function boot() {\n");
		print_file("/Users/alan/working/golf/boot/clientside.js");
		print_file(cgiPathTranslated);
		fprintf(cgiOut, "\n}\n");
		fprintf(cgiOut, "</script>\n</head>\n");
		fprintf(cgiOut, "<body onload = \"boot();\">\n");
		fprintf(cgiOut, "</body>\n</html>");
		
	}
	
	return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: golf_native.c プロジェクト: alandipert/cgolf
void
g_include(
	struct SEE_interpreter *interp, 
	struct SEE_object *self, 
	struct SEE_object *thisobj, 
	int argc, 
	struct SEE_value **argv, 
	struct SEE_value *res)
{
    struct SEE_value s;
    SEE_ToString(interp, argv[0], &s);
    
    char *filename = (char*)malloc(sizeof(char)*(s.u.string->length+1));
    int i;
    for (i = 0; i < s.u.string->length; i++) {
    	filename[i] = s.u.string->data[i];
    }
    
    filename[s.u.string->length] = '\0';
	
		evaluate_file(interp, res, filename);
	
		free(filename);
		SEE_SET_BOOLEAN(res, 1);
}
コード例 #3
0
ファイル: tainted.c プロジェクト: agumonkey/Tainted-Oyster
int main(int argc, char *argv[])
{
    init_oyster();

    FILE *file;
    int print;
    if (argc == 1) {
        file = stdin;
        print = 1;
    } else {
        file = fopen(argv[1], "r");
        print = 0;
    }
    if (errno) {
        error(errno, errno, "File error");
    }

    /// g'damn g_scanner won't return a token until EOF is reached.
    /// all my trickery is for naught.
    oyster *ret = evaluate_file(file, print);
    decref(ret);


    clean_up_oyster();

    return 0;

}
コード例 #4
0
int
main(int argc, char *argv[])
{
	cmd_ln_t *config;
	ngram_model_t *lm = NULL;
	logmath_t *lmath;
	const char *lmfn, *probdefn, *lsnfn, *text;

	if ((config = cmd_ln_parse_r(NULL, defn, argc, argv, TRUE)) == NULL)
		return 1;

        verbose = cmd_ln_boolean_r(config, "-verbose");

	/* Create log math object. */
	if ((lmath = logmath_init
	     (cmd_ln_float64_r(config, "-logbase"), 0, 0)) == NULL) {
		E_FATAL("Failed to initialize log math\n");
	}

	/* Load the language model. */
	lmfn = cmd_ln_str_r(config, "-lm");
	if (lmfn == NULL
	    || (lm = ngram_model_read(config, lmfn,
				      NGRAM_AUTO, lmath)) == NULL) {
		E_FATAL("Failed to load language model from %s\n",
			cmd_ln_str_r(config, "-lm"));
	}
        if ((probdefn = cmd_ln_str_r(config, "-probdef")) != NULL)
            ngram_model_read_classdef(lm, probdefn);
        ngram_model_apply_weights(lm,
                                  cmd_ln_float32_r(config, "-lw"),
                                  cmd_ln_float32_r(config, "-wip"),
                                  cmd_ln_float32_r(config, "-uw"));

	/* Now evaluate some text. */
	lsnfn = cmd_ln_str_r(config, "-lsn");
	text = cmd_ln_str_r(config, "-text");
	if (lsnfn) {
		evaluate_file(lm, lmath, lsnfn);
	}
	else if (text) {
		evaluate_string(lm, lmath, text);
	}

	return 0;
}
コード例 #5
0
ファイル: gojira.c プロジェクト: mushrom/gojira
int main( int argc, char *argv[] ){
	int ret = 0;
	signed char option;
	int i = 0;
	int lastopt = 0;
	bool interactive = false;
	bool load_libs = true;
	bool set_a_gc_profile = false;
	unsigned new_gc_profile = 0;

	stack_frame_t *global_frame;

	if ( argc < 2 ){
		// By default, go into an REPL
		interactive = true;

	} else {
		// otherwise parse options
		lastopt = 1;

		for ( i = 1; i < argc && argv[i][0] == '-'; i++ ){
			option = argv[i][1];

			switch ( option ){
				case 'i':
					interactive = true;
					break;

				case 'h':
					print_help( );
					exit( 0 );
					break;

				case 'L':
					load_libs = false;
					break;

				case 'g':
					{
						char *profile = argv[++i];

						set_a_gc_profile = true;

						if ( strcmp( profile, "fast" ) == 0 ){
							new_gc_profile = GC_PROFILE_FAST;

						} else if ( strcmp( profile, "balanced" ) == 0 ){
							new_gc_profile = GC_PROFILE_BALANCED;

						} else if ( strcmp( profile, "lowmem" ) == 0 ){
							new_gc_profile = GC_PROFILE_LOWMEM;

						} else {
							printf( "Unknown garbage collector profile \"%s\", "
							        "using \"balanced\" instead...\n", profile );

							new_gc_profile = GC_PROFILE_BALANCED;
						}
					}

				case 'v':
					break;

				default:
					print_help( );
					exit( 1 );
					break;
			}

			/* This keeps track of where the argument after the current argument is,
			   in order to find the filenames after option parsing is done.          */
			lastopt = i + 1;
		}
	}

	// print some info about the interpreter going into a REPL
	if ( interactive ){
		printf( "%s\n", GOJIRA_BUILD_NAME );
	}

	// Initialize the global interpreter state
	global_frame = frame_create( NULL, NULL, MAKE_ENV );
	init_global_frame( global_frame );

	if ( set_a_gc_profile ){
		gc_set_profile( get_current_gc( global_frame ), new_gc_profile );
	}

	// Load the 'base' library for needed primatives
	if ( load_libs ){
		evaluate_file( global_frame, BASE_LIB );
	}

	make_argument_var( global_frame, lastopt, argc, argv );

	if ( lastopt ){
		evaluate_file( global_frame, argv[lastopt] );
	}

	// Go into the REPL if the interpreter flag is set
	if ( interactive ){
		read_eval_print( global_frame );
	}

	// Clean up the global frame, and free all tokens left in the token cache
	gc_collect( get_current_gc( global_frame ));
	destroy_token_cache( );

	return ret;
}