Alias_s Parser::parseKeywords(char *exp) { Alias_s alias = { NULL, NULL, NULL, 0 }; Alias_s a = heap.getAlias(exp); char *stack = strstr(exp, ":stk"); char *address = strstr(exp, "#"); char *and = strstr(exp, "&"); if (a.len > 0) { memcpy(&alias, &a, sizeof(a)); } else if (stack) { char *pop = strstr(stack, "pop"); char *pushAt = strstr(stack, "pushAt"); char *pushTop = strstr(stack, "pushTop"); char *getAt = strstr(stack, "getAt"); char *getTop = strstr(stack, "getTop"); char *identifyType = strstr(exp, "\""); if (pop) { stackPop(); } else if (pushAt) { stackPushAt(stack); } else if (pushTop) { stackPushTop(pushTop); } else if (getAt) { alias = stackGetAt(getAt); } else if (getTop) { alias = heap.getTop(); } else { //unsupported stack command. } } else if (address && !isAdress) { trimBothParanthesis(address); int len = strlen(address) - 1; memcpy(tmpStr, address +1, len); tmpStr[len] = '\0'; int a = atoi(tmpStr); alias = heap.getAlias(a); } else if (address && isAdress) { trimBothParanthesis(address); int len = strlen(address) - 1; memcpy(alias.type, "address", 7); memcpy(alias.name, tmpStr, len); int digits = heap.getAddress(tmpStr); sprintf(alias.value, "%d", digits); alias.len = strlen(alias.value); } else if (and && !isAdress) { trimBothParanthesis(and); int len = strlen(and) - 1; memcpy(tmpStr, and + 1, len); tmpStr[len] = '\0'; alias = heap.getAlias(tmpStr); } else if (and && isAdress) { trimBothParanthesis(and); int len = strlen(and) - 1; memcpy(tmpStr, and + 1, len); tmpStr[len] = '\0'; alias.len = len; memcpy(alias.type, "address", 6); memcpy(alias.name, tmpStr, alias.len); int digits = heap.getAddress(tmpStr); sprintf(alias.value, "%d", digits); } else if (strstr(exp, "\"") == NULL) { trimBothParanthesis(exp); //Digits alias.len = strlen(exp); memcpy(alias.value, exp, alias.len); alias.value[alias.len] = '\0'; memcpy(alias.type, "int", 3); alias.type[3] = '\0'; } else if (strstr(exp, "\"")) { trimBothParanthesis(exp); //Letters trimText(exp); alias.len = strlen(exp); memcpy(alias.value, exp, alias.len); alias.value[alias.len] = '\0'; memcpy(alias.type, "string", 6); alias.type[6] = '\0'; } else { //Syntax for expression is wrong DO CRASH!! } return alias; }
bool WidgetInput::logic(int x, int y) { Point mouse(x, y); // Change the hover state hover = isWithinRect(pos, mouse); if (checkClick()) { edit_mode = true; } // if clicking elsewhere unfocus the text box if (inpt->pressing[MAIN1]) { if (!isWithinRect(pos, inpt->mouse)) { edit_mode = false; } } if (edit_mode) { inpt->slow_repeat[DEL] = true; inpt->slow_repeat[LEFT] = true; inpt->slow_repeat[RIGHT] = true; inpt->startTextInput(); if (inpt->inkeys != "") { // handle text input // only_numbers will restrict our input to 0-9 characters if (!only_numbers || (inpt->inkeys[0] >= 48 && inpt->inkeys[0] <= 57)) { text.insert(cursor_pos, inpt->inkeys); cursor_pos += inpt->inkeys.length(); trimText(); } // HACK: this prevents normal keys from triggering common menu shortcuts for (size_t i = 0; i < inpt->key_count; ++i) { if (inpt->pressing[i]) { inpt->lock[i] = true; inpt->repeat_ticks[i] = 1; } } } // handle backspaces if (inpt->pressing[DEL] && inpt->repeat_ticks[DEL] == 0) { if (!text.empty() && cursor_pos > 0) { // remove utf-8 character // size_t old_cursor_pos = cursor_pos; size_t n = cursor_pos-1; while (n > 0 && ((text[n] & 0xc0) == 0x80)) { n--; } text = text.substr(0, n) + text.substr(cursor_pos, text.length()); cursor_pos -= (cursor_pos) - n; trimText(); } } // cursor movement if (!text.empty() && cursor_pos > 0 && inpt->pressing[LEFT] && inpt->repeat_ticks[LEFT] == 0) { cursor_pos--; trimText(); } else if (!text.empty() && cursor_pos < text.length() && inpt->pressing[RIGHT] && inpt->repeat_ticks[RIGHT] == 0) { inpt->lock[RIGHT] = true; cursor_pos++; trimText(); } // defocus with Enter or Escape if (accept_to_defocus && inpt->pressing[ACCEPT] && !inpt->lock[ACCEPT]) { inpt->lock[ACCEPT] = true; edit_mode = false; } else if (inpt->pressing[CANCEL] && !inpt->lock[CANCEL]) { inpt->lock[CANCEL] = true; edit_mode = false; } } else { inpt->slow_repeat[DEL] = false; inpt->slow_repeat[LEFT] = false; inpt->slow_repeat[RIGHT] = false; inpt->stopTextInput(); } return true; }