📄 checks.cpp
字号:
// Copyright (C) 1999-2005 Open Source Telecom Corporation.// // This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.// // This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.// // As a special exception, you may use this file as part of a free software// library without restriction. Specifically, if other files instantiate// templates or use macros or inline functions from this file, or you compile// this file and link it with other files to produce an executable, this// file does not by itself cause the resulting executable to be covered by// the GNU General Public License. This exception does not however// invalidate any other reasons why the executable file might be covered by// the GNU General Public License.//// This exception applies only to the code released under the name GNU// ccScript. If you copy code from other releases into a copy of GNU// ccScript, as the General Public License permits, the exception does// not apply to the code that you add in this way. To avoid misleading// anyone as to the status of such modified files, you must delete// this exception notice from them.//// If you write modifications of your own for GNU ccScript, it is your choice// whether to permit this exception to apply to your modifications.// If you do not wish that, delete this exception notice.//#include "engine.h"using namespace std;using namespace ost;const char *ScriptChecks::chkKeywords(Line *line, ScriptImage *img){ char proto[80]; Name *scr = img->getCurrent(); unsigned idx = 0; const char *cp; if(getMember(line)) return "no members defined"; if(hasKeywords(line)) return "keywords defined, not used"; if(!line->argc) return "keyword list missing"; while(NULL != (cp = getOption(line, &idx))) { if(!isalpha(*cp) && !isdigit(*cp)) return "invalid keyword entry"; } snprintf(proto, sizeof(proto), "keywords.%s", scr->name); if(img->getPointer(proto)) return "keywords already defined for this function"; img->setPointer(proto, line); return "";}const char *ScriptChecks::chkUse(Line *line, ScriptImage *img){ return ScriptBinder::check(line, img);}const char *ScriptChecks::chkRestart(Line *line, ScriptImage *img){ if(getMember(line)) return "member not used in this command"; return chkNoArgs(line, img);}const char *ScriptChecks::chkCall(Line *line, ScriptImage *img){ const char *cp = getMember(line); unsigned idx = 0; Line *list = NULL; char proto[256]; unsigned len = 0, diff; Name *scr = img->getCurrent(); char *p; if(cp) return "members not used in this command"; cp = getOption(line, &idx); if(!cp) return "target label missing"; if(*cp == '&') ++cp; if(strchr(cp, ':') || stricmp(line->cmd, "call")) { snprintf(proto, sizeof(proto), "keywords.%s", cp); list = (Line *)img->getPointer(proto); } else if(!stricmp(line->cmd, "call")) { snprintf(proto, sizeof(proto), "keywords.%s", scr->name); p = strchr(proto, ':'); if(!p) p = proto + strlen(proto); diff = (unsigned)(p - proto); snprintf(proto + diff, sizeof(proto) - diff, "::%s", cp); list = (Line *)img->getPointer(proto); } if(*cp == '^' || *cp == '@') return "invalid label used"; cp = getOption(line, &idx); if(cp) return "only single target label allowed"; if(!list) return NULL; idx = 0; while(NULL != (cp = getOption(list, &idx))) { snprintf(proto + len, sizeof(proto) - len, "=%s", cp); len = (unsigned)strlen(proto); } if(len) { if(!useKeywords(line, proto)) return "invalid keyword used for function call"; } return NULL;}const char *ScriptChecks::chkSession(Line *line, ScriptImage *img){ if(getMember(line)) return "member not used in this command"; if(!line->argc) return NULL; if(line->argc > 1) return "only one session allowed"; return NULL;}const char *ScriptChecks::chkLock(Line *line, ScriptImage *img){ const char *cp; if(getMember(line)) return "member not used in this command"; if(!line->argc) return "lock symbol missing"; if(line->argc > 1) return "only one lock symbol allowed"; cp = line->args[0]; if(*cp != '%' && *cp != '&') return "lock target must be symbol"; return NULL;}const char *ScriptChecks::chkSignal(Line *line, ScriptImage *img){ const char *cp = getMember(line); if(cp) return "member not used in this command"; if(!line->argc) return "target handler missing"; if(line->argc > 1) return "only single target handler allowed"; cp = line->args[0]; if(*cp != '^') return "target must refer to signal handler"; return NULL;}const char *ScriptChecks::chkThrow(Line *line, ScriptImage *img){ const char *cp = getMember(line); if(cp) return "member not used in this command"; if(!line->argc) return "target handler missing"; if(line->argc > 1) return "only single target handler allowed"; cp = line->args[0]; if(*cp != '@' && *cp != '{') return "target must refer to event handler"; return NULL;}const char *ScriptChecks::chkGoto(Line *line, ScriptImage *img){ unsigned opt = 0; if(getMember(line)) return "goto has no member"; if(!getOption(line, &opt)) return "goto label missing"; if(getOption(line, &opt)) return "only one goto label"; return NULL;}const char *ScriptChecks::chkLabel(Line *line, ScriptImage *img){ const char *cp = getMember(line); if(cp) return "member not used in this command"; if(!line->argc) return "target label missing"; if(line->argc > 1) return "only single target label allowed"; cp = line->args[0]; if(*cp == '^' || *cp == '{' || *cp == '@') return "invalid label used"; return NULL;}const char *ScriptChecks::chkReturn(Line *line, ScriptImage *img){ const char *cp = getMember(line); if(cp) return "member not used in this command"; return NULL;} const char *ScriptChecks::chkIgnore(Line *line, ScriptImage *img){ return NULL;}const char *ScriptChecks::chkDecimal(Line *line, ScriptImage *img){ if(getMember(line)) return "member not used for this command"; if(line->argc != 1) return "decimal argument missing"; return NULL;}const char *ScriptChecks::chkOnlyCommand(Line *line, ScriptImage *img){ if(getMember(line)) return "member not used for this command"; return chkNoArgs(line, img);}const char *ScriptChecks::chkConditional(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 chkExpression(line, img);}const char *ScriptChecks::chkError(Line *line, ScriptImage *img){ if(getMember(line)) return "member not used for this command"; return chkOnlyArgs(line, img);}const char *ScriptChecks::chkNoArgs(Line *line, ScriptImage *img){ if(line->argc) return "arguments not used for this command"; return NULL;}const char *ScriptChecks::chkSlog(Line *line, ScriptImage *img){ const char *member = getMember(line); if(member) { if(!stricmp(member, "debug")) member = NULL; else if(!stricmp(member, "info")) member = NULL; else if(!stricmp(member, "notice")) member = NULL; else if(!strnicmp(member, "warn", 4)) member = NULL; else if(!strnicmp(member, "err", 3)) member = NULL; else if(!strnicmp(member, "crit", 4)) member = NULL; else if(!stricmp(member, "alert")) member = NULL; else if(!strnicmp(member, "emerg", 5)) member = NULL; } if(member) return "invalid or unknown log level used"; return chkHasArgs(line, img);}const char *ScriptChecks::chkHasArgs(Line *line, ScriptImage *img){ if(!line->argc) return "arguments missing"; return NULL;}const char *ScriptChecks::chkOnlyArgs(Line *line, ScriptImage *img){ if(!line->argc) return "arguments missing"; if(hasKeywords(line)) return "keywords not used for this command"; return NULL;} const char *ScriptChecks::chkOnlyOneArg(Line *line, ScriptImage *img){ if(line->argc > 1) return "too many arguments"; return chkOnlyArgs(line, img);}const char *ScriptChecks::chkRepeat(Line *line, ScriptImage *img){ if(getMember(line)) return "member not used for this command"; if(hasKeywords(line)) return "keywords not used for this command"; if(line->argc < 1) return "at least repeat value required"; return chkExpression(line, img);}const char *ScriptChecks::chkIndex(Line *line, ScriptImage *img){ if(getMember(line)) return "member not used for this command";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -