expression.cpp

来自「GNU ccScript is a C++ class framework fo」· C++ 代码 · 共 897 行 · 第 1/2 页

CPP
897
字号
		if(!sym->data[0])			return true;		time(&now);		if((long)now >= atol(sym->data))			return false;		return true;	}	if(!stricmp(op, "-expired"))	{		sym = mapSymbol(v2, 0);		if(!sym)			return false;		if(sym->type != symTIMER)			return false;		if(!sym->data[0])			return false;		time(&now);		if((long)now >= atol(sym->data))			return true;		return false;	}	if(!stricmp(op, "-modify") || !stricmp(op, "!const"))	{		sym = mapSymbol(v2, 0);		if(!sym)			return false;		switch(sym->type)		{		case symLOCK:		case symCONST:		case symSEQUENCE:			return false;		default:			return true;		}	}        if(!stricmp(op, "!modify") || !stricmp(op, "-const"))        {                sym = mapSymbol(v2, 0);                if(!sym)                        return true;                switch(sym->type)                {                case symLOCK:                  case symCONST:                case symSEQUENCE:                        return true;		default:			return false;                }        }          if(!stricmp(op, "-queue"))        {                sym = mapSymbol(v2, 0);                if(!sym)                        return false;                switch(sym->type)                {                case symSTACK:		case symFIFO:                        return true;		default:			return false;                }        }        if(!stricmp(op, "!queue"))        {                sym = mapSymbol(v2, 0);                if(!sym)                        return false;                switch(sym->type)                {                case symFIFO:		case symSTACK:                        return false;		default:			return true;                }        }	if(!stricmp(op, "-array"))	{                sym = mapSymbol(v2, 0);                if(!sym)                        return false;		switch(sym->type)		{		case symARRAY:			return true;		default:			return false;		}	}        if(!stricmp(op, "!array"))          {                sym = mapSymbol(v2, 0);                if(!sym)                        return true;                switch(sym->type)                {                case symARRAY:                        return false;		default:			return true;                }        }      	if(!stricmp(op, "-defined"))	{		sym = mapSymbol(v2, 0);		if(sym && sym->type != symINITIAL)			return true;		return false;	}	if(!stricmp(op, "!defined"))	{		sym = mapSymbol(v2, 0);		if(!sym || sym->type == symINITIAL)			return true;		return false;	}	if(!stricmp(op, "-active"))	{		sym = mapSymbol(v2, 0);		if(!sym)			return false;		a = (Array *)&sym->data;		switch(sym->type)		{		case symARRAY:			if(!a->tail)				return false;			return true;		case symSTACK:		case symFIFO:			if(a->tail == a->head)				return false;			return true;		case symLOCK:			if(strchr(sym->data, ':'))				return true;			return false;		case symCONST:		case symSEQUENCE:		case symNORMAL:		case symPROPERTY:		case symORIGINAL:		case symMODIFIED:		case symCOUNTER:			return true;		case symINITIAL:			return false;		case symTIMER:		case symNUMBER:			if(!sym->data[0])				return false;		default:			return true;		}	}	if(!stricmp(op, "!active"))	{		sym = mapSymbol(v2, 0);		if(!sym)			return false;		a = (Array *)&sym->data;		switch(sym->type)		{		case symARRAY:			if(!a->tail)				return true;			return false;		case symSTACK:		case symFIFO:			a = (Array *)&sym->data;			if(a->tail == a->head)				return true;			return false;		case symLOCK:			if(strchr(sym->data, ':'))				return false;			return true;		case symCONST:		case symSEQUENCE:		case symNORMAL:		case symPROPERTY:		case symORIGINAL:		case symMODIFIED:		case symCOUNTER:			return false;		case symINITIAL:			return true;		case symTIMER:		case symNUMBER:			if(!sym->data[0])				return true;		default:			return false;		}	}	if(!stricmp(op, "-empty"))	{		v2 = getContent(v2);		if(!v2)			return true;		if(!*v2)			return true;		return false;	}	if(!stricmp(op, "!empty"))	{		v2 = getContent(v2);		if(!v2)			return false;		if(!*v2)			return false;		return true;	}	if(!strcmp(v2, "("))	{		numericExpression(&ival, 1, frame[stack].decimal);		snprintf(n2, sizeof(n2), "%ld", ival);		v2 = n2;	}	else		v2 = getContent(v2);	if(!v1)		v1 = "";	if(!v2)		v2 = "";	if(!stricmp(op, "=") || !stricmp(op, "-eq"))	{		if(atol(v1) == atol(v2))			return true;		return false;	}	if(!stricmp(op, "<>") || !stricmp(op, "-ne"))	{		if(atol(v1) != atol(v2))			return true;		return false;	}	if(!stricmp(op, "==") || !stricmp(op, ".eq."))	{		if(!stricmp(v1, v2))			return true;		return false;	}	if(!stricmp(op, "!=") || !stricmp(op, ".ne."))	{		if(stricmp(v1, v2))			return true;		return false;	}	if(!stricmp(op, "$") || !stricmp(op, ".in."))	{		if(strstr(v2, v1))			return true;		return false;	}	if(!stricmp(op, "!$"))	{		if(strstr(v2, v1))			return false;		return true;	}#ifdef	HAVE_REGEX_H	if(!stricmp(op, "~") || !stricmp(op, "!~"))	{		frame[stack].tranflag = false;		rtn = false;		regex = new regex_t;		memset(regex, 0, sizeof(regex_t));		if(regcomp(regex, v2, REG_ICASE|REG_NOSUB|REG_NEWLINE))		{			regfree(regex);			delete regex;			return false;		}		if(regexec(regex, v1, 0, NULL, 0))			rtn = false;		else			rtn = true;		regfree(regex);		delete regex;		if(*op == '!')			return !rtn;		return rtn;	}#endif	if(!stricmp(op, "$<") || !stricmp(op, "$+") || !stricmp(op, ".prefix."))	{		if(!strnicmp(v1, v2, strlen(v1)))			return true;		return false;	}	if(!stricmp(op, "$>") || !stricmp(op, "$-") || !stricmp(op, ".suffix."))	{		l1 = strlen(v1);		l2 = strlen(v2);		if(l1 <= l2)			if(!strnicmp(v1, v2 + l2 - l1, l1))				return true;		return false;	}	if(!stricmp(op, "<") || !stricmp(op, "-lt"))	{		if(atol(v1) < atol(v2))			return true;		return false;	}	if(!stricmp(op, ".le."))	{		if(stricmp(v1, v2) <= 0)			return true;		return false;	}	if(!stricmp(op, ".ge."))	{		if(stricmp(v1, v2) >= 0)			return true;		return false;	}	if(!stricmp(op, "<=") || !stricmp(op, "=<") || !stricmp(op, "-le"))	{		if(atol(v1) <= atol(v2))			return true;		return false;	}	if(!stricmp(op, ">") || !stricmp(op, "-gt"))	{		if(atol(v1) > atol(v2))			return true;		return false;	}	if(!stricmp(op, ">=") || !stricmp(op, "=>") || !stricmp(op, "-ge"))	{		if(atol(v1) >= atol(v2))			return true;		return false;	}	// if no op, assume ifdef format	frame[stack].index = 1;	if(*v1)		return true;	return false;}bool ScriptInterp::conditional(void){	Line *line = getLine();	const char *joiner;	bool rtn;	bool andfalse = false;	bool ortrue = false;	for(;;)	{		rtn = conditionalExpression();		if(frame[stack].index < line->argc)			joiner = line->args[frame[stack].index];		else			joiner = "";		if(!stricmp(joiner, "and"))		{			if(!rtn)				andfalse = true;		}		else if(!stricmp(joiner, "or"))		{			if(rtn)				ortrue = true;		}		else			break;		++frame[stack].index;	}	if(andfalse)		return false;	if(ortrue)		return true;	return rtn;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?