
#include <tcl.h>
#include <stdio.h>
#include <stdlib.h>

static int MyCmd(ClientData clientData, Tcl_Interp *interp,
		 int argc, char *argv[])
{
  printf("Tcl is there!\n");
  return TCL_OK;
}

int main()
{
  Tcl_Interp *interp;

  /* create Tcl interpreter */
  interp = Tcl_CreateInterp();

  /* initialize Tcl ==> crashes with Tcl 8.4a4 */
  if (Tcl_Init(interp) != TCL_OK) {
    fprintf(stderr, "Tcl_Init failed: %s\n", Tcl_GetStringResult(interp));
    return -1;
  }

  /* create a command */
  if (Tcl_CreateCommand(interp, "MyCmd", MyCmd, 0, 0) == NULL) {
    fprintf(stderr, "Tcl_CreateCmd failed: %s\n", Tcl_GetStringResult(interp));
    return -1;
  }

  /* call the command */
  if (Tcl_Eval(interp, "MyCmd") != TCL_OK) {
    fprintf(stderr, "Tcl_Eval failed: %s\n", Tcl_GetStringResult(interp));
    return -1;
  }

  /* use predefined Tcl commands, e.g. eval a supplied script
     ==> crashes with Tcl 8.4a4 */
  if (Tcl_Eval(interp, "source anyscript.tcl") != TCL_OK) {
    fprintf(stderr, "Tcl_Eval failed: %s\n", Tcl_GetStringResult(interp));
    return -1;
  }

  return 0;
}
