00001 // -*- c++ -*- 00002 00003 // This file is part of the Collective Variables module (Colvars). 00004 // The original version of Colvars and its updates are located at: 00005 // https://github.com/Colvars/colvars 00006 // Please update all Colvars source files before making any changes. 00007 // If you wish to distribute your changes, please submit them to the 00008 // Colvars repository at GitHub. 00009 00010 #include <vector> 00011 #include <cstdlib> 00012 #include <string.h> 00013 00014 #include "colvarproxy.h" 00015 #include "colvardeps.h" 00016 #include "colvarscript.h" 00017 #include "colvarscript_commands.h" 00018 00019 00020 00021 extern "C" 00022 int cvscript_n_commands() 00023 { 00024 return static_cast<int>(colvarscript::cv_n_commands); 00025 } 00026 00027 00028 extern "C" 00029 char const **cvscript_command_names() 00030 { 00031 colvarscript *script = colvarscript_obj(); 00032 return script->get_command_names(); 00033 } 00034 00035 00036 extern "C" 00037 char const *cvscript_command_help(char const *c) 00038 { 00039 colvarscript *script = colvarscript_obj(); 00040 return script->get_command_help(c); 00041 } 00042 00043 00044 extern "C" 00045 char const *cvscript_command_rethelp(char const *c) 00046 { 00047 colvarscript *script = colvarscript_obj(); 00048 return script->get_command_rethelp(c); 00049 } 00050 00051 00052 extern "C" 00053 char const *cvscript_command_arghelp(char const *c, int i) 00054 { 00055 colvarscript *script = colvarscript_obj(); 00056 return script->get_command_arghelp(c, i); 00057 } 00058 00059 00060 extern "C" 00061 char const *cvscript_command_full_help(char const *c) 00062 { 00063 colvarscript *script = colvarscript_obj(); 00064 return script->get_command_full_help(c); 00065 } 00066 00067 00068 extern "C" 00069 int cvscript_command_n_args_min(char const *c) 00070 { 00071 colvarscript *script = colvarscript_obj(); 00072 return script->get_command_n_args_min(c); 00073 } 00074 00075 00076 extern "C" 00077 int cvscript_command_n_args_max(char const *c) 00078 { 00079 colvarscript *script = colvarscript_obj(); 00080 return script->get_command_n_args_max(c); 00081 } 00082 00083 00084 // Instantiate the body of all script commands 00085 00086 #define CVSCRIPT_COMM_FN(COMM,N_ARGS_MIN,N_ARGS_MAX,ARGS,FN_BODY) \ 00087 int CVSCRIPT_COMM_FNAME(COMM)(void *pobj, \ 00088 int objc, unsigned char *const objv[]) \ 00089 { \ 00090 if (cvm::debug()) { \ 00091 cvm::log("Executing script function \""+std::string(#COMM)+"\""); \ 00092 } \ 00093 colvarscript *script = colvarscript_obj(); \ 00094 script->clear_str_result(); \ 00095 if (script->check_module_cmd_nargs(#COMM, \ 00096 objc, N_ARGS_MIN, N_ARGS_MAX) != \ 00097 COLVARSCRIPT_OK) { \ 00098 return COLVARSCRIPT_ERROR; \ 00099 } \ 00100 if (objc > 1) { \ 00101 /* Silence unused parameter warning */ \ 00102 (void) pobj; \ 00103 (void) objv[0]; \ 00104 } \ 00105 FN_BODY; \ 00106 } 00107 #undef CVSCRIPT 00108 #define CVSCRIPT(COMM,HELP,N_ARGS_MIN,N_ARGS_MAX,ARGS,FN_BODY) \ 00109 CVSCRIPT_COMM_FN(COMM,N_ARGS_MIN,N_ARGS_MAX,ARGS,FN_BODY) 00110 00111 // Skips the colvar- and bias- specific commands 00112 #define COLVARSCRIPT_COMMANDS_GLOBAL 00113 00114 #undef COLVARSCRIPT_COMMANDS_H 00115 #include "colvarscript_commands.h" 00116 00117 #undef CVSCRIPT_COMM_FN 00118 #undef CVSCRIPT