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 | |
parent | e33a0caada7278a17cac044aaf753e624489623d (diff) | |
download | tcl-b07bb89f2a73a18a69b6666c3484f3e2271f53bf.zip tcl-b07bb89f2a73a18a69b6666c3484f3e2271f53bf.tar.gz tcl-b07bb89f2a73a18a69b6666c3484f3e2271f53bf.tar.bz2 |
Implemented [lreverse] from TIP#272
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclBasic.c | 3 | ||||
-rw-r--r-- | generic/tclCmdIL.c | 52 | ||||
-rw-r--r-- | generic/tclInt.h | 5 |
3 files changed, 57 insertions, 3 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 40cc7fb..22b715a 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -13,7 +13,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclBasic.c,v 1.216 2006/11/04 00:09:33 msofer Exp $ + * RCS: @(#) $Id: tclBasic.c,v 1.217 2006/11/09 15:19:02 dkf Exp $ */ #include "tclInt.h" @@ -139,6 +139,7 @@ static CmdInfo builtInCmds[] = { {"lrange", Tcl_LrangeObjCmd, NULL, 1}, {"lrepeat", Tcl_LrepeatObjCmd, NULL, 1}, {"lreplace", Tcl_LreplaceObjCmd, NULL, 1}, + {"lreverse", Tcl_LreverseObjCmd, NULL, 1}, {"lsearch", Tcl_LsearchObjCmd, NULL, 1}, {"lset", Tcl_LsetObjCmd, TclCompileLsetCmd, 1}, {"lsort", Tcl_LsortObjCmd, NULL, 1}, 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. */ diff --git a/generic/tclInt.h b/generic/tclInt.h index 54a27bc..796ae21 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclInt.h,v 1.292 2006/11/02 16:57:54 dgp Exp $ + * RCS: @(#) $Id: tclInt.h,v 1.293 2006/11/09 15:19:03 dkf Exp $ */ #ifndef _TCLINT @@ -2426,6 +2426,9 @@ MODULE_SCOPE int Tcl_LrepeatObjCmd(ClientData clientData, MODULE_SCOPE int Tcl_LreplaceObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); +MODULE_SCOPE int Tcl_LreverseObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *CONST objv[]); MODULE_SCOPE int Tcl_LsearchObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); |