]>
cvs.zerfleddert.de Git - micropolis/blob - src/tcl/tclcmdil.c
4 * This file contains the top-level command routines for most of
5 * the Tcl built-in commands whose names begin with the letters
6 * I through L. It contains only commands in the generic core
7 * (i.e. those that don't depend much upon UNIX facilities).
9 * Copyright 1987-1991 Regents of the University of California
10 * Permission to use, copy, modify, and distribute this
11 * software and its documentation for any purpose and without
12 * fee is hereby granted, provided that the above copyright
13 * notice appear in all copies. The University of California
14 * makes no representations about the suitability of this
15 * software for any purpose. It is provided "as is" without
16 * express or implied warranty.
20 static char rcsid
[] = "$Header: /user6/ouster/tcl/RCS/tclCmdIL.c,v 1.84 91/12/06 10:42:36 ouster Exp $ SPRITE (Berkeley)";
26 * Global absolute file name:
29 char *TCL_Library
= TCL_LIBRARY
;
32 * Forward declarations for procedures defined in this file:
35 static int SortCompareProc
_ANSI_ARGS_((CONST VOID
*first
,
39 *----------------------------------------------------------------------
43 * This procedure is invoked to process the "if" Tcl command.
44 * See the user documentation for details on what it does.
47 * A standard Tcl result.
50 * See the user documentation.
52 *----------------------------------------------------------------------
57 Tcl_IfCmd(dummy
, interp
, argc
, argv
)
58 ClientData dummy
; /* Not used. */
59 Tcl_Interp
*interp
; /* Current interpreter. */
60 int argc
; /* Number of arguments. */
61 char **argv
; /* Argument strings. */
63 char *condition
, *ifPart
, *elsePart
, *cmd
, *name
;
70 Tcl_AppendResult(interp
, "wrong # args: should be \"", name
,
71 " bool ?then? command ?else? ?command?\"", (char *) NULL
);
77 if ((**argv
== 't') && (strncmp(*argv
, "then", strlen(*argv
)) == 0)) {
90 if ((**argv
== 'e') && (strncmp(*argv
, "else", strlen(*argv
)) == 0)) {
101 clause
= "\"then\" clause";
102 result
= Tcl_ExprBoolean(interp
, condition
, &value
);
103 if (result
!= TCL_OK
) {
104 if (result
== TCL_ERROR
) {
106 sprintf(msg
, "\n (\"if\" test line %d)", interp
->errorLine
);
107 Tcl_AddErrorInfo(interp
, msg
);
113 clause
= "\"else\" clause";
118 result
= Tcl_Eval(interp
, cmd
, 0, (char **) NULL
);
119 if (result
== TCL_ERROR
) {
121 sprintf(msg
, "\n (%s line %d)", clause
, interp
->errorLine
);
122 Tcl_AddErrorInfo(interp
, msg
);
128 *----------------------------------------------------------------------
132 * This procedure is invoked to process the "incr" Tcl command.
133 * See the user documentation for details on what it does.
136 * A standard Tcl result.
139 * See the user documentation.
141 *----------------------------------------------------------------------
146 Tcl_IncrCmd(dummy
, interp
, argc
, argv
)
147 ClientData dummy
; /* Not used. */
148 Tcl_Interp
*interp
; /* Current interpreter. */
149 int argc
; /* Number of arguments. */
150 char **argv
; /* Argument strings. */
153 char *oldString
, *result
;
156 if ((argc
!= 2) && (argc
!= 3)) {
157 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
158 " varName ?increment?\"", (char *) NULL
);
162 oldString
= Tcl_GetVar(interp
, argv
[1], TCL_LEAVE_ERR_MSG
);
163 if (oldString
== NULL
) {
166 if (Tcl_GetInt(interp
, oldString
, &value
) != TCL_OK
) {
167 Tcl_AddErrorInfo(interp
,
168 "\n (reading value of variable to increment)");
176 if (Tcl_GetInt(interp
, argv
[2], &increment
) != TCL_OK
) {
177 Tcl_AddErrorInfo(interp
,
178 "\n (reading increment)");
183 sprintf(newString
, "%d", value
);
184 result
= Tcl_SetVar(interp
, argv
[1], newString
, TCL_LEAVE_ERR_MSG
);
185 if (result
== NULL
) {
188 interp
->result
= result
;
193 *----------------------------------------------------------------------
197 * This procedure is invoked to process the "info" Tcl command.
198 * See the user documentation for details on what it does.
201 * A standard Tcl result.
204 * See the user documentation.
206 *----------------------------------------------------------------------
211 Tcl_InfoCmd(dummy
, interp
, argc
, argv
)
212 ClientData dummy
; /* Not used. */
213 Tcl_Interp
*interp
; /* Current interpreter. */
214 int argc
; /* Number of arguments. */
215 char **argv
; /* Argument strings. */
217 register Interp
*iPtr
= (Interp
*) interp
;
225 Tcl_HashSearch search
;
228 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
229 " option ?arg arg ...?\"", (char *) NULL
);
233 length
= strlen(argv
[1]);
234 if ((c
== 'a') && (strncmp(argv
[1], "args", length
)) == 0) {
236 Tcl_AppendResult(interp
, "wrong # args: should be \"",
237 argv
[0], " args procname\"", (char *) NULL
);
240 procPtr
= TclFindProc(iPtr
, argv
[2]);
241 if (procPtr
== NULL
) {
243 Tcl_AppendResult(interp
, "\"", argv
[2],
244 "\" isn't a procedure", (char *) NULL
);
247 for (argPtr
= procPtr
->argPtr
; argPtr
!= NULL
;
248 argPtr
= argPtr
->nextPtr
) {
249 Tcl_AppendElement(interp
, argPtr
->name
, 0);
252 } else if ((c
== 'b') && (strncmp(argv
[1], "body", length
)) == 0) {
254 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
255 " body procname\"", (char *) NULL
);
258 procPtr
= TclFindProc(iPtr
, argv
[2]);
259 if (procPtr
== NULL
) {
262 iPtr
->result
= procPtr
->command
;
264 } else if ((c
== 'c') && (strncmp(argv
[1], "cmdcount", length
) == 0)
267 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
268 " cmdcount\"", (char *) NULL
);
271 sprintf(iPtr
->result
, "%d", iPtr
->cmdCount
);
273 } else if ((c
== 'c') && (strncmp(argv
[1], "commands", length
) == 0)
276 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
277 " commands [pattern]\"", (char *) NULL
);
280 for (hPtr
= Tcl_FirstHashEntry(&iPtr
->commandTable
, &search
);
281 hPtr
!= NULL
; hPtr
= Tcl_NextHashEntry(&search
)) {
282 char *name
= Tcl_GetHashKey(&iPtr
->commandTable
, hPtr
);
283 if ((argc
== 3) && !Tcl_StringMatch(name
, argv
[2])) {
286 Tcl_AppendElement(interp
, name
, 0);
289 } else if ((c
== 'd') && (strncmp(argv
[1], "default", length
)) == 0) {
291 Tcl_AppendResult(interp
, "wrong # args: should be \"",
292 argv
[0], " default procname arg varname\"",
296 procPtr
= TclFindProc(iPtr
, argv
[2]);
297 if (procPtr
== NULL
) {
300 for (argPtr
= procPtr
->argPtr
; ; argPtr
= argPtr
->nextPtr
) {
301 if (argPtr
== NULL
) {
302 Tcl_AppendResult(interp
, "procedure \"", argv
[2],
303 "\" doesn't have an argument \"", argv
[3],
304 "\"", (char *) NULL
);
307 if (strcmp(argv
[3], argPtr
->name
) == 0) {
308 if (argPtr
->defValue
!= NULL
) {
309 if (Tcl_SetVar((Tcl_Interp
*) iPtr
, argv
[4],
310 argPtr
->defValue
, 0) == NULL
) {
312 Tcl_AppendResult(interp
,
313 "couldn't store default value in variable \"",
314 argv
[4], "\"", (char *) NULL
);
319 if (Tcl_SetVar((Tcl_Interp
*) iPtr
, argv
[4], "", 0)
328 } else if ((c
== 'e') && (strncmp(argv
[1], "exists", length
) == 0)) {
331 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
332 " exists varName\"", (char *) NULL
);
335 p
= Tcl_GetVar((Tcl_Interp
*) iPtr
, argv
[2], 0);
338 * The code below handles the special case where the name is for
339 * an array: Tcl_GetVar will reject this since you can't read
340 * an array variable without an index.
347 if (strchr(argv
[2], '(') != NULL
) {
352 if (iPtr
->varFramePtr
== NULL
) {
353 hPtr
= Tcl_FindHashEntry(&iPtr
->globalTable
, argv
[2]);
355 hPtr
= Tcl_FindHashEntry(&iPtr
->varFramePtr
->varTable
, argv
[2]);
360 varPtr
= (Var
*) Tcl_GetHashValue(hPtr
);
361 if (varPtr
->flags
& VAR_UPVAR
) {
362 varPtr
= (Var
*) Tcl_GetHashValue(varPtr
->value
.upvarPtr
);
364 if (!(varPtr
->flags
& VAR_ARRAY
)) {
370 } else if ((c
== 'g') && (strncmp(argv
[1], "globals", length
) == 0)) {
374 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
375 " globals [pattern]\"", (char *) NULL
);
378 for (hPtr
= Tcl_FirstHashEntry(&iPtr
->globalTable
, &search
);
379 hPtr
!= NULL
; hPtr
= Tcl_NextHashEntry(&search
)) {
380 varPtr
= (Var
*) Tcl_GetHashValue(hPtr
);
381 if (varPtr
->flags
& VAR_UNDEFINED
) {
384 name
= Tcl_GetHashKey(&iPtr
->globalTable
, hPtr
);
385 if ((argc
== 3) && !Tcl_StringMatch(name
, argv
[2])) {
388 Tcl_AppendElement(interp
, name
, 0);
391 } else if ((c
== 'l') && (strncmp(argv
[1], "level", length
) == 0)
394 if (iPtr
->varFramePtr
== NULL
) {
397 sprintf(iPtr
->result
, "%d", iPtr
->varFramePtr
->level
);
400 } else if (argc
== 3) {
404 if (Tcl_GetInt(interp
, argv
[2], &level
) != TCL_OK
) {
408 if (iPtr
->varFramePtr
== NULL
) {
410 Tcl_AppendResult(interp
, "bad level \"", argv
[2],
411 "\"", (char *) NULL
);
414 level
+= iPtr
->varFramePtr
->level
;
416 for (framePtr
= iPtr
->varFramePtr
; framePtr
!= NULL
;
417 framePtr
= framePtr
->callerVarPtr
) {
418 if (framePtr
->level
== level
) {
422 if (framePtr
== NULL
) {
425 iPtr
->result
= Tcl_Merge(framePtr
->argc
, framePtr
->argv
);
426 iPtr
->freeProc
= (Tcl_FreeProc
*) free
;
429 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
430 " level [number]\"", (char *) NULL
);
432 } else if ((c
== 'l') && (strncmp(argv
[1], "library", length
) == 0)
435 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
436 " library\"", (char *) NULL
);
440 interp
->result
= TCL_Library
;
443 interp
->result
= "there is no Tcl library at this installation";
446 } else if ((c
== 'l') && (strncmp(argv
[1], "locals", length
) == 0)
451 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
452 " locals [pattern]\"", (char *) NULL
);
455 if (iPtr
->varFramePtr
== NULL
) {
458 for (hPtr
= Tcl_FirstHashEntry(&iPtr
->varFramePtr
->varTable
, &search
);
459 hPtr
!= NULL
; hPtr
= Tcl_NextHashEntry(&search
)) {
460 varPtr
= (Var
*) Tcl_GetHashValue(hPtr
);
461 if (varPtr
->flags
& (VAR_UNDEFINED
|VAR_UPVAR
)) {
464 name
= Tcl_GetHashKey(&iPtr
->varFramePtr
->varTable
, hPtr
);
465 if ((argc
== 3) && !Tcl_StringMatch(name
, argv
[2])) {
468 Tcl_AppendElement(interp
, name
, 0);
471 } else if ((c
== 'p') && (strncmp(argv
[1], "procs", length
)) == 0) {
473 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
474 " procs [pattern]\"", (char *) NULL
);
477 for (hPtr
= Tcl_FirstHashEntry(&iPtr
->commandTable
, &search
);
478 hPtr
!= NULL
; hPtr
= Tcl_NextHashEntry(&search
)) {
479 char *name
= Tcl_GetHashKey(&iPtr
->commandTable
, hPtr
);
481 cmdPtr
= (Command
*) Tcl_GetHashValue(hPtr
);
482 if (!TclIsProc(cmdPtr
)) {
485 if ((argc
== 3) && !Tcl_StringMatch(name
, argv
[2])) {
488 Tcl_AppendElement(interp
, name
, 0);
491 } else if ((c
== 's') && (strncmp(argv
[1], "script", length
) == 0)) {
493 Tcl_AppendResult(interp
, "wrong # args: should be \"",
494 argv
[0], " script\"", (char *) NULL
);
497 if (iPtr
->scriptFile
!= NULL
) {
498 interp
->result
= iPtr
->scriptFile
;
501 } else if ((c
== 't') && (strncmp(argv
[1], "tclversion", length
) == 0)) {
503 Tcl_AppendResult(interp
, "wrong # args: should be \"",
504 argv
[0], " tclversion\"", (char *) NULL
);
509 * Note: TCL_VERSION below is expected to be set with a "-D"
510 * switch in the Makefile.
513 strcpy(iPtr
->result
, TCL_VERSION
);
515 } else if ((c
== 'v') && (strncmp(argv
[1], "vars", length
)) == 0) {
516 Tcl_HashTable
*tablePtr
;
520 Tcl_AppendResult(interp
, "wrong # args: should be \"",
521 argv
[0], " vars [pattern]\"", (char *) NULL
);
524 if (iPtr
->varFramePtr
== NULL
) {
525 tablePtr
= &iPtr
->globalTable
;
527 tablePtr
= &iPtr
->varFramePtr
->varTable
;
529 for (hPtr
= Tcl_FirstHashEntry(tablePtr
, &search
);
530 hPtr
!= NULL
; hPtr
= Tcl_NextHashEntry(&search
)) {
531 varPtr
= (Var
*) Tcl_GetHashValue(hPtr
);
532 if (varPtr
->flags
& VAR_UNDEFINED
) {
535 name
= Tcl_GetHashKey(tablePtr
, hPtr
);
536 if ((argc
== 3) && !Tcl_StringMatch(name
, argv
[2])) {
539 Tcl_AppendElement(interp
, name
, 0);
543 Tcl_AppendResult(interp
, "bad option \"", argv
[1],
544 "\": should be args, body, commands, cmdcount, default, ",
545 "exists, globals, level, library, locals, procs, ",
546 "script, tclversion, or vars",
553 *----------------------------------------------------------------------
557 * This procedure is invoked to process the "join" Tcl command.
558 * See the user documentation for details on what it does.
561 * A standard Tcl result.
564 * See the user documentation.
566 *----------------------------------------------------------------------
571 Tcl_JoinCmd(dummy
, interp
, argc
, argv
)
572 ClientData dummy
; /* Not used. */
573 Tcl_Interp
*interp
; /* Current interpreter. */
574 int argc
; /* Number of arguments. */
575 char **argv
; /* Argument strings. */
583 } else if (argc
== 3) {
584 joinString
= argv
[2];
586 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
587 " list ?joinString?\"", (char *) NULL
);
591 if (Tcl_SplitList(interp
, argv
[1], &listArgc
, &listArgv
) != TCL_OK
) {
594 for (i
= 0; i
< listArgc
; i
++) {
596 Tcl_AppendResult(interp
, listArgv
[0], (char *) NULL
);
598 Tcl_AppendResult(interp
, joinString
, listArgv
[i
], (char *) NULL
);
601 ckfree((char *) listArgv
);
606 *----------------------------------------------------------------------
610 * This procedure is invoked to process the "lindex" Tcl command.
611 * See the user documentation for details on what it does.
614 * A standard Tcl result.
617 * See the user documentation.
619 *----------------------------------------------------------------------
624 Tcl_LindexCmd(dummy
, interp
, argc
, argv
)
625 ClientData dummy
; /* Not used. */
626 Tcl_Interp
*interp
; /* Current interpreter. */
627 int argc
; /* Number of arguments. */
628 char **argv
; /* Argument strings. */
631 int index
, size
, parenthesized
, result
;
634 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
635 " list index\"", (char *) NULL
);
638 if (Tcl_GetInt(interp
, argv
[2], &index
) != TCL_OK
) {
644 for (p
= argv
[1] ; index
>= 0; index
--) {
645 result
= TclFindElement(interp
, p
, &element
, &p
, &size
,
647 if (result
!= TCL_OK
) {
654 if (size
>= TCL_RESULT_SIZE
) {
655 interp
->result
= (char *) ckalloc((unsigned) size
+1);
656 interp
->freeProc
= (Tcl_FreeProc
*) free
;
659 memcpy((VOID
*) interp
->result
, (VOID
*) element
, size
);
660 interp
->result
[size
] = 0;
662 TclCopyAndCollapse(size
, element
, interp
->result
);
668 *----------------------------------------------------------------------
672 * This procedure is invoked to process the "linsert" Tcl command.
673 * See the user documentation for details on what it does.
676 * A standard Tcl result.
679 * See the user documentation.
681 *----------------------------------------------------------------------
686 Tcl_LinsertCmd(dummy
, interp
, argc
, argv
)
687 ClientData dummy
; /* Not used. */
688 Tcl_Interp
*interp
; /* Current interpreter. */
689 int argc
; /* Number of arguments. */
690 char **argv
; /* Argument strings. */
692 char *p
, *element
, savedChar
;
693 int i
, index
, count
, result
, size
;
696 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
697 " list index element ?element ...?\"", (char *) NULL
);
700 if (Tcl_GetInt(interp
, argv
[2], &index
) != TCL_OK
) {
705 * Skip over the first "index" elements of the list, then add
706 * all of those elements to the result.
711 for (count
= 0, p
= argv
[1]; (count
< index
) && (*p
!= 0); count
++) {
712 result
= TclFindElement(interp
, p
, &element
, &p
, &size
, (int *) NULL
);
713 if (result
!= TCL_OK
) {
718 Tcl_AppendResult(interp
, argv
[1], (char *) NULL
);
723 if (element
!= argv
[1]) {
724 while ((*end
!= 0) && !isspace(*end
)) {
730 Tcl_AppendResult(interp
, argv
[1], (char *) NULL
);
735 * Add the new list elements.
738 for (i
= 3; i
< argc
; i
++) {
739 Tcl_AppendElement(interp
, argv
[i
], 0);
743 * Append the remainder of the original list.
747 Tcl_AppendResult(interp
, " ", p
, (char *) NULL
);
753 *----------------------------------------------------------------------
757 * This procedure is invoked to process the "list" Tcl command.
758 * See the user documentation for details on what it does.
761 * A standard Tcl result.
764 * See the user documentation.
766 *----------------------------------------------------------------------
771 Tcl_ListCmd(dummy
, interp
, argc
, argv
)
772 ClientData dummy
; /* Not used. */
773 Tcl_Interp
*interp
; /* Current interpreter. */
774 int argc
; /* Number of arguments. */
775 char **argv
; /* Argument strings. */
778 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
779 " arg ?arg ...?\"", (char *) NULL
);
782 interp
->result
= Tcl_Merge(argc
-1, argv
+1);
783 interp
->freeProc
= (Tcl_FreeProc
*) free
;
788 *----------------------------------------------------------------------
792 * This procedure is invoked to process the "llength" Tcl command.
793 * See the user documentation for details on what it does.
796 * A standard Tcl result.
799 * See the user documentation.
801 *----------------------------------------------------------------------
806 Tcl_LlengthCmd(dummy
, interp
, argc
, argv
)
807 ClientData dummy
; /* Not used. */
808 Tcl_Interp
*interp
; /* Current interpreter. */
809 int argc
; /* Number of arguments. */
810 char **argv
; /* Argument strings. */
816 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
817 " list\"", (char *) NULL
);
820 for (count
= 0, p
= argv
[1]; *p
!= 0 ; count
++) {
821 result
= TclFindElement(interp
, p
, &element
, &p
, (int *) NULL
,
823 if (result
!= TCL_OK
) {
830 sprintf(interp
->result
, "%d", count
);
835 *----------------------------------------------------------------------
839 * This procedure is invoked to process the "lrange" Tcl command.
840 * See the user documentation for details on what it does.
843 * A standard Tcl result.
846 * See the user documentation.
848 *----------------------------------------------------------------------
853 Tcl_LrangeCmd(notUsed
, interp
, argc
, argv
)
854 ClientData notUsed
; /* Not used. */
855 Tcl_Interp
*interp
; /* Current interpreter. */
856 int argc
; /* Number of arguments. */
857 char **argv
; /* Argument strings. */
859 int first
, last
, result
;
860 char *begin
, *end
, c
, *dummy
;
864 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
865 " list first last\"", (char *) NULL
);
868 if (Tcl_GetInt(interp
, argv
[2], &first
) != TCL_OK
) {
874 if ((*argv
[3] == 'e') && (strncmp(argv
[3], "end", strlen(argv
[3])) == 0)) {
877 if (Tcl_GetInt(interp
, argv
[3], &last
) != TCL_OK
) {
878 Tcl_ResetResult(interp
);
879 Tcl_AppendResult(interp
,
880 "expected integer or \"end\" but got \"",
881 argv
[3], "\"", (char *) NULL
);
890 * Extract a range of fields.
893 for (count
= 0, begin
= argv
[1]; count
< first
; count
++) {
894 result
= TclFindElement(interp
, begin
, &dummy
, &begin
, (int *) NULL
,
896 if (result
!= TCL_OK
) {
903 for (count
= first
, end
= begin
; (count
<= last
) && (*end
!= 0);
905 result
= TclFindElement(interp
, end
, &dummy
, &end
, (int *) NULL
,
907 if (result
!= TCL_OK
) {
913 * Chop off trailing spaces.
916 while (isspace(end
[-1])) {
921 Tcl_SetResult(interp
, begin
, TCL_VOLATILE
);
927 *----------------------------------------------------------------------
931 * This procedure is invoked to process the "lreplace" Tcl command.
932 * See the user documentation for details on what it does.
935 * A standard Tcl result.
938 * See the user documentation.
940 *----------------------------------------------------------------------
945 Tcl_LreplaceCmd(notUsed
, interp
, argc
, argv
)
946 ClientData notUsed
; /* Not used. */
947 Tcl_Interp
*interp
; /* Current interpreter. */
948 int argc
; /* Number of arguments. */
949 char **argv
; /* Argument strings. */
951 char *p1
, *p2
, *element
, savedChar
, *dummy
;
952 int i
, first
, last
, count
, result
, size
;
955 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
956 " list first last ?element element ...?\"", (char *) NULL
);
959 if (Tcl_GetInt(interp
, argv
[2], &first
) != TCL_OK
) {
962 if (TclGetListIndex(interp
, argv
[3], &last
) != TCL_OK
) {
972 Tcl_AppendResult(interp
, "first index must not be greater than second",
978 * Skip over the elements of the list before "first".
983 for (count
= 0, p1
= argv
[1]; (count
< first
) && (*p1
!= 0); count
++) {
984 result
= TclFindElement(interp
, p1
, &element
, &p1
, &size
,
986 if (result
!= TCL_OK
) {
991 Tcl_AppendResult(interp
, "list doesn't contain element ",
992 argv
[2], (char *) NULL
);
997 * Skip over the elements of the list up through "last".
1000 for (p2
= p1
; (count
<= last
) && (*p2
!= 0); count
++) {
1001 result
= TclFindElement(interp
, p2
, &dummy
, &p2
, (int *) NULL
,
1003 if (result
!= TCL_OK
) {
1009 * Add the elements before "first" to the result. Be sure to
1010 * include quote or brace characters that might terminate the
1011 * last of these elements.
1015 if (element
!= argv
[1]) {
1016 while ((*p1
!= 0) && !isspace(*p1
)) {
1022 Tcl_AppendResult(interp
, argv
[1], (char *) NULL
);
1026 * Add the new list elements.
1029 for (i
= 4; i
< argc
; i
++) {
1030 Tcl_AppendElement(interp
, argv
[i
], 0);
1034 * Append the remainder of the original list.
1038 if (*interp
->result
== 0) {
1039 Tcl_SetResult(interp
, p2
, TCL_VOLATILE
);
1041 Tcl_AppendResult(interp
, " ", p2
, (char *) NULL
);
1048 *----------------------------------------------------------------------
1052 * This procedure is invoked to process the "lsearch" Tcl command.
1053 * See the user documentation for details on what it does.
1056 * A standard Tcl result.
1059 * See the user documentation.
1061 *----------------------------------------------------------------------
1066 Tcl_LsearchCmd(notUsed
, interp
, argc
, argv
)
1067 ClientData notUsed
; /* Not used. */
1068 Tcl_Interp
*interp
; /* Current interpreter. */
1069 int argc
; /* Number of arguments. */
1070 char **argv
; /* Argument strings. */
1077 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1078 " list pattern\"", (char *) NULL
);
1081 if (Tcl_SplitList(interp
, argv
[1], &listArgc
, &listArgv
) != TCL_OK
) {
1085 for (i
= 0; i
< listArgc
; i
++) {
1086 if (Tcl_StringMatch(listArgv
[i
], argv
[2])) {
1091 sprintf(interp
->result
, "%d", match
);
1092 ckfree((char *) listArgv
);
1097 *----------------------------------------------------------------------
1101 * This procedure is invoked to process the "lsort" Tcl command.
1102 * See the user documentation for details on what it does.
1105 * A standard Tcl result.
1108 * See the user documentation.
1110 *----------------------------------------------------------------------
1115 Tcl_LsortCmd(notUsed
, interp
, argc
, argv
)
1116 ClientData notUsed
; /* Not used. */
1117 Tcl_Interp
*interp
; /* Current interpreter. */
1118 int argc
; /* Number of arguments. */
1119 char **argv
; /* Argument strings. */
1125 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1126 " list\"", (char *) NULL
);
1129 if (Tcl_SplitList(interp
, argv
[1], &listArgc
, &listArgv
) != TCL_OK
) {
1132 qsort((VOID
*) listArgv
, listArgc
, sizeof (char *), SortCompareProc
);
1133 interp
->result
= Tcl_Merge(listArgc
, listArgv
);
1134 interp
->freeProc
= (Tcl_FreeProc
*) free
;
1135 ckfree((char *) listArgv
);
1140 * The procedure below is called back by qsort to determine
1141 * the proper ordering between two elements.
1145 SortCompareProc(first
, second
)
1146 CONST VOID
*first
, *second
; /* Elements to be compared. */
1148 return strcmp(*((char **) first
), *((char **) second
));