コード例 #1
0
ファイル: variables.cpp プロジェクト: aqssxlzc/FastQSP
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));
  }
}
コード例 #2
0
ファイル: variables.c プロジェクト: ktoto1/QtQSP
QSPVariant qspGetVar(QSP_CHAR *name)
{
	QSPVar *var;
	int index;
	if (!(var = qspGetVarData(name, QSP_FALSE, &index))) return qspGetEmptyVariant(QSP_FALSE);
	return qspGetVarValueByReference(var, index, *name == QSP_STRCHAR[0]);
}