QSPVariant qspGetEmptyVariant(QSP_BOOL isStringType) { QSPVariant ret; if (ret.IsStr = isStringType) QSP_STR(ret) = qspGetNewText(QSP_FMT(""), 0); else QSP_NUM(ret) = 0; return ret; }
QSP_BOOL qspStatementKillVar(QSPVariant *args, int count, QSP_CHAR **jumpTo, int extArg) { if (count == 1) qspRemoveArray(QSP_STR(args[0])); else if (count == 2) qspRemoveArrayItem(QSP_STR(args[0]), QSP_NUM(args[1])); else qspClearVars(QSP_FALSE); return QSP_FALSE; }
QSPVariant qspArrayMinMaxItem(QSP_CHAR *name, QSP_BOOL isMin) { QSPVar *var; QSP_CHAR *str; QSP_BOOL isString; int curInd, count; QSPVariant res; if (!(var = qspVarReferenceWithType(name, QSP_FALSE, &isString))) return qspGetEmptyVariant(QSP_FALSE); curInd = -1; count = var->ValsCount; while (--count >= 0) { if (isString) { str = var->Values[count].Str; if (str && *str) { if (curInd >= 0) { if (isMin) { if (QSP_STRCOLL(str, var->Values[curInd].Str) < 0) curInd = count; } else if (QSP_STRCOLL(str, var->Values[curInd].Str) > 0) curInd = count; } else curInd = count; } } else if (curInd >= 0) { if (isMin) { if (var->Values[count].Num < var->Values[curInd].Num) curInd = count; } else if (var->Values[count].Num > var->Values[curInd].Num) curInd = count; } else curInd = count; } if (curInd < 0) return qspGetEmptyVariant(isString); if (res.IsStr = isString) QSP_STR(res) = qspGetNewText(var->Values[curInd].Str, -1); else QSP_NUM(res) = var->Values[curInd].Num; return res; }
/* Ф-я предназначена только для вызова из CallBack'а QSP_CALL_SHOWMENU */ AS3_Val QSPSelectMenuItem(void *param, AS3_Val args) { int index; QSPVariant arg; AS3_ArrayValue(args, "IntType", &index); if (index >= 0 && index < qspCurMenuItems) { if (qspIsDisableCodeExec) return AS3_True(); arg.IsStr = QSP_FALSE; QSP_NUM(arg) = index + 1; qspExecLocByNameWithArgs(qspCurMenuLocs[index], &arg, 1); } return AS3_True(); }
QSPVariant qspGetVarValueByReference(QSPVar *var, int ind, QSP_BOOL isStringType) { QSPVariant ret; QSP_CHAR *text; if (ind >= 0 && ind < var->ValsCount) { if (ret.IsStr = isStringType) { text = var->Values[ind].Str; QSP_STR(ret) = (text ? qspGetNewText(text, -1) : qspGetNewText(QSP_FMT(""), 0)); } else QSP_NUM(ret) = var->Values[ind].Num; return ret; } return qspGetEmptyVariant(isStringType); }
QSP_BOOL qspStatementDelObj(QSPVariant *args, int count, QSP_CHAR **jumpTo, int extArg) { switch (extArg) { case 0: qspRemoveObject(qspObjIndex(QSP_STR(args[0]))); break; case 1: if (count) qspRemoveObject(QSP_NUM(args[0]) - 1); else qspClearObjectsWithNotify(); break; } return QSP_FALSE; }
static QSPVar *qspGetVarData(QSP_CHAR *s, QSP_BOOL isSet, int *index) { QSPVar *var; QSPVariant ind; int oldRefreshCount; QSP_CHAR *temp, *rPos, *lPos = qspStrChar(s, QSP_LSBRACK[0]); if (lPos) { rPos = qspStrPos(lPos, QSP_RSBRACK, QSP_FALSE); if (!rPos) { qspSetError(QSP_ERR_BRACKNOTFOUND); return 0; } *lPos = 0; var = qspVarReference(s, isSet); *lPos = QSP_LSBRACK[0]; if (!var) return 0; temp = qspSkipSpaces(lPos + 1); if (temp == rPos) { if (isSet) *index = var->ValsCount; else *index = (var->ValsCount ? var->ValsCount - 1 : 0); } else { oldRefreshCount = qspRefreshCount; *rPos = 0; ind = qspExprValue(temp); *rPos = QSP_RSBRACK[0]; if (qspRefreshCount != oldRefreshCount || qspErrorNum) return 0; if (ind.IsStr) { *index = qspGetVarTextIndex(var, QSP_STR(ind), isSet); free(QSP_STR(ind)); } else *index = QSP_NUM(ind); } return var; } *index = 0; return qspVarReference(s, isSet); }
/* Получить значение указанного выражения */ QSP_BOOL QSPGetExprValue(const QSP_CHAR *expr, QSP_BOOL *isString, int *numVal, QSP_CHAR *strVal, int strValBufSize) { QSPVariant v; if (qspIsExitOnError && qspErrorNum) return QSP_FALSE; qspResetError(); if (qspIsDisableCodeExec) return QSP_FALSE; v = qspExprValue((QSP_CHAR *)expr); if (qspErrorNum) return QSP_FALSE; *isString = v.IsStr; if (v.IsStr) { qspStrNCopy(strVal, QSP_STR(v), strValBufSize - 1); free(QSP_STR(v)); strVal[strValBufSize - 1] = 0; } else *numVal = QSP_NUM(v); return QSP_TRUE; }
static void qspSetVar(QSP_CHAR *name, QSPVariant *val, QSP_CHAR op) { QSPVariant oldVal; QSPVar *var; int index; if (!(var = qspGetVarData(name, QSP_TRUE, &index))) return; if (op == QSP_EQUAL[0]) { if (qspConvertVariantTo(val, *name == QSP_STRCHAR[0])) { qspSetError(QSP_ERR_TYPEMISMATCH); return; } qspSetVarValueByReference(var, index, val); } else if (op == QSP_ADD[0]) { oldVal = qspGetVarValueByReference(var, index, *name == QSP_STRCHAR[0]); if (oldVal.IsStr && val->IsStr) QSP_STR(oldVal) = qspGetAddText(QSP_STR(oldVal), QSP_PSTR(val), -1, -1); else if (qspIsCanConvertToNum(&oldVal) && qspIsCanConvertToNum(val)) { qspConvertVariantTo(&oldVal, QSP_FALSE); qspConvertVariantTo(val, QSP_FALSE); QSP_NUM(oldVal) += QSP_PNUM(val); qspConvertVariantTo(&oldVal, *name == QSP_STRCHAR[0]); } else { if (!oldVal.IsStr) { qspSetError(QSP_ERR_TYPEMISMATCH); return; } qspConvertVariantTo(val, QSP_TRUE); QSP_STR(oldVal) = qspGetAddText(QSP_STR(oldVal), QSP_PSTR(val), -1, -1); } qspSetVarValueByReference(var, index, &oldVal); if (oldVal.IsStr) free(QSP_STR(oldVal)); } else if (qspIsInList(QSP_SUB QSP_DIV QSP_MUL, op)) { if (qspConvertVariantTo(val, QSP_FALSE)) { qspSetError(QSP_ERR_TYPEMISMATCH); return; } oldVal = qspGetVarValueByReference(var, index, *name == QSP_STRCHAR[0]); if (qspConvertVariantTo(&oldVal, QSP_FALSE)) { qspSetError(QSP_ERR_TYPEMISMATCH); free(QSP_STR(oldVal)); return; } if (op == QSP_SUB[0]) QSP_NUM(oldVal) -= QSP_PNUM(val); else if (op == QSP_DIV[0]) { if (!QSP_PNUM(val)) { qspSetError(QSP_ERR_DIVBYZERO); return; } QSP_NUM(oldVal) /= QSP_PNUM(val); } else QSP_NUM(oldVal) *= QSP_PNUM(val); qspConvertVariantTo(&oldVal, *name == QSP_STRCHAR[0]); qspSetVarValueByReference(var, index, &oldVal); if (oldVal.IsStr) free(QSP_STR(oldVal)); } }
int qspArrayPos(QSPVariant *args, int argsCount, QSP_BOOL isRegExp) { int num, count, ind; QSPVar *var; QSPVariant *val; QSP_CHAR *str; OnigUChar *tempBeg, *tempEnd; regex_t *onigExp; OnigErrorInfo onigInfo; QSP_BOOL isString; if (qspConvertVariantTo(args, argsCount == 2)) { qspSetError(QSP_ERR_TYPEMISMATCH); return -1; } if (argsCount == 2) { str = QSP_STR(args[0]); ind = 0; val = args + 1; } else { qspConvertVariantTo(args + 1, QSP_TRUE); str = QSP_STR(args[1]); ind = QSP_NUM(args[0]); val = args + 2; if (ind < 0) ind = 0; } if (!(var = qspVarReferenceWithType(str, QSP_FALSE, &isString))) return -1; if (qspConvertVariantTo(val, isRegExp || isString)) { qspSetError(QSP_ERR_TYPEMISMATCH); return -1; } if (isRegExp) { tempBeg = (OnigUChar *)QSP_PSTR(val); tempEnd = (OnigUChar *)qspStrEnd(QSP_PSTR(val)); if (onig_new(&onigExp, tempBeg, tempEnd, ONIG_OPTION_DEFAULT, QSP_ONIG_ENC, ONIG_SYNTAX_PERL_NG, &onigInfo)) { qspSetError(QSP_ERR_INCORRECTREGEXP); return -1; } } count = var->ValsCount; if (ind > count) ind = count; while (ind <= count) { if (val->IsStr) { if (!(ind < count && (str = var->Values[ind].Str))) str = QSP_FMT(""); if (isRegExp) { tempBeg = (OnigUChar *)str; tempEnd = (OnigUChar *)qspStrEnd(str); if (onig_match(onigExp, tempBeg, tempEnd, tempBeg, 0, ONIG_OPTION_NONE) == tempEnd - tempBeg) { onig_free(onigExp); return ind; } } else if (!qspStrsComp(str, QSP_PSTR(val))) return ind; } else { num = (ind < count ? var->Values[ind].Num : 0); if (num == QSP_PNUM(val)) return ind; } ++ind; } if (isRegExp) onig_free(onigExp); return -1; }
/* Получить значение указанного выражения */ AS3_Val QSPGetExprValue(void *param, AS3_Val args) { char *expr; QSP_CHAR *exprWC; char *strUTF8; QSPVariant v; AS3_Val res; AS3_ArrayValue(args, "StrType", &expr); if (qspIsExitOnError && qspErrorNum) return AS3_Null(); qspResetError(); if (qspIsDisableCodeExec) return AS3_Null(); exprWC = qspC2W(expr); v = qspExprValue(exprWC); free(exprWC); if (qspErrorNum) return AS3_Null(); if (v.IsStr) { strUTF8 = qspW2C(QSP_STR(v)); free(QSP_STR(v)); res = AS3_Object("isString:IntType, numVal:IntType, strVal:StrType", QSP_TRUE, 0, strUTF8); free(strUTF8); } else res = AS3_Object("isString:IntType, numVal:IntType, strVal:StrType", QSP_FALSE, QSP_NUM(v), 0); return res; }
QSP_BOOL qspStatementPlayFile(QSPVariant *args, int count, QSP_CHAR **jumpTo, int extArg) { int volume = (count == 2 ? QSP_NUM(args[1]) : 100); qspPlayFile(QSP_STR(args[0]), volume, QSP_TRUE); return QSP_FALSE; }
QSP_BOOL qspStatementShowMenu(QSPVariant *args, int count, QSP_CHAR **jumpTo, int extArg) { QSPVar *var; QSPVariant arg; int ind, itemsCount, maxItems, len; QSP_CHAR *menuLocs[QSP_MAXMENUITEMS], *imgPath, *str, *pos, *pos2; if (!(var = qspVarReferenceWithType(QSP_STR(args[0]), QSP_FALSE, 0))) return QSP_FALSE; qspCallDeleteMenu(); if (count == 1) { ind = 0; maxItems = QSP_MAXMENUITEMS; } else { ind = QSP_NUM(args[1]); if (ind < 0) ind = 0; if (count == 2) maxItems = QSP_MAXMENUITEMS; else { maxItems = QSP_NUM(args[2]); if (maxItems < 0) maxItems = 0; } } itemsCount = 0; while (ind < var->ValsCount) { if (itemsCount == maxItems) break; if (!((str = var->Values[ind].Str) && qspIsAnyString(str))) break; if (!(pos2 = qspInStrRChars(str, QSP_MENUDELIM, 0))) { qspSetError(QSP_ERR_COLONNOTFOUND); return QSP_FALSE; } if (itemsCount == QSP_MAXMENUITEMS) { qspSetError(QSP_ERR_CANTADDMENUITEM); return QSP_FALSE; } if (pos = qspInStrRChars(str, QSP_MENUDELIM, pos2)) { len = (int)(pos2 - pos) - 1; imgPath = (qspIsAnyString(++pos2) ? qspGetAbsFromRelPath(pos2) : 0); } else { pos = pos2; len = -1; imgPath = 0; } menuLocs[itemsCount++] = qspGetNewText(pos + 1, len); *pos = 0; qspCallAddMenuItem(str, imgPath); *pos = QSP_MENUDELIM[0]; if (imgPath) free(imgPath); ++ind; } if (itemsCount) { ind = qspCallShowMenu(); if (ind >= 0 && ind < itemsCount) { arg.IsStr = QSP_FALSE; QSP_NUM(arg) = ind + 1; qspExecLocByNameWithArgs(menuLocs[ind], &arg, 1, 0); } while (--itemsCount >= 0) free(menuLocs[itemsCount]); } return QSP_FALSE; }