Changeset 227 for trunk/src


Ignore:
Timestamp:
Feb 28, 2006 11:20:59 PM (18 years ago)
Author:
dkearney
Message:

added Rappture::LibraryObj::value function to tcl bindings.

File:
1 edited

Legend:

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

    r225 r227  
    5050static int RpTclLibResult _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
    5151                                        int argc, const char *argv[]    ));
     52static int RpTclLibValue  _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
     53                                        int argc, const char *argv[]    ));
    5254static int RpTclLibXml    _ANSI_ARGS_(( ClientData cdata, Tcl_Interp *interp,
    5355                                        int argc, const char *argv[]    ));
     
    107109        RpTclResult, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
    108110
     111    Tcl_CreateCommand(interp, "::Rappture::LibraryObj::value",
     112        RpTclLibValue, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
     113
    109114    return TCL_OK;
    110115}
     
    830835
    831836int
     837RpTclLibValue   (   ClientData cdata,
     838                    Tcl_Interp *interp,
     839                    int argc,
     840                    const char *argv[]  )
     841{
     842
     843    Tcl_CmdInfo info;                // pointer to the command info
     844    std::string path        = "";
     845    std::string libStr      = "";
     846    RpLibrary* lib          = NULL;
     847    int nextarg             = 1;     // start parsing using the '1'th argument
     848    int argsLeft            = 0;     // temp variable for calculation
     849    int noerr               = 0;     // err flag for Tcl_GetCommandInfo
     850
     851    std::list<std::string> valList; // list to store the return value
     852                                     // from diff command
     853    std::list<std::string>::iterator valListIter;
     854
     855    if ( argc != 3 ) {
     856        Tcl_AppendResult(interp,
     857            "usage: ", argv[0], " <xmlobj> <path>",
     858            (char*)NULL);
     859        return TCL_ERROR;
     860    }
     861
     862    // parse input arguments
     863    argsLeft = (argc-nextarg);
     864    if (argsLeft == 2) {
     865        libStr = std::string(argv[nextarg++]);
     866        noerr = Tcl_GetCommandInfo(interp, libStr.c_str(), &info);
     867        if (noerr == 1) {
     868            if (info.proc == RpLibCallCmd) {
     869                lib = (RpLibrary*) (info.clientData);
     870            }
     871            else {
     872                Tcl_AppendResult(interp,
     873                    "wrong arg type: xmlobj should be a Rappture Library",
     874                    (char*)NULL);
     875                return TCL_ERROR;
     876            }
     877        }
     878        else {
     879            // there was an error getting the command info
     880            Tcl_AppendResult(interp,
     881                "There was an error getting the command info for "
     882                "the provided library \"", libStr.c_str(), "\'",
     883                "\nAre you sure its a Rappture Library Object?",
     884                (char*)NULL);
     885            return TCL_ERROR;
     886        }
     887        path = std::string(argv[nextarg++]);
     888    }
     889    else {
     890        Tcl_ResetResult(interp);
     891        Tcl_AppendResult(interp,
     892            "wrong # args: should be \"", argv[0], " <xmlobj> <path>\"",
     893            (char*)NULL);
     894        return TCL_ERROR;
     895    }
     896
     897    // perform the value command
     898    valList = lib->value(path);
     899    valListIter = valList.begin();
     900
     901    // parse through the output of the diff command
     902    // put it into the return result
     903    while (valListIter != valList.end()) {
     904        Tcl_AppendElement(interp,(*valListIter).c_str());
     905
     906        // increment the iterator
     907        valListIter++;
     908    }
     909
     910    return TCL_OK;
     911}
     912
     913int
    832914RpTclLibXml     (   ClientData cdata,
    833915                    Tcl_Interp *interp,
Note: See TracChangeset for help on using the changeset viewer.