00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <tcl.h>
00022 #include "tcl_commands.h"
00023 #include "VMDApp.h"
00024 #include "config.h"
00025
00026 int text_cmd_plugin(ClientData cd, Tcl_Interp *interp, int argc,
00027 const char *argv[]) {
00028
00029 VMDApp *app = (VMDApp *)cd;
00030 if (!app)
00031 return TCL_ERROR;
00032
00033
00034 if (argc == 3 && !strupncmp(argv[1], "dlopen", CMDLEN)) {
00035 int rc = app->plugin_dlopen(argv[2]);
00036 if (rc < 0) {
00037 Tcl_AppendResult(interp, "Unable to dlopen plugin file ", argv[2], NULL);
00038 return TCL_ERROR;
00039 }
00040 Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
00041 return TCL_OK;
00042 }
00043
00044 if (argc == 2 && !strupncmp(argv[1], "update", CMDLEN)) {
00045 app->plugin_update();
00046 return TCL_OK;
00047 }
00048
00049
00050
00051 if ((argc == 2 || argc == 3) && !strupncmp(argv[1], "list", CMDLEN)) {
00052 const char *type = NULL;
00053 if (argc == 3)
00054 type = argv[2];
00055
00056 PluginList pluginlist;
00057 app->list_plugins(pluginlist, type);
00058 const int num = pluginlist.num();
00059 Tcl_Obj *result = Tcl_NewListObj(0, NULL);
00060 for (int i=0; i<num; i++) {
00061 vmdplugin_t *p = pluginlist[i];
00062 Tcl_Obj *listelem = Tcl_NewListObj(0, NULL);
00063 Tcl_ListObjAppendElement(interp, listelem, Tcl_NewStringObj(p->type,-1));
00064 Tcl_ListObjAppendElement(interp, listelem, Tcl_NewStringObj(p->name,-1));
00065 Tcl_ListObjAppendElement(interp, result, listelem);
00066 }
00067 Tcl_SetObjResult(interp, result);
00068 return TCL_OK;
00069 }
00070
00071
00072
00073
00074
00075
00076 if (argc == 5 && !strupncmp(argv[1], "info", CMDLEN)) {
00077 vmdplugin_t *p = app->get_plugin(argv[2], argv[3]);
00078 if (!p) {
00079 Tcl_SetResult(interp, (char *) "0", TCL_STATIC);
00080 return TCL_OK;
00081 }
00082 char major[32], minor[32], reentrant[32];
00083 sprintf(major, "%d", p->majorv);
00084 sprintf(minor, "%d", p->minorv);
00085 sprintf(reentrant, "%d", p->is_reentrant);
00086
00087 if (!Tcl_SetVar2(interp,argv[4], "type", p->type, TCL_LEAVE_ERR_MSG) ||
00088 !Tcl_SetVar2(interp,argv[4], "name", p->name, TCL_LEAVE_ERR_MSG) ||
00089 !Tcl_SetVar2(interp,argv[4], "author", p->author, TCL_LEAVE_ERR_MSG) ||
00090 !Tcl_SetVar2(interp,argv[4], "majorversion", major, TCL_LEAVE_ERR_MSG) ||
00091 !Tcl_SetVar2(interp,argv[4], "minorversion", minor, TCL_LEAVE_ERR_MSG) ||
00092 !Tcl_SetVar2(interp,argv[4], "reentrant", reentrant, TCL_LEAVE_ERR_MSG)) {
00093 Tcl_AppendResult(interp, "Unable to return plugin information in variable ", argv[4], NULL);
00094 return TCL_ERROR;
00095 }
00096 Tcl_SetResult(interp, (char *) "1", TCL_STATIC);
00097 return TCL_OK;
00098 }
00099 Tcl_AppendResult(interp, "Usage: \n\tplugin dlopen <filename> -- Load plugins from a dynamic library\n",
00100 "\tplugin update -- Update the list of plugins in the GUI\n",
00101 "\tplugin list [<plugin type>] -- List all plugins of the given type\n",
00102 "\tplugin info <type> <name> <arrayname> -- Store info about plugin in array\n",
00103 NULL);
00104 return TCL_ERROR;
00105 }
00106