* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
+ * Copyright (C) 2007,2008 Øyvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
* part of this file is taken from libcli (libcli.sourceforge.net) *
* Copyright (C) David Parrish (david@dparrish.com) *
* *
#include "log.h"
#include "time_support.h"
+#include "jim-eventloop.h"
#include <stdlib.h>
#include <string.h>
log_remove_callback(tcl_output, tclOutput);
/* We dump output into this local variable */
- Jim_SetVariableStr(interp, "ocd_output", tclOutput);
+ Jim_SetResult(interp, tclOutput);
Jim_DecrRefCount(interp, tclOutput);
for (i = 0; i < nwords; i++)
free((void *)full_name);
/* we now need to add an overrideable proc */
- const char *override_name=alloc_printf("proc %s%s%s {args} {return [eval \"ocd_%s%s%s $args\"]}", t1, t2, t3, t1, t2, t3);
+ const char *override_name=alloc_printf("proc %s%s%s {args} {if {[catch {eval \"ocd_%s%s%s $args\"}]==0} {return \"\"} else { return -code error }", t1, t2, t3, t1, t2, t3);
Jim_Eval(interp, override_name);
free((void *)override_name);
add_default_dirs();
+#ifdef JIM_EMBEDDED
+ Jim_EventLoopOnLoad(interp);
+#endif
if (Jim_Eval(interp, startup_tcl)==JIM_ERR)
{
LOG_ERROR("Failed to run startup.tcl (embedded into OpenOCD compile time)");
return ERROR_OK;
}
+void process_jim_events()
+{
+#ifdef JIM_EMBEDDED
+ static int recursion = 0;
+
+ if (!recursion)
+ {
+ recursion++;
+ Jim_ProcessEvents (interp, JIM_ALL_EVENTS|JIM_DONT_WAIT);
+ recursion--;
+ }
+#endif
+}
+
void register_jim(struct command_context_s *cmd_ctx, const char *name, int (*cmd)(Jim_Interp *interp, int argc, Jim_Obj *const *argv), const char *help)
{
Jim_CreateCommand(interp, name, cmd, NULL, NULL);