00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2019 The Board of Trustees of the 00004 *cr University of Illinois 00005 *cr All Rights Reserved 00006 *cr 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * RCS INFORMATION: 00011 * 00012 * $RCSfile: cmd_util.C,v $ 00013 * $Author: johns $ $Locker: $ $State: Exp $ 00014 * $Revision: 1.36 $ $Date: 2019年01月17日 21:21:03 $ 00015 * 00016 *************************************************************************** 00017 * DESCRIPTION: 00018 * 00019 * Command objects for doing various utilities, such as executing a shell, 00020 * displaying help, or quitting 00021 * 00022 ***************************************************************************/ 00023 00024 #include <string.h> 00025 #include <stdlib.h> 00026 #include <ctype.h> 00027 #include <tcl.h> 00028 00029 #include "config.h" 00030 #include "CommandQueue.h" 00031 #include "utilities.h" 00032 #include "VMDApp.h" 00033 #include "TextEvent.h" 00034 00035 int text_cmd_sleep(ClientData, Tcl_Interp *, int argc, const char *argv[]) { 00036 00037 if(argc == 2) { 00038 vmd_sleep((int) atof(argv[1])); 00039 } 00040 else { 00041 return TCL_ERROR; 00042 } 00043 // if here, no problem with command 00044 return TCL_OK; 00045 } 00046 00047 int text_cmd_gopython(ClientData cd, Tcl_Interp *interp, 00048 int argc, const char *argv[]) { 00049 00050 VMDApp *app = (VMDApp *)cd; 00051 CommandQueue *cmdQueue = app->commandQueue; 00052 00053 if (argc == 1) { 00054 if (!app->textinterp_change("python")) { 00055 Tcl_AppendResult(interp, "Unable to change to Python interpreter.", 00056 NULL); 00057 return TCL_ERROR; 00058 } 00059 } else if (argc == 2) { 00060 // change to python, run the script, then change back to Tcl 00061 if (app->textinterp_change("python")) { 00062 app->logfile_read(argv[1]); 00063 app->textinterp_change("tcl"); 00064 } else { 00065 Tcl_AppendResult(interp, "Unable to change to Python interpreter.", 00066 NULL); 00067 return TCL_ERROR; 00068 } 00069 } else if (argc == 3 && !strupncmp(argv[1], "-command", CMDLEN)) { 00070 // run the specified text in the Python interpreter. 00071 if (app->textinterp_change("python")) { 00072 cmdQueue->runcommand(new PythonEvalEvent(argv[2])); 00073 app->textinterp_change("tcl"); 00074 } else { 00075 Tcl_AppendResult(interp, "Unable to change to Python interpreter.", 00076 NULL); 00077 return TCL_ERROR; 00078 } 00079 } else { 00080 Tcl_AppendResult(interp, "gopython usage: \n", 00081 "gopython -- switch to python interpreter\n", 00082 "gopython <filename> -- run given file in Python interpreter\n", 00083 "gopython -command <cmd> -- execute <cmd> as literal Python command\n", 00084 NULL); 00085 return TCL_ERROR; 00086 } 00087 return TCL_OK; 00088 } 00089