MCPcopy Create free account
hub / github.com/SimHacker/micropolis / TextFetchSelection

Function TextFetchSelection

micropolis-activity/src/tk/tktext.c:1023–1135  ·  view source on GitHub ↗
(clientData, offset, buffer, maxBytes)

Source from the content-addressed store, hash-verified

1021 * at buffer. Buffer is filled (or partially filled) with a
1022 * NULL-terminated string containing part or all of the selection,
1023 * as given by offset and maxBytes.
1024 *
1025 * Side effects:
1026 * None.
1027 *
1028 *----------------------------------------------------------------------
1029 */
1030
1031static int
1032TextFetchSelection(clientData, offset, buffer, maxBytes)
1033 ClientData clientData; /* Information about text widget. */
1034 int offset; /* Offset within selection of first
1035 * character to be returned. */
1036 char *buffer; /* Location in which to place
1037 * selection. */
1038 int maxBytes; /* Maximum number of bytes to place
1039 * at buffer, not including terminating
1040 * NULL character. */
1041{
1042 register TkText *textPtr = (TkText *) clientData;
1043 register TkTextLine *linePtr;
1044 int count, chunkSize;
1045 TkTextSearch search;
1046
1047 if (!textPtr->exportSelection) {
1048 return -1;
1049 }
1050
1051 /*
1052 * Find the beginning of the next range of selected text. Note: if
1053 * the selection is being retrieved in multiple pieces (offset != 0)
1054 * and some modification has been made to the text that affects the
1055 * selection (textPtr->selOffset != offset) then reject the selection
1056 * request (make 'em start over again).
1057 */
1058
1059 if (offset == 0) {
1060 textPtr->selLine = 0;
1061 textPtr->selCh = 0;
1062 textPtr->selOffset = 0;
1063 } else if (textPtr->selOffset != offset) {
1064 return 0;
1065 }
1066 TkBTreeStartSearch(textPtr->tree, textPtr->selLine, textPtr->selCh+1,
1067 TkBTreeNumLines(textPtr->tree), 0, textPtr->selTagPtr, &search);
1068 if (!TkBTreeCharTagged(search.linePtr, textPtr->selCh,
1069 textPtr->selTagPtr)) {
1070 if (!TkBTreeNextTag(&search)) {
1071 if (offset == 0) {
1072 return -1;
1073 } else {
1074 return 0;
1075 }
1076 }
1077 textPtr->selLine = search.line1;
1078 textPtr->selCh = search.ch1;
1079 }
1080

Callers

nothing calls this directly

Calls 5

TkBTreeStartSearchFunction · 0.85
TkBTreeNumLinesFunction · 0.85
TkBTreeCharTaggedFunction · 0.85
TkBTreeNextTagFunction · 0.85
panicFunction · 0.85

Tested by

no test coverage detected