コード例 #1
0
ファイル: jim_command.c プロジェクト: BitThunder/bitthunder
/*
 * Now we try to write big enough code to duplication our array in Jim's
 * list implementation. Later, we try to load a sample script in Tcl that
 * could print our list.
 */
int
main(int argc, char **argv)
{
	Jim_Interp *interp;
	int error;

	/* Create an interpreter. */
	interp = Jim_CreateInterp();
	assert(interp != NULL && "couldn't create interpreter");

	/* We register base commands, so that we actually implement Tcl. */
	Jim_RegisterCoreCommands(interp);

	/* And initialise any static extensions */
	Jim_InitStaticExtensions(interp);

	/* Register our Jim commands. */
	Jim_CreateCommand(interp, "MySampleCommand", MySampleCommandFunc,
	    NULL, NULL);

	/* Run a script. */
	error = Jim_Eval(interp, JIM_PROGRAM);
	if (error == JIM_ERR) {
		Jim_MakeErrorMessage(interp);
		fprintf(stderr, "%s\n", Jim_GetString(Jim_GetResult(interp), NULL));
		Jim_FreeInterp(interp);
		exit(EXIT_FAILURE);
	}

	Jim_FreeInterp(interp);
	return (EXIT_SUCCESS);
}
コード例 #2
0
ファイル: jim_hello.c プロジェクト: BitThunder/bitthunder
int
main(int argc, char **argv)
{
	Jim_Interp *interp;

	interp = NULL;

	/* Create Jim instance */
	interp = Jim_CreateInterp();
	assert(interp != NULL && "couldn't create interpreter!");

	/* We register base commands, so that we actually implement Tcl. */
	Jim_RegisterCoreCommands(interp);

	/* And initialise any static extensions */
	Jim_InitStaticExtensions(interp);


	/* Print a string to standard output */
	Jim_Eval(interp, "puts {Hello world!}");

	/* Free the interpreter */
	Jim_FreeInterp(interp);
	return (EXIT_SUCCESS);
}
コード例 #3
0
ファイル: jim-interp.c プロジェクト: evanhunter/jimtcl
/**
 * [interp] creates a new interpreter.
 */
static int JimInterpCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    Jim_Interp *child;
    char buf[32];

    if (argc != 1) {
        Jim_WrongNumArgs(interp, 1, argv, "");
        return JIM_ERR;
    }

    /* Create the interpreter command */
    child = Jim_CreateInterp();
    Jim_RegisterCoreCommands(child);
    Jim_InitStaticExtensions(child);

    /* Copy some core variables to the new interpreter */
    JimInterpCopyVariable(child, interp, "argv", NULL);
    JimInterpCopyVariable(child, interp, "argc", NULL);
    JimInterpCopyVariable(child, interp, "argv0", NULL);
    JimInterpCopyVariable(child, interp, "jim::argv0", NULL);
    JimInterpCopyVariable(child, interp, "jim::exe", NULL);

    /* Allow the child interpreter to find the parent */
    Jim_SetAssocData(child, "interp.parent", NULL, interp);

    snprintf(buf, sizeof(buf), "interp.handle%ld", Jim_GetId(interp));
    Jim_CreateCommand(interp, buf, JimInterpSubCmdProc, child, JimInterpDelProc);
    Jim_SetResultString(interp, buf, -1);
    return JIM_OK;
}
コード例 #4
0
ファイル: jim_conf.c プロジェクト: wkoszek/jimctl
/*
 * Now we try to write big enough code to duplication our array in Jim's
 * list implementation. Later, we try to load a sample script in Tcl that
 * could print our list.
 */
int
main(int argc, char **argv)
{
	struct mystate *jconf;
	Jim_Interp *interp;
	Jim_Obj *errstr;
	Jim_Obj *n;
	Jim_Obj *v;
	int error;

	errstr = n = v = NULL;
	error = 0;

	/* This is the first function embedders should call. */
	Jim_InitEmbedded();

	/* Create an interpreter */
	interp = Jim_CreateInterp();
	assert(interp != NULL && "couldn't create interpreter");

	/*
	 * Then, we register base commands, so that we actually implement Tcl.
	 */
	Jim_RegisterCoreCommands(interp);

	/*
	 * Create unique state for our sample parser and register all
	 * Jim commands.
	 */
	jconf = mystate_new();
	Jim_CreateCommand(interp, "interface", InterfaceFunc, jconf, NULL);
	Jim_CreateCommand(interp, "ip", InterfaceIPFunc, jconf, NULL);

	/*
	 * Parse a script.
	 */
	error = Jim_EvalFile(interp, "./net.tcl");
	if (error == JIM_ERR) {
		fprintf(stderr, "Couldn't execute Jim's script. "
		    "Error occured\n");
		Jim_PrintErrorMessage(interp);
		Jim_FreeInterp(interp);
		exit(EXIT_FAILURE);
	}

	ShowInterfaces(jconf->head);
	
	mystate_destroy(jconf);

	if (n != NULL)
		Jim_FreeObj(interp, n);
	Jim_FreeInterp(interp);
	return (EXIT_SUCCESS);
}
コード例 #5
0
ファイル: interp.c プロジェクト: openETCS/modeling
es_Interp* es_init_interp() {
  es_Interp *interp = NULL;

  interp = Jim_CreateInterp();
  Jim_RegisterCoreCommands(interp);
  Jim_InitStaticExtensions(interp);

  // load scripts
  es_eval_tcl(interp,es_tcl_script_config);

  // register commands
  es_jim_register_commands(interp);

  return interp;
}
コード例 #6
0
ファイル: dispatcher.c プロジェクト: AllardJ/Tomato
int main(int argc, char **argv)
{
	int i, retval;
	char arg[MAX_ARGSIZE];
	char arglist[MAX_ARGSIZE]; 

	Jim_Interp *interp;

	interp = NULL;
	arglist[0] = '\0';

	for (i=1; i<argc; i++) {
		if (strlen(argv[i]) > MAX_ARGSIZE-4) {
			printf("Argument #%d extends maximum size, skip it\n", i);
			continue;
		}
		if ( (strlen(arglist) + strlen(argv[i])) > MAX_ARGSIZE-4) {
			printf("Argument #%d would extend maximum list size, skip it\n", i);
			continue;
		}
		sprintf(arg,"{%s} ",argv[i]);
		strncat(arglist,arg,MAX_ARGSIZE-1);
	}

	char code[sizeof(RAW) + sizeof(arglist) + 28];
	sprintf(code, "set argv {%s}\nset argc %d\n", arglist, argc-1);
	strncat(code, RAW, sizeof(RAW));

	/* Create Jim instance */
	interp = Jim_CreateInterp();
	assert(interp != NULL && "Could not create interpreter!");

	/* Register base commands, actually implementing Tcl */
	Jim_RegisterCoreCommands(interp);

	/* Initialize any static extensions */
	Jim_InitStaticExtensions(interp);

	/* Evaluate the script that's now in "code" */
	retval = Jim_Eval(interp, code);
	if (retval < 0)
		printf("Evaluation returned error %d\n", retval);

	/* Free the interpreter */
	Jim_FreeInterp(interp);
	return (EXIT_SUCCESS);
}
コード例 #7
0
ファイル: Tcl.cpp プロジェクト: wibbe/zum
  void initialize()
  {
    interpreter_ = Jim_CreateInterp();
    Jim_RegisterCoreCommands(interpreter_);

    // Register extensions
    ::Jim_clockInit(interpreter_);
    ::Jim_regexpInit(interpreter_);

    // Register built in commands
    for (auto * cmd : builtInProcs())
      Jim_CreateCommand(interpreter_, cmd->name(), cmdProc, cmd, nullptr);

    for (auto * cmd : builtInSubCmdProcs())
      Jim_CreateCommand(interpreter_, cmd->name(), subCmdProc, cmd, nullptr);

    // Register built in variables
    for (auto * var : builtInVariables())
      Jim_SetGlobalVariableStr(interpreter_, var->name(), var->defaultValue());

#if DEBUG
    // Use the file from the source directory
    Jim_EvalFileGlobal(interpreter_, "../src/ScriptingLib.tcl");
#else
    Jim_EvalSource(interpreter_, __FILE__, __LINE__, std::string((char *)&ScriptingLib[0], BX_COUNTOF(ScriptingLib)).c_str());
#endif


    std::string configFile = "";
#if BX_PLATFORM_LINUX || BX_PLATFORM_OSX
    // Try to load the config file
    char * home = getenv("HOME");
    if (home)
      configFile = std::string(home) + "/." + CONFIG_FILE;
    else
      configFile = "~/." + CONFIG_FILE;
#else
    char pwd[1024];
    configFile = std::string(bx::pwd(pwd, 1024)) + "/" + CONFIG_FILE;
#endif

    logInfo("Loading config file: ", configFile);
    Jim_EvalFileGlobal(interpreter_, configFile.c_str());
  }