void vsx_widget_popup_menu::init_extra_commands() { commands.reset(); vsx_command_s* t; while ( (t = commands.pop()) ) add_commands(t); }
static void show_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * command_table, int argc, Jim_Obj *const *argv) { Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), "Usage: \"", Jim_String(argv[0]), " command ... \", where command is one of: ", NULL); add_commands(interp, command_table, ", "); }
static void bad_subcmd(Jim_Interp *interp, const jim_subcmd_type * command_table, const char *type, Jim_Obj *cmd, Jim_Obj *subcmd) { Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), Jim_String(cmd), ", ", type, " command \"", Jim_String(subcmd), "\": should be ", NULL); add_commands(interp, command_table, ", "); }
void vsx_widget_popup_menu::init() { req(!init_run); widget_type = VSX_WIDGET_TYPE_2D_MENU_POPUP; coord_type = VSX_WIDGET_COORD_CORNER; coord_related_parent = false; render_type = render_2d; topmost = true; visible = 0; commands.reset(); vsx_command_s* t; while ( (t = commands.pop()) ) add_commands(t); init_run = true; }
void vsx_widget_popup_menu::init() { if (init_run) return; widget_type = VSX_WIDGET_TYPE_2D_MENU_POPUP; coord_type = VSX_WIDGET_COORD_CORNER; coord_related_parent = false; topmost = true; row_size = 0.02; visible = 0; over = 0; oversub = false; commands.reset(); vsx_command_s* t; while ( (t = commands.get()) ) { add_commands(t); // } init_run = true; }
TclTextInterp::TclTextInterp(VMDApp *vmdapp, int guienabled, int mpienabled) : app(vmdapp) { interp = Tcl_CreateInterp(); #if 0 Tcl_InitMemory(interp); // enable Tcl memory debugging features // when compiled with TCL_MEM_DEBUG #endif commandPtr = Tcl_NewObj(); Tcl_IncrRefCount(commandPtr); consoleisatty = vmd_isatty(0); // whether we're interactive or not ignorestdin = 0; gotPartial = 0; needPrompt = 1; callLevel = 0; starttime = delay = 0; #if defined(VMDMPI) // // MPI builds of VMD cannot try to read any command input from the // console because it creates shutdown problems, at least with MPICH. // File-based command input is fine however. // // don't check for interactive console input if running in parallel if (mpienabled) ignorestdin = 1; #endif #if defined(ANDROIDARMV7A) // // For the time being, the Android builds won't attempt to get any // console input. Any input we're going to get is going to come via // some means other than stdin, such as a network socket, text box, etc. // // Don't check for interactive console input if compiled for Android ignorestdin = 1; #endif // set tcl_interactive, lets us run unix commands as from a shell #if !defined(VMD_NANOHUB) Tcl_SetVar(interp, "tcl_interactive", "1", 0); #else Tcl_SetVar(interp, "tcl_interactive", "0", 0); Tcl_Channel channel; #define CLIENT_READ (3) #define CLIENT_WRITE (4) channel = Tcl_MakeFileChannel((ClientData)CLIENT_READ, TCL_READABLE); if (channel != NULL) { const char *result; Tcl_RegisterChannel(interp, channel); result = Tcl_SetVar2(interp, "vmd_client", "read", Tcl_GetChannelName(channel), TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG); if (result == NULL) { fprintf(stderr, "can't create variable for client read channel\n"); } } channel = Tcl_MakeFileChannel((ClientData)CLIENT_WRITE, TCL_WRITABLE); if (channel != NULL) { const char *result; Tcl_RegisterChannel(interp, channel); result = Tcl_SetVar2(interp, "vmd_client", "write", Tcl_GetChannelName(channel), TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG); if (result == NULL) { fprintf(stderr, "can't create variable for client write channel\n"); } } write(CLIENT_WRITE, "vmd 1.0\n", 8); #endif // pass our instance of VMDApp to a hash table assoc. with the interpreter Tcl_SetAssocData(interp, "VMDApp", NULL, app); // Set up argc, argv0, and argv variables { char argcbuf[20]; sprintf(argcbuf, "%d", app->argc_m); Tcl_SetVar(interp, "argc", argcbuf, TCL_GLOBAL_ONLY); // it might be better to use the same thing that was passed to // Tcl_FindExecutable, but this is now Tcl_SetVar(interp, "argv0", app->argv_m[0], TCL_GLOBAL_ONLY); char *args = Tcl_Merge(app->argc_m-1, app->argv_m+1); Tcl_SetVar(interp, "argv", args, TCL_GLOBAL_ONLY); Tcl_Free(args); } #if defined(_MSC_VER) && TCL_MINOR_VERSION >= 4 // The Windows versions of Tcl 8.5.x have trouble finding // the Tcl library subdirectory for unknown reasons. // We force the appropriate env variables to be set in Tcl, // despite Windows. { char vmdinitscript[4096]; char * tcl_library = getenv("TCL_LIBRARY"); char * tk_library = getenv("TK_LIBRARY"); if (tcl_library) { sprintf(vmdinitscript, "set env(TCL_LIBRARY) {%s}", tcl_library); if (Tcl_Eval(interp, vmdinitscript) != TCL_OK) { msgErr << Tcl_GetStringResult(interp) << sendmsg; } } if (tk_library) { sprintf(vmdinitscript, "set env(TK_LIBRARY) {%s}", tk_library); if (Tcl_Eval(interp, vmdinitscript) != TCL_OK) { msgErr << Tcl_GetStringResult(interp) << sendmsg; } } } #endif if (Tcl_Init(interp) == TCL_ERROR) { // new with 7.6 msgErr << "Tcl startup error: " << Tcl_GetStringResult(interp) << sendmsg; } #ifdef VMDTK // and the Tk commands (but only if a GUI is available!) if (guienabled) { if (Tk_Init(interp) == TCL_ERROR) { msgErr << "Tk startup error: " << Tcl_GetStringResult(interp) << sendmsg; } else { Tcl_StaticPackage(interp, "Tk", (Tcl_PackageInitProc *) Tk_Init, (Tcl_PackageInitProc *) NULL); } } // end of check that GUI is allowed #endif add_commands(); }
const jim_subcmd_type *Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type * command_table, int argc, Jim_Obj *const *argv) { const jim_subcmd_type *ct; const jim_subcmd_type *partial = 0; int cmdlen; Jim_Obj *cmd; const char *cmdstr; const char *cmdname; int help = 0; cmdname = Jim_String(argv[0]); if (argc < 2) { Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), "wrong # args: should be \"", cmdname, " command ...\"\n", NULL); Jim_AppendStrings(interp, Jim_GetResult(interp), "Use \"", cmdname, " -help ?command?\" for help", NULL); return 0; } cmd = argv[1]; /* Check for the help command */ if (Jim_CompareStringImmediate(interp, cmd, "-help")) { if (argc == 2) { /* Usage for the command, not the subcommand */ show_cmd_usage(interp, command_table, argc, argv); return &dummy_subcmd; } help = 1; /* Skip the 'help' command */ cmd = argv[2]; } /* Check for special builtin '-commands' command first */ if (Jim_CompareStringImmediate(interp, cmd, "-commands")) { /* Build the result here */ Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); add_commands(interp, command_table, " "); return &dummy_subcmd; } cmdstr = Jim_GetString(cmd, &cmdlen); for (ct = command_table; ct->cmd; ct++) { if (Jim_CompareStringImmediate(interp, cmd, ct->cmd)) { /* Found an exact match */ break; } if (strncmp(cmdstr, ct->cmd, cmdlen) == 0) { if (partial) { /* Ambiguous */ if (help) { /* Just show the top level help here */ show_cmd_usage(interp, command_table, argc, argv); return &dummy_subcmd; } bad_subcmd(interp, command_table, "ambiguous", argv[0], argv[1 + help]); return 0; } partial = ct; } continue; } /* If we had an unambiguous partial match */ if (partial && !ct->cmd) { ct = partial; } if (!ct->cmd) { /* No matching command */ if (help) { /* Just show the top level help here */ show_cmd_usage(interp, command_table, argc, argv); return &dummy_subcmd; } bad_subcmd(interp, command_table, "unknown", argv[0], argv[1 + help]); return 0; } if (help) { Jim_SetResultString(interp, "Usage: ", -1); /* subcmd */ add_cmd_usage(interp, ct, argv[0]); return &dummy_subcmd; } /* Check the number of args */ if (argc - 2 < ct->minargs || (ct->maxargs >= 0 && argc - 2 > ct->maxargs)) { Jim_SetResultString(interp, "wrong # args: should be \"", -1); /* subcmd */ add_cmd_usage(interp, ct, argv[0]); Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL); return 0; } /* Good command */ return ct; }