Changeset 262 for trunk/src/tcl
- Timestamp:
- Mar 2, 2006 5:52:05 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tcl/src/RpUnitsTclInterface.cc
r225 r262 28 28 const char *argv[] )); 29 29 30 static int RpTclUnitsDesc _ANSI_ARGS_(( ClientData cdata, 31 Tcl_Interp *interp, 32 int argc, 33 const char *argv[] )); 34 35 static int RpTclUnitsSysFor _ANSI_ARGS_(( ClientData cdata, 36 Tcl_Interp *interp, 37 int argc, 38 const char *argv[] )); 39 40 static int RpTclUnitsSysAll _ANSI_ARGS_(( ClientData cdata, 41 Tcl_Interp *interp, 42 int argc, 43 const char *argv[] )); 44 30 45 #ifdef __cplusplus 31 46 } … … 47 62 Tcl_CreateCommand(interp, "::Rappture::Units::convert", 48 63 RpTclUnitsConvert, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 64 65 Tcl_CreateCommand(interp, "::Rappture::Units::description", 66 RpTclUnitsDesc, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 67 68 Tcl_CreateCommand(interp, "::Rappture::Units::System::for", 69 RpTclUnitsSysFor, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 70 71 Tcl_CreateCommand(interp, "::Rappture::Units::System::all", 72 RpTclUnitsSysAll, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 49 73 50 74 return TCL_OK; … … 125 149 // unrecognized value for -units option 126 150 Tcl_AppendResult(interp, 127 "value for -units must be \" yes\" or \"no\"",151 "value for -units must be \"on\" or \"off\"", 128 152 (char*)NULL); 129 153 return TCL_ERROR; … … 190 214 } 191 215 216 int 217 RpTclUnitsDesc ( ClientData cdata, 218 Tcl_Interp *interp, 219 int argc, 220 const char *argv[] ) 221 { 222 std::string unitsName = ""; // name of the units provided by user 223 std::string type = ""; // name of the units provided by user 224 std::string listStr = ""; // name of the units provided by user 225 const RpUnits* unitsObj = NULL; 226 std::list<std::string> compatList; 227 std::list<std::string>::iterator compatListIter; 228 229 int nextarg = 1; // start parsing using the '2'th argument 230 231 Tcl_ResetResult(interp); 232 233 // parse through command line options 234 if (argc != 2) { 235 Tcl_AppendResult(interp, "usage: ", argv[0], " <units>", (char*)NULL); 236 return TCL_ERROR; 237 } 238 239 unitsName = std::string(argv[nextarg]); 240 241 unitsObj = RpUnits::find(unitsName); 242 if (unitsObj == NULL) { 243 Tcl_AppendResult(interp, 244 "The units named: \"", unitsName.c_str(), 245 "\" is not a recognized unit for rappture", 246 (char*)NULL); 247 return TCL_ERROR; 248 } 249 250 type = unitsObj->getType(); 251 252 Tcl_AppendResult(interp, type.c_str(), (char*)NULL); 253 254 compatList = unitsObj->getCompatible(); 255 compatListIter = compatList.begin(); 256 257 while (compatListIter != compatList.end()) { 258 if ( listStr.empty() ) { 259 listStr = *compatListIter; 260 } 261 else { 262 listStr = listStr + "," + *compatListIter; 263 } 264 265 // increment the iterator 266 compatListIter++; 267 } 268 269 Tcl_AppendResult(interp, " (", listStr.c_str() ,")", (char*)NULL); 270 271 return TCL_OK; 272 } 273 274 int 275 RpTclUnitsSysFor ( ClientData cdata, 276 Tcl_Interp *interp, 277 int argc, 278 const char *argv[] ) 279 { 280 std::string unitsName = ""; // name of the units provided by user 281 std::string type = ""; // name of the units provided by user 282 const RpUnits* unitsObj = NULL; 283 int nextarg = 1; // start parsing using the '2'th argument 284 285 Tcl_ResetResult(interp); 286 287 // parse through command line options 288 if (argc != 2) { 289 Tcl_AppendResult(interp, "usage: ", argv[0], " <units>", (char*)NULL); 290 return TCL_ERROR; 291 } 292 293 unitsName = std::string(argv[nextarg]); 294 295 unitsObj = RpUnits::find(unitsName); 296 if (unitsObj == NULL) { 297 Tcl_AppendResult(interp, 298 "The units named: \"", unitsName.c_str(), 299 "\" is not a recognized unit for rappture", 300 (char*)NULL); 301 return TCL_ERROR; 302 } 303 304 type = unitsObj->getType(); 305 306 Tcl_AppendResult(interp, type.c_str(), (char*)NULL); 307 return TCL_OK; 308 309 } 310 311 int 312 RpTclUnitsSysAll ( ClientData cdata, 313 Tcl_Interp *interp, 314 int argc, 315 const char *argv[] ) 316 { 317 std::string unitsName = ""; // name of the units provided by user 318 const RpUnits* unitsObj = NULL; 319 std::list<std::string> compatList; 320 std::list<std::string>::iterator compatListIter; 321 int nextarg = 1; // start parsing using the '2'th argument 322 323 Tcl_ResetResult(interp); 324 325 // parse through command line options 326 if (argc != 2) { 327 Tcl_AppendResult(interp, "usage: ", argv[0], " <units>", (char*)NULL); 328 return TCL_ERROR; 329 } 330 331 unitsName = std::string(argv[nextarg]); 332 333 unitsObj = RpUnits::find(unitsName); 334 if (unitsObj == NULL) { 335 Tcl_AppendResult(interp, 336 "The units named: \"", unitsName.c_str(), 337 "\" is not a recognized unit for rappture", 338 (char*)NULL); 339 return TCL_ERROR; 340 } 341 342 compatList = unitsObj->getCompatible(); 343 compatListIter = compatList.begin(); 344 345 while (compatListIter != compatList.end()) { 346 Tcl_AppendElement(interp,(*compatListIter).c_str()); 347 // increment the iterator 348 compatListIter++; 349 } 350 351 return TCL_OK; 352 }
Note: See TracChangeset
for help on using the changeset viewer.