Changeset 685
- Timestamp:
- Apr 27, 2007, 7:06:34 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tcl/src/RpLibraryTclInterface.cc
r528 r685 15 15 #include <tcl.h> 16 16 #include <sstream> 17 #include <string> 18 #include "RpLibrary.h" 17 #include "core/RpLibrary.h" 19 18 #include "RpLibraryTclInterface.h" 20 19 … … 26 25 27 26 28 static int RpLibraryCmd _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 29 int argc, const char *argv[] )); 30 static int RpLibCallCmd _ANSI_ARGS_(( ClientData cData, Tcl_Interp *interp, 31 int argc, const char* argv[] )); 32 33 static int RpTclLibChild _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 34 int argc, const char *argv[] )); 35 static int RpTclLibCopy _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 36 int argc, const char *argv[] )); 37 static int RpTclLibDiff _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 38 int argc, const char *argv[] )); 39 static int RpTclLibElem _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 40 int argc, const char *argv[] )); 41 static int RpTclLibGet _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 42 int argc, const char *argv[] )); 43 static int RpTclLibInfo _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 44 int argc, const char *argv[] )); 45 static int RpTclLibIsa _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 46 int argc, const char *argv[] )); 47 static int RpTclLibParent _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 48 int argc, const char *argv[] )); 49 static int RpTclLibPut _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 50 int argc, const char *argv[] )); 51 static int RpTclLibRemove _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 52 int argc, const char *argv[] )); 53 /* 54 static int RpTclLibResult _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 55 int argc, const char *argv[] )); 56 static int RpTclLibValue _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 57 int argc, const char *argv[] )); 58 */ 59 static int RpTclLibXml _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp, 60 int argc, const char *argv[] )); 61 62 static int RpTclResult _ANSI_ARGS_(( ClientData cdata, 63 Tcl_Interp *interp, 64 int argc, 65 const char *argv[] )); 66 67 68 void appendExpectErr _ANSI_ARGS_(( Tcl_Interp *interp, 69 const char* errTxt, 70 const char* receivedArg)); 27 static int RpLibraryCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 28 int objc, Tcl_Obj *CONST *objv)); 29 static int RpLibCallCmd _ANSI_ARGS_((ClientData cData, Tcl_Interp *interp, 30 int objc, Tcl_Obj *CONST *objv)); 31 static int RpTclLibChild _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 32 int objc, Tcl_Obj *CONST *objv)); 33 static int RpTclLibCopy _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 34 int objc, Tcl_Obj *CONST *objv)); 35 static int RpTclLibDiff _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 36 int objc, Tcl_Obj *CONST *objv)); 37 static int RpTclLibElem _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 38 int objc, Tcl_Obj *CONST *objv)); 39 static int RpTclLibGet _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 40 int objc, Tcl_Obj *CONST *objv)); 41 static int RpTclLibInfo _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 42 int objc, Tcl_Obj *CONST *objv)); 43 static int RpTclLibIsa _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 44 int objc, Tcl_Obj *CONST *objv)); 45 static int RpTclLibParent _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 46 int objc, Tcl_Obj *CONST *objv)); 47 static int RpTclLibPut _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 48 int objc, Tcl_Obj *CONST *objv)); 49 static int RpTclLibRemove _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 50 int objc, Tcl_Obj *CONST *objv)); 51 static int RpTclLibResult _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 52 int objc, Tcl_Obj *CONST *objv)); 53 static int RpTclLibValue _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 54 int objc, Tcl_Obj *CONST *objv)); 55 static int RpTclLibXml _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 56 int objc, Tcl_Obj *CONST *objv)); 57 58 static int RpTclResult _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, 59 int objc, Tcl_Obj *CONST *objv)); 60 61 static std::string rpLib2command _ANSI_ARGS_((Tcl_Interp *interp, 62 RpLibrary* newRpLibObj)); 63 static int rpGetLibraryFromObj _ANSI_ARGS_((Tcl_Interp *interp, 64 Tcl_Obj* obj, RpLibrary **rval)); 71 65 72 66 // member function, function pointer mainly used in 'element' implementation … … 77 71 "?-as <fval>? ?-type <name>? ?<path>?",}, 78 72 {"copy", 2, (Blt_Op)RpTclLibCopy, 5, 6, 79 " path from ?xmlobj? path",},80 {"diff", 1, (Blt_Op)RpTclLibDiff, 3, 3, " xmlobj",},81 {"element", 1, (Blt_Op)RpTclLibElem, 2, 5, "?-as fval? ?path?",},82 {"get", 1, (Blt_Op)RpTclLibGet, 2, 3, "? path?",},83 {"info", 1, (Blt_Op)RpTclLibInfo, 3, 3, " objType",},84 {"isa", 1, (Blt_Op)RpTclLibIsa, 3, 3, " objType",},73 "<path> from ?<xmlobj>? <path>",}, 74 {"diff", 1, (Blt_Op)RpTclLibDiff, 3, 3, "<xmlobj>",}, 75 {"element", 1, (Blt_Op)RpTclLibElem, 2, 5, "?-as <fval>? ?<path>?",}, 76 {"get", 1, (Blt_Op)RpTclLibGet, 2, 3, "?<path>?",}, 77 {"info", 1, (Blt_Op)RpTclLibInfo, 3, 3, "<objType>",}, 78 {"isa", 1, (Blt_Op)RpTclLibIsa, 3, 3, "<objType>",}, 85 79 {"parent", 2, (Blt_Op)RpTclLibParent, 2, 5, "?-as <fval>? ?<path>?",}, 86 80 {"put", 2, (Blt_Op)RpTclLibPut, 2, 8, … … 96 90 } 97 91 #endif 98 static std::string rpLib2command _ANSI_ARGS_(( Tcl_Interp *interp,99 RpLibrary* newRpLibObj ));100 92 101 93 /* … … 108 100 * ------------------------------------------------------------------------ 109 101 */ 110 111 102 std::string 112 103 rpLib2command (Tcl_Interp *interp, RpLibrary* newRpLibObj) … … 117 108 libName << "::libraryObj" << libCount++; 118 109 119 Tcl_Create Command(interp, libName.str().c_str(),110 Tcl_CreateObjCommand(interp, libName.str().c_str(), 120 111 RpLibCallCmd, (ClientData)newRpLibObj, (Tcl_CmdDeleteProc*)NULL); 121 112 … … 125 116 /* 126 117 * ------------------------------------------------------------------------ 127 * appendExpectErr() 128 * 129 * dsk defined helper function for appending error messages to the 130 * tcl interpreter without worrying if the receivedArg is empty 131 * 118 * rpGetLibraryFromObj() 119 * 120 * Tries to decode the given argument as a Rappture Library object. 121 * Returns TCL_OK if successful, along with a pointer to the library 122 * in rval. Otherwise, it returns TCL_ERROR, along with an error 123 * message in the interp. 132 124 * ------------------------------------------------------------------------ 133 125 */ 134 135 void 136 appendExpectErr (Tcl_Interp *interp, const char* errTxt, const char* receivedArg) 137 { 138 if (receivedArg) { 139 Tcl_AppendResult(interp, errTxt, "\"", 140 receivedArg, "\"", (char*)NULL); 141 } 142 else { 143 Tcl_AppendResult(interp, errTxt, "\"\"", (char*)NULL); 144 } 126 int 127 rpGetLibraryFromObj(Tcl_Interp *interp, Tcl_Obj* obj, RpLibrary **rval) 128 { 129 Tcl_CmdInfo info; 130 char *cmdname = Tcl_GetString(obj); 131 if (Tcl_GetCommandInfo(interp, cmdname, &info)) { 132 if (info.objProc == RpLibCallCmd) { 133 *rval = (RpLibrary*)(info.objClientData); 134 return TCL_OK; 135 } 136 } 137 Tcl_AppendResult(interp, "bad value \"", cmdname, 138 "\": should be a Rappture library object", 139 (char*)NULL); 140 return TCL_ERROR; 145 141 } 146 142 … … 153 149 * ------------------------------------------------------------------------ 154 150 */ 155 156 151 int 157 152 Rappturelibrary_Init(Tcl_Interp *interp) 158 153 { 159 154 160 Tcl_Create Command(interp, "::Rappture::library",155 Tcl_CreateObjCommand(interp, "::Rappture::library", 161 156 RpLibraryCmd, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 162 157 163 Tcl_Create Command(interp, "::Rappture::result",158 Tcl_CreateObjCommand(interp, "::Rappture::result", 164 159 RpTclResult, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 165 160 166 161 /* 167 Tcl_Create Command(interp, "::Rappture::LibraryObj::value",162 Tcl_CreateObjCommand(interp, "::Rappture::LibraryObj::value", 168 163 RpTclLibValue, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 169 164 */ … … 173 168 174 169 /* 175 *176 170 * USAGE: library <file> 177 171 * USAGE: library standard 178 172 * USAGE: library isvalid <object> 179 * 180 */ 181 182 int 183 RpLibraryCmd ( ClientData cData, 184 Tcl_Interp *interp, 185 int argc, 186 const char* argv[] ) 187 { 188 RpLibrary *rpptr = NULL; 189 std::string libName = ""; 190 int noerr = 0; 191 std::stringstream result; 192 std::string path = ""; 193 Tcl_CmdInfo info; // pointer to the command info 194 const char * var = NULL; // the path of Rappture installation 195 196 197 if ( (argc > 2) && (*argv[1] == 'i') && (strncmp(argv[1],"isvalid",7) == 0) ) { 198 result.str("0"); 199 if (argc != 3) { 200 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 201 "\": isvalid <object>", 173 */ 174 int 175 RpLibraryCmd (ClientData cData, Tcl_Interp *interp, 176 int objc, Tcl_Obj* CONST *objv[]) 177 { 178 char *flag = Tcl_GetString(objv[1]); 179 if (objc > 2 && strcmp(flag,"isvalid") == 0) { 180 if (objc != 3) { 181 Tcl_AppendResult(interp, "wrong # args: should be \"", 182 Tcl_GetString(objv[0]), "\": isvalid object", 202 183 (char*)NULL); 203 184 return TCL_ERROR; 204 185 } 205 186 206 noerr = Tcl_GetCommandInfo(interp, argv[2], &info); 207 if (noerr == 1) { 208 if (info.proc == &RpLibCallCmd) { 209 result.clear(); 210 result.str("1"); 211 } 212 } 213 214 Tcl_ResetResult(interp); 215 Tcl_AppendResult(interp, result.str().c_str(), (char*)NULL); 187 // 188 // Check to see if the object is valid. It should be a 189 // recognized Tcl command with the appropriate handler 190 // function. 191 // 192 int found = 0; 193 RpLibrary *rlib; 194 if (rpGetLibraryFromObj(interp, objv[2], &rlib) == TCL_OK && rlib) { 195 found = 1; 196 } 197 Tcl_SetObjResult(interp, Tcl_NewIntObj(found)); 216 198 return TCL_OK; 217 199 } 218 200 219 if (argc != 2) { 220 Tcl_AppendResult(interp, 221 "wrong # args: should be \"", argv[0], 222 "\" [ <file> | standard | isvalid <object> ]", 223 (char*)NULL); 224 return TCL_ERROR; 225 } 226 227 if ( (*argv[1] == 's') && (strncmp(argv[1],"standard",8) == 0) ) { 228 var = Tcl_GetVar(interp,"Rappture::installdir",0); 229 if (var) { 230 path = std::string(var) + "/lib/library.xml"; 231 rpptr = new RpLibrary(path); 232 libName = rpLib2command(interp,rpptr); 233 Tcl_AppendResult(interp, libName.c_str(), (char*)NULL); 234 } 235 else { 236 Tcl_AppendResult(interp, 237 "Rappture::installdir is not a valid variable", 238 (char*)NULL); 239 return TCL_ERROR; 240 } 241 } 242 else { 243 // create a new command 244 rpptr = new RpLibrary(argv[1]); 245 libName = rpLib2command(interp,rpptr); 246 Tcl_AppendResult(interp, libName.c_str(), (char*)NULL); 247 } 248 249 return TCL_OK; 250 } 251 252 253 int 254 RpLibCallCmd ( ClientData cData, 255 Tcl_Interp *interp, 256 int argc, 257 const char* argv[] ) 201 if (objc != 2) { 202 Tcl_AppendResult(interp, "usage: ", Tcl_GetString(objv[0]), 203 " <xmlfile>",(char*)NULL); 204 return TCL_ERROR; 205 } 206 207 // create a new command 208 RpLibrary *rpptr = new RpLibrary( Tcl_GetString(objv[1]) ); 209 std::string libName = rpLib2command(interp,rpptr); 210 211 Tcl_AppendResult(interp, libName.c_str(), (char*)NULL); 212 return TCL_OK; 213 } 214 215 216 int 217 RpLibCallCmd (ClientData cData, Tcl_Interp *interp, 218 int objc, Tcl_Obj *CONST *objv) 258 219 { 259 220 Blt_Op proc; 260 221 261 if (argc < 2) { 262 Tcl_AppendResult(interp, 263 "wrong # args: should be one of...\n", 264 " ", argv[0], " cget -option\n", 265 " ", argv[0], " children ?arg arg ...?\n", 266 " ", argv[0], " configure ?-option? ?value -option value...?\n", 267 " ", argv[0], " copy path from ?arg arg ...?\n", 268 " ", argv[0], " diff libobj\n", 269 " ", argv[0], " element ?arg arg ...?\n", 270 " ", argv[0], " get ?path?\n", 271 " ", argv[0], " info infoType\n", 272 " ", argv[0], " isa className\n", 273 " ", argv[0], " parent ?arg arg ...?\n", 274 " ", argv[0], " put ?arg arg ...?\n", 275 " ", argv[0], " remove ?path?\n", 276 " ", argv[0], " xml\n", 277 (char*)NULL); 278 return TCL_ERROR; 279 } 280 281 proc = Blt_GetOp(interp, nRpLibOps, rpLibOps, BLT_OP_ARG1, 282 argc, (char**)argv, 0); 222 proc = Blt_GetOpFromObj(interp, nRpLibOps, rpLibOps, BLT_OP_ARG1, 223 objc, (char**)objv, 0); 283 224 284 225 if (proc == NULL) { 285 226 return TCL_ERROR; 286 } 287 return (*proc)(cData, interp, argc, argv); 288 289 } 290 291 int checkAsArgs(Tcl_Interp *interp, const char* testStr, rpMbrFxnPtr asProc) 292 { 293 if ( (*testStr == 'c') && 294 (strncmp(testStr,"component",9) == 0) ) { 295 asProc = &RpLibrary::nodeComp; 296 } 297 else if ((*testStr == 'i') && 298 (strncmp(testStr,"id",2) == 0 ) ) { 299 asProc = &RpLibrary::nodeId; 300 } 301 else if ((*testStr == 't') && 302 (strncmp(testStr,"type",4) == 0 ) ) { 303 asProc = &RpLibrary::nodeType; 304 } 305 else if ((*testStr == 'p') && 306 (strncmp(testStr,"path",4) == 0 ) ) { 307 asProc = &RpLibrary::nodePath; 308 } 309 else if ((*testStr == 'o') && 310 (strncmp(testStr,"object",6) == 0 ) ) { 311 asProc = NULL; 312 } 313 else { 314 return TCL_ERROR; 315 } 316 317 return TCL_OK; 227 } 228 return (*proc)(cData, interp, objc, objv); 318 229 } 319 230 … … 331 242 * component - return the component name of child node, ex: type(id) 332 243 * id - return the id attribute of child node 244 * type - return the type attribute of child node 245 * path - return the full path of child node 333 246 * object - return a Rappture Library Object 334 * path - return the full path of child node335 * type - return the type attribute of child node336 247 * 337 248 * -type option tells function to only look for nodes of type <name> … … 341 252 * parent node and all its children will be returned. 342 253 */ 343 344 int 345 RpTclLibChild ( ClientData cdata, 346 Tcl_Interp *interp, 347 int argc, 348 const char *argv[] ) 254 int 255 RpTclLibChild (ClientData cdata, Tcl_Interp *interp, 256 int objc, Tcl_Obj *CONST *objv) 349 257 { 350 258 std::string path = ""; // path of where to place data inside xml tree … … 352 260 std::string retStr = ""; // path of where to place data inside xml tree 353 261 int nextarg = 2; // start parsing using the '2'th argument 354 int opt_argc = 2; // max number of optional parameters 355 int argsLeft = 0; // temp variable for calculation 262 int opt_objc = 2; // max number of optional parameters 356 263 357 264 RpLibrary* node = NULL; … … 359 266 360 267 // parse through -'d arguments 361 while (opt_argc--) { 362 if (nextarg < argc && *argv[nextarg] == '-') { 363 if (strncmp(argv[nextarg],"-as",3) == 0) { 268 while (opt_objc--) { 269 char *opt = Tcl_GetString(objv[nextarg]); 270 if (nextarg < objc && *opt == '-') { 271 if (strcmp(opt,"-as") == 0) { 364 272 nextarg++; 365 if (nextarg < argc) { 366 if ( (*argv[nextarg] == 'c') && 367 (strncmp(argv[nextarg],"component",9) == 0) ) { 273 if (nextarg < objc) { 274 if (*opt == 'c' && strcmp(opt,"component") == 0) { 368 275 asProc = &RpLibrary::nodeComp; 369 276 nextarg++; 370 277 } 371 else if ((*argv[nextarg] == 'i') && 372 (strncmp(argv[nextarg],"id",2) == 0 ) ) { 278 else if (*opt == 'i' && strcmp(opt,"id") == 0) { 373 279 asProc = &RpLibrary::nodeId; 374 280 nextarg++; 375 281 } 376 else if ((*argv[nextarg] == 't') && 377 (strncmp(argv[nextarg],"type",4) == 0 ) ) { 282 else if (*opt == 't' && strcmp(opt,"type") == 0) { 378 283 asProc = &RpLibrary::nodeType; 379 284 nextarg++; 380 285 } 381 else if ((*argv[nextarg] == 'p') && 382 (strncmp(argv[nextarg],"path",4) == 0 ) ) { 286 else if (*opt == 'p' && strcmp(opt,"path") == 0) { 383 287 asProc = &RpLibrary::nodePath; 384 288 nextarg++; 385 289 } 386 else if ((*argv[nextarg] == 'o') && 387 (strncmp(argv[nextarg],"object",6) == 0 ) ) { 290 else if (*opt == 'o' && strcmp(opt,"object") == 0) { 388 291 asProc = NULL; 389 292 nextarg++; 390 293 } 391 294 else { 392 Tcl_AppendResult(interp, "bad flavor \"", argv[nextarg],393 "\" for -as: should be component, id, object, path, type",394 (char*)NULL);295 Tcl_AppendResult(interp, "bad flavor \"", opt, 296 "\" for -as: should be component, id, type,", 297 " path, object", (char*)NULL); 395 298 return TCL_ERROR; 396 299 } … … 398 301 else { 399 302 Tcl_AppendResult(interp, "bad flavor \"\" for -as", 400 ": should be component, id, object, path, type",401 303 ": should be component, id, type, path, object", 304 (char*)NULL); 402 305 return TCL_ERROR; 403 306 } 404 307 } 405 else if (str ncmp(argv[nextarg],"-type",5) == 0) {308 else if (strcmp(opt,"-type") == 0) { 406 309 nextarg++; 407 if (nextarg < argc) {408 type = std::string( argv[nextarg]);310 if (nextarg < objc) { 311 type = std::string(opt); 409 312 nextarg++; 410 313 } 411 314 else { 412 Tcl_AppendResult(interp, "bad flavor \"\" for -type option",413 " : should be a type of node within the xml",315 Tcl_AppendResult(interp, "bad flavor \"\" for -type ", 316 "option: should be a type of node within the xml", 414 317 (char*)NULL); 415 318 return TCL_ERROR; … … 417 320 } 418 321 else { 419 Tcl_AppendResult(interp, "bad option \"", argv[nextarg],322 Tcl_AppendResult(interp, "bad option \"", opt, 420 323 "\": should be -as, -type", (char*)NULL); 421 324 return TCL_ERROR; … … 424 327 } 425 328 426 argsLeft = (argc-nextarg);329 int argsLeft = (objc-nextarg); 427 330 if (argsLeft > 1) { 428 331 Tcl_AppendResult(interp, 429 332 "wrong # args: should be ", 430 "\"children ?-as fval? ?-type name? ?path?\"",333 "\"children ?-as <fval>? ?-type <name>? ?<path>?\"", 431 334 (char*)NULL); 432 335 return TCL_ERROR; 433 336 } 434 337 else if (argsLeft == 1) { 435 path = std::string( argv[nextarg++]);338 path = std::string( Tcl_GetString(objv[nextarg++]) ); 436 339 } 437 340 else { … … 442 345 while ( (node = ((RpLibrary*) cdata)->children(path,node,type)) ) { 443 346 if (node) { 444 445 // clear any previous result in the interpreter446 // Tcl_ResetResult(interp);447 448 347 if (asProc) { 449 348 // evaluate the "-as" flag on the returned node 450 349 retStr = (node->*asProc)(); 451 // remove the object, keep memory clean452 delete node;453 350 } 454 351 else { … … 461 358 } 462 359 } 463 464 return TCL_OK; 465 } 466 467 /**********************************************************************/ 468 // FUNCTION: RpTclLibCopy() 469 /// copy function in Tcl, used to copy an xml object between locations 470 /** 471 * Copies an xml object, whose location is described by <path2>, 472 * Full function call: 473 * copy <path1> from ?<xmlobj>? <path2> 474 */ 475 476 int 477 RpTclLibCopy ( ClientData cdata, 478 Tcl_Interp *interp, 479 int argc, 480 const char *argv[] ) 360 return TCL_OK; 361 } 362 363 int 364 RpTclLibCopy (ClientData cdata, Tcl_Interp *interp, 365 int objc, Tcl_Obj *CONST *objv) 481 366 { 482 367 std::string fromPath = ""; // path of where to copy data from 483 368 std::string toPath = ""; // path of where to copy data to 484 369 std::string from = ""; // string that should == "from" 485 std::string fromObjStr = ""; // string that represents the486 // string name of the object487 370 RpLibrary* fromObj = NULL; 488 371 int nextarg = 2; // start parsing using the '2'th argument 489 372 int argsLeft = 0; // temp variable for calculation 490 int noerr = 0; // err flag for Tcl_GetCommandInfo 491 Tcl_CmdInfo info; // pointer to the command info 492 493 if (nextarg+2 < argc) { 494 toPath = std::string(argv[nextarg++]); 495 from = std::string(argv[nextarg++]); 373 374 if (nextarg+2 < objc) { 375 toPath = std::string( Tcl_GetString(objv[nextarg++]) ); 376 from = std::string( Tcl_GetString(objv[nextarg++]) ); 496 377 } 497 378 else { 498 379 Tcl_AppendResult(interp, 499 380 "wrong # args: should be \"", 500 argv[0], "copy path from ?xmlobj? path\"",381 Tcl_GetString(objv[0]), " path from ?<xmlobj>? path\"", 501 382 (char*)NULL); 502 383 return TCL_ERROR; 503 384 } 504 385 505 argsLeft = ( argc-nextarg);386 argsLeft = (objc-nextarg); 506 387 if (argsLeft == 2) { 507 fromObjStr = std::string(argv[nextarg++]); 508 noerr = Tcl_GetCommandInfo(interp, fromObjStr.c_str(), &info); 509 if (noerr == 1) { 510 if (info.proc == RpLibCallCmd) { 511 fromObj = (RpLibrary*) (info.clientData); 512 } 513 else { 514 Tcl_AppendResult(interp, 515 "wrong arg type: xmlobj should be a Rappture Library\"", 516 (char*)NULL); 517 return TCL_ERROR; 518 } 519 } 520 else { 521 // Tcl_GetCommandInfo failed, not able to retrieve xmlobj 522 Tcl_AppendResult(interp, 523 "wrong arg type: xmlobj should be a valid Rappture Library\"", 524 (char*)NULL); 388 if (rpGetLibraryFromObj(interp, objv[nextarg++], &fromObj) != TCL_OK) { 525 389 return TCL_ERROR; 526 390 } 527 fromPath = std::string( argv[nextarg++]);391 fromPath = std::string( Tcl_GetString(objv[nextarg++]) ); 528 392 } 529 393 else if (argsLeft == 1) { 530 fromPath = std::string( argv[nextarg++]);394 fromPath = std::string( Tcl_GetString(objv[nextarg++]) ); 531 395 } 532 396 else { … … 550 414 551 415 // clear any previous result in the interpreter 552 // store the new result in the interpreter553 416 Tcl_ResetResult(interp); 554 Tcl_AppendResult(interp, "", (char*)NULL);555 556 417 return TCL_OK; 557 418 } … … 567 428 568 429 int 569 RpTclLibDiff ( ClientData cdata, 570 Tcl_Interp *interp, 571 int argc, 572 const char *argv[] ) 573 { 574 575 Tcl_CmdInfo info; // pointer to the command info 576 std::string otherLibStr = ""; 577 RpLibrary* otherLib = NULL; 578 int nextarg = 2; // start parsing using the '2'th argument 579 int argsLeft = 0; // temp variable for calculation 580 int noerr = 0; // err flag for Tcl_GetCommandInfo 430 RpTclLibDiff (ClientData cdata, Tcl_Interp *interp, 431 int objc, Tcl_Obj *CONST *objv) 432 { 433 RpLibrary* otherLib = NULL; 581 434 582 435 std::list<std::string> diffList; // list to store the return value … … 585 438 586 439 // parse input arguments 587 argsLeft = (argc-nextarg); 588 if (argsLeft == 1) { 589 otherLibStr = std::string(argv[nextarg++]); 590 noerr = Tcl_GetCommandInfo(interp, otherLibStr.c_str(), &info); 591 if (noerr == 1) { 592 if (info.proc == RpLibCallCmd) { 593 otherLib = (RpLibrary*) (info.clientData); 594 } 595 else { 596 Tcl_ResetResult(interp); 597 Tcl_AppendResult(interp, 598 "wrong arg type: xmlobj should be a Rappture Library", 599 (char*)NULL); 600 return TCL_ERROR; 601 } 602 } 603 else { 604 // there was an error getting the command info 605 Tcl_AppendResult(interp, 606 "invalid command name \"", otherLibStr.c_str(), "\"", 607 (char*)NULL); 608 return TCL_ERROR; 609 } 610 } 611 else { 612 Tcl_ResetResult(interp); 613 Tcl_AppendResult(interp, 614 "wrong # args: should be \"diff xmlobj\"", 615 (char*)NULL); 440 if (rpGetLibraryFromObj(interp, objv[2], &otherLib) != TCL_OK) { 616 441 return TCL_ERROR; 617 442 } … … 631 456 diffListIter++; 632 457 } 633 634 635 // Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL);636 458 return TCL_OK; 637 459 } … … 639 461 /**********************************************************************/ 640 462 // FUNCTION: RpTclLibElem() 641 /// element function in Tcl, retrieves the xml object for a given path463 /// element function in Tcl, used to retrieve a xml objects 642 464 /** 643 465 * Returns a xml object. 644 * Returns a list of children of the node located at <path>645 466 * Full function call: 646 *647 467 * element ?-as <fval>? ?<path>? 648 * 649 * -as option specifies how to return the result 650 * <fval> is one of the following: 651 * component - return the component name of xml node, ex: type(id) 652 * id - return the id attribute of xml node 653 * type - return the type attribute of xml node 654 * path - return the full path of xml node 655 * object - return a Rappture Library Object 656 * 657 * <path> is the path of the xml node you are requesting. 658 * if <path> is left blank, the current node will 659 * be considered the xml node and it will be returned. 660 */ 661 662 int 663 RpTclLibElem ( ClientData cdata, 664 Tcl_Interp *interp, 665 int argc, 666 const char *argv[] ) 468 */ 469 int 470 RpTclLibElem (ClientData cdata, Tcl_Interp *interp, 471 int objc, Tcl_Obj *CONST *objv) 667 472 { 668 473 std::string path = ""; // path of where to place data inside xml tree 669 474 std::string retStr = ""; // path of where to place data inside xml tree 670 475 int nextarg = 2; // start parsing using the '2'th argument 671 int opt_argc = 1; // max number of optional parameters 672 int argsLeft = 0; // temp variable for calculation 476 int opt_objc = 1; // max number of optional parameters 673 477 674 478 RpLibrary* node = NULL; … … 676 480 677 481 // parse through -'d arguments 678 while (opt_argc--) { 679 if (nextarg < argc && *argv[nextarg] == '-') { 680 if (strncmp(argv[nextarg],"-as",3) == 0) { 482 while (opt_objc--) { 483 char *opt = Tcl_GetString(objv[nextart]); 484 if (nextarg < objc && *opt == '-') { 485 if (strcmp(opt,"-as") == 0) { 681 486 nextarg++; 682 if (nextarg < argc) { 683 if ( (*argv[nextarg] == 'c') && 684 (strncmp(argv[nextarg],"component",9) == 0) ) { 487 if (nextarg < objc) { 488 if (*opt == 'c' && strcmp(opt,"component") == 0) { 685 489 asProc = &RpLibrary::nodeComp; 686 490 nextarg++; 687 491 } 688 else if ((*argv[nextarg] == 'i') && 689 (strncmp(argv[nextarg],"id",2) == 0 ) ) { 492 else if (*opt == 'i' && strcmp(opt,"id") == 0) { 690 493 asProc = &RpLibrary::nodeId; 691 494 nextarg++; 692 495 } 693 else if ((*argv[nextarg] == 't') && 694 (strncmp(argv[nextarg],"type",4) == 0 ) ) { 496 else if (*opt == 't' && strcmp(opt,"type") == 0) { 695 497 asProc = &RpLibrary::nodeType; 696 498 nextarg++; 697 499 } 698 else if ((*argv[nextarg] == 'p') && 699 (strncmp(argv[nextarg],"path",4) == 0 ) ) { 500 else if (*opt == 'p' && strcmp(opt,"path") == 0) { 700 501 asProc = &RpLibrary::nodePath; 701 502 nextarg++; 702 503 } 703 else if ((*argv[nextarg] == 'o') && 704 (strncmp(argv[nextarg],"object",6) == 0 ) ) { 504 else if (*opt == 'o' && strcmp(opt,"object") == 0) { 705 505 asProc = NULL; 706 506 nextarg++; 707 507 } 708 508 else { 709 Tcl_AppendResult(interp, "bad flavor \"", argv[nextarg], 710 "\" for -as: should be component, id, object, path, type", 711 (char*)NULL); 509 Tcl_AppendResult(interp, "bad flavor \"", 510 Tcl_GetString(objv[nextarg]), 511 "\" for -as: should be component, id, type," 512 " path, object", (char*)NULL); 712 513 return TCL_ERROR; 713 514 } … … 715 516 else { 716 517 Tcl_AppendResult(interp, "bad flavor \"\" for -as:", 717 " should be component, id, object, path, type",518 " should be component, id, type, path, object", 718 519 (char*)NULL); 719 520 return TCL_ERROR; … … 721 522 } 722 523 else { 723 Tcl_AppendResult(interp, "bad option \"", argv[nextarg],524 Tcl_AppendResult(interp, "bad option \"", opt, 724 525 "\": should be -as", (char*)NULL); 725 526 return TCL_ERROR; … … 728 529 } 729 530 730 argsLeft = (argc-nextarg);531 int argsLeft = (objc-nextarg); 731 532 if (argsLeft > 1) { 732 533 Tcl_AppendResult(interp, 733 "wrong # args: should be \"element ?-as fval? ?path?\"",534 "wrong # args: should be \"element ?-as <fval>? ?<path>?\"", 734 535 (char*)NULL); 735 536 return TCL_ERROR; 736 537 } 737 538 else if (argsLeft == 1) { 738 path = std::string( argv[nextarg++]);539 path = std::string( Tcl_GetString(objv[nextarg++]) ); 739 540 } 740 541 else { … … 745 546 node = ((RpLibrary*) cdata)->element(path); 746 547 if (node) { 747 748 548 // clear any previous result in the interpreter 749 549 Tcl_ResetResult(interp); … … 752 552 // evaluate the "-as" flag on the returned node 753 553 retStr = (node->*asProc)(); 754 // remove the object, keep memory clean755 delete node;756 554 } 757 555 else { … … 762 560 Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL); 763 561 } 764 765 766 562 return TCL_OK; 767 563 } … … 775 571 * get ?<path>? 776 572 */ 777 778 int 779 RpTclLibGet ( ClientData cdata, 780 Tcl_Interp *interp, 781 int argc, 782 const char *argv[] ) 573 int 574 RpTclLibGet (ClientData cdata, Tcl_Interp *interp, 575 int objc, Tcl_Obj *CONST *objv) 783 576 { 784 577 … … 786 579 std::string path = ""; 787 580 788 if ( argc == 3) {789 path = std::string( argv[2]);790 } 791 else if ( argc != 2) {581 if (objc == 3) { 582 path = std::string( Tcl_GetString(objv[2]) ); 583 } 584 else if (objc != 2) { 792 585 Tcl_ResetResult(interp); 793 586 Tcl_AppendResult(interp, … … 827 620 828 621 int 829 RpTclLibInfo ( ClientData cdata, 830 Tcl_Interp *interp, 831 int argc, 832 const char *argv[] ) 622 RpTclLibInfo (ClientData cdata, Tcl_Interp *interp, 623 int objc, Tcl_Obj *CONST *objv) 833 624 { 834 625 … … 836 627 std::string retStr = ""; // return value of rappture get fxn 837 628 838 if ( argc == 3) {839 infoType = std::string( argv[2]);629 if (objc == 3) { 630 infoType = std::string( Tcl_GetString(objv[2]) ); 840 631 } 841 632 else { 842 633 Tcl_ResetResult(interp); 843 634 Tcl_AppendResult(interp, 844 "wrong # args: should be \"info objType\"",635 "wrong # args: should be \"info <infoType>\"", 845 636 (char*)NULL); 846 637 return TCL_ERROR; … … 884 675 885 676 int 886 RpTclLibIsa ( ClientData cdata, 887 Tcl_Interp *interp, 888 int argc, 889 const char *argv[] ) 677 RpTclLibIsa (ClientData cdata, Tcl_Interp *interp, 678 int objc, Tcl_Obj *CONST *objv) 890 679 { 891 680 … … 893 682 std::string retStr = ""; // return value of rappture get fxn 894 683 895 if ( argc == 3) {896 compVal = std::string( argv[2]);684 if (objc == 3) { 685 compVal = std::string( Tcl_GetString(objv[2]) ); 897 686 } 898 687 else { 899 688 Tcl_ResetResult(interp); 900 689 Tcl_AppendResult(interp, 901 "wrong # args: should be \"isa objType\"",690 "wrong # args: should be \"isa <objType>\"", 902 691 (char*)NULL); 903 692 return TCL_ERROR; … … 919 708 } 920 709 921 /**********************************************************************/ 922 // FUNCTION: RpTclLibParent() 923 /// parent function in Tcl, retrieves the parent xml object for a given path 924 /** 925 * Returns the xml object repersenting the parent of the given path. 926 * Full function call: 927 * 928 * parent ?-as <fval>? ?<path>? 929 * 930 * -as option specifies how to return the result 931 * <fval> is one of the following: 932 * component - return the component name of the parent node, ex: type(id) 933 * id - return the id attribute of the parent node 934 * type - return the type attribute of the parent node 935 * path - return the full path of the parent node 936 * object - return a Rappture Library Object 937 * 938 * <path> is the path of the xml node you are requesting the parent of. 939 * if <path> is left blank, the current node will 940 * be considered the child xml node and it's parent will be returned. 941 */ 942 943 int 944 RpTclLibParent ( ClientData cdata, 945 Tcl_Interp *interp, 946 int argc, 947 const char *argv[] ) 710 int 711 RpTclLibParent (ClientData cdata, Tcl_Interp *interp, 712 int objc, Tcl_Obj *CONST *objv) 948 713 { 949 714 … … 951 716 std::string retStr = ""; // path of where to place data inside xml tree 952 717 int nextarg = 2; // start parsing using the '2'th argument 953 int opt_argc = 1; // max number of optional parameters 954 int argsLeft = 0; // temp variable for calculation 718 int opt_objc = 1; // max number of optional parameters 955 719 956 720 RpLibrary* node = NULL; … … 958 722 959 723 // parse through -'d arguments 960 while (opt_argc--) { 961 if (nextarg < argc && *argv[nextarg] == '-') { 962 if (strncmp(argv[nextarg],"-as",3) == 0) { 724 while (opt_objc--) { 725 char *opt = Tcl_GetString(objv[nextart]); 726 if (nextarg < objc && *opt == '-') { 727 if (strcmp(opt,"-as") == 0) { 963 728 nextarg++; 964 if (nextarg < argc) { 965 if ( (*argv[nextarg] == 'c') && 966 (strncmp(argv[nextarg],"component",9) == 0) ) { 729 if (nextarg < objc) { 730 if (*opt == 'c' && strcmp(opt,"component") == 0) { 967 731 asProc = &RpLibrary::nodeComp; 968 732 nextarg++; 969 733 } 970 else if ((*argv[nextarg] == 'i') && 971 (strncmp(argv[nextarg],"id",2) == 0 ) ) { 734 else if (*opt == 'i' && strcmp(opt,"id") == 0) { 972 735 asProc = &RpLibrary::nodeId; 973 736 nextarg++; 974 737 } 975 else if ((*argv[nextarg] == 't') && 976 (strncmp(argv[nextarg],"type",4) == 0 ) ) { 738 else if (*opt == 't' && strcmp(opt,"type") == 0) { 977 739 asProc = &RpLibrary::nodeType; 978 740 nextarg++; 979 741 } 980 else if ((*argv[nextarg] == 'p') && 981 (strncmp(argv[nextarg],"path",4) == 0 ) ) { 742 else if (*opt == 'p' && strcmp(opt,"path") == 0) { 982 743 asProc = &RpLibrary::nodePath; 983 744 nextarg++; 984 745 } 985 else if ((*argv[nextarg] == 'o') && 986 (strncmp(argv[nextarg],"object",6) == 0 ) ) { 746 else if (*opt == 'o' && strcmp(opt,"object") == 0) { 987 747 asProc = NULL; 988 748 nextarg++; 989 749 } 990 750 else { 991 Tcl_AppendResult(interp, "bad flavor \"", argv[nextarg], 992 "\": should be component, id, object, path, type", 751 Tcl_AppendResult(interp, "bad flavor \"", 752 Tcl_GetString(objv[nextarg]), 753 "\": should be component, id, type, path, object", 993 754 (char*)NULL); 994 755 return TCL_ERROR; … … 997 758 else { 998 759 Tcl_AppendResult(interp, "bad flavor \"\" for -as: ", 999 "should be component, id, object, path, type",760 "should be component, id, type, path, object", 1000 761 (char*)NULL); 1001 762 return TCL_ERROR; … … 1003 764 } 1004 765 else { 1005 Tcl_AppendResult(interp, "bad option \"", argv[nextarg],766 Tcl_AppendResult(interp, "bad option \"", opt, 1006 767 "\": should be -as", (char*)NULL); 1007 768 return TCL_ERROR; … … 1010 771 } 1011 772 1012 argsLeft = (argc-nextarg);773 int argsLeft = (objc-nextarg); 1013 774 if ( argsLeft > 1) { 1014 775 Tcl_AppendResult(interp, … … 1018 779 } 1019 780 else if (argsLeft == 1) { 1020 path = std::string( argv[nextarg++]);781 path = std::string( Tcl_GetString(objv[nextarg++]) ); 1021 782 } 1022 783 else { … … 1027 788 node = ((RpLibrary*) cdata)->parent(path); 1028 789 if (node) { 1029 1030 790 // clear any previous result in the interpreter 1031 791 Tcl_ResetResult(interp); … … 1034 794 // evaluate the "-as" flag on the returned node 1035 795 retStr = (node->*asProc)(); 1036 // remove the object, keep memory clean1037 delete node;1038 796 } 1039 797 else { … … 1043 801 // store the new result string in the interpreter 1044 802 Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL); 1045 1046 } 1047 1048 803 } 1049 804 return TCL_OK; 1050 805 } … … 1057 812 * 1058 813 * Full function call: 1059 * put ?-append yes? ?-id num? ?<path>? <string>814 * put <path> 1060 815 * 1061 816 * Return Value: … … 1063 818 * On failure, an error message is returned 1064 819 */ 1065 1066 int 1067 RpTclLibPut ( ClientData cdata, 1068 Tcl_Interp *interp, 1069 int argc, 1070 const char *argv[] ) 1071 { 1072 820 int 821 RpTclLibPut (ClientData cdata, Tcl_Interp *interp, 822 int objc, Tcl_Obj *CONST *objv) 823 { 1073 824 std::string id = ""; // id tag for the given path 1074 825 std::string path = ""; // path of where to place data inside xml tree … … 1076 827 int nextarg = 2; // start parsing using the '2'th argument 1077 828 int append = 0; // append flag - 0 means no, 1 means yes 1078 int opt_argc = 2; // max number of optional parameters 1079 int argsLeft = 0; // temp variable for calculation 1080 int noerr = 0; 1081 Tcl_CmdInfo info; // pointer to the command info 1082 1083 while (opt_argc--) { 1084 if (nextarg < argc && *argv[nextarg] == '-') { 1085 if (strncmp(argv[nextarg],"-append",7) == 0) { 1086 nextarg++; 1087 if (argv[nextarg] != NULL) { 1088 if (Tcl_GetBoolean(interp, argv[nextarg], &append)) { 1089 // unrecognized value for -append option 1090 // Tcl_GetBoolean fills in error message 1091 // Tcl_AppendResult(interp, 1092 // "expected boolean value but got \"", 1093 // argv[nextarg], "\"", (char*)NULL); 829 int opt_objc = 2; // max number of optional parameters 830 831 while (opt_objc--) { 832 char *opt = Tcl_GetString(objv[nextarg]); 833 if (nextarg < objc && *opt == '-') { 834 if (strcmp(opt,"-append") == 0) { 835 ++nextarg; 836 if (nextarg < objc) { 837 if (Tcl_GetBooleanFromObj(interp, objv[nextarg], 838 &append) != TCL_OK) { 1094 839 return TCL_ERROR; 1095 840 } 1096 // nextarg++;1097 841 } 1098 842 else { 1099 // if user does not specify wishes for this option, 1100 // return error. 1101 // unrecognized value for -units option 1102 Tcl_AppendResult(interp, 1103 "expected boolean value but got \"\"", (char*)NULL); 843 Tcl_AppendResult(interp, "missing value for -append", 844 (char*)NULL); 1104 845 return TCL_ERROR; 1105 846 } 1106 847 } 1107 else if (strncmp(argv[nextarg],"-id",3) == 0) { 848 else if (strcmp(opt,"-id") == 0) { 849 id = std::string( Tcl_GetString(objv[++nextarg]) ); 1108 850 nextarg++; 1109 id = std::string(argv[nextarg]);1110 // nextarg++;1111 851 } 1112 852 else { 1113 Tcl_AppendResult(interp, "bad option \"", argv[nextarg],853 Tcl_AppendResult(interp, "bad option \"", opt, 1114 854 "\": should be -append or -id", (char*)NULL); 1115 855 return TCL_ERROR; 1116 856 } 1117 nextarg++; 1118 } 1119 } 1120 1121 argsLeft = (argc-nextarg); 857 } 858 } 859 860 int argsLeft = (objc-nextarg); 1122 861 if (argsLeft == 2) { 1123 path = std::string( argv[nextarg++]);1124 addStr = std::string( argv[nextarg++]);862 path = std::string( Tcl_GetString(objv[nextarg++]) ); 863 addStr = std::string( Tcl_GetString(objv[nextarg++]) ); 1125 864 } 1126 865 else if (argsLeft == 1) { 1127 866 path = ""; 1128 addStr = std::string( argv[nextarg++]);867 addStr = std::string( Tcl_GetString(objv[nextarg++]) ); 1129 868 } 1130 869 else { … … 1135 874 } 1136 875 1137 noerr = Tcl_GetCommandInfo(interp, addStr.c_str(), &info);1138 if (noerr == 1) {1139 // valid command1140 if (info.proc == &RpLibCallCmd) {1141 // call the rappture library put function with the Rappture Object1142 ((RpLibrary*) cdata)->put( path,1143 (RpLibrary*)info.clientData,1144 id, append);1145 }1146 else {1147 // object is not a RpLibrary1148 // call the rappture library put function with the inputted string1149 ((RpLibrary*) cdata)->put(path, addStr, id, append);1150 }1151 }1152 else {1153 // invalid command1154 // call the rappture library put function with the inputted string1155 ((RpLibrary*) cdata)->put(path, addStr, id, append);1156 }1157 1158 876 // call the rappture library put function 1159 // ((RpLibrary*) cdata)->put(path, addStr, id, append); 1160 1161 // clear any previous result in the interpreter 1162 // store the new result in the interpreter 877 ((RpLibrary*) cdata)->put(path, addStr, id, append); 878 879 // return nothing for this operation 1163 880 Tcl_ResetResult(interp); 1164 Tcl_AppendResult(interp, "", (char*)NULL);1165 1166 881 return TCL_OK; 1167 882 } … … 1181 896 * On failure, an error message is returned 1182 897 */ 1183 1184 int 1185 RpTclLibRemove ( ClientData cdata, 1186 Tcl_Interp *interp, 1187 int argc, 1188 const char *argv[] ) 1189 { 1190 1191 std::string path = std::string(""); // path of where to remove data from 1192 int nextarg = 2; 1193 1194 1195 if (argc == 2) { 1196 path = std::string(""); 1197 } 1198 else if (argc == 3) { 1199 path = std::string(argv[nextarg]); 1200 } 1201 else { 1202 Tcl_AppendResult(interp, 1203 "wrong # args: should be \"remove ?path?\"", 1204 (char*)NULL); 1205 return TCL_ERROR; 898 int 899 RpTclLibRemove (ClientData cdata, Tcl_Interp *interp, 900 int objc, Tcl_Obj *CONST *objv) 901 { 902 std::string path = std::string(""); // path of where to remove data from 903 904 if (objc == 3) { 905 path = std::string( Tcl_GetString(objv[2]) ); 1206 906 } 1207 907 … … 1210 910 1211 911 // clear any previous result in the interpreter 1212 // store the new result in the interpreter1213 912 Tcl_ResetResult(interp); 1214 Tcl_AppendResult(interp, "", (char*)NULL); 1215 1216 return TCL_OK; 1217 } 1218 1219 /* 1220 int 1221 RpTclLibResult ( ClientData cdata, 1222 Tcl_Interp *interp, 1223 int argc, 1224 const char *argv[] ) 1225 { 1226 if (argc == 2) { 1227 // call the rappture library result function 1228 ((RpLibrary*) cdata)->result(); 1229 } 1230 else { 1231 Tcl_AppendResult(interp, 1232 "wrong # args: should be \"result \"", 1233 (char*)NULL); 1234 return TCL_ERROR; 1235 } 1236 913 return TCL_OK; 914 } 915 916 int 917 RpTclLibResult (ClientData cdata, Tcl_Interp *interp, 918 int objc, Tcl_Obj *CONST *objv) 919 { 920 // call the rappture library result function 921 ((RpLibrary*) cdata)->result(); 1237 922 1238 923 // clear any previous result in the interpreter 1239 // store the new result in the interpreter1240 924 Tcl_ResetResult(interp); 1241 Tcl_AppendResult(interp, "", (char*)NULL); 1242 1243 return TCL_OK; 1244 } 1245 */ 925 return TCL_OK; 926 } 1246 927 1247 928 /**********************************************************************/ … … 1259 940 * - second element is the normalization of the value at location <path> 1260 941 */ 1261 1262 /* 1263 int 1264 RpTclLibValue ( ClientData cdata, 1265 Tcl_Interp *interp, 1266 int argc, 1267 const char *argv[] ) 1268 { 1269 1270 Tcl_CmdInfo info; // pointer to the command info 1271 std::string path = ""; 1272 std::string libStr = ""; 1273 RpLibrary* lib = NULL; 1274 int nextarg = 1; // start parsing using the '1'th argument 1275 int argsLeft = 0; // temp variable for calculation 1276 int noerr = 0; // err flag for Tcl_GetCommandInfo 1277 1278 std::list<std::string> valList; // list to store the return value 942 int 943 RpTclLibValue (ClientData cdata, Tcl_Interp *interp, 944 int objc, Tcl_Obj *CONST *objv) 945 { 946 std::list<std::string> valList; // list to store the return value 1279 947 // from diff command 1280 948 std::list<std::string>::iterator valListIter; 1281 949 1282 if ( argc != 3) {950 if (objc != 3) { 1283 951 Tcl_AppendResult(interp, 1284 "wrong # args: should be \"", argv[0], " <xmlobj> <path>\"",1285 (char*)NULL);952 "wrong # args: should be \"", Tcl_GetString(objv[0]), 953 " <xmlobj> <path>\"", (char*)NULL); 1286 954 return TCL_ERROR; 1287 955 } 1288 956 1289 957 // parse input arguments 1290 argsLeft = (argc-nextarg); 1291 if (argsLeft == 2) { 1292 libStr = std::string(argv[nextarg++]); 1293 noerr = Tcl_GetCommandInfo(interp, libStr.c_str(), &info); 1294 if (noerr == 1) { 1295 if (info.proc == RpLibCallCmd) { 1296 lib = (RpLibrary*) (info.clientData); 1297 } 1298 else { 1299 Tcl_AppendResult(interp, 1300 "wrong arg type: xmlobj should be a Rappture Library", 1301 (char*)NULL); 1302 return TCL_ERROR; 1303 } 1304 } 1305 else { 1306 // there was an error getting the command info 1307 Tcl_AppendResult(interp, 1308 "There was an error getting the command info for " 1309 "the provided library \"", libStr.c_str(), "\'", 1310 "\nAre you sure its a Rappture Library Object?", 1311 (char*)NULL); 1312 return TCL_ERROR; 1313 } 1314 path = std::string(argv[nextarg++]); 1315 } 1316 else { 1317 Tcl_ResetResult(interp); 1318 Tcl_AppendResult(interp, 1319 "wrong # args: should be \"", argv[0], " <xmlobj> <path>\"", 1320 (char*)NULL); 1321 return TCL_ERROR; 1322 } 958 RpLibrary* lib; 959 if (rpGetLibraryFromObj(interp, objv[1], &lib) != TCL_OK) { 960 return TCL_ERROR; 961 } 962 std::string path = std::string(Tcl_GetString(objv[2])); 1323 963 1324 964 // perform the value command … … 1334 974 valListIter++; 1335 975 } 1336 1337 return TCL_OK; 1338 } 1339 */ 976 return TCL_OK; 977 } 1340 978 1341 979 /**********************************************************************/ … … 1353 991 1354 992 int 1355 RpTclLibXml ( ClientData cdata, 1356 Tcl_Interp *interp, 1357 int argc, 1358 const char *argv[] ) 993 RpTclLibXml (ClientData cdata, Tcl_Interp *interp, 994 int objc, Tcl_Obj *CONST *objv) 1359 995 { 1360 996 1361 997 std::string retStr = ""; // return value of rappture get fxn 1362 998 1363 if ( argc != 2) {999 if (objc != 2) { 1364 1000 Tcl_AppendResult(interp, "wrong # args: should be \"", 1365 argv[0], " xml\"", (char*)NULL);1001 Tcl_GetString(objv[0]), " xml\"", (char*)NULL); 1366 1002 return TCL_ERROR; 1367 1003 } … … 1394 1030 * None 1395 1031 */ 1396 1397 int 1398 RpTclResult ( ClientData cdata, 1399 Tcl_Interp *interp, 1400 int argc, 1401 const char *argv[] ) 1402 { 1403 Tcl_CmdInfo info; // pointer to the command info 1404 int noerr = 0; // err flag for Tcl_GetCommandInfo 1405 std::string libName = ""; 1406 RpLibrary* lib = NULL; 1407 1032 int 1033 RpTclResult (ClientData cdata, Tcl_Interp *interp, 1034 int objc, Tcl_Obj *CONST *objv) 1035 { 1408 1036 // parse through command line options 1409 if ( argc != 2) {1037 if (objc != 2) { 1410 1038 Tcl_AppendResult(interp, "wrong # args: should be \"", 1411 argv[0], " <xmlobj>\"", (char*)NULL); 1412 return TCL_ERROR; 1413 } 1414 1415 libName = std::string(argv[1]); 1416 1417 noerr = Tcl_GetCommandInfo(interp, libName.c_str(), &info); 1418 if (noerr == 1) { 1419 if (info.proc == RpLibCallCmd) { 1420 lib = (RpLibrary*) (info.clientData); 1421 } 1422 else { 1423 Tcl_AppendResult(interp, 1424 "wrong arg type: xmlobj should be a Rappture Library\"", 1425 (char*)NULL); 1426 return TCL_ERROR; 1427 } 1428 } 1429 else { 1430 // there was an error getting the command info 1431 Tcl_AppendResult(interp, 1432 "wrong arg type: \"", libName.c_str(), 1433 "\" should be a valid Rappture Library Object", 1434 (char*)NULL); 1435 return TCL_ERROR; 1436 } 1437 1039 Tcl_GetString(objv[0]), " <xmlobj>\"", (char*)NULL); 1040 return TCL_ERROR; 1041 } 1042 1043 RpLibrary* lib; 1044 if (rpGetLibraryFromObj(interp, objv[1], &lib) != TCL_OK) { 1045 return TCL_ERROR; 1046 } 1438 1047 lib->result(); 1439 Tcl_AppendResult(interp,"",(char*)NULL); 1440 return TCL_OK; 1441 } 1048 1049 // returns nothing 1050 Tcl_ResetResult(interp); 1051 return TCL_OK; 1052 }
Note: See TracChangeset
for help on using the changeset viewer.