Пример #1
0
void VDScriptInterpreter::ExecuteLine(const char *s) {
	int t;

	mErrorExtraToken.clear();

	TokenBegin(s);

	while(t = Token()) {
		if (isExprFirstToken(t)) {
			TokenUnput(t);
			VDASSERT(mStack.empty());
			ParseExpression();

			VDASSERT(!mStack.empty());

			VDScriptValue& val = mStack.back();

			mStack.pop_back();
			VDASSERT(mStack.empty());

			if (Token() != ';')
				SCRIPT_ERROR(SEMICOLON_EXPECTED);
		} else if (t == TOK_DECLARE) {

			do {
				t = Token();

				if (t != TOK_IDENT)
					SCRIPT_ERROR(IDENTIFIER_EXPECTED);

				VariableTableEntry *vte = vartbl.Declare(szIdent);

				t = Token();

				if (t == '=') {
					ParseExpression();

					VDASSERT(!mStack.empty());
					vte->v = mStack.back();
					mStack.pop_back();

					t = Token();
				}

			} while(t == ',');

			if (t != ';')
				SCRIPT_ERROR(SEMICOLON_EXPECTED);

		} else
			SCRIPT_ERROR(PARSE_ERROR);
	}

	VDASSERT(mStack.empty());

	GC();
}
Пример #2
0
bool VDRegistryKey::getString(const char *pszName, VDStringA& str) const {
	DWORD type, s = sizeof(DWORD);

	if (!pHandle || RegQueryValueEx((HKEY)pHandle, pszName, 0, &type, NULL, &s) || type != REG_SZ)
		return false;

	str.resize(s);
	if (RegQueryValueEx((HKEY)pHandle, pszName, 0, NULL, (BYTE *)str.data(), &s))
		return false;

	if (!s)
		str.clear();
	else
		str.resize(strlen(str.c_str()));		// Trim off pesky terminating NULLs.

	return true;
}
Пример #3
0
void VDDumpChangeLog() {
    HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(IDR_CHANGES), "STUFF");

    if (!hResource)
        return;

    HGLOBAL hGlobal = LoadResource(NULL, hResource);
    if (!hGlobal)
        return;

    LPVOID lpData = LockResource(hGlobal);
    if (!lpData)
        return;

    const char *s = (const char *)lpData;

    while(*s!='\r') ++s;

    s+=2;

    tTextStream lineBuffer;
    VDStringA breakLineBuffer;

    bool foundNonIndentedLine = false;

    while(*s) {
        // parse line
        if (*s != ' ') {
            if (foundNonIndentedLine)
                break;

            foundNonIndentedLine = true;
        }

        const char *end = s;
        while(*end && *end != '\r' && *end != '\n')
            ++end;

        lineBuffer.clear();
        append_cooked(lineBuffer, s, end, false);

        // skip line termination
        s = end;
        if (*s == '\r' || *s == '\n') {
            ++s;
            if ((s[0] ^ s[-1]) == ('\r' ^ '\n'))
                ++s;
        }

        lineBuffer.push_back(0);

        // break into lines
        const char *t = lineBuffer.data();
        int maxLine = 78;

        breakLineBuffer.clear();

        do {
            const char *lineStart = t;
            const char *break1 = NULL;
            const char *break2 = NULL;

            do {
                while(*t && *t != ' ')
                    ++t;

                const char *u = t;

                while(*t && *t == ' ')
                    ++t;

                if (u - lineStart > maxLine) {
                    if (!break1) {
                        break1 = u + maxLine;
                        break2 = break1;
                    }

                    break;
                }

                break1 = u;
                break2 = t;
            } while(*t);

            breakLineBuffer.append(lineStart, break1);
            VDLog(kVDLogInfo, VDTextAToW(breakLineBuffer.data(), breakLineBuffer.size()));

            t = break2;
            breakLineBuffer.clear();
            breakLineBuffer.resize(5, ' ');

            maxLine = 73;
        } while(*t);
    }
}