Пример #1
0
void fixEnvVariables(QString &x)
{
    int rep;
    QRegExp reg_var("\\$\\(.*\\)");
    reg_var.setMinimal( TRUE );
    while((rep = reg_var.search(x)) != -1)
	x.replace(rep, reg_var.matchedLength(), QString(getenv(x.mid(rep + 2, reg_var.matchedLength() - 3).latin1())));
}
Пример #2
0
QString
Option::fixString(QString string, uchar flags)
{
    const QString orig_string = string;
    static QHash<FixStringCacheKey, QString> *cache = 0;
    if(!cache) {
        cache = new QHash<FixStringCacheKey, QString>;
        qmakeAddCacheClear(qmakeDeleteCacheClear_QHashFixStringCacheKeyQString, (void**)&cache);
    }
    FixStringCacheKey cacheKey(string, flags);
    if(cache->contains(cacheKey)) {
        const QString ret = cache->value(cacheKey);
        //qDebug() << "Fix (cached) " << orig_string << "->" << ret;
        return ret;
    }

    //fix the environment variables
    if(flags & Option::FixEnvVars) {
        int rep;
        QRegExp reg_var("\\$\\(.*\\)");
        reg_var.setMinimal(true);
        while((rep = reg_var.indexIn(string)) != -1)
            string.replace(rep, reg_var.matchedLength(),
                           QString::fromLocal8Bit(qgetenv(string.mid(rep + 2, reg_var.matchedLength() - 3).toLatin1().constData()).constData()));
    }

    //canonicalize it (and treat as a path)
    if(flags & Option::FixPathCanonicalize) {
#if 0
        string = QFileInfo(string).canonicalFilePath();
#endif
        string = QDir::cleanPath(string);
    }

    if(string.length() > 2 && string[0].isLetter() && string[1] == QLatin1Char(':'))
        string[0] = string[0].toLower();

    //fix separators
    Q_ASSERT(!((flags & Option::FixPathToLocalSeparators) && (flags & Option::FixPathToTargetSeparators)));
    if(flags & Option::FixPathToLocalSeparators) {
#if defined(Q_OS_WIN32)
        string = string.replace('/', '\\');
#else
        string = string.replace('\\', '/');
#endif
    } else if(flags & Option::FixPathToTargetSeparators) {
        string = string.replace('/', Option::dir_sep).replace('\\', Option::dir_sep);
    }

    if (string.startsWith("\"") && string.endsWith("\"") ||
            string.startsWith("\'") && string.endsWith("\'"))
        string = string.mid(1, string.length()-2);

    //cache
    //qDebug() << "Fix" << orig_string << "->" << string;
    cache->insert(cacheKey, string);
    return string;
}
Пример #3
0
 char *reg_svar(
     const char *name, const char *def_v,
     char **storage, void (*callback)(), int flags
 )
 {
     String_Variable *nvar = new String_Variable(
         name, def_v, storage, callback, flags
     );
     reg_var(name, nvar);
     return *storage;
 }
Пример #4
0
 float reg_fvar(
     const char *name, float min_v, float def_v, float max_v,
     float *storage, void (*callback)(), int flags
 )
 {
     Float_Variable *nvar = new Float_Variable(
         name, min_v, def_v, max_v, storage, callback, flags
     );
     reg_var(name, nvar);
     return *storage;
 }
Пример #5
0
 int reg_ivar(
     const char *name, int min_v, int def_v, int max_v,
     int *storage, void (*callback)(), int flags
 )
 {
     Int_Variable *nvar = new Int_Variable(
         name, min_v, def_v, max_v, storage, callback, flags
     );
     reg_var(name, nvar);
     return *storage;
 }
Пример #6
0
static void regfunc(Pu *L)
{
	PU_NUMBER fpos = (PU_NUMBER)TOKEN.optype;
	NEXT_TOKEN;
	if (TOKEN.type == VAR)
	{	
		__pu_value fv(L);
		fv.SetType(FUN);
		fv.numVal() = fpos;
		fv.userdata() = L->cur_nup;
 		if (L->cur_nup)
 		{
 			L->cur_nup->refcount++;
 		}
        __pu_value *got = reg_var(L, TOKEN.value.strVal());
        TOKEN.regvar = got;
        *got = fv;
		L->cur_token = L->funclist[(int)fv.numVal()].end;
		NEXT_TOKEN;
		return;
	}
	error(L, 29);
}
Пример #7
0
static const __pu_value *exp(Pu *L) 
{
	Token *ptoken = &TOKEN;
	__pu_value *temp = NULL;
	do{
		if (ptoken->type == VAR)
		{
			NEXT_TOKEN;
			PuType tp = TOKEN.type;
			OperatorType nv = TOKEN.optype;
			if (tp == OP 
				&& (nv == OPT_SET || nv == OPT_ADDS || nv == OPT_SUBS || nv == OPT_MULS || nv == OPT_DIVS))
			{
				break;
			}
			PREV_TOKEN;
		}

		LOGC(L,temp);
        CHECK_EXP_RETURN(temp, temp);

	}while(false);

	PuType tp = TOKEN.type;
	OperatorType nv = TOKEN.optype;
	if (!(tp == OP 
		&& (nv == OPT_SET || nv == OPT_ADDS || nv == OPT_SUBS || nv == OPT_MULS || nv == OPT_DIVS)))
		return temp;

	if (ptoken->type != VAR)
	{
		error(L,22);
		__pu_value *result = NULL;
        MAKE_TEMP_VALUE(result);
        return result;
	}

	NEXT_TOKEN;
	const __pu_value *t = exp(L);
    CHECK_EXP_RETURN(t, t);

    switch (nv)
	{
	case OPT_SET:{// =
	if (!ptoken->regvar)
	{
		ptoken->regvar = reg_var(L, ptoken->value.strVal());
	}
        __pu_value *var_value = ptoken->regvar;
	//__pu_value *var_value = reg_var(L, ptoken->value.strVal());
	assert( !(var_value->type() == UNKNOWN && temp != NULL) );

        if (temp == NULL)
        {
            temp = var_value;
        }
        
        *temp = *t;
        return temp;}
	case OPT_ADDS:// +=
		{
			__pu_value *pv = get_varref(L, ptoken->value.strVal());
            ptoken->regvar = pv;
            CHECK_EXP_RETURNERR(pv);
			return &pv->operator+=(*t);

		}
	case OPT_SUBS:// -=
		{
			__pu_value *pv = get_varref(L, ptoken->value.strVal());
            ptoken->regvar = pv;
            CHECK_EXP_RETURNERR(pv);
			return &pv->operator-=(*t);
		}
	case OPT_MULS:// *=
		{
			__pu_value *pv = get_varref(L, ptoken->value.strVal());
            ptoken->regvar = pv;
            CHECK_EXP_RETURNERR(pv);
			return &pv->operator*=(*t);
		}
	case OPT_DIVS:// /=
		{
			__pu_value *pv = get_varref(L, ptoken->value.strVal());
            ptoken->regvar = pv;
            CHECK_EXP_RETURNERR(pv);
			return &pv->operator/=(*t);
		}
	default:
		;
	}

    return t;	
}