UCHAR include( int c ) { size_t n; char *s; if (c == '\n' || c == EOF) makeError(line,SYNTAX_NO_NAME); *buf = (char) c; if (!fgets(buf+1,MAXBUF - 1,file)) { if (feof(file)) makeError(line,SYNTAX_UNEXPECTED_TOKEN,"EOF"); makeError(line,CANT_READ_FILE); } n = _tcslen(buf) - 1; if (buf[n] == '\n') { buf[n] = '\0'; } s = buf; while (WHITESPACE(*s)) ++s; return(processIncludeFile(s)); }
void makeMacro() { STRINGLIST *q; char *t; if (_tcschr(name, '$')) { // expand name q = macros; t = expandMacros(name, ¯os); // name holds result if (!*t) // error if macro to left of = is undefined makeError(currentLine, SYNTAX_NO_MACRO_NAME); while ((macros = q)) { q = q->next; FREE_STRINGLIST(macros); } FREE(name); name = t; } for (t = name; *t && MACRO_CHAR(*t); t = _tcsinc (t)) // Check for illegal chars ; if (*t) makeError(currentLine, SYNTAX_BAD_CHAR, *t); fInheritUserEnv = (BOOL)TRUE; // Put Env Var in Env & macros in table. if (!putMacro(name, string, 0)) { FREE(name); FREE(string); } name = string = NULL; }
void assignBuildCommands() { BOOL okToFreeList = TRUE; BOOL fFirstTarg = (BOOL)TRUE; STRINGLIST *p; const char *which = NULL; if (ON(actionFlags, A_RULE)) // no macros found yet for inference rules rules->buildCommands = list; else if (ON(actionFlags, A_SILENT) || ON(actionFlags, A_IGNORE) || ON(actionFlags, A_PRECIOUS) || ON(actionFlags, A_SUFFIX) ) { if (list) { if (ON(actionFlags, A_SILENT)) which = silent; else if (ON(actionFlags, A_IGNORE)) which = ignore; else if (ON(actionFlags, A_PRECIOUS)) which = precious; else if (ON(actionFlags, A_SUFFIX)) which = suffixes; makeError(currentLine, CMDS_ON_PSEUDO, which); } } else { block->buildCommands = list; block->buildMacros = macros; block->flags = currentFlags; while ((p = targetList)) { // make a struct for each targ if (doSpecial(p->text)) // in list, freeing list when makeError(currentLine, MIXED_TARGETS); makeTarget(p->text, fFirstTarg, &block); // done, don't free name if (!makeTargets) { // field -- it's still in use makeTargets = p; // if no targs given on cmdlin okToFreeList = FALSE; // put first target(s) from } // mkfile in makeTargets list targetList = p->next; // (makeTargets defined in if (okToFreeList) // nmake.c) FREE_STRINGLIST(p); if (fFirstTarg) fFirstTarg = (BOOL)FALSE; } } targetList = NULL; list = NULL; macros = NULL; block = NULL; actionFlags = 0; }
bool Parser::Impl::parseBlock() { // our ABNF: // block := "{" [ command-list ] "}" if(!obtainToken() || atEnd()) return false; if(token() != Lexer::Special || tokenValue() != "{") return false; if(scriptBuilder()) scriptBuilder()->blockStart(); consumeToken(); if(!obtainToken()) return false; if(atEnd()) { makeError(Error::PrematureEndOfBlock); return false; } if(token() == Lexer::Identifier) { if(!parseCommandList()) { assert(error()); return false; } } if(!obtainToken()) return false; if(atEnd()) { makeError(Error::PrematureEndOfBlock); return false; } if(token() != Lexer::Special || tokenValue() != "}") { makeError(Error::NonCommandInCommandList); return false; } if(scriptBuilder()) scriptBuilder()->blockEnd(); consumeToken(); return true; }
bool Parser::Impl::parseNumber() { // The lexer returns the number including the quantifier as a // single token value. Here, we split is an check that the number // is not out of range: if(!obtainToken() || atEnd()) return false; if(token() != Lexer::Number) return false; // number: unsigned long result = 0; unsigned int i = 0; const QCString s = tokenValue().latin1(); for(const unsigned int len = s.length() ; i < len && isdigit(s[i]) ; ++i) { const unsigned long digitValue = s[i] - '0' ; if(willOverflowULong(result, digitValue)) { makeError(Error::NumberOutOfRange); return false; } else { result *= 10 ; result += digitValue ; } } // optional quantifier: char quantifier = '\0'; if(i < s.length()) { assert(i + 1 == s.length()); quantifier = s[i]; const unsigned long factor = factorForQuantifier(quantifier); if(result > double(ULONG_MAX) / double(factor)) { makeError(Error::NumberOutOfRange); return false; } result *= factor; } if(scriptBuilder()) scriptBuilder()->numberArgument(result, quantifier); consumeToken(); return true; }
Value *ExpressionCompiler::evaluate(NONS_VariableStore *store,bool invert_terms){ if (!this->expr) return makeError(this->error); std::vector<Expression *> full_expression; this->expr->vectorize(full_expression); std::vector<Value *> evaluation_stack; ErrorCode e=this->run(store,invert_terms,full_expression,evaluation_stack,full_expression.size()); if (e!=NONS_NO_ERROR) return makeError(e); evaluation_stack[0]->negate(invert_terms); return evaluation_stack[0]; }
Optional<SchemaError> validate(ValidationContext& vc, const dynamic& value) const override { if (vc.validate(validator_.get(), value)) { return none; } return makeError("Expected schema validation to fail", value); }
void makeTarget( char *s, BOOL firstTarg, BUILDBLOCK **block ) { BUILDLIST *build; MAKEOBJECT *object; if (!*block) *block = makeNewBuildBlock(); if (firstTarg) { build = makeNewBldListElement(); build->buildBlock = *block; } else build = makeBuildList(*block); if ((object = findTarget(s))) { if (ON(object->flags2, F2_DOUBLECOLON) != ON(currentFlags, F2_DOUBLECOLON)) makeError(currentLine, MIXED_SEPARATORS); appendItem((STRINGLIST**)&(object->buildList), (STRINGLIST*)build); FREE(s); } else { build->next = NULL; object = makeNewObject(); object->name = s; object->buildList = build; object->flags2 = currentFlags; prependItem((STRINGLIST**)targetTable+hash(s, MAXTARGET, (BOOL)TRUE), (STRINGLIST*)object); } }
Optional<SchemaError> validate(ValidationContext& vc, const dynamic& value) const override { std::vector<SchemaError> errors; for (const auto& val : validators_) { if (auto se = vc.validate(val.get(), value)) { errors.emplace_back(*se); } } const int success = validators_.size() - errors.size(); if (success == 0) { return makeError("at least one valid schema", value); } else if (success > 1 && type_ == Type::EXACTLY_ONE) { return makeError("exactly one valid schema", value); } return none; }
void getRestOfLine( char *s[], size_t *n ) { size_t temp; char *t; t = buf; while ((*s)[*n-1] != '\n') { // get rest of line if (!fgets(t,MAXBUF,file)) break; // we hit EOF temp = _tcslen(t); if (t[temp-2] == '\\' && t[temp-1] == '\n') { //Replace \n by \0 and \\ by a space; Also reset length t[temp-1] = '\0'; t[temp-2] = ' '; } temp = *n; *n += _tcslen(t); *s = (char *) REALLOC(*s,*n+1); // + 1 for NULL byte if (!*s) makeError(line, MACRO_TOO_LONG); _tcscpy(*s+temp,t); } }
Optional<SchemaError> validate(ValidationContext& vc, const dynamic& value) const override { if (!value.isArray()) { return none; } if (itemsValidator_) { for (const auto& v : value) { if (auto se = vc.validate(itemsValidator_.get(), v)) { return se; } } return none; } size_t pos = 0; for (; pos < value.size() && pos < itemsValidators_.size(); ++pos) { if (auto se = vc.validate(itemsValidators_[pos].get(), value[pos])) { return se; } } if (!allowAdditionalItems_ && pos < value.size()) { return makeError("no more additional items", value); } if (additionalItemsValidator_) { for (; pos < value.size(); ++pos) { if (auto se = vc.validate(additionalItemsValidator_.get(), value[pos])) { return se; } } } return none; }
void readCommandFile( char *name ) { char *s, // buffer **vector; // local versions of arg vector unsigned count = 0; // count size_t n; if (!(file = FILEOPEN(name,"rt"))) makeError(0,CANT_OPEN_FILE,name); vector = NULL; // no args yet while (fgets(buf,MAXBUF,file)) { n = _tcslen(buf); // if we didn't get the whole line, OR the line ended with a backSlash if ((n == MAXBUF-1 && buf[n-1] != '\n') || (buf[n-1] == '\n' && buf[n-2] == '\\') ) { if (buf[n-2] == '\\' && buf[n-1] == '\n') { // Replace \n by \0 and \\ by a space; Also reset length buf[n-1] = '\0'; buf[n-2] = ' '; n--; } s = makeString(buf); getRestOfLine(&s,&n); } else s = buf; processLine(s,&count,&vector); // separate into args if (s != buf) FREE(s); } if (fclose(file) == EOF) makeError(0, ERROR_CLOSING_FILE, name); parseCommandLine(count,vector); // evaluate the args while (count--) // free the arg vector if(vector[count]) FREE(vector[count]); // NULL entries mean that the space the } // entry used to pt to is still in use
Optional<SchemaError> validate(ValidationContext&, const dynamic& value) const override { auto it = std::find(allowedTypes_.begin(), allowedTypes_.end(), value.type()); if (it == allowedTypes_.end()) { return makeError("a value of type ", typeStr_, value); } return none; }
void addItemToList() { STRINGLIST *p; // from lexer STRINGLIST *NewList; if (name) { SET(actionFlags, A_TARGET); startNameList(); name = NULL; } if (ON(actionFlags, A_TARGET)) { if (isRule(buf)) { if (ON(actionFlags, A_RULE)) makeError(currentLine, TOO_MANY_RULE_NAMES); makeError(currentLine, MIXED_RULES); } } p = makeNewStrListElement(); if (ON(actionFlags, A_STRING)) { // we collect macros p->text = string; // for dependents & string = NULL; // build lines for } else // non-implicit rules p->text = makeString(buf); NewList = p; // build lines for if (OFF(actionFlags, A_RULE) // rules get expanded || ON(actionFlags, A_TARGET)) // after entire make- { findMacroValues(p->text, ¯os, NULL, NULL, 0, 0, 0); // file parsed } if (ON(actionFlags, A_TARGET)) { p = macros; expandFileNames("$", &NewList, ¯os); expandFileNames("*?", &NewList, NULL); while ((macros = p)) { p = p->next; FREE_STRINGLIST(macros); } } appendItem(&list, NewList); }
Optional<SchemaError> validate(ValidationContext&, const dynamic& value) const override { if (!value.isString() || regex_.empty()) { return none; } if (!boost::regex_search(value.getString().toStdString(), regex_)) { return makeError("string matching regex", value); } return none; }
void popFileStack() { if (fclose(file) == EOF) makeError(0, ERROR_CLOSING_FILE, fName); FREE(fName); file = incStack[--incTop].file; fName = incStack[incTop].name; line = incStack[incTop].line; }
//------------------------------------------------------------------------------------------------------------------ ///This handles command directed at this oject pMolStackObject* pMolStackObject::exec(pMolCmd* cmd, pMolKernelInterface* interface) { //no paramaters, return this as object if (cmd==NULL) return (pMolStackObject*) this; //no paramaters, return me //if no command but not empty, something is wrong (needs to be empty or have subcommand) so return with error if (cmd->type() != pMolCmd::NAME) return makeError(interface,"exec","empty field or parameter list expected"); pMolCmdName* cmdName = dynamic_cast<pMolCmdName*>(cmd); //safe to assume this is a pMolCmdName return NULL; //return command(cmdName, interface); };
Optional<SchemaError> validate(ValidationContext&, const dynamic& value) const override { if (!schema_.isArray()) { return none; } for (const auto& item : schema_) { if (value == item) { return none; } } return makeError("one of enum values: ", schema_, value); }
Optional<SchemaError> validate(ValidationContext&, const dynamic& value) const override { if (value.isObject()) { for (const auto& prop : properties_) { auto* p = value.get_ptr(prop); if (!value.get_ptr(prop)) { return makeError("to have property", prop, value); } } } return none; }
// append dependents to existing ones (if any) void assignDependents() { const char *which = NULL; if (ON(actionFlags, A_DEPENDENT)) CLEAR(actionFlags, A_DEPENDENT); if (ON(actionFlags, A_RULE)) { if (list) makeError(currentLine, DEPENDENTS_ON_RULE); } else if (ON(actionFlags, A_SILENT) || ON(actionFlags, A_IGNORE)) { if (list) { if (ON(actionFlags, A_SILENT)) which = silent; else if (ON(actionFlags, A_IGNORE)) which = ignore; makeError(currentLine, DEPS_ON_PSEUDO, which); } } else if (ON(actionFlags, A_SUFFIX)) { if (!list) clearSuffixes(); else appendPseudoTargetList(&dotSuffixList, list); } else if (ON(actionFlags, A_PRECIOUS)) { if (list) appendPseudoTargetList(&dotPreciousList, list); } else { block = makeNewBuildBlock(); block->dependents = list; block->dependentMacros = macros; } list = NULL; macros = NULL; SET(actionFlags, A_STRING); // expecting build cmd }
Optional<SchemaError> validate(ValidationContext&, const dynamic& value) const override { if (length_ < 0) { return none; } if (value.type() != type_) { return none; } if (!Comparison()(length_, value.size())) { return makeError("different length string/array/object", value); } return none; }
Optional<SchemaError> validate(ValidationContext&, const dynamic& value) const override { if (!unique_ || !value.isArray()) { return none; } for (const auto& i : value) { for (const auto& j : value) { if (&i != &j && i == j) { return makeError("unique items in array", value); } } } return none; }
void addArgument( // puts s in vector char *s, unsigned count, char **vector[] ) { if (!(*vector)) { *vector = (char**) allocate(CHUNKSIZE*sizeof(char*)); } else if (!(count % CHUNKSIZE)) { *vector = (char**) REALLOC(*vector,(count+CHUNKSIZE)*sizeof(char*)); if (!*vector) { makeError(0,OUT_OF_MEMORY); } } (*vector)[count] = makeString(s); }
BOOL defineMacro( char *s, // commandline or env definitions char *t, UCHAR flags ) { char *u; for (u = s; *u && MACRO_CHAR(*u); u = _tcsinc(u)) // check for illegal ; if (*u) { if (ON(flags, M_ENVIRONMENT_DEF)) { // ignore bad macros return(FALSE); } makeError(currentLine, SYNTAX_BAD_CHAR, *u); // chars, bad syntax } return(putMacro(s, t, flags)); // put macro in table }
Optional<SchemaError> validate(ValidationContext& vc, const dynamic& value) const override { if (!value.isObject()) { return none; } for (const auto& pair : value.items()) { if (!pair.first.isString()) { continue; } const fbstring& key = pair.first.getString(); auto it = propertyValidators_.find(key); bool matched = false; if (it != propertyValidators_.end()) { if (auto se = vc.validate(it->second.get(), pair.second)) { return se; } matched = true; } const std::string& strkey = key.toStdString(); for (const auto& ppv : patternPropertyValidators_) { if (boost::regex_search(strkey, ppv.first)) { if (auto se = vc.validate(ppv.second.get(), pair.second)) { return se; } matched = true; } } if (matched) { continue; } if (!allowAdditionalProperties_) { return makeError("no more additional properties", value); } if (additionalPropertyValidator_) { if (auto se = vc.validate(additionalPropertyValidator_.get(), pair.second)) { return se; } } } return none; }
void startNameList() { STRINGLIST *p; currentFlags = flags; // set flags for cur target p = makeNewStrListElement(); p->text = name; list = p; // list contains name p = macros; expandFileNames("$", &list, ¯os); // expand macros in name expandFileNames("*?", &list, NULL); // expand wildcards while ((macros = p)) { // free macro list p = p->next; FREE_STRINGLIST(macros); } if (!list && OFF(actionFlags, A_TARGET)) makeError(line, TARGET_MACRO_IS_NULL, name); // target null & 1 target if (list && isRule(list->text)) SET(actionFlags, A_RULE); }
Optional<SchemaError> validate(ValidationContext& vc, const dynamic& value) const override { if (!value.isObject()) { return none; } for (const auto& pair : propertyDep_) { if (value.count(pair.first)) { for (const auto& prop : pair.second) { if (!value.count(prop)) { return makeError("property", prop, value); } } } } for (const auto& pair : schemaDep_) { if (value.count(pair.first)) { if (auto se = vc.validate(pair.second.get(), value)) { return se; } } } return none; }
void CBuilder::make() { if (!valid) { return; } makeProcess = new QProcess; if (!makeProcess) { emit buildError("create build process failed."); return; } connect(makeProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(makeFinished(int, QProcess::ExitStatus))); connect(makeProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(makeError(QProcess::ProcessError))); makeProcess->setProcessChannelMode(QProcess::MergedChannels); QStringList args; if (developMode == "UserDefined") { // 如果是用户自定义模式 makeProcess->setWorkingDirectory(workingDir); args << "-f" << makefile; } else { makeProcess->setWorkingDirectory(rootPath + "/" + developMode); } if (targetList.isEmpty()) args << "all"; else args << targetList; QString makeTool = cprojectObject->make(); if (makeTool.isEmpty()) makeTool = "make"; makeProcess->start(makeTool, args); } // runMakeProcess
void endNameList() { if (name) { // if only one name to left of : startNameList(); // it hasn't been put in list yet name = NULL; } else CLEAR(actionFlags, A_TARGET); // clear target flag if (buf[1]) SET(currentFlags, F2_DOUBLECOLON); // so addItemToList() if (!list) // won't expand names makeError(currentLine, SYNTAX_NO_TARGET_NAME); // of dependents if (ON(actionFlags, A_RULE)) { BOOL fBatch; // A rule with a doublecolon on the dependency line // is a "batch rule", i.e., a rule that applies the // command block in batch mode for all affected // dependents. fBatch = !!(ON(currentFlags, F2_DOUBLECOLON)); makeRule(list, fBatch); FREE_STRINGLIST(list); } else if (!(list->next) && doSpecial(list->text)) { // special pseudotarget ... FREE(list->text); // don't need ".SUFFIXES" etc FREE_STRINGLIST(list); } else // regular target targetList = list; list = NULL; // We are now looking for a dependent SET(actionFlags, A_DEPENDENT); }
void tokenizeLine( // gets args delimited char *s, // by whitespace and unsigned *count, // constructs an arg char **vector[] // vector ) { char *t; if ((t = _tcschr(s,'\\'))) { if (WHITESPACE(*(t-1)) && (*(t+1) == '\n')) { *t = '\0'; } } for (t = _tcstok(s," \t\n"); t; t = _tcstok(NULL," \t\n")) { if (*t == '@') { makeError(0,SYNTAX_CMDFILE,t+1); break; // should we keep on parsing here? } addArgument(t,*count,vector); ++*count; } }