/** * Cycle all patterns and search matching pattern. Execute command callback. * @param context * @result TRUE if context->paramlist is filled with correct values */ static scpi_bool_t findCommandHeader(scpi_t * context, const char * header, int len) { int32_t i; #if USE_64K_PROGMEM_FOR_CMD_LIST PGM_P pattern; for (i = 0; (pattern = (PGM_P)pgm_read_word(&context->cmdlist[i].pattern)) != 0; ++i) { strncpy_P(context->param_list.cmd_pattern_s, pattern, SCPI_MAX_CMD_PATTERN_SIZE); context->param_list.cmd_pattern_s[SCPI_MAX_CMD_PATTERN_SIZE] = '\0'; if (matchCommand(context->param_list.cmd_pattern_s, header, len, NULL, 0, 0)) { context->param_list.cmd_s.callback = (scpi_command_callback_t)pgm_read_word(&context->cmdlist[i].callback); #if USE_COMMAND_TAGS context->param_list.cmd_s.tag = (int32_t)pgm_read_dword(&context->cmdlist[i].tag); #endif return TRUE; } } #elif USE_FULL_PROGMEM_FOR_CMD_LIST uint_farptr_t p_cmd = context->cmdlist; uint_farptr_t p_pattern = context->cmdpatterns; uint16_t pattern_length; for (i = 0; (pattern_length = pgm_read_word_far(p_cmd + offsetof(scpi_command_t, pattern))) != 0; ++i, p_cmd += sizeof(scpi_command_t), p_pattern += pattern_length) { strncpy_PF(context->param_list.cmd_pattern_s, p_pattern, pattern_length); context->param_list.cmd_pattern_s[pattern_length] = '\0'; if (matchCommand(context->param_list.cmd_pattern_s, header, len, NULL, 0, 0)) { context->param_list.cmd_s.callback = (scpi_command_callback_t)pgm_read_word_far(p_cmd + offsetof(scpi_command_t, callback)); #if USE_COMMAND_TAGS context->param_list.cmd_s.tag = (int32_t)pgm_read_dword_far(p_cmd + offsetof(scpi_command_t, tag)); #endif return TRUE; } } #else const scpi_command_t * cmd; for (i = 0; context->cmdlist[i].pattern != NULL; i++) { cmd = &context->cmdlist[i]; if (matchCommand(cmd->pattern, header, len, NULL, 0, 0)) { context->param_list.cmd = cmd; return TRUE; } } #endif return FALSE; }
sVector WavefrontFileReader::parseColor(const char*& current) { sVector col; col.Init(); if(matchCommand(current, "spectral")) diagnostic(false, current, "spectral colors not supported"); else if(matchCommand(current, "xyz")) diagnostic(false, current, "XYZ colors not supported"); else { for(int i=0;i<3;i++) col[i] = parseFloat(current); } return col; }
scpi_bool_t SCPI_IsCmd(scpi_t * context, const char * cmd) { if (! context->paramlist.cmd) { return FALSE; } const char * pattern = context->paramlist.cmd->pattern; return matchCommand (pattern, cmd, strlen (cmd)); }
/** * Cycle all patterns and search matching pattern. Execute command callback. * @param context * @result TRUE if context->paramlist is filled with correct values */ static scpi_bool_t findCommandHeader(scpi_t * context, const char * header, int len) { int32_t i; const scpi_command_t * cmd; for (i = 0; context->cmdlist[i].pattern != NULL; i++) { cmd = &context->cmdlist[i]; if (matchCommand(cmd->pattern, header, len, NULL, 0, 0)) { context->param_list.cmd = cmd; return TRUE; } } return FALSE; }
/** * Cycle all patterns and search matching pattern. Execute command callback. * @param context * @result TRUE if context.paramlist is filled with correct values */ scpi_bool_t SCPIParser::findCommand(const char * cmdline_ptr, size_t cmdline_len, size_t cmd_len) { int32_t i; const scpi_command_t * cmd; for (i = 0; context.cmdlist[i].pattern != NULL; i++) { cmd = &context.cmdlist[i]; if (matchCommand(cmd->pattern, cmdline_ptr, cmd_len)) { context.paramlist.cmd = cmd; context.paramlist.parameters = cmdline_ptr + cmd_len; context.paramlist.length = cmdline_len - cmd_len; return TRUE; } } return FALSE; }
/** * Cycle all patterns and search matching pattern. Execute command callback. * @param context * @result TRUE if context->paramlist is filled with correct values */ static scpi_bool_t findCommand(scpi_t * context, const char * cmdline_ptr, size_t cmdline_len, size_t cmd_len) { int32_t i; const scpi_command_t * cmd; for (i = 0; context->cmdlist[i].pattern != NULL; i++) { cmd = &context->cmdlist[i]; if (matchCommand(cmd->pattern, cmdline_ptr, cmd_len)) { context->paramlist.cmd = cmd; context->paramlist.parameters = cmdline_ptr + cmd_len; context->paramlist.length = cmdline_len - cmd_len; context->paramlist.cmd_raw.data = cmdline_ptr; context->paramlist.cmd_raw.length = cmd_len; context->paramlist.cmd_raw.position = 0; return TRUE; } } return FALSE; }
Command* createCommand(char* command) { CommandType type = matchCommand(command); switch (type) { case comments: return new Comments; case newlines: return new Normalise(command); case indentation: return new Indentation(command); case format: return new Format; case html: default: throw std::invalid_argument("No such command!"); } }
scpi_bool_t SCPI_CommandNumbers(scpi_t * context, int32_t * numbers, size_t len, int32_t default_value) { return matchCommand (context->param_list.cmd->pattern, context->param_list.cmd_raw.data, context->param_list.cmd_raw.length, numbers, len, default_value); }
scpi_bool_t SCPI_Match(const char * pattern, const char * value, size_t len) { return matchCommand (pattern, value, len, NULL, 0, 0); }
bool ParserImpl::run(Context * ctx, const class Properties ** pDst, volatile bool * stop) const { input.set_mutex(ctx->m_mutex); * pDst = 0; bool ownStop = false; if(stop == 0) stop = &ownStop; ctx->m_aliasUsed.clear(); const unsigned sz = sizeof(ctx->m_tokenBuffer); ctx->m_currentToken = input.gets(ctx->m_tokenBuffer, sz); if(Eof(ctx->m_currentToken)){ ctx->m_status = Parser<Dummy>::Eof; return false; } int last= (int)strlen(ctx->m_currentToken); if(last>0) last--; if(ctx->m_currentToken[last] !='\n'){ ctx->m_status = Parser<Dummy>::NoLine; ctx->m_tokenBuffer[0]= '\0'; return false; } if(Empty(ctx->m_currentToken)){ ctx->m_status = Parser<Dummy>::EmptyLine; return false; } trim(ctx->m_currentToken); ctx->m_currentCmd = matchCommand(ctx, ctx->m_currentToken, m_rows); if(ctx->m_currentCmd == 0){ ctx->m_status = Parser<Dummy>::UnknownCommand; return false; } Properties * p = new Properties(); bool invalidArgument = false; ctx->m_currentToken = input.gets(ctx->m_tokenBuffer, sz); while((! * stop) && !Eof(ctx->m_currentToken) && !Empty(ctx->m_currentToken)){ if(ctx->m_currentToken[0] != 0){ trim(ctx->m_currentToken); if(!parseArg(ctx, ctx->m_currentToken, ctx->m_currentCmd + 1, p)){ delete p; invalidArgument = true; break; } } ctx->m_currentToken = input.gets(ctx->m_tokenBuffer, sz); } if(invalidArgument){ // Invalid argument found, return error return false; } if(* stop){ delete p; ctx->m_status = Parser<Dummy>::ExternalStop; return false; } if(!checkMandatory(ctx, p)){ ctx->m_status = Parser<Dummy>::MissingMandatoryArgument; delete p; return false; } /** * Add alias to properties */ for(unsigned i = 0; i<ctx->m_aliasUsed.size(); i++){ const ParserRow<Dummy> * alias = ctx->m_aliasUsed[i]; Properties tmp; tmp.put("name", alias->name); tmp.put("realName", alias->realName); p->put("$ALIAS", i, &tmp); } p->put("$ALIAS", ctx->m_aliasUsed.size()); ctx->m_status = Parser<Dummy>::Ok; * pDst = p; return true; }
Dialog::Dialog(MadsM4Engine *vm, const char *msgData, const char *title): View(vm, Common::Rect(0, 0, 0, 0)) { assert(msgData); _vm->_font->setFont(FONT_INTERFACE_MADS); const char *srcP = msgData; bool skipLine = false; bool initFlag = false; bool cmdFlag = false; bool crFlag = false; bool underline = false; _screenType = LAYER_DIALOG; _widthChars = 0; _dialogIndex = 0; _askPosition.x = 0; _askPosition.y = 0; _lineX = 0; _widthX = 0; _dialogWidth = 0; _commandCase = false; char dialogLine[256]; char cmdText[80]; char *lineP = &dialogLine[0]; char *cmdP = NULL; while (srcP && *(srcP - 1) != '\0') { if ((*srcP == '\n') || (*srcP == '\0')) { // Line completed *lineP = '\0'; ++srcP; if (!initFlag) { initDialog(); initFlag = true; } if (!skipLine) writeChars(dialogLine); else { addLine(dialogLine, underline); if (crFlag) incLine(); } // Clear the current line contents dialogLine[0] = '\0'; lineP = &dialogLine[0]; skipLine = crFlag = underline = false; continue; } else if (*srcP == '[') { // Start of a command sequence cmdFlag = true; cmdP = &cmdText[0]; ++srcP; continue; } else if (*srcP == ']') { // End of a command sequence *cmdP = '\0'; cmdFlag = false; strToUpper(cmdText); if (matchCommand(cmdText, "ASK")) { setupInputArea(); } else if (matchCommand(cmdText, "BAR")) { // Adds a full-width line instead of normal text addBarLine(); } else if (matchCommand(cmdText, "CENTER")) { // Center command skipLine = true; } else if (matchCommand(cmdText, "CR")) { // CR command if (skipLine) crFlag = true; else if (!initFlag) { initDialog(); initFlag = true; } } else if (matchCommand(cmdText, "NOUN1")) { // Noun command 1 handleNounSuffix(lineP, 1, cmdText + 5); } else if (matchCommand(cmdText, "NOUN2")) { // Noun command 2 handleNounSuffix(lineP, 2, cmdText + 5); } else if (matchCommand(cmdText, "SENTENCE")) { // Sentence command - loads the title into the line buffer strcpy(dialogLine, title); strToUpper(dialogLine); lineP += strlen(dialogLine) + 1; } else if (matchCommand(cmdText, "TAB")) { // Specifies the X offset for the current line _lines[_lines.size() - 1].xp = atoi(cmdText + 3); } else if (matchCommand(cmdText, "TITLE")) { // Title command - specifies the dialog width in number of characters skipLine = true; crFlag = true; underline = true; int id = atoi(cmdText + 5); if (id > 0) { // Suffix provided - specifies the dialog width in number of chars _widthChars = id * 2; _dialogWidth = id * (_vm->_font->current()->getMaxWidth() + DIALOG_SPACING) + 10; } } else if (matchCommand(cmdText, "UNDER")) { // Underline command underline = true; } else if (matchCommand(cmdText, "VERB")) { // Verb/vocab retrieval int verbId = 1; // TODO: Get correct vocab getVocab(verbId, &lineP); } else if (matchCommand(cmdText, "INDEX")) { // Index command _dialogIndex = atoi(cmdText + 5); } else { error("Unknown dialog command '%s' encountered", cmdText); } } *lineP++ = *srcP; if (cmdFlag) *cmdP++ = *srcP; ++srcP; } draw(); }
void OBJFileReader::parseLine(const char*& current, const char* endOfLine) { if(matchCommand(current, "v")) positions.push_back(parseVec3(current)); else if(matchCommand(current, "vn")) normals.push_back(parseVec3(current)); else if(matchCommand(current, "vt")) texcoords.push_back(parseVec2(current)); else if(matchCommand(current, "f")) // face { int count = 0; while(!errThisLine && *current) { VertInfo nfo; nfo.pos = parseIndex(current, positions.size()); if(*current == '/') nfo.tex = parseIndex(++current, texcoords.size()); else nfo.tex = -1; if(*current == '/') nfo.norm = parseIndex(++current, normals.size()); else nfo.norm = -1; if(*current && !isspace(*current)) diagnostic(false, current, "unexpected character after vertex indices"); vertices.push_back(nfo); count++; } if(count < 3) diagnostic(false, current, "need at least 3 vertices for a face"); else if(count > 4) diagnostic(true, current, "non-tri/quad face"); FaceInfo nfo; nfo.start = vertices.size() - count; nfo.count = count; nfo.mtrl = currentMaterial; nfo.smoothing_group = currentSmoothingGroup; faces.push_back(nfo); } else if(matchCommand(current, "g")) // group { current = endOfLine; } else if(matchCommand(current, "o")) // object { current = endOfLine; } else if(matchCommand(current, "s")) // smooth shading { if(matchCommand(current, "off")) currentSmoothingGroup = -1; else currentSmoothingGroup = parseInt(current) - 1; } else if(matchCommand(current, "usemtl")) { currentMaterial = findMaterial(current); current = endOfLine; } else if(matchCommand(current, "mtllib")) { MTLFileReader mtlreader; if(!mtlreader.read((basepath + current).c_str())) diagnostic(false, current, "error reading material library"); else { materials.swap(mtlreader.materials); current = endOfLine; defaultMaterial = -1; defaultMaterial = findMaterial("default"); sVERIFY(defaultMaterial != -1); currentMaterial = defaultMaterial; } } else diagnostic(false, current, "unknown command"); }
void MTLFileReader::parseLine(const char*& current, const char* endOfLine) { if(matchCommand(current, "newmtl")) { WavefrontMaterial mat; mat.name = current; materials.push_back(mat); current = endOfLine; } else if(matchCommand(current, "Ka")) // ambient color curMaterial().ambient = parseColor(current); else if(matchCommand(current, "Kd")) // diffuse color curMaterial().diffuse = parseColor(current); else if(matchCommand(current, "Ks")) // specular color curMaterial().specular = parseColor(current); else if(matchCommand(current, "Ns")) // specular exponent curMaterial().specularExp = parseFloat(current); else if(matchCommand(current, "Km")) // no idea what this is parseFloat(current); else if(matchCommand(current, "Ni")) // optical density curMaterial().refractiveInd = parseFloat(current); else if(matchCommand(current, "illum")) // illumination model curMaterial().illuminationModel = parseInt(current); else if(matchCommand(current, "d")) // dissolve { if(matchCommand(current, "-halo")) diagnostic(true, current, "dissolve halo not supported"); curMaterial().opacity = parseFloat(current); } else if(matchCommand(current, "map_Kd")) // diffuse texture { curMaterial().diffuseTex = current; current = endOfLine; } else if(matchCommand(current, "map_Bump")) // bump texture { curMaterial().bumpTex = current; current = endOfLine; } else if(matchCommand(current, "map_d") || matchCommand(current, "map_D")) // opacity texture { curMaterial().opacityTex = current; current = endOfLine; } else diagnostic(false, current, "unknown command"); }
/** * This checks the Serial stream for characters, and assembles them into a buffer. * When the terminator character (default '\n') is seen, it starts parsing the * buffer for a prefix command, and calls handlers setup by addCommand() member */ void SerialCommand::processCommand() { matchCommand(); runCommand(); clearBuffer(); }
static void xPLListener(xPL_MessagePtr theMessage, xPL_ObjectPtr userValue) { if(!xPL_isBroadcastMessage(theMessage)){ /* If not a broadcast message */ if(xPL_MESSAGE_COMMAND == xPL_getMessageType(theMessage)){ /* If the message is a command */ const String iID = xPL_getTargetInstanceID(theMessage); const String type = xPL_getSchemaType(theMessage); const String class = xPL_getSchemaClass(theMessage); const String command = xPL_getMessageNamedValue(theMessage, "command"); const String request = xPL_getMessageNamedValue(theMessage, "request"); debug(DEBUG_EXPECTED,"Non-broadcast message received: type=%s, class=%s", type, class); /* Allocate a working string */ if((!strcmp(instanceID, iID)) && (!strcmp(class, "security"))){ if(!strcmp(type, "basic")){ /* Basic command schema */ if(command){ int index; switch((index = matchCommand(basicCommandList, command))){ case 0: /* arm-away */ case 1: /* arm-home */ case 2: /* disarm */ doArmDisarm(theMessage, index); break; default: break; } } } else if(!strcmp(type, "request")){ /* Request command schema */ if(request){ switch(matchCommand(requestCommandList, request)){ case 0: /* gateinfo */ doGateInfo(); break; case 1: /* zonelist */ doZoneList(); break; case 2: /* zoneinfo */ doZoneInfo(theMessage); break; case 3: /* gatestat */ doGateStat(); break; default: break; } } } } } } }