diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2006-11-09 15:19:01 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2006-11-09 15:19:01 (GMT) |
commit | b07bb89f2a73a18a69b6666c3484f3e2271f53bf (patch) | |
tree | c99380de0e89bc86e1accd8eef22508a2650412a /generic/tclCmdIL.c | |
parent | e33a0caada7278a17cac044aaf753e624489623d (diff) | |
download | tcl-b07bb89f2a73a18a69b6666c3484f3e2271f53bf.zip tcl-b07bb89f2a73a18a69b6666c3484f3e2271f53bf.tar.gz tcl-b07bb89f2a73a18a69b6666c3484f3e2271f53bf.tar.bz2 |
Implemented [lreverse] from TIP#272
Diffstat (limited to 'generic/tclCmdIL.c')
-rw-r--r-- | generic/tclCmdIL.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index fdbc293..6f9d9ac 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -16,7 +16,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdIL.c,v 1.92 2006/11/02 15:58:05 dgp Exp $ + * RCS: @(#) $Id: tclCmdIL.c,v 1.93 2006/11/09 15:19:03 dkf Exp $ */ #include "tclInt.h" @@ -3158,6 +3158,56 @@ Tcl_LreplaceObjCmd(dummy, interp, objc, objv) */ int +Tcl_LreverseObjCmd( + ClientData clientData, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument values. */ +{ + Tcl_Obj *resultObj, **dataArray, **elemv; + int elemc, i, j; + List *listPtr; + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "list"); + return TCL_ERROR; + } + if (Tcl_ListObjGetElements(interp, objv[1], &elemc, &elemv) != TCL_OK) { + return TCL_ERROR; + } + + resultObj = Tcl_NewListObj(elemc, NULL); + listPtr = (List *) resultObj->internalRep.twoPtrValue.ptr1; + listPtr->elemCount = elemc; + dataArray = &listPtr->elements; + + for (i=0,j=elemc-1 ; i<elemc ; i++,j--) { + dataArray[j] = elemv[i]; + Tcl_IncrRefCount(elemv[i]); + } + + Tcl_SetObjResult(interp, resultObj); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * Tcl_LsearchObjCmd -- + * + * This procedure is invoked to process the "lsearch" Tcl command. See + * the user documentation for details on what it does. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +int Tcl_LsearchObjCmd(clientData, interp, objc, objv) ClientData clientData; /* Not used. */ Tcl_Interp *interp; /* Current interpreter. */ |