- Timestamp:
- Dec 7, 2006, 3:45:47 AM (18 years ago)
- Location:
- trunk/src/tcl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tcl/src/RpUnitsTclInterface.cc
r537 r549 23 23 // EXTERN int Rapptureunits_Init _ANSI_ARGS_((Tcl_Interp * interp)); 24 24 25 static int RpTclUnitsConvert _ANSI_ARGS_((ClientData cdata,25 static int RpTclUnitsConvert _ANSI_ARGS_(( ClientData cdata, 26 26 Tcl_Interp *interp, 27 27 int argc, 28 28 const char *argv[] )); 29 29 30 static int RpTclUnitsDesc _ANSI_ARGS_((ClientData cdata,30 static int RpTclUnitsDesc _ANSI_ARGS_(( ClientData cdata, 31 31 Tcl_Interp *interp, 32 32 int argc, 33 33 const char *argv[] )); 34 34 35 static int RpTclUnitsSysFor _ANSI_ARGS_((ClientData cdata,35 static int RpTclUnitsSysFor _ANSI_ARGS_(( ClientData cdata, 36 36 Tcl_Interp *interp, 37 37 int argc, 38 38 const char *argv[] )); 39 39 40 static int RpTclUnitsSysAll _ANSI_ARGS_(( ClientData cdata, 40 static int RpTclUnitsSysAll _ANSI_ARGS_(( ClientData cdata, 41 Tcl_Interp *interp, 42 int argc, 43 const char *argv[] )); 44 45 static int RpTclUnitsSearchFor _ANSI_ARGS_(( ClientData cdata, 41 46 Tcl_Interp *interp, 42 47 int argc, … … 64 69 * ::Rappture::Units::System::for 65 70 * ::Rappture::Units::System::all 71 * ::Rappture::Units::Search::for 66 72 */ 67 73 … … 81 87 Tcl_CreateCommand(interp, "::Rappture::Units::System::all", 82 88 RpTclUnitsSysAll, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 89 90 Tcl_CreateCommand(interp, "::Rappture::Units::Search::for", 91 RpTclUnitsSearchFor, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 83 92 84 93 return TCL_OK; … … 468 477 469 478 /**********************************************************************/ 479 // FUNCTION: RpTclUnitsSearchfor() 480 /// Rappture::Units::Search::for fxn in Tcl, returns string of found units 481 /** 482 * Returns a list of all units from the given units string that 483 * were found within the units dictionary. This function takes in a 484 * string with or without a value. The string at the very least should 485 * contain the units you are searching for in the dictionary. If the 486 * string contains a value as well, the value will be ignored. A value 487 * is considered any numeric sequence as defined by the function 488 * strtod(). 489 * 490 * Full function call: 491 * ::Rappture::Units::Search::for <units> 492 */ 493 494 int 495 RpTclUnitsSearchFor ( ClientData cdata, 496 Tcl_Interp *interp, 497 int argc, 498 const char *argv[] ) 499 { 500 std::string unitsName = ""; // name of the units provided by user 501 std::string type = ""; // junk variable that validate() needs 502 int nextarg = 1; // start parsing using the '2'th argument 503 int err = 0; // err code for validate 504 char* endptr = NULL; 505 506 Tcl_ResetResult(interp); 507 508 // parse through command line options 509 if (argc != 2) { 510 Tcl_AppendResult(interp, "wrong # args: should be \"", 511 argv[0], " units\"", (char*)NULL); 512 return TCL_ERROR; 513 } 514 515 // find where the unitsName begins 516 strtod(argv[nextarg],&endptr); 517 unitsName = std::string(endptr); 518 519 err = RpUnits::validate(unitsName,type); 520 if (err) { 521 /* 522 * according to tcl version, in this case we 523 * should return an empty string. i happen to disagree. 524 * the next few lines is what i think the user should see. 525 Tcl_AppendResult(interp, 526 "The units named: \"", unitsName.c_str(), 527 "\" is not a recognized unit for rappture", 528 (char*)NULL); 529 return TCL_ERROR; 530 */ 531 return TCL_OK; 532 } 533 534 Tcl_AppendResult(interp, unitsName.c_str(), (char*)NULL); 535 536 return TCL_OK; 537 } 538 539 /**********************************************************************/ 470 540 // FUNCTION: list2str() 471 541 /// Convert a std::list<std::string> into a comma delimited std::string -
trunk/src/tcl/tests/units.test
r545 r549 4 4 # Rappture::Units::System::for 5 5 # Rappture::Units::System::all 6 # Rappture::Units::Search::for 6 7 # 7 8 # This file contains a collection of tests for one of the Rappture Tcl … … 802 803 } {0 2e-07M2/KVUS} 803 804 805 #-------------------------------------------------------------------- 806 # Rappture::Units::Search::for <units> 807 #-------------------------------------------------------------------- 808 809 test search-for-6.0.0.1 {Rappture::Units::Search::for, 300K} { 810 list [catch {Rappture::Units::Search::for 300K} msg] $msg 811 } {0 K} 812 813 test search-for-6.0.0.2 {Rappture::Units::Search::for, 300cm2/Vs} { 814 list [catch {Rappture::Units::Search::for 300cm2/Vs} msg] $msg 815 } {0 cm2/Vs} 816 817 test search-for-6.0.0.3 {Rappture::Units::Search::for, cm2/Vs} { 818 list [catch {Rappture::Units::Search::for cm2/Vs} msg] $msg 819 } {0 cm2/Vs} 820 821 test search-for-6.0.1.1 {Rappture::Units::Search::for, 4notaunit} { 822 list [catch {Rappture::Units::Search::for 4notaunit} msg] $msg 823 } {0 {}} 824 825 test search-for-6.0.1.2 {Rappture::Units::Search::for, notaunit} { 826 list [catch {Rappture::Units::Search::for notaunit} msg] $msg 827 } {0 {}} 828 829 test search-for-6.0.1.2 {Rappture::Units::Search::for, notaunit} { 830 list [catch {Rappture::Units::Search::for ^&} msg] $msg 831 } {0 {}} 804 832 805 833 ::tcltest::cleanupTests
Note: See TracChangeset
for help on using the changeset viewer.