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

Function GetEntryIndex

micropolis-activity/src/tk/tkentry.c:1269–1343  ·  view source on GitHub ↗
(interp, entryPtr, string, indexPtr)

Source from the content-addressed store, hash-verified

1267 * A standard Tcl result. If all went well, then *indexPtr is
1268 * filled in with the index (into entryPtr) corresponding to
1269 * string. The index value is guaranteed to lie between 0 and
1270 * the number of characters in the string, inclusive. If an
1271 * error occurs then an error message is left in interp->result.
1272 *
1273 * Side effects:
1274 * None.
1275 *
1276 *--------------------------------------------------------------
1277 */
1278
1279static int
1280GetEntryIndex(interp, entryPtr, string, indexPtr)
1281 Tcl_Interp *interp; /* For error messages. */
1282 Entry *entryPtr; /* Entry for which the index is being
1283 * specified. */
1284 char *string; /* Specifies character in entryPtr. */
1285 int *indexPtr; /* Where to store converted index. */
1286{
1287 int length;
1288
1289 length = strlen(string);
1290
1291 if (string[0] == 'e') {
1292 if (strncmp(string, "end", length) == 0) {
1293 *indexPtr = entryPtr->numChars;
1294 } else {
1295 badIndex:
1296
1297 /*
1298 * Some of the paths here leave messages in interp->result,
1299 * so we have to clear it out before storing our own message.
1300 */
1301
1302 Tcl_SetResult(interp, (char *) NULL, TCL_STATIC);
1303 Tcl_AppendResult(interp, "bad entry index \"", string,
1304 "\"", (char *) NULL);
1305 return TCL_ERROR;
1306 }
1307 } else if (string[0] == 'c') {
1308 if (strncmp(string, "cursor", length) == 0) {
1309 *indexPtr = entryPtr->cursorPos;
1310 } else {
1311 goto badIndex;
1312 }
1313 } else if (string[0] == 's') {
1314 if (entryPtr->selectFirst == -1) {
1315 interp->result = "selection isn't in entry";
1316 return TCL_ERROR;
1317 }
1318 if (length < 5) {
1319 goto badIndex;
1320 }
1321 if (strncmp(string, "sel.first", length) == 0) {
1322 *indexPtr = entryPtr->selectFirst;
1323 } else if (strncmp(string, "sel.last", length) == 0) {
1324 *indexPtr = entryPtr->selectLast;
1325 } else {
1326 goto badIndex;

Callers 1

EntryWidgetCmdFunction · 0.85

Calls 4

Tcl_SetResultFunction · 0.85
Tcl_AppendResultFunction · 0.85
Tcl_GetIntFunction · 0.85
TkMeasureCharsFunction · 0.85

Tested by

no test coverage detected