예제 #1
0
QSP_CHAR *qspJoinStrs(QSP_CHAR **s, int count, QSP_CHAR *delim)
{
	int i, txtLen = 0, txtRealLen = 0, bufSize = 256, lastIndex = count - 1, delimLen = qspStrLen(delim);
	QSP_CHAR *txt = (QSP_CHAR *)malloc(bufSize * sizeof(QSP_CHAR));
	*txt = 0;
	for (i = 0; i < count; ++i)
	{
		if ((txtLen += qspStrLen(s[i])) >= bufSize)
		{
			bufSize = txtLen + 128;
			txt = (QSP_CHAR *)realloc(txt, bufSize * sizeof(QSP_CHAR));
		}
		qspStrCopy(txt + txtRealLen, s[i]);
		if (i == lastIndex) break;
		txtRealLen = txtLen;
		if ((txtLen += delimLen) >= bufSize)
		{
			bufSize = txtLen + 128;
			txt = (QSP_CHAR *)realloc(txt, bufSize * sizeof(QSP_CHAR));
		}
		qspStrCopy(txt + txtRealLen, delim);
		txtRealLen = txtLen;
	}
	return txt;
}
예제 #2
0
QSP_CHAR *qspFormatText(QSP_CHAR *txt, QSP_BOOL canReturnSelf)
{
	QSPVariant val;
	QSP_CHAR *newTxt, *lPos, *rPos;
	int oldRefreshCount, len, txtLen, oldTxtLen, bufSize;
	if (qspGetVarNumValue(QSP_FMT("DISABLESUBEX")))
	{
		if (canReturnSelf) return txt;
		return qspGetNewText(txt, -1);
	}
	lPos = qspStrStr(txt, QSP_LSUBEX);
	if (!lPos)
	{
		if (canReturnSelf) return txt;
		return qspGetNewText(txt, -1);
	}
	bufSize = 256;
	newTxt = (QSP_CHAR *)malloc(bufSize * sizeof(QSP_CHAR));
	txtLen = oldTxtLen = 0;
	oldRefreshCount = qspRefreshCount;
	do
	{
		len = (int)(lPos - txt);
		if ((txtLen += len) >= bufSize)
		{
			bufSize = txtLen + 128;
			newTxt = (QSP_CHAR *)realloc(newTxt, bufSize * sizeof(QSP_CHAR));
		}
		qspStrNCopy(newTxt + oldTxtLen, txt, len);
		oldTxtLen = txtLen;
		txt = lPos + QSP_LEN(QSP_LSUBEX);
		rPos = qspStrPos(txt, QSP_RSUBEX, QSP_FALSE);
		if (!rPos)
		{
			qspSetError(QSP_ERR_BRACKNOTFOUND);
			free(newTxt);
			return 0;
		}
		*rPos = 0;
		val = qspExprValue(txt);
		*rPos = QSP_RSUBEX[0];
		if (qspRefreshCount != oldRefreshCount || qspErrorNum)
		{
			free(newTxt);
			return 0;
		}
		qspConvertVariantTo(&val, QSP_TRUE);
		if ((txtLen += qspStrLen(QSP_STR(val))) >= bufSize)
		{
			bufSize = txtLen + 128;
			newTxt = (QSP_CHAR *)realloc(newTxt, bufSize * sizeof(QSP_CHAR));
		}
		qspStrCopy(newTxt + oldTxtLen, QSP_STR(val));
		free(QSP_STR(val));
		oldTxtLen = txtLen;
		txt = rPos + QSP_LEN(QSP_RSUBEX);
		lPos = qspStrStr(txt, QSP_LSUBEX);
	} while (lPos);
	return qspGetAddText(newTxt, txt, txtLen, -1);
}
예제 #3
0
QSP_CHAR *qspReplaceText(QSP_CHAR *txt, QSP_CHAR *searchTxt, QSP_CHAR *repTxt)
{
	int txtLen, oldTxtLen, bufSize, searchLen, repLen, len;
	QSP_CHAR *newTxt, *pos = qspStrStr(txt, searchTxt);
	if (!pos) return qspGetNewText(txt, -1);
	bufSize = 256;
	txtLen = oldTxtLen = 0;
	searchLen = qspStrLen(searchTxt);
	repLen = qspStrLen(repTxt);
	newTxt = (QSP_CHAR *)malloc(bufSize * sizeof(QSP_CHAR));
	do
	{
		len = (int)(pos - txt);
		if ((txtLen += len + repLen) >= bufSize)
		{
			bufSize = txtLen + 128;
			newTxt = (QSP_CHAR *)realloc(newTxt, bufSize * sizeof(QSP_CHAR));
		}
		qspStrNCopy(newTxt + oldTxtLen, txt, len);
		qspStrCopy(newTxt + oldTxtLen + len, repTxt);
		oldTxtLen = txtLen;
		txt = pos + searchLen;
		pos = qspStrStr(txt, searchTxt);
	} while (pos);
	return qspGetAddText(newTxt, txt, txtLen, -1);
}
예제 #4
0
int qspSplitStr(QSP_CHAR *str, QSP_CHAR *delim, QSP_CHAR ***res)
{
	int allocChars, count = 0, bufSize = 8, delimLen = qspStrLen(delim);
	QSP_CHAR *newStr, **ret, *curPos = str, *found = qspStrStr(str, delim);
	ret = (QSP_CHAR **)malloc(bufSize * sizeof(QSP_CHAR *));
	while (found)
	{
		allocChars = (int)(found - curPos);
		newStr = (QSP_CHAR *)malloc((allocChars + 1) * sizeof(QSP_CHAR));
		qspStrNCopy(newStr, curPos, allocChars);
		newStr[allocChars] = 0;
		if (++count > bufSize)
		{
			bufSize += 16;
			ret = (QSP_CHAR **)realloc(ret, bufSize * sizeof(QSP_CHAR *));
		}
		ret[count - 1] = newStr;
		curPos = found + delimLen;
		found = qspStrStr(curPos, delim);
	}
	newStr = (QSP_CHAR *)malloc((qspStrLen(curPos) + 1) * sizeof(QSP_CHAR));
	qspStrCopy(newStr, curPos);
	if (++count > bufSize)
		ret = (QSP_CHAR **)realloc(ret, count * sizeof(QSP_CHAR *));
	ret[count - 1] = newStr;
	*res = ret;
	return count;
}
예제 #5
0
파일: objects.c 프로젝트: yuryfdr/pbqsp
int qspObjIndex(QSP_CHAR *name)
{
	int i, objNameLen, bufSize;
	QSP_CHAR *uName, *buf;
	if (!qspCurObjectsCount) return -1;
	qspUpperStr(uName = qspGetNewText(name, -1));
	bufSize = 32;
	buf = (QSP_CHAR *)malloc(bufSize * sizeof(QSP_CHAR));
	for (i = 0; i < qspCurObjectsCount; ++i)
	{
		objNameLen = qspStrLen(qspCurObjects[i].Desc);
		if (objNameLen >= bufSize)
		{
			bufSize = objNameLen + 8;
			buf = (QSP_CHAR *)realloc(buf, bufSize * sizeof(QSP_CHAR));
		}
		qspStrCopy(buf, qspCurObjects[i].Desc);
		qspUpperStr(buf);
		if (!qspStrsComp(buf, uName))
		{
			free(uName);
			free(buf);
			return i;
		}
	}
	free(uName);
	free(buf);
	return -1;
}
예제 #6
0
static int qspActIndex(QSP_CHAR *name)
{
	int i, actNameLen, bufSize;
	QSP_CHAR *uName, *buf;
	if (!qspCurActionsCount) return -1;
	qspUpperStr(uName = qspGetNewText(name, -1));
	bufSize = 64;
	buf = (QSP_CHAR *)malloc(bufSize * sizeof(QSP_CHAR));
	for (i = 0; i < qspCurActionsCount; ++i)
	{
		actNameLen = qspStrLen(qspCurActions[i].Desc);
		if (actNameLen >= bufSize)
		{
			bufSize = actNameLen + 16;
			buf = (QSP_CHAR *)realloc(buf, bufSize * sizeof(QSP_CHAR));
		}
		qspStrCopy(buf, qspCurActions[i].Desc);
		qspUpperStr(buf);
		if (!qspStrsComp(buf, uName))
		{
			free(uName);
			free(buf);
			return i;
		}
	}
	free(uName);
	free(buf);
	return -1;
}
예제 #7
0
static int qspSearchPlayList(QSP_CHAR *file)
{
	QSP_CHAR *uName, *buf;
	int i, bufSize, itemLen, len;
	if (!qspPLFilesCount) return -1;
	len = qspStrLen(file);
	qspUpperStr(uName = qspGetNewText(file, len));
	bufSize = 32;
	buf = (QSP_CHAR *)malloc(bufSize * sizeof(QSP_CHAR));
	for (i = 0; i < qspPLFilesCount; ++i)
	{
		itemLen = qspStrLen(qspPLFiles[i]);
		if (itemLen >= bufSize)
		{
			bufSize = itemLen + 8;
			buf = (QSP_CHAR *)realloc(buf, bufSize * sizeof(QSP_CHAR));
		}
		qspStrCopy(buf, qspPLFiles[i]);
		qspUpperStr(buf);
		if (!qspStrsNComp(buf, uName, len) && qspIsInListEOL(QSP_PLVOLUMEDELIM, buf[len]))
		{
			free(uName);
			free(buf);
			return i;
		}
	}
	free(uName);
	free(buf);
	return -1;
}