static QSP_CHAR *qspGetVarNameOnly(QSP_CHAR *s) { QSP_CHAR *brackPos = qspStrChar(s, QSP_LSBRACK[0]); if (brackPos) return qspGetNewText(s, (int)(brackPos - s)); return qspDelSpc(s); }
void qspStatementLocal(QSP_CHAR *s) { QSPVariant v; QSPVar *var; QSP_BOOL isVarFound; QSP_CHAR *curPos, *varName, *commaPos, *eqPos; int i, groupInd, count, bufSize, oldRefreshCount; s = qspSkipSpaces(s); if (!(*s)) { qspSetError(QSP_ERR_SYNTAX); return; } groupInd = qspSavedVarsGroupsCount - 1; count = bufSize = qspSavedVarsGroups[groupInd].VarsCount; isVarFound = QSP_FALSE; curPos = s; eqPos = qspStrPos(curPos, QSP_EQUAL, QSP_FALSE); if (eqPos) *eqPos = 0; while (1) { /* Skip type char */ if (*curPos == QSP_STRCHAR[0]) ++curPos; /* Get variable's name */ commaPos = qspStrPos(curPos, QSP_COMMA, QSP_FALSE); if (commaPos) { *commaPos = 0; varName = (eqPos ? qspGetVarNameOnly(curPos) : qspDelSpc(curPos)); *commaPos = QSP_COMMA[0]; } else varName = (eqPos ? qspGetVarNameOnly(curPos) : qspDelSpc(curPos)); qspUpperStr(varName); /* Check for the existence */ for (i = 0; i < count; ++i) { if (!qspStrsComp(varName, qspSavedVarsGroups[groupInd].Vars[i].Name)) { isVarFound = QSP_TRUE; break; } } /* Get variable's data */ if (isVarFound) { /* Already exists */ isVarFound = QSP_FALSE; free(varName); } else { /* Add variable to the local group */ if (!(var = qspVarReference(varName, QSP_FALSE))) { free(varName); if (eqPos) *eqPos = QSP_EQUAL[0]; return; } if (count >= bufSize) { bufSize = count + 4; qspSavedVarsGroups[groupInd].Vars = (QSPVar *)realloc(qspSavedVarsGroups[groupInd].Vars, bufSize * sizeof(QSPVar)); } qspMoveVar(qspSavedVarsGroups[groupInd].Vars + count, var); qspSavedVarsGroups[groupInd].Vars[count].Name = varName; qspSavedVarsGroups[groupInd].VarsCount = ++count; } if (!commaPos) break; curPos = qspSkipSpaces(commaPos + QSP_LEN(QSP_COMMA)); if (!(*curPos)) { qspSetError(QSP_ERR_SYNTAX); if (eqPos) *eqPos = QSP_EQUAL[0]; return; } } if (eqPos) { oldRefreshCount = qspRefreshCount; v = qspExprValue(eqPos + QSP_LEN(QSP_EQUAL)); if (qspRefreshCount != oldRefreshCount || qspErrorNum) { *eqPos = QSP_EQUAL[0]; return; } varName = qspDelSpcCanRetSelf(s); qspSetVarValue(varName, &v, QSP_EQUAL[0]); if (varName != s) free(varName); if (v.IsStr) free(QSP_STR(v)); *eqPos = QSP_EQUAL[0]; } }
static int qspProcessPreformattedStrings(QSPString data, QSPLineOfCode **strs) { QSPLineOfCode *ret, *line; QSP_BOOL isNewLine; QSP_CHAR *str, *pos, quot = 0; QSPString strsDelim; int lineNum = 0, lastLineNum = 0, count = 0, quotsCount = 0, strLen = 0, bufSize = 8, strBufSize = 256; str = (QSP_CHAR *)malloc(strBufSize * sizeof(QSP_CHAR)); ret = (QSPLineOfCode *)malloc(bufSize * sizeof(QSPLineOfCode)); strsDelim = QSP_STATIC_STR(QSP_STRSDELIM); pos = data.Str; while (pos < data.End) { isNewLine = (qspStrsNComp(data, strsDelim, QSP_STATIC_LEN(QSP_STRSDELIM)) == 0); if (isNewLine) ++lineNum; if (quotsCount || quot || !isNewLine) { if (strLen >= strBufSize) { strBufSize = strLen + 256; str = (QSP_CHAR *)realloc(str, strBufSize * sizeof(QSP_CHAR)); } str[strLen++] = *pos; if (quot) { if (*pos == quot) { if (++pos < data.End && *pos == quot) { if (strLen >= strBufSize) { strBufSize = strLen + 256; str = (QSP_CHAR *)realloc(str, strBufSize * sizeof(QSP_CHAR)); } str[strLen++] = *pos++; } else quot = 0; } else ++pos; } else { if (*pos == QSP_LQUOT[0]) ++quotsCount; else if (*pos == QSP_RQUOT[0]) { if (quotsCount) --quotsCount; } else if (qspIsInList(QSP_QUOTS, *pos)) quot = *pos; ++pos; } } else { if (count >= bufSize) { bufSize = count + 16; ret = (QSPLineOfCode *)realloc(ret, bufSize * sizeof(QSPLineOfCode)); } line = ret + count++; line->Str = qspGetNewText(qspDelSpc(qspStringFromLen(str, strLen))); line->LineNum = lastLineNum; line->Label = qspNullString; line->Stats = 0; lastLineNum = lineNum; strLen = 0; pos += QSP_STATIC_LEN(QSP_STRSDELIM); } data.Str = pos; } if (count >= bufSize) ret = (QSPLineOfCode *)realloc(ret, (count + 1) * sizeof(QSPLineOfCode)); line = ret + count++; line->Str = qspGetNewText(qspDelSpc(qspStringFromLen(str, strLen))); line->LineNum = lastLineNum; line->Label = qspNullString; line->Stats = 0; free(str); *strs = ret; return count; }