checks.cpp

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

CPP
787
字号
	if(hasKeywords(line))		return "keywords not used for this command";	return chkExpression(line, img);}const char *ScriptChecks::chkExpr(Line *line, ScriptImage *img){        const char *cp = getMember(line);        if(cp && !isdigit(cp[1]))	{                cp = chkProperty(line, img);		if(cp)			return cp;	}	if(cp && atoi(++cp) > 6)		return "numbers only valid to 6 decimal places";	if(hasKeywords(line))		return "keywords not used in this command";	return chkExpression(line, img);}const char *ScriptChecks::chkChar(Line *line, ScriptImage *img){	if(getMember(line))		return "char always size 1";	if(hasKeywords(line))		return "no keywords used in char";	return chkAllVars(line, img);}const char *ScriptChecks::chkString(Line *line, ScriptImage *img){	const char *cp = getMember(line);	if(cp && !isdigit(cp[1]))		return "member when used must be size";	if(!useKeywords(line, "=size"))		return "invalid keyword used for this command";	return chkAllVars(line, img);}const char *ScriptChecks::chkDefine(Line *line, ScriptImage *img){        unsigned idx = 0;        const char *cp = line->cmd;        if(!line->argc)                return "define requires arguments";	while(idx < line->argc)	{		cp = line->args[idx++];		if(*cp == '=')		{			++cp;			++idx;		}		if(*cp == '%' || *cp == '&')			continue;		if(*cp == '.')			++cp;		cp = strchr(cp, ':');		if(cp)		{			++cp;			if(!isdigit(*cp))				return "invalid field size used";		}	}	return NULL;}const char *ScriptChecks::chkVarType(Line *line, ScriptImage *img){  	if(getMember(line))		return "no members in type";	if(hasKeywords(line))		return "no keywords in type";	return chkAllVars(line, img);}	const char *ScriptChecks::chkVar(Line *line, ScriptImage *img)    {        const char *cp = getMember(line);        if(cp && !isdigit(cp[1]))	{                cp = chkProperty(line, img);		if(!cp)			return "property invalid for var";	}        else                cp = NULL;        if(!useKeywords(line, "=size=value"))                return "invalid keyword used";        return chkAllVars(line, img);}const char *ScriptChecks::chkNumber(Line *line, ScriptImage *img){	const char *cp = getMember(line);	if(cp && !isdigit(cp[1]))		return "member must be decimal place";	if(cp && atoi(++cp) > 6)		return "numbers supported only to 6 decimal places";	if(!useKeywords(line, "=decimal"))		return "invalid keyword used";	return chkAllVars(line, img);}const char *ScriptChecks::chkPack(Line *line, ScriptImage *img){	if(getMember(line))		return "member not used for this command";	if(!useKeywords(line, "=field=offset=token=size=quote=prefix=suffix"))		return "invalid keyword used for this command";	return chkAllVars(line, img);}const char *ScriptChecks::chkClear(Line *line, ScriptImage *img){	if(getMember(line))		return "member not used for this command";	if(hasKeywords(line))		return "keywords not used for this command";	return chkAllVars(line, img);}const char *ScriptChecks::chkExpression(Line *line, ScriptImage *img){	unsigned idx = 0;	unsigned paren = 0;	const char *cp;	while(NULL != (cp = getOption(line, &idx)))	{		if(*cp == '(')			++paren;		else if(*cp == ')')			--paren;		if(paren < 0)			return "unbalanced parenthesis in expression";	}	if(paren)		return "unbalanced parenthesis in expression";	return NULL;}	const char *ScriptChecks::chkAllVars(Line *line, ScriptImage *img){	unsigned idx = 0;	const char *cp;	while(NULL != (cp = getOption(line, &idx)))	{		switch(*cp)		{		case '%':		case '@':		case '&':			break;		default:			return "arguments must be symbols";		}	}	return chkHasArgs(line, img);}const char *ScriptChecks::chkType(Line *line, ScriptImage *img){	if(getMember(line))		return "type does not use member";	if(hasKeywords(line))		return "type does not use keyword";	if(line->argc < 1)		return "type requires at least one var";		return chkAllVars(line, img);}const char *ScriptChecks::chkFirstVar(Line *line, ScriptImage *img){	const char *cp;	unsigned idx = 0;	cp = getOption(line, &idx);	if(!cp)		return "too few arguments";	if(*cp != '%' && *cp != '@' && *cp != '&')		return "first argument must be symbol";	return chkProperty(line, img);}const char *ScriptChecks::chkArray(Line *line, ScriptImage *img){	const char *cp = getMember(line);	if(cp && !isdigit(*(++cp)))		return "invalid member used";	if(!useKeywords(line, "=count=size"))		return "invalid keywords used";	if(!getMember(line))		if(!findKeyword(line, "count"))			return "requires count either in member or keyword";	return chkAllVars(line, img);}const char *ScriptChecks::chkSet(Line *line, ScriptImage *img){	const char *cp = getMember(line);	if(cp && !isdigit(*(++cp)))		cp = chkProperty(line, img);	else		cp = NULL;	if(cp)		return cp;	if(!useKeywords(line, "=size=offset"))		return "invalid keyword used";	return chkFirstVar(line, img);	}const char *ScriptChecks::chkFor(Line *line, ScriptImage *img){	if(getMember(line))		return "member not used for this command";	if(!useKeywords(line, "=index=size"))		return "invalid keyword used";	return chkFirstVar(line, img);}const char *ScriptChecks::chkForeach(Line *line, ScriptImage *img){	if(getMember(line))		return "member not used for this command";        if(!useKeywords(line, "=index=size=token"))                return "invalid keyword used";	if(getCount(line) != 2)		return "incorrect number of arguments";	return chkAllVars(line, img);}const char *ScriptChecks::chkCat(Line *line, ScriptImage *img){	if(getMember(line))		return "member not used for this command";	if(hasKeywords(line))		return "keywords not used for this command";	return chkFirstVar(line, img);}const char *ScriptChecks::chkRemove(Line *line, ScriptImage *img)     {        if(getMember(line))                  return "member not used for this command";          if(!useKeywords(line, "=field=token=offset"))                return "invalid keyword used for this command";        return chkFirstVar(line, img);}const char *ScriptChecks::chkSequence(Line *line, ScriptImage *img){	if(hasKeywords(line))		return "keywords not used for this command";	if(getMember(line))		return "member not used for this command";	return chkFirstVar(line, img);}const char *ScriptChecks::chkConst(Line *line, ScriptImage *img){	const char *cp = chkProperty(line, img);	if(cp)		return cp;	if(hasKeywords(line))		return "keywords not used for this command";	return chkFirstVar(line, img);}const char *ScriptChecks::chkCounter(Line *line, ScriptImage *img){	const char *cp = getMember(line);	if(cp && atoi(++cp) < 1)		return "member must be initial value and greater than zero";	if(hasKeywords(line))		return "keywords not used for this command";	return chkAllVars(line, img);}const char *ScriptChecks::chkTimer(Line *line, ScriptImage *img){	if(getMember(line))		return "timer has no member";	if(!useKeywords(line, "=offset=expires"))		return "invalid keyword used for this command";	return chkAllVars(line, img);}const char *ScriptChecks::chkRefArgs(Line *line, ScriptImage *img){	if(hasKeywords(line))		return "keywords not used for this command";	if(getMember(line))		return "member not used for this command";	if(line->argc != 2)		return "invalid number of arguments";	if(!isSymbol(line->args[0]))		return "reference target not symbol";	if(!isSymbol(line->args[1]))		return "reference source not symbol";	return NULL;}const char *ScriptChecks::chkProperty(Line *line, ScriptImage *img){        const char *cp = getMember(line);        ScriptProperty *prop;                                if(!cp)                 return NULL;        prop = ScriptProperty::find(++cp);        if(!prop)                return "unknown script property referenced";	return NULL;}

⌨️ 快捷键说明

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