00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #include "Mouse.h"
00025 #include "utilities.h"
00026 #include "DisplayDevice.h"
00027 #include "JString.h"
00028 #include "VMDApp.h"
00029 #include <ctype.h>
00030 #include <tcl.h>
00031
00032 static int check_canonical_form(const char *s) {
00033 if (s[0] == 'A') {
00034
00035 s++;
00036 if (*s == 0) {
00037 return TRUE;
00038 }
00039
00040
00041 if (*s != 'l' && *s != 'u') {
00042 return FALSE;
00043 }
00044
00045 if (*s == 'l') {
00046 s++;
00047 if (*s++ != 't') return FALSE;
00048 if (*s++ != '-') return FALSE;
00049 } else if (*s == 'u') {
00050 s++;
00051 if (*s++ != 'x') return FALSE;
00052 if (*s++ != '-') return FALSE;
00053 }
00054 }
00055
00056 if (s[0] == 'C') {
00057
00058 s++;
00059 if (*s == 0) {
00060 return TRUE;
00061 }
00062
00063 if (*s++ != 'o') return FALSE;
00064 if (*s++ != 'n') return FALSE;
00065 if (*s++ != 't') return FALSE;
00066 if (*s++ != 'r') return FALSE;
00067 if (*s++ != 'o') return FALSE;
00068 if (*s++ != 'l') return FALSE;
00069 if (*s++ != '-') return FALSE;
00070 }
00071
00072
00073 if (s[0] == 0) return FALSE;
00074
00075 if (s[1] == 0) return TRUE;
00076
00077 return FALSE;
00078 }
00079
00080 int text_cmd_user(ClientData cd, Tcl_Interp *interp, int argc,
00081 const char *argv[]) {
00082
00083 VMDApp *app = (VMDApp *)cd;
00084
00085 if(argc < 3) {
00086 Tcl_SetResult(interp,
00087 (char *)
00088 "user list keys\n"
00089 "user print keys\n"
00090 "user add key <character> <command>",
00091 TCL_STATIC);
00092 return TCL_ERROR;
00093 }
00094
00095 if(!strupncmp(argv[1], "add", CMDLEN)) {
00096 if (!strupncmp(argv[2], "key", CMDLEN)) {
00097 if(argc < 5)
00098 return TCL_ERROR;
00099
00100 if (check_canonical_form(argv[3])) {
00101 const char *combstr = argv[4];
00102 const char *desc = NULL;
00103 if (argc > 5) desc = argv[5];
00104 int indx = app->userKeys.typecode(argv[3]);
00105 if (indx < 0) {
00106 app->userKeys.add_name(argv[3], stringdup(combstr));
00107 } else {
00108 delete [] app->userKeys.data(indx);
00109 app->userKeys.set_data(indx, stringdup(combstr));
00110 }
00111 if (desc) {
00112 indx = app->userKeyDesc.typecode(argv[3]);
00113 if (indx < 0) {
00114 app->userKeyDesc.add_name(argv[3], stringdup(desc));
00115 } else {
00116 delete [] app->userKeyDesc.data(indx);
00117 app->userKeys.set_data(indx, stringdup(desc));
00118 }
00119 }
00120 } else {
00121 Tcl_AppendResult(interp, "user key ", argv[3], " is not valid",
00122 NULL);
00123 return TCL_ERROR;
00124 }
00125 } else
00126 return TCL_ERROR;
00127
00128 } else if(!strupncmp(argv[1], "list", CMDLEN)) {
00129
00130 if (argc != 3) {
00131 return TCL_ERROR;
00132 }
00133 if (!strcmp(argv[2], "keys")) {
00134 int num = app->userKeys.num();
00135 for (int i=0; i<num; i++) {
00136
00137 Tcl_AppendResult(interp, i==0?"":" ", "{", NULL);
00138 Tcl_AppendElement(interp, app->userKeys.name(i));
00139 Tcl_AppendElement(interp,
00140 (const char *) app->userKeys.data(i));
00141 int desc_typecode = app->userKeyDesc.typecode(app->userKeys.name(i));
00142 if (desc_typecode >= 0) {
00143 Tcl_AppendElement(interp,
00144 (const char *) app->userKeyDesc.data(i));
00145 } else {
00146 Tcl_AppendElement(interp, "");
00147 }
00148 Tcl_AppendResult(interp, "}", NULL);
00149 }
00150 return TCL_OK;
00151 } else {
00152 return TCL_ERROR;
00153 }
00154
00155
00156 } else if(!strupncmp(argv[1], "print", CMDLEN)) {
00157
00158 Tcl_AppendResult(interp,
00159 "Keyboard shortcuts:\n",
00160 "-------------------\n", NULL);
00161 for (int i=0; i<app->userKeys.num(); i++) {
00162 const char *key = app->userKeys.name(i);
00163 Tcl_AppendResult(interp, "'", key, "' : ", app->userKeys.data(i), "\n",
00164 NULL);
00165 if (app->userKeyDesc.typecode(key) >= 0) {
00166 Tcl_AppendResult(interp, " Description: ",
00167 app->userKeyDesc.data(key), NULL);
00168 }
00169 }
00170 } else
00171 return TCL_ERROR;
00172
00173
00174 return TCL_OK;
00175 }
00176