Changeset 685 for trunk


Ignore:
Timestamp:
Apr 27, 2007, 7:06:34 PM (17 years ago)
Author:
mmc
Message:

Converted Library object interface to use Tcl_Obj's so it can handle
binary data. We need this for the get/put functions. I got this all
fixed up and then realized that we're still using the Tcl implementation
for these functions. Oh well, I haven't tested this carefully, but it's
a good start.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tcl/src/RpLibraryTclInterface.cc

    r528 r685  
    1515#include <tcl.h>
    1616#include <sstream>
    17 #include <string>
    18 #include "RpLibrary.h"
     17#include "core/RpLibrary.h"
    1918#include "RpLibraryTclInterface.h"
    2019
     
    2625
    2726
    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));
     27static int RpLibraryCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     28    int objc, Tcl_Obj *CONST *objv));
     29static int RpLibCallCmd _ANSI_ARGS_((ClientData cData, Tcl_Interp *interp,
     30    int objc, Tcl_Obj *CONST *objv));
     31static int RpTclLibChild _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     32    int objc, Tcl_Obj *CONST *objv));
     33static int RpTclLibCopy _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     34    int objc, Tcl_Obj *CONST *objv));
     35static int RpTclLibDiff _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     36    int objc, Tcl_Obj *CONST *objv));
     37static int RpTclLibElem _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     38    int objc, Tcl_Obj *CONST *objv));
     39static int RpTclLibGet _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     40    int objc, Tcl_Obj *CONST *objv));
     41static int RpTclLibInfo _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     42    int objc, Tcl_Obj *CONST *objv));
     43static int RpTclLibIsa _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     44    int objc, Tcl_Obj *CONST *objv));
     45static int RpTclLibParent _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     46    int objc, Tcl_Obj *CONST *objv));
     47static int RpTclLibPut _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     48    int objc, Tcl_Obj *CONST *objv));
     49static int RpTclLibRemove _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     50    int objc, Tcl_Obj *CONST *objv));
     51static int RpTclLibResult _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     52    int objc, Tcl_Obj *CONST *objv));
     53static int RpTclLibValue _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     54    int objc, Tcl_Obj *CONST *objv));
     55static int RpTclLibXml _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     56    int objc, Tcl_Obj *CONST *objv));
     57
     58static int RpTclResult _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp,
     59    int objc, Tcl_Obj *CONST *objv));
     60
     61static std::string rpLib2command _ANSI_ARGS_((Tcl_Interp *interp,
     62    RpLibrary* newRpLibObj));
     63static int rpGetLibraryFromObj _ANSI_ARGS_((Tcl_Interp *interp,
     64    Tcl_Obj* obj, RpLibrary **rval));
    7165
    7266// member function, function pointer mainly used in 'element' implementation
     
    7771        "?-as <fval>? ?-type <name>? ?<path>?",},
    7872    {"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>",},
    8579    {"parent", 2, (Blt_Op)RpTclLibParent, 2, 5, "?-as <fval>? ?<path>?",},
    8680    {"put", 2, (Blt_Op)RpTclLibPut, 2, 8,
     
    9690}
    9791#endif
    98 static std::string rpLib2command _ANSI_ARGS_(( Tcl_Interp *interp,
    99                                                RpLibrary* newRpLibObj   ));
    10092
    10193/*
     
    108100 * ------------------------------------------------------------------------
    109101 */
    110 
    111102std::string
    112103rpLib2command (Tcl_Interp *interp, RpLibrary* newRpLibObj)
     
    117108    libName << "::libraryObj" << libCount++;
    118109
    119     Tcl_CreateCommand(interp, libName.str().c_str(),
     110    Tcl_CreateObjCommand(interp, libName.str().c_str(),
    120111        RpLibCallCmd, (ClientData)newRpLibObj, (Tcl_CmdDeleteProc*)NULL);
    121112
     
    125116/*
    126117 * ------------------------------------------------------------------------
    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.
    132124 * ------------------------------------------------------------------------
    133125 */
    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     }
     126int
     127rpGetLibraryFromObj(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;
    145141}
    146142
     
    153149 * ------------------------------------------------------------------------
    154150 */
    155 
    156151int
    157152Rappturelibrary_Init(Tcl_Interp *interp)
    158153{
    159154
    160     Tcl_CreateCommand(interp, "::Rappture::library",
     155    Tcl_CreateObjCommand(interp, "::Rappture::library",
    161156        RpLibraryCmd, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
    162157
    163     Tcl_CreateCommand(interp, "::Rappture::result",
     158    Tcl_CreateObjCommand(interp, "::Rappture::result",
    164159        RpTclResult, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
    165160
    166161    /*
    167     Tcl_CreateCommand(interp, "::Rappture::LibraryObj::value",
     162    Tcl_CreateObjCommand(interp, "::Rappture::LibraryObj::value",
    168163        RpTclLibValue, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
    169164    */
     
    173168
    174169/*
    175  *
    176170 * USAGE: library <file>
    177171 * USAGE: library standard
    178172 * 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 */
     174int
     175RpLibraryCmd (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",
    202183                (char*)NULL);
    203184            return TCL_ERROR;
    204185        }
    205186
    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));
    216198        return TCL_OK;
    217199    }
    218200
    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
     216int
     217RpLibCallCmd (ClientData cData, Tcl_Interp *interp,
     218    int objc, Tcl_Obj *CONST *objv)
    258219{
    259220    Blt_Op proc;
    260221
    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);
    283224
    284225    if (proc == NULL) {
    285226        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);
    318229}
    319230
     
    331242 *     component - return the component name of child node, ex: type(id)
    332243 *     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
    333246 *     object    - return a Rappture Library Object
    334  *     path      - return the full path of child node
    335  *     type      - return the type attribute of child node
    336247 *
    337248 * -type option tells function to only look for nodes of type <name>
     
    341252 *        parent node and all its children will be returned.
    342253 */
    343 
    344 int
    345 RpTclLibChild   (   ClientData cdata,
    346                     Tcl_Interp *interp,
    347                     int argc,
    348                     const char *argv[]  )
     254int
     255RpTclLibChild (ClientData cdata, Tcl_Interp *interp,
     256    int objc, Tcl_Obj *CONST *objv)
    349257{
    350258    std::string path   = "";    // path of where to place data inside xml tree
     
    352260    std::string retStr = "";    // path of where to place data inside xml tree
    353261    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
    356263
    357264    RpLibrary* node    = NULL;
     
    359266
    360267    // 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) {
    364272                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) {
    368275                        asProc = &RpLibrary::nodeComp;
    369276                        nextarg++;
    370277                    }
    371                     else if ((*argv[nextarg] == 'i') &&
    372                              (strncmp(argv[nextarg],"id",2) == 0 ) ) {
     278                    else if (*opt == 'i' && strcmp(opt,"id") == 0) {
    373279                        asProc = &RpLibrary::nodeId;
    374280                        nextarg++;
    375281                    }
    376                     else if ((*argv[nextarg] == 't') &&
    377                              (strncmp(argv[nextarg],"type",4) == 0 ) ) {
     282                    else if (*opt == 't' && strcmp(opt,"type") == 0) {
    378283                        asProc = &RpLibrary::nodeType;
    379284                        nextarg++;
    380285                    }
    381                     else if ((*argv[nextarg] == 'p') &&
    382                              (strncmp(argv[nextarg],"path",4) == 0 ) ) {
     286                    else if (*opt == 'p' && strcmp(opt,"path") == 0) {
    383287                        asProc = &RpLibrary::nodePath;
    384288                        nextarg++;
    385289                    }
    386                     else if ((*argv[nextarg] == 'o') &&
    387                              (strncmp(argv[nextarg],"object",6) == 0 ) ) {
     290                    else if (*opt == 'o' && strcmp(opt,"object") == 0) {
    388291                        asProc = NULL;
    389292                        nextarg++;
    390293                    }
    391294                    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);
    395298                        return TCL_ERROR;
    396299                    }
     
    398301                else {
    399302                    Tcl_AppendResult(interp, "bad flavor \"\" for -as",
    400                             ": should be component, id, object, path, type",
    401                             (char*)NULL);
     303                        ": should be component, id, type, path, object",
     304                        (char*)NULL);
    402305                    return TCL_ERROR;
    403306                }
    404307            }
    405             else if (strncmp(argv[nextarg],"-type",5) == 0) {
     308            else if (strcmp(opt,"-type") == 0) {
    406309                nextarg++;
    407                 if (nextarg < argc) {
    408                     type = std::string(argv[nextarg]);
     310                if (nextarg < objc) {
     311                    type = std::string(opt);
    409312                    nextarg++;
    410313                }
    411314                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",
    414317                        (char*)NULL);
    415318                    return TCL_ERROR;
     
    417320            }
    418321            else {
    419                 Tcl_AppendResult(interp, "bad option \"", argv[nextarg],
     322                Tcl_AppendResult(interp, "bad option \"", opt,
    420323                    "\": should be -as, -type", (char*)NULL);
    421324                return TCL_ERROR;
     
    424327    }
    425328
    426     argsLeft = (argc-nextarg);
     329    int argsLeft = (objc-nextarg);
    427330    if (argsLeft > 1) {
    428331        Tcl_AppendResult(interp,
    429332                "wrong # args: should be ",
    430                 "\"children ?-as fval? ?-type name? ?path?\"",
     333                "\"children ?-as <fval>? ?-type <name>? ?<path>?\"",
    431334                (char*)NULL);
    432335        return TCL_ERROR;
    433336    }
    434337    else if (argsLeft == 1) {
    435         path = std::string(argv[nextarg++]);
     338        path = std::string( Tcl_GetString(objv[nextarg++]) );
    436339    }
    437340    else {
     
    442345    while ( (node = ((RpLibrary*) cdata)->children(path,node,type)) ) {
    443346        if (node) {
    444 
    445             // clear any previous result in the interpreter
    446             // Tcl_ResetResult(interp);
    447 
    448347            if (asProc) {
    449348                // evaluate the "-as" flag on the returned node
    450349                retStr = (node->*asProc)();
    451                 // remove the object, keep memory clean
    452                 delete node;
    453350            }
    454351            else {
     
    461358        }
    462359    }
    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
     363int
     364RpTclLibCopy (ClientData cdata, Tcl_Interp *interp,
     365    int objc, Tcl_Obj *CONST *objv)
    481366{
    482367    std::string fromPath = "";    // path of where to copy data from
    483368    std::string toPath   = "";    // path of where to copy data to
    484369    std::string from     = "";    // string that should == "from"
    485     std::string fromObjStr = "";  // string that represents the
    486                                   // string name of the object
    487370    RpLibrary* fromObj   = NULL;
    488371    int nextarg          = 2;     // start parsing using the '2'th argument
    489372    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++]) );
    496377    }
    497378    else {
    498379        Tcl_AppendResult(interp,
    499380            "wrong # args: should be \"",
    500             argv[0], "copy path from ?xmlobj? path\"",
     381            Tcl_GetString(objv[0]), " path from ?<xmlobj>? path\"",
    501382            (char*)NULL);
    502383        return TCL_ERROR;
    503384    }
    504385
    505     argsLeft = (argc-nextarg);
     386    argsLeft = (objc-nextarg);
    506387    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) {
    525389            return TCL_ERROR;
    526390        }
    527         fromPath = std::string(argv[nextarg++]);
     391        fromPath = std::string( Tcl_GetString(objv[nextarg++]) );
    528392    }
    529393    else if (argsLeft == 1) {
    530         fromPath = std::string(argv[nextarg++]);
     394        fromPath = std::string( Tcl_GetString(objv[nextarg++]) );
    531395    }
    532396    else {
     
    550414
    551415    // clear any previous result in the interpreter
    552     // store the new result in the interpreter
    553416    Tcl_ResetResult(interp);
    554     Tcl_AppendResult(interp, "", (char*)NULL);
    555 
    556417    return TCL_OK;
    557418}
     
    567428
    568429int
    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
     430RpTclLibDiff (ClientData cdata, Tcl_Interp *interp,
     431    int objc, Tcl_Obj *CONST *objv)
     432{
     433    RpLibrary* otherLib = NULL;
    581434
    582435    std::list<std::string> diffList; // list to store the return value
     
    585438
    586439    // 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) {
    616441        return TCL_ERROR;
    617442    }
     
    631456        diffListIter++;
    632457    }
    633 
    634 
    635     // Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL);
    636458    return TCL_OK;
    637459}
     
    639461/**********************************************************************/
    640462// FUNCTION: RpTclLibElem()
    641 /// element function in Tcl, retrieves the xml object for a given path
     463/// element function in Tcl, used to retrieve a xml objects
    642464/**
    643465 * Returns a xml object.
    644  * Returns a list of children of the node located at <path>
    645466 * Full function call:
    646  *
    647467 * 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 */
     469int
     470RpTclLibElem (ClientData cdata, Tcl_Interp *interp,
     471    int objc, Tcl_Obj *CONST *objv)
    667472{
    668473    std::string path   = "";    // path of where to place data inside xml tree
    669474    std::string retStr = "";    // path of where to place data inside xml tree
    670475    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
    673477
    674478    RpLibrary* node    = NULL;
     
    676480
    677481    // 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) {
    681486                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) {
    685489                        asProc = &RpLibrary::nodeComp;
    686490                        nextarg++;
    687491                    }
    688                     else if ((*argv[nextarg] == 'i') &&
    689                              (strncmp(argv[nextarg],"id",2) == 0 ) ) {
     492                    else if (*opt == 'i' && strcmp(opt,"id") == 0) {
    690493                        asProc = &RpLibrary::nodeId;
    691494                        nextarg++;
    692495                    }
    693                     else if ((*argv[nextarg] == 't') &&
    694                              (strncmp(argv[nextarg],"type",4) == 0 ) ) {
     496                    else if (*opt == 't' && strcmp(opt,"type") == 0) {
    695497                        asProc = &RpLibrary::nodeType;
    696498                        nextarg++;
    697499                    }
    698                     else if ((*argv[nextarg] == 'p') &&
    699                              (strncmp(argv[nextarg],"path",4) == 0 ) ) {
     500                    else if (*opt == 'p' && strcmp(opt,"path") == 0) {
    700501                        asProc = &RpLibrary::nodePath;
    701502                        nextarg++;
    702503                    }
    703                     else if ((*argv[nextarg] == 'o') &&
    704                              (strncmp(argv[nextarg],"object",6) == 0 ) ) {
     504                    else if (*opt == 'o' && strcmp(opt,"object") == 0) {
    705505                        asProc = NULL;
    706506                        nextarg++;
    707507                    }
    708508                    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);
    712513                        return TCL_ERROR;
    713514                    }
     
    715516                else {
    716517                    Tcl_AppendResult(interp, "bad flavor \"\" for -as:",
    717                            " should be component, id, object, path, type",
     518                           " should be component, id, type, path, object",
    718519                            (char*)NULL);
    719520                    return TCL_ERROR;
     
    721522            }
    722523            else {
    723                 Tcl_AppendResult(interp, "bad option \"", argv[nextarg],
     524                Tcl_AppendResult(interp, "bad option \"", opt,
    724525                    "\": should be -as", (char*)NULL);
    725526                return TCL_ERROR;
     
    728529    }
    729530
    730     argsLeft = (argc-nextarg);
     531    int argsLeft = (objc-nextarg);
    731532    if (argsLeft > 1) {
    732533        Tcl_AppendResult(interp,
    733             "wrong # args: should be \"element ?-as fval? ?path?\"",
     534            "wrong # args: should be \"element ?-as <fval>? ?<path>?\"",
    734535            (char*)NULL);
    735536        return TCL_ERROR;
    736537    }
    737538    else if (argsLeft == 1) {
    738         path = std::string(argv[nextarg++]);
     539        path = std::string( Tcl_GetString(objv[nextarg++]) );
    739540    }
    740541    else {
     
    745546    node = ((RpLibrary*) cdata)->element(path);
    746547    if (node) {
    747 
    748548        // clear any previous result in the interpreter
    749549        Tcl_ResetResult(interp);
     
    752552            // evaluate the "-as" flag on the returned node
    753553            retStr = (node->*asProc)();
    754             // remove the object, keep memory clean
    755             delete node;
    756554        }
    757555        else {
     
    762560        Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL);
    763561    }
    764 
    765 
    766562    return TCL_OK;
    767563}
     
    775571 * get ?<path>?
    776572 */
    777 
    778 int
    779 RpTclLibGet     (   ClientData cdata,
    780                     Tcl_Interp *interp,
    781                     int argc,
    782                     const char *argv[]  )
     573int
     574RpTclLibGet (ClientData cdata, Tcl_Interp *interp,
     575    int objc, Tcl_Obj *CONST *objv)
    783576{
    784577
     
    786579    std::string path = "";
    787580
    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) {
    792585        Tcl_ResetResult(interp);
    793586        Tcl_AppendResult(interp,
     
    827620
    828621int
    829 RpTclLibInfo    (   ClientData cdata,
    830                     Tcl_Interp *interp,
    831                     int argc,
    832                     const char *argv[]  )
     622RpTclLibInfo (ClientData cdata, Tcl_Interp *interp,
     623    int objc, Tcl_Obj *CONST *objv)
    833624{
    834625
     
    836627    std::string retStr   = ""; // return value of rappture get fxn
    837628
    838     if (argc == 3) {
    839         infoType = std::string(argv[2]);
     629    if (objc == 3) {
     630        infoType = std::string( Tcl_GetString(objv[2]) );
    840631    }
    841632    else {
    842633        Tcl_ResetResult(interp);
    843634        Tcl_AppendResult(interp,
    844             "wrong # args: should be \"info objType\"",
     635            "wrong # args: should be \"info <infoType>\"",
    845636            (char*)NULL);
    846637        return TCL_ERROR;
     
    884675
    885676int
    886 RpTclLibIsa     (   ClientData cdata,
    887                     Tcl_Interp *interp,
    888                     int argc,
    889                     const char *argv[]  )
     677RpTclLibIsa (ClientData cdata, Tcl_Interp *interp,
     678    int objc, Tcl_Obj *CONST *objv)
    890679{
    891680
     
    893682    std::string retStr  = ""; // return value of rappture get fxn
    894683
    895     if (argc == 3) {
    896         compVal = std::string(argv[2]);
     684    if (objc == 3) {
     685        compVal = std::string( Tcl_GetString(objv[2]) );
    897686    }
    898687    else {
    899688        Tcl_ResetResult(interp);
    900689        Tcl_AppendResult(interp,
    901             "wrong # args: should be \"isa objType\"",
     690            "wrong # args: should be \"isa <objType>\"",
    902691            (char*)NULL);
    903692        return TCL_ERROR;
     
    919708}
    920709
    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[]  )
     710int
     711RpTclLibParent (ClientData cdata, Tcl_Interp *interp,
     712    int objc, Tcl_Obj *CONST *objv)
    948713{
    949714
     
    951716    std::string retStr = "";    // path of where to place data inside xml tree
    952717    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
    955719
    956720    RpLibrary* node    = NULL;
     
    958722
    959723    // 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) {
    963728                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) {
    967731                        asProc = &RpLibrary::nodeComp;
    968732                        nextarg++;
    969733                    }
    970                     else if ((*argv[nextarg] == 'i') &&
    971                              (strncmp(argv[nextarg],"id",2) == 0 ) ) {
     734                    else if (*opt == 'i' && strcmp(opt,"id") == 0) {
    972735                        asProc = &RpLibrary::nodeId;
    973736                        nextarg++;
    974737                    }
    975                     else if ((*argv[nextarg] == 't') &&
    976                              (strncmp(argv[nextarg],"type",4) == 0 ) ) {
     738                    else if (*opt == 't' && strcmp(opt,"type") == 0) {
    977739                        asProc = &RpLibrary::nodeType;
    978740                        nextarg++;
    979741                    }
    980                     else if ((*argv[nextarg] == 'p') &&
    981                              (strncmp(argv[nextarg],"path",4) == 0 ) ) {
     742                    else if (*opt == 'p' && strcmp(opt,"path") == 0) {
    982743                        asProc = &RpLibrary::nodePath;
    983744                        nextarg++;
    984745                    }
    985                     else if ((*argv[nextarg] == 'o') &&
    986                              (strncmp(argv[nextarg],"object",6) == 0 ) ) {
     746                    else if (*opt == 'o' && strcmp(opt,"object") == 0) {
    987747                        asProc = NULL;
    988748                        nextarg++;
    989749                    }
    990750                    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",
    993754                            (char*)NULL);
    994755                        return TCL_ERROR;
     
    997758                else {
    998759                    Tcl_AppendResult(interp, "bad flavor \"\" for -as: ",
    999                             "should be component, id, object, path, type",
     760                            "should be component, id, type, path, object",
    1000761                            (char*)NULL);
    1001762                    return TCL_ERROR;
     
    1003764            }
    1004765            else {
    1005                 Tcl_AppendResult(interp, "bad option \"", argv[nextarg],
     766                Tcl_AppendResult(interp, "bad option \"", opt,
    1006767                    "\": should be -as", (char*)NULL);
    1007768                return TCL_ERROR;
     
    1010771    }
    1011772
    1012     argsLeft = (argc-nextarg);
     773    int argsLeft = (objc-nextarg);
    1013774    if ( argsLeft > 1) {
    1014775        Tcl_AppendResult(interp,
     
    1018779    }
    1019780    else if (argsLeft == 1) {
    1020         path = std::string(argv[nextarg++]);
     781        path = std::string( Tcl_GetString(objv[nextarg++]) );
    1021782    }
    1022783    else {
     
    1027788    node = ((RpLibrary*) cdata)->parent(path);
    1028789    if (node) {
    1029 
    1030790        // clear any previous result in the interpreter
    1031791        Tcl_ResetResult(interp);
     
    1034794            // evaluate the "-as" flag on the returned node
    1035795            retStr = (node->*asProc)();
    1036             // remove the object, keep memory clean
    1037             delete node;
    1038796        }
    1039797        else {
     
    1043801        // store the new result string in the interpreter
    1044802        Tcl_AppendResult(interp, retStr.c_str(), (char*)NULL);
    1045 
    1046     }
    1047 
    1048 
     803    }
    1049804    return TCL_OK;
    1050805}
     
    1057812 *
    1058813 * Full function call:
    1059  * put ?-append yes? ?-id num? ?<path>? <string>
     814 * put <path>
    1060815 *
    1061816 * Return Value:
     
    1063818 * On failure, an error message is returned
    1064819 */
    1065 
    1066 int
    1067 RpTclLibPut     (   ClientData cdata,
    1068                     Tcl_Interp *interp,
    1069                     int argc,
    1070                     const char *argv[]  )
    1071 {
    1072 
     820int
     821RpTclLibPut (ClientData cdata, Tcl_Interp *interp,
     822    int objc, Tcl_Obj *CONST *objv)
     823{
    1073824    std::string id     = "";    // id tag for the given path
    1074825    std::string path   = "";    // path of where to place data inside xml tree
     
    1076827    int nextarg        = 2;     // start parsing using the '2'th argument
    1077828    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) {
    1094839                        return TCL_ERROR;
    1095840                    }
    1096                     // nextarg++;
    1097841                }
    1098842                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);
    1104845                    return TCL_ERROR;
    1105846                }
    1106847            }
    1107             else if (strncmp(argv[nextarg],"-id",3) == 0) {
     848            else if (strcmp(opt,"-id") == 0) {
     849                id = std::string( Tcl_GetString(objv[++nextarg]) );
    1108850                nextarg++;
    1109                 id = std::string(argv[nextarg]);
    1110                 // nextarg++;
    1111851            }
    1112852            else {
    1113                 Tcl_AppendResult(interp, "bad option \"", argv[nextarg],
     853                Tcl_AppendResult(interp, "bad option \"", opt,
    1114854                    "\": should be -append or -id", (char*)NULL);
    1115855                return TCL_ERROR;
    1116856            }
    1117             nextarg++;
    1118         }
    1119     }
    1120 
    1121     argsLeft = (argc-nextarg);
     857        }
     858    }
     859
     860    int argsLeft = (objc-nextarg);
    1122861    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++]) );
    1125864    }
    1126865    else if (argsLeft == 1) {
    1127866        path = "";
    1128         addStr = std::string(argv[nextarg++]);
     867        addStr = std::string( Tcl_GetString(objv[nextarg++]) );
    1129868    }
    1130869    else {
     
    1135874    }
    1136875
    1137     noerr = Tcl_GetCommandInfo(interp, addStr.c_str(), &info);
    1138     if (noerr == 1) {
    1139         // valid command
    1140         if (info.proc == &RpLibCallCmd) {
    1141             // call the rappture library put function with the Rappture Object
    1142             ((RpLibrary*) cdata)->put( path,
    1143                                        (RpLibrary*)info.clientData,
    1144                                        id, append);
    1145         }
    1146         else {
    1147             // object is not a RpLibrary
    1148             // call the rappture library put function with the inputted string
    1149             ((RpLibrary*) cdata)->put(path, addStr, id, append);
    1150         }
    1151     }
    1152     else {
    1153         // invalid command
    1154         // call the rappture library put function with the inputted string
    1155         ((RpLibrary*) cdata)->put(path, addStr, id, append);
    1156     }
    1157 
    1158876    // 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
    1163880    Tcl_ResetResult(interp);
    1164     Tcl_AppendResult(interp, "", (char*)NULL);
    1165 
    1166881    return TCL_OK;
    1167882}
     
    1181896 * On failure, an error message is returned
    1182897 */
    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;
     898int
     899RpTclLibRemove (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]) );
    1206906    }
    1207907
     
    1210910
    1211911    // clear any previous result in the interpreter
    1212     // store the new result in the interpreter
    1213912    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
     916int
     917RpTclLibResult (ClientData cdata, Tcl_Interp *interp,
     918    int objc, Tcl_Obj *CONST *objv)
     919{
     920    // call the rappture library result function
     921    ((RpLibrary*) cdata)->result();
    1237922
    1238923    // clear any previous result in the interpreter
    1239     // store the new result in the interpreter
    1240924    Tcl_ResetResult(interp);
    1241     Tcl_AppendResult(interp, "", (char*)NULL);
    1242 
    1243     return TCL_OK;
    1244 }
    1245 */
     925    return TCL_OK;
     926}
    1246927
    1247928/**********************************************************************/
     
    1259940 *   - second element is the normalization of the value at location <path>
    1260941 */
    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
     942int
     943RpTclLibValue (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
    1279947                                     // from diff command
    1280948    std::list<std::string>::iterator valListIter;
    1281949
    1282     if ( argc != 3 ) {
     950    if (objc != 3) {
    1283951        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);
    1286954        return TCL_ERROR;
    1287955    }
    1288956
    1289957    // 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]));
    1323963
    1324964    // perform the value command
     
    1334974        valListIter++;
    1335975    }
    1336 
    1337     return TCL_OK;
    1338 }
    1339 */
     976    return TCL_OK;
     977}
    1340978
    1341979/**********************************************************************/
     
    1353991
    1354992int
    1355 RpTclLibXml     (   ClientData cdata,
    1356                     Tcl_Interp *interp,
    1357                     int argc,
    1358                     const char *argv[]  )
     993RpTclLibXml (ClientData cdata, Tcl_Interp *interp,
     994    int objc, Tcl_Obj *CONST *objv)
    1359995{
    1360996
    1361997    std::string retStr = ""; // return value of rappture get fxn
    1362998
    1363     if ( argc != 2 ) {
     999    if (objc != 2) {
    13641000        Tcl_AppendResult(interp, "wrong # args: should be \"",
    1365                 argv[0], " xml\"", (char*)NULL);
     1001            Tcl_GetString(objv[0]), " xml\"", (char*)NULL);
    13661002        return TCL_ERROR;
    13671003    }
     
    13941030 * None
    13951031 */
    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 
     1032int
     1033RpTclResult (ClientData cdata, Tcl_Interp *interp,
     1034    int objc, Tcl_Obj *CONST *objv)
     1035{
    14081036    // parse through command line options
    1409     if (argc != 2) {
     1037    if (objc != 2) {
    14101038        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    }
    14381047    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.