(entryPtr, index, string)
| 1019 | * |
| 1020 | * Side effects: |
| 1021 | * New information gets added to entryPtr; it will be redisplayed |
| 1022 | * soon, but not necessarily immediately. |
| 1023 | * |
| 1024 | *---------------------------------------------------------------------- |
| 1025 | */ |
| 1026 | |
| 1027 | static void |
| 1028 | InsertChars(entryPtr, index, string) |
| 1029 | register Entry *entryPtr; /* Entry that is to get the new |
| 1030 | * elements. */ |
| 1031 | int index; /* Add the new elements before this |
| 1032 | * element. */ |
| 1033 | char *string; /* New characters to add (NULL-terminated |
| 1034 | * string). */ |
| 1035 | { |
| 1036 | int length; |
| 1037 | char *new; |
| 1038 | |
| 1039 | length = strlen(string); |
| 1040 | if (length == 0) { |
| 1041 | return; |
| 1042 | } |
| 1043 | new = (char *) ckalloc((unsigned) (entryPtr->numChars + length + 1)); |
| 1044 | strncpy(new, entryPtr->string, index); |
| 1045 | strcpy(new+index, string); |
| 1046 | strcpy(new+index+length, entryPtr->string+index); |
| 1047 | ckfree(entryPtr->string); |
| 1048 | entryPtr->string = new; |
| 1049 | entryPtr->numChars += length; |
| 1050 | |
| 1051 | /* |
| 1052 | * Inserting characters invalidates all indexes into the string. |
| 1053 | * Touch up the indexes so that they still refer to the same |
| 1054 | * characters (at new positions). |
| 1055 | */ |
| 1056 | |
| 1057 | if (entryPtr->selectFirst >= index) { |
| 1058 | entryPtr->selectFirst += length; |
| 1059 | } |
| 1060 | if (entryPtr->selectLast >= index) { |
| 1061 | entryPtr->selectLast += length; |
| 1062 | } |
| 1063 | if (entryPtr->selectAnchor >= index) { |
| 1064 | entryPtr->selectAnchor += length; |
| 1065 | } |
| 1066 | if (entryPtr->leftIndex > index) { |
| 1067 | entryPtr->leftIndex += length; |
| 1068 | } |
| 1069 | if (entryPtr->cursorPos >= index) { |
| 1070 | entryPtr->cursorPos += length; |
| 1071 | } |
| 1072 | |
| 1073 | if (entryPtr->textVarName != NULL) { |
| 1074 | Tcl_SetVar(entryPtr->interp, entryPtr->textVarName, entryPtr->string, |
| 1075 | TCL_GLOBAL_ONLY); |
| 1076 | } |
no test coverage detected