void EmsMessage::parseRCHKMonitorMessage(EmsValue::SubType subtype) { parseNumeric(2, 1, 2, EmsValue::SollTemp, EmsValue::Raum); parseNumeric(3, 2, 10, EmsValue::IstTemp, EmsValue::Raum); if (canAccess(7, 3)) { EmsValue value(EmsValue::HKKennlinie, subtype, m_data[7 - m_offset], m_data[8 - m_offset], m_data[9 - m_offset]); m_valueHandler(value); } parseNumeric(14, 1, 1, EmsValue::SollTemp, subtype); parseInteger(5, 1, EmsValue::EinschaltoptimierungsZeit, subtype); parseInteger(6, 1, EmsValue::AusschaltoptimierungsZeit, subtype); if (canAccess(15, 1) && (m_data[15 - m_offset] & 1) == 0) { parseNumeric(10, 2, 100, EmsValue::TemperaturAenderung, EmsValue::Raum); } parseBool(0, 2, EmsValue::Automatikbetrieb, subtype); parseBool(0, 0, EmsValue::Ausschaltoptimierung, subtype); parseBool(0, 1, EmsValue::Einschaltoptimierung, subtype); parseBool(0, 3, EmsValue::WWVorrang, subtype); parseBool(0, 4, EmsValue::Estrichtrocknung, subtype); parseBool(0, 6, EmsValue::Frostschutzbetrieb, subtype); parseBool(1, 0, EmsValue::Sommerbetrieb, subtype); parseBool(1, 1, EmsValue::Tagbetrieb, subtype); parseBool(13, 2, EmsValue::Party, subtype); parseBool(13, 3, EmsValue::Pause, subtype); parseBool(13, 6, EmsValue::Urlaub, subtype); parseBool(13, 7, EmsValue::Ferien, subtype); parseBool(13, 4, EmsValue::SchaltuhrEin, subtype); }
void RequestParser::parseRetrySpecification(const Item& aItem, RetrySpecification& aRetrySpec) { Item lDelay; Item lStatuses; aRetrySpec.theRetry = true; getArray(aItem, "delay", true, lDelay); uint64_t lDelaySize = lDelay.getArraySize(); if (lDelaySize == 0) theThrower->raiseException("REQUEST", "The specified request is not valid. The delay array is empty."); for(uint32_t i = 1; i <= lDelaySize; ++i) { Item lMember = lDelay.getArrayValue(i); int lValue = parseInteger(lMember, "entry of delay"); if (lValue <= 0) theThrower->raiseException("REQUEST", "The specified delays are not valid: they must all be greater than 0."); aRetrySpec.theRetryDelays.push_back(lValue); } getBoolean(aItem, "on-connection-error", false, aRetrySpec.theRetryOnConnectionError); getArray(aItem, "on-statuses", true, lDelay); uint64_t lStatusesSize = lDelay.getArraySize(); if (!aRetrySpec.theRetryOnConnectionError && lStatusesSize == 0) theThrower->raiseException("REQUEST", "The specified request is not valid. Retry on connection error is false, and the on-status array is empty."); for(uint32_t i = 1; i <= lStatusesSize; ++i) { Item lMember = lDelay.getArrayValue(i); aRetrySpec.theRetryStatuses.push_back(parseInteger(lMember, "entry of statuses")); } }
static vString *parseNumeric (int c) { vString *string = vStringNew (); vString *integer = parseInteger (c); vStringCopy (string, integer); vStringDelete (integer); c = getcFromInputFile (); if (c == '.') { integer = parseInteger ('\0'); vStringPut (string, c); vStringCat (string, integer); vStringDelete (integer); c = getcFromInputFile (); } if (tolower (c) == 'e') { integer = parseInteger ('\0'); vStringPut (string, c); vStringCat (string, integer); vStringDelete (integer); } else if (!isspace (c)) ungetcToInputFile (c); vStringTerminate (string); return string; }
Expression parseArguments(int argc, char** argv) { if (argc == 1) { help(argv[0]); exit(0); } else if (argc != 4) { printf("ERROR: Should be 3 arguments.\n\n"); help(argv[0]); exit(1); } Expression expression; try { expression.value = static_cast<double>(parseDouble(argv[1])); if (expression.value < 0) { printf("Wrong value! Value must be > 0"); exit(2); } expression.curUnit = static_cast<AreaType>(parseInteger(argv[2])); expression.newUnit = static_cast<AreaType>(parseInteger(argv[3])); } catch(...) { printf("Wrong format!"); exit(2); } return expression; }
static vString *parseNumeric (int c) { static vString *string = NULL; if (string == NULL) string = vStringNew (); vStringCopy (string, parseInteger (c)); c = fileGetc (); if (c == '.') { vStringPut (string, c); vStringCat (string, parseInteger ('\0')); c = fileGetc (); } if (tolower (c) == 'e') { vStringPut (string, c); vStringCat (string, parseInteger ('\0')); } else if (!isspace (c)) fileUngetc (c); vStringTerminate (string); return string; }
Expression parseArguments(int argc, char** argv) { if (argc == 1) { help(argv[0]); exit(0); } else if (argc != 4) { printf("ERROR: Should be 3 arguments.\n\n"); help(argv[0]); exit(1); } Expression expression; try { expression.arg1 = static_cast<int>(parseInteger(argv[1])); expression.arg2 = static_cast<int>(parseInteger(argv[2])); } catch(...) { printf("Wrong number format!\n"); exit(2); } expression.operation = *argv[3]; if ((strlen(argv[3]) != 1) || (expression.operation != '+' && expression.operation != '-')) { printf("%s - Wrong operation!\n", argv[3]); exit(3); } else { printf("%s is valid operation\n", argv[3]); } return expression; }
void EmsMessage::parseUBAMonitorSlowMessage() { parseNumeric(0, 2, 10, EmsValue::IstTemp, EmsValue::Aussen); parseNumeric(2, 2, 10, EmsValue::IstTemp, EmsValue::Waermetauscher); parseNumeric(4, 2, 10, EmsValue::IstTemp, EmsValue::Abgas); parseNumeric(9, 1, 1, EmsValue::IstModulation, EmsValue::KesselPumpe); parseInteger(10, 3, EmsValue::Brennerstarts, EmsValue::Kessel); parseInteger(13, 3, EmsValue::BetriebsZeit, EmsValue::Kessel); parseInteger(19, 3, EmsValue::HeizZeit, EmsValue::Kessel); }
void EmsMessage::parseUBAParametersMessage() { parseBool(0, 1, EmsValue::KesselSchalter, EmsValue::Kessel); parseNumeric(1, 1, 1, EmsValue::SetTemp, EmsValue::Kessel); parseNumeric(2, 1, 1, EmsValue::MaxModulation, EmsValue::Brenner); parseNumeric(3, 1, 1, EmsValue::MinModulation, EmsValue::Brenner); parseNumeric(4, 1, 1, EmsValue::AusschaltHysterese, EmsValue::Kessel); parseNumeric(5, 1, 1, EmsValue::EinschaltHysterese, EmsValue::Kessel); parseInteger(6, 1, EmsValue::AntipendelZeit, EmsValue::None); parseInteger(8, 1, EmsValue::NachlaufZeit, EmsValue::KesselPumpe); parseNumeric(9, 1, 1, EmsValue::MaxModulation, EmsValue::KesselPumpe); parseNumeric(10, 1, 1, EmsValue::MinModulation, EmsValue::KesselPumpe); }
int getInteger() { std::cin.ignore( std::numeric_limits<std::streampos>::max(), '\n' ) ; std::cin.clear() ; // to be safe, clear error flags which may be set int results; std::string line; while (1){ while ( ! std::getline( std::cin, line ) ) { std::cin.ignore( std::numeric_limits<std::streampos>::max(), '\n' ) ; std::cin.clear() ; // to be safe, clear error flags which may be set } if (! parseInteger( line, results )) { std::cout << "Only 'numeric' value(s) allowed:" << std::endl; } else{ break; } } return results; }
ir::Type* TypeParser::_parseArray() { if(!_lexer->scan("[")) { throw std::runtime_error("Failed to parse array " "type, expecting '['."); } std::string dimensionToken = _lexer->nextToken(); unsigned int dimension = parseInteger(dimensionToken); if(!_lexer->scan("x")) { throw std::runtime_error("Failed to parse array " "type, expecting 'x'."); } auto base = _parseType(); if(!_lexer->scan("]")) { throw std::runtime_error("Failed to parse array " "type, expecting ']'."); } return *_compiler->getOrInsertType(ir::ArrayType(_compiler, base, dimension)); }
static integer cmdCount(char *cmdLine, integer deflt) { while (isSpaceChar((codePoint) *cmdLine)) cmdLine++; if (uniStrLen(cmdLine) == 0) return deflt; else return parseInteger(cmdLine, uniStrLen(cmdLine)); }
UInt32 Configuration::getIntegerValue(OSObject *obj, UInt32 defValue) { UInt32 result = defValue; if (OSNumber* num = OSDynamicCast(OSNumber, obj)) result = num->unsigned32BitValue(); else if (OSString* str = OSDynamicCast(OSString, obj)) result = parseInteger(str->getCStringNoCopy()); return result; }
void EmsMessage::parseUBAMonitorWWMessage() { parseNumeric(0, 1, 1, EmsValue::SollTemp, EmsValue::WW); parseNumeric(1, 2, 10, EmsValue::IstTemp, EmsValue::WW); parseInteger(10, 3, EmsValue::WarmwasserbereitungsZeit, EmsValue::None); parseInteger(13, 3, EmsValue::WarmwasserBereitungen, EmsValue::None); parseBool(5, 0, EmsValue::Tagbetrieb, EmsValue::WW); parseBool(5, 1, EmsValue::EinmalLadungAktiv, EmsValue::WW); parseBool(5, 2, EmsValue::DesinfektionAktiv, EmsValue::WW); parseBool(5, 3, EmsValue::WarmwasserBereitung, EmsValue::None); parseBool(5, 4, EmsValue::NachladungAktiv, EmsValue::WW); parseBool(5, 5, EmsValue::WarmwasserTempOK, EmsValue::None); parseBool(7, 0, EmsValue::Tagbetrieb, EmsValue::Zirkulation); parseBool(7, 2, EmsValue::ZirkulationAktiv, EmsValue::None); parseEnum(8, EmsValue::WWSystemType, EmsValue::None); }
void EmsMessage::parseUBAMaintenanceSettingsMessage() { parseEnum(0,EmsValue::Wartungsmeldungen, EmsValue::Kessel); parseInteger(1, 1, EmsValue::HektoStundenVorWartung, EmsValue::Kessel); if (canAccess(2, sizeof(EmsProto::DateRecord))) { EmsProto::DateRecord *record = (EmsProto::DateRecord *) &m_data.at(2 - m_offset); m_valueHandler(EmsValue(EmsValue::Wartungstermin, EmsValue::Kessel, *record)); } }
int Sandbox::universal_jump(string name, int linenum, JumpType type, Var* pvar1, Var* pvar2){ int retline; bool retlineSet = false; map<string, int>::iterator rj; if(checkInteger(name)){ int line = parseInteger(name); retline = line + linenum; retlineSet = true; }else{ if((rj=jmap.find(name))==jmap.end()){ errAbort(Error_JptNotFound); } } if(type==Jump_DIRECT){ if(retlineSet) return retline; return (*rj).second; // direct jump } int *p1 = pvar1->p(); int *p2 = pvar2->p(); if(pvar1->len()>1) p1 = pvar1->arrayp(); if(pvar2->len()>1) p2 = pvar2->arrayp(); // conditional jump bool jumpSuccess = false; switch(type){ case Jump_E: if(*p1 == *p2) jumpSuccess = true; break; case Jump_NE: if(*p1 != *p2) jumpSuccess = true; break; case Jump_L: if(*p1 < *p2) jumpSuccess = true; break; case Jump_LE: if(*p1 <= *p2) jumpSuccess = true; break; case Jump_G: if(*p1 > *p2) jumpSuccess = true; break; case Jump_GE: if(*p1 >= *p2) jumpSuccess = true; break; } if(jumpSuccess){ if(retlineSet) return retline; return (*rj).second; } return JUMPNCON; }
static retCode setDebuggerPort(char *option, logical enable, void *cl) { debuggerPort = parseInteger(option, uniStrLen(option)); if (debuggerPort <= 0) return Error; else{ lineDebugging = True; /* set up for remote symbolic insDebugging */ interactive = True; showPkgFile = True; showColors = False; } return Ok; }
static int parseEscapedCharacter (void) { int d = '\0'; int c = fileGetc (); switch (c) { case 'A': d = '@'; break; case 'B': d = '\b'; break; case 'C': d = '^'; break; case 'D': d = '$'; break; case 'F': d = '\f'; break; case 'H': d = '\\'; break; case 'L': d = '~'; break; case 'N': d = '\n'; break; #ifdef QDOS case 'Q': d = 0x9F; break; #else case 'Q': d = '`'; break; #endif case 'R': d = '\r'; break; case 'S': d = '#'; break; case 'T': d = '\t'; break; case 'U': d = '\0'; break; case 'V': d = '|'; break; case '%': d = '%'; break; case '\'': d = '\''; break; case '"': d = '"'; break; case '(': d = '['; break; case ')': d = ']'; break; case '<': d = '{'; break; case '>': d = '}'; break; case '\n': skipToCharacter ('%'); break; case '/': { vString *string = parseInteger ('\0'); const char *value = vStringValue (string); const unsigned long ascii = atol (value); vStringDelete (string); c = fileGetc (); if (c == '/' && ascii < 256) d = ascii; break; } default: break; } return d; }
void EmsMessage::parseRCWWOpmodeMessage() { parseBool(0, 1, EmsValue::EigenesProgrammAktiv, EmsValue::WW); parseBool(1, 1, EmsValue::EigenesProgrammAktiv, EmsValue::Zirkulation); parseEnum(2, EmsValue::Betriebsart, EmsValue::WW); parseEnum(3, EmsValue::Betriebsart, EmsValue::Zirkulation); parseBool(4, 1, EmsValue::Desinfektion, EmsValue::WW); parseEnum(5, EmsValue::DesinfektionTag, EmsValue::WW); parseInteger(6, 1, EmsValue::DesinfektionStunde, EmsValue::WW); parseNumeric(8, 1, 1, EmsValue::MaxTemp, EmsValue::WW); parseBool(9 ,1, EmsValue::EinmalLadungsLED, EmsValue::WW); }
bool JsonSingleValue::parseSignedInteger(T& value) const { auto parsedValue = parseInteger(m_StringRef.begin(), m_StringRef.end(), true); if (!parsedValue.second) return false; auto actualValue = static_cast<T>(parsedValue.first); if (actualValue == parsedValue.first) { value = actualValue; return true; } return false; }
bool RequestParser::getInteger(const Item& aItem, const String& aName, const bool aMandatory, int& aResult) { Item lOption = aItem.getObjectValue(aName); if (lOption.isNull()) { if (aMandatory) raiseMissingError(aName); return false; } else { aResult = parseInteger(lOption, aName); return true; } }
/** * Parse a pattern string starting at offset pos. Keywords are * matched case-insensitively. Spaces may be skipped and may be * optional or required. Integer values may be parsed, and if * they are, they will be returned in the given array. If * successful, the offset of the next non-space character is * returned. On failure, -1 is returned. * @param pattern must only contain lowercase characters, which * will match their uppercase equivalents as well. A space * character matches one or more required spaces. A '~' character * matches zero or more optional spaces. A '#' character matches * an integer and stores it in parsedInts, which the caller must * ensure has enough capacity. * @param parsedInts array to receive parsed integers. Caller * must ensure that parsedInts.length is >= the number of '#' * signs in 'pattern'. * @return the position after the last character parsed, or -1 if * the parse failed */ int32_t ICU_Utility::parsePattern(const UnicodeString& rule, int32_t pos, int32_t limit, const UnicodeString& pattern, int32_t* parsedInts) { // TODO Update this to handle surrogates int32_t p; int32_t intCount = 0; // number of integers parsed for (int32_t i=0; i<pattern.length(); ++i) { UChar cpat = pattern.charAt(i); UChar c; switch (cpat) { case 32 /*' '*/: if (pos >= limit) { return -1; } c = rule.charAt(pos++); if (!PatternProps::isWhiteSpace(c)) { return -1; } // FALL THROUGH to skipWhitespace U_FALLTHROUGH; case 126 /*'~'*/: pos = skipWhitespace(rule, pos); break; case 35 /*'#'*/: p = pos; parsedInts[intCount++] = parseInteger(rule, p, limit); if (p == pos) { // Syntax error; failed to parse integer return -1; } pos = p; break; default: if (pos >= limit) { return -1; } c = (UChar) u_tolower(rule.charAt(pos++)); if (c != cpat) { return -1; } break; } } return pos; }
bool JsonSingleValue::parseUnsignedInteger(T& value) const { if (m_StringRef.size == 0 || *m_StringRef.begin() == '-') return false; auto parsedValue = parseInteger(m_StringRef.begin(), m_StringRef.end(), true); if (!parsedValue.second) return false; auto unsignedValue = static_cast<uint64_t>(parsedValue.first); auto actualValue = static_cast<T>(unsignedValue); if (actualValue == unsignedValue) { value = actualValue; return true; } return false; }
void Bencoder::parseNextType(const std::string& str, unsigned int& pos, ListPtr list) { m_logger->log(logger::Logger::FINE, "Bencoder::parseNextType()"); switch (str[pos]) { case 'd': break; case 'l': { ListPtr l = parseList(str, pos); //m_lists.push_back( reinterpret_cast<AnyType>(l) ); break; } case 'i': { list->push_back( parseInteger(str, pos) ); break; } default: list->push_back( parseString(str, pos) ); break; } }
static integer parseSize(char *text) { char *p = text; integer scale = 1; while (*p != '\0' && isDigit(*p)) p++; if (*p != '\0') { switch (*p) { case 'k': case 'K': scale = 1024; break; case 'm': case 'M': scale = 1024 * 1024; break; case 'g': case 'G': scale = 1024 * 1024 * 1024; break; default:; } } return parseInteger(text, (integer) (p - text)) * scale; }
Ref<Mesh> MeshReader::read(const String& name, const Path& path) { std::ifstream stream(path.name().c_str(), std::ios::in | std::ios::binary); if (stream.fail()) { logError("Failed to open mesh %s", name.c_str()); return nullptr; } String line; uint lineNumber = 0; std::vector<vec3> positions; std::vector<vec3> normals; std::vector<vec2> texcoords; std::vector<Triplet> triplets; std::vector<FaceGroup> groups; FaceGroup* group = nullptr; while (std::getline(stream, line)) { const char* text = line.c_str(); ++lineNumber; if (!interesting(&text)) continue; try { String command = parseName(&text); if (command == "g") { // Silently ignore group names } else if (command == "o") { // Silently ignore object names } else if (command == "s") { // Silently ignore smoothing } else if (command == "v") { vec3 vertex; vertex.x = parseFloat(&text); vertex.y = parseFloat(&text); vertex.z = parseFloat(&text); positions.push_back(vertex); } else if (command == "vt") { vec2 texcoord; texcoord.x = parseFloat(&text); texcoord.y = parseFloat(&text); texcoords.push_back(texcoord); } else if (command == "vn") { vec3 normal; normal.x = parseFloat(&text); normal.y = parseFloat(&text); normal.z = parseFloat(&text); normals.push_back(normalize(normal)); } else if (command == "usemtl") { String materialName = parseName(&text); group = nullptr; for (auto& g : groups) { if (g.name == materialName) group = &g; } if (!group) { groups.push_back(FaceGroup()); groups.back().name = materialName; group = &(groups.back()); } } else if (command == "mtllib") { // Silently ignore .mtl material files } else if (command == "f") { if (!group) throw Exception("Expected \'usemtl\' before \'f\'"); triplets.clear(); while (*text != '\0') { triplets.push_back(Triplet()); Triplet& triplet = triplets.back(); triplet.vertex = parseInteger(&text); triplet.texcoord = 0; triplet.normal = 0; if (*text == '/') { if (std::isdigit(*(++text))) triplet.texcoord = parseInteger(&text); if (*text == '/') { if (std::isdigit(*(++text))) triplet.normal = parseInteger(&text); } } while (std::isspace(*text)) text++; } for (size_t i = 2; i < triplets.size(); i++) { group->faces.push_back(Face()); Face& face = group->faces.back(); face.p[0] = triplets[0]; face.p[1] = triplets[i - 1]; face.p[2] = triplets[i]; } } else { logWarning("Unknown command %s in mesh %s line %d", command.c_str(), name.c_str(), lineNumber); } } catch (Exception& e) { logError("%s in mesh %s line %d", e.what(), name.c_str(), lineNumber); return nullptr; } } Ref<Mesh> mesh = new Mesh(ResourceInfo(cache, name, path)); mesh->vertices.resize(positions.size()); for (size_t i = 0; i < positions.size(); i++) mesh->vertices[i].position = positions[i]; VertexTool tool(mesh->vertices); for (auto& g : groups) { mesh->sections.push_back(MeshSection()); MeshSection& geometry = mesh->sections.back(); const FaceList& faces = g.faces; geometry.materialName = g.name; geometry.triangles.resize(faces.size()); for (size_t i = 0; i < faces.size(); i++) { const Face& face = faces[i]; MeshTriangle& triangle = geometry.triangles[i]; for (size_t j = 0; j < 3; j++) { const Triplet& point = face.p[j]; vec3 normal; if (point.normal) normal = normals[point.normal - 1]; vec2 texcoord; if (point.texcoord) texcoord = texcoords[point.texcoord - 1]; triangle.indices[j] = tool.addAttributeLayer(point.vertex - 1, normal, texcoord); } } } tool.realizeVertices(mesh->vertices); return mesh; }
void *doInput(void *details) { prodcons *toProg; Action action; const size_t BUFF_INC = 1000; char inputBuffer[BUFF_INC], *wholeBuffer, *newline, *stripped, *theinput, *firstspace, *command; char *rest; int temp, xboardmode = 0, done = 0; size_t commandLength, currentMaxLength, currentBufferLength; #ifdef DEBUG FILE *debugFile; debugFile = fopen("iolog.log","w"); setlinebuf(debugFile); #endif newline = NULL; toProg = ((threadParameter *) details)->input; wholeBuffer = (char *) xmalloc(BUFF_INC); currentMaxLength = BUFF_INC; while (done == 0) { currentBufferLength = 0; memset((void *) wholeBuffer, '\0', currentMaxLength); do { if (fgets(inputBuffer, BUFF_INC, stdin) == NULL) { done = -1; break; } currentBufferLength += BUFF_INC; if (currentBufferLength > currentMaxLength) { wholeBuffer = (char *) xrealloc((void *) wholeBuffer, currentBufferLength); currentMaxLength = currentBufferLength; } wholeBuffer = strcat(wholeBuffer, inputBuffer); newline = strchr(wholeBuffer, '\n'); } while (newline == NULL); if (newline == NULL) { fprintf(stderr, "Error reading from input\n"); continue; } *newline = '\0'; #ifdef DEBUG fprintf(debugFile,"%s\n",wholeBuffer); #endif stripped = strip(wholeBuffer); action.command = xstrdup(stripped); theinput = uppercase(stripped); free(stripped); if ((theinput != NULL) && (strlen(theinput) > 0)) { firstspace = strchr(theinput, ' '); if (firstspace == NULL) { commandLength = strlen(theinput); rest = NULL; } else { commandLength = firstspace - theinput; rest = xstrdup(firstspace + 1); } /* if (rest != NULL) { * printf("rest: %s\n",rest); * } */ command = (char *) xmalloc(commandLength + 1); memcpy(command, theinput, commandLength); command[commandLength] = '\0'; if (strcmp(command, "USERMOVE") == 0) { action.theType = USERMOVE; if (parseMove(rest, &action.data.move) < 0) { action.data.move.from = -1; } putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_SANMOVE") == 0) || ((!xboardmode) && (strcmp(command, "SANMOVE") == 0))) { action.theType = SP_SANMOVE; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "XBOARD") == 0) { xboardmode = 1; action.theType = XBOARD; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "PROTOVER") == 0) { action.theType = PROTOVER; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "ACCEPTED") == 0) { action.theType = ACCEPTED; action.data.feature = stringToFeature(rest); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "REJECTED") == 0) { action.theType = REJECTED; action.data.feature = stringToFeature(rest); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "NEW") == 0) { action.theType = NEW; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "VARIANT") == 0) { action.theType = VARIANT; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "QUIT") == 0) { action.theType = QUIT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "RANDOM") == 0) { action.theType = RANDOM; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "FORCE") == 0) { action.theType = FORCE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "GO") == 0) { action.theType = GO; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "PLAYOTHER") == 0) { action.theType = PLAYOTHER; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "WHITE") == 0) { action.theType = WHITE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "BLACK") == 0) { action.theType = BLACK; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "LEVEL") == 0) { action.theType = LEVEL; if (parseLevel(rest, &action.data.timecontrol) == 0) { putAction(toProg, &action); } if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "SD") == 0) { action.theType = SD; action.data.depth = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "ST") == 0) { action.theType = ST; action.data.time = parseInteger(rest) * 100; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "TIME") == 0) { action.theType = TIME; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "OTIM") == 0) { action.theType = OTIM; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "?") == 0) { action.theType = MOVENOW; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "PING") == 0) { action.theType = PING; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "DRAW") == 0) { action.theType = DRAW; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "RESULT") == 0) { action.theType = RESULT; if (parseResult(rest, &action.data.result) == 0) { putAction(toProg, &action); } if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if (strcmp(command, "SETBOARD") == 0) { action.theType = SETBOARD; if (rest != NULL) { free(rest); rest = NULL; } action.data.message = (char *) xstrdup(action.command + commandLength + 1); putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "EDIT") == 0) { action.theType = EDIT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "HINT") == 0) { action.theType = HINT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "BK") == 0) { action.theType = BK; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "UNDO") == 0) { action.theType = UNDO; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "REMOVE") == 0) { action.theType = REMOVE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "HARD") == 0) { action.theType = HARD; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "EASY") == 0) { action.theType = EASY; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "POST") == 0) { action.theType = POST; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "NOPOST") == 0) { action.theType = NOPOST; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "EXIT") == 0) { action.theType = EXIT; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "ANALYZE") == 0) { action.theType = ANALYZE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, ".") == 0) { action.theType = UPDATESTATUS; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "NAME") == 0) { action.theType = NAME; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "RATING") == 0) { action.theType = RATING; temp = parseRatings(rest, &action.data.ratings); if (rest != NULL) { free(rest); rest = NULL; } if (temp == 0) { putAction(toProg, &action); } else { free(action.command); } goto ENDPARSE; } if (strcmp(command, "ICS") == 0) { action.theType = ICS; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "COMPUTER") == 0) { action.theType = COMPUTER; putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_DEBUG") == 0) || ((!xboardmode) && (strcmp(command, "DEBUG") == 0))){ action.theType = DEBUG; action.data.message = rest; putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_MOVETOSAN") == 0) || ((!xboardmode) && (strcmp(command, "MOVETOSAN") == 0))){ action.theType = SP_MOVETOSAN; if (parseMove(rest, &action.data.move) < 0) { action.data.move.from = -1; } putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHMOVEUNMOVE") == 0) || ((!xboardmode) && (strcmp(command, "BENCHMOVEUNMOVE") == 0))) { action.theType = SP_BENCHMOVEUNMOVE; if (parseMove(rest, &action.data.move) < 0) { action.data.move.from = -1; } putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHMOVEGEN") == 0) || ((!xboardmode) && (strcmp(command, "BENCHMOVEGEN") == 0))){ action.theType = SP_BENCHMOVEGEN; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHMOVECYCLE") == 0) || ((!xboardmode) && (strcmp(command, "BENCHMOVECYCLE") == 0))) { action.theType = SP_BENCHMOVECYCLE; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_BENCHEVAL") == 0) || ((!xboardmode) && (strcmp(command, "BENCHEVAL") == 0))) { action.theType = SP_BENCHEVAL; action.data.time = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_PERFT") == 0) || ((!xboardmode) && (strcmp(command, "PERFT") == 0))) { action.theType = SP_PERFT; action.data.depth = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } if ((strcmp(command, "SP_EPDSUITE") == 0) || ((!xboardmode) && (strcmp(command, "EPDSUITE") == 0))) { action.theType = SP_EPDSUITE; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_EPDLINE") == 0) || ((!xboardmode) && (strcmp(command, "EPDLINE") == 0))) { action.theType = SP_EPDLINE; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_MODIFYBOOK") == 0) || ((!xboardmode) && (strcmp(command, "MODIFYBOOK") == 0))) { action.theType = SP_MODIFYBOOK; action.data.message = (char *) xstrdup(action.command + commandLength + 1); if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_CLOSEBOOK") == 0) || ((!xboardmode) && (strcmp(command, "CLOSEBOOK") == 0))) { action.theType = SP_CLOSEBOOK; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_SHOWMOVES") == 0) || ((!xboardmode) && (strcmp(command, "SHOWMOVES") == 0))) { action.theType = SP_SHOWMOVES; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_EVALUATE") == 0) || ((!xboardmode) && (strcmp(command, "EVALUATE") == 0))) { action.theType = SP_EVALUATE; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if (strcmp(command, "HELP") == 0) { action.theType = HELP; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); goto ENDPARSE; } if ((strcmp(command, "SP_EPDMINDEPTH") == 0) || ((!xboardmode) && (strcmp(command, "EPDMINDEPTH") == 0))) { action.theType = SP_EPDMINDEPTH; action.data.depth = parseInteger(rest); putAction(toProg, &action); if (rest != NULL) { free(rest); rest = NULL; } goto ENDPARSE; } action.theType = UNKNOWN_COMMAND; if (rest != NULL) { free(rest); rest = NULL; } putAction(toProg, &action); ENDPARSE:; } free(theinput); theinput = NULL; } free(wholeBuffer); #ifdef DEBUG fclose(debugFile); #endif return NULL; }
static void processConfigFile(char *fname) { FILE *rcFile = NULL; char buf[1024]; char *tmp, *tmp2; if (fname) rcFile = fopen(fname,"r"); if (!rcFile) rcFile = fopen("sp.rc", "r"); if (!rcFile) rcFile = fopen("sp.ini","r"); if(!rcFile) return; while(fgets(buf, 1023, rcFile)) { char *x = buf; char *key, *value; if(buf[0] == '#') continue; key = nextToken(&x, "=\t\n\r"); if(key == NULL) continue; value = nextToken(&x, "\n\n\r"); if(value == NULL) continue; tmp = lowercase(key); key = strip(tmp); free(tmp); if(!strcmp(key, "hashkilobytes")) { configvalues.hashkilobytes = parseInteger(value); } else if(!strcmp(key, "hashentries")) { configvalues.hashentries = parseInteger(value); } else if(!strcmp(key, "resign")) { configvalues.resign = - ((int) (parseDouble(value) * 100)); } else if(!strcmp(key, "verbose")) { configvalues.verbose = parseInteger(value); } else if(!strcmp(key, "logfile")) { configvalues.logfilename = strip(value); } else if(!strcmp(key, "record")) { configvalues.record = 1; } else if(!strcmp(key, "gamefile")) { configvalues.gamefilename = strip(value); } else if(!strcmp(key, "random")) { configvalues.random = parseInteger(value); } else if(!strcmp(key, "searcher")) { tmp = strip(value); tmp2 = lowercase(tmp); free(tmp); if (!strcmp(tmp2,"random")) { configvalues.engine = RANDOM_ENGINE; } else if (!strcmp(tmp2,"negascout")) { configvalues.engine = NEGASCOUT_ENGINE; } else if (!strcmp(tmp2,"onestep")) { configvalues.engine = ONESTEP_ENGINE; } else if (!strcmp(tmp2,"complete")) { configvalues.engine = COMPLETENEGAMAX_ENGINE; } else if (!strcmp(tmp2,"fixeddepth")) { configvalues.engine = MULTISTEP_ENGINE; } free(tmp2); } else if(!strcmp(key, "evaluation")) { tmp = strip(value); tmp2 = lowercase(tmp); free(tmp); if (!strcmp(tmp2,"standard")) { configvalues.evaltype = POSITIONPIECE_EVAL; } else if (!strcmp(tmp2,"relative")) { configvalues.evaltype = RELATIVEPOSITIONPIECE_EVAL; } free(tmp2); } else if(!strcmp(key, "computername")) { configvalues.computername = strip(value); } else if(!strcmp(key, "bookfile")) { configvalues.bookfilename = strip(value); } else if(!strcmp(key, "valuefile")) { configvalues.valuefilename = strip(value); } else if(!strcmp(key, "nobook")) { configvalues.usebook = 0; } else if(!strcmp(key, "novaluefile")) { configvalues.usevaluefile = 0; } else if(!strcmp(key, "noresign")) { configvalues.resign = MINVALUE - 1; } else if(!strcmp(key, "maxdepth")) { configvalues.maxdepth = parseInteger(value); } else if(!strcmp(key, "epdmindepth")) { configvalues.epdmindepth = parseInteger(value); } else if(!strcmp(key, "drawvalue")) { configvalues.drawvalue = parseInteger(value); } else if(!strcmp(key, "timeaggression")) { configvalues.timeaggression = parseInteger(value); } free(key); } fclose(rcFile); }
bool ChangeCommandParser::parseValueString(const Common::String &valueString, bool changeEntity, uint8 &sceneId, uint8 &entityId, ChangeCommand::ChangeRegister ®, ChangeCommand::ChangeOperation &op, ChangeCommandValue &ccv) { if (changeEntity) { if (valueString.size() < 8) { return false; } } else { if (valueString.size() < 7) { return false; } } sceneId = atoi(valueString.c_str() + 3); if (changeEntity) { entityId = atoi(valueString.c_str() + 6); } const char *val = ""; if (changeEntity) { if (valueString.size() >= 9) { val = valueString.c_str() + 9; } } else { if (valueString.size() >= 6) { val = valueString.c_str() + 6; } } if (valueString.hasPrefix("NM")) { reg = ChangeCommand::NM; op = ChangeCommand::SetValue; strncpy(ccv._strVal, val, MAX_ENTITY_NAME_LENGTH); } else if (valueString.hasPrefix("LT")) { reg = ChangeCommand::LT; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("SX")) { reg = ChangeCommand::SX; ccv._wordVal = parseInteger(val, op); } else if (valueString.hasPrefix("SY")) { reg = ChangeCommand::SY; ccv._wordVal = parseInteger(val, op); } else if (valueString.hasPrefix("XX")) { reg = ChangeCommand::XX; ccv._wordVal = parseInteger(val, op); } else if (valueString.hasPrefix("YY")) { reg = ChangeCommand::YY; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("XL")) { reg = ChangeCommand::XL; ccv._wordVal = parseInteger(val, op); } else if (valueString.hasPrefix("YL")) { reg = ChangeCommand::YL; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("WX")) { reg = ChangeCommand::WX; ccv._wordVal = parseInteger(val, op); } else if (valueString.hasPrefix("WY")) { reg = ChangeCommand::WY; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("AC")) { reg = ChangeCommand::AC; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("FA")) { reg = ChangeCommand::FA; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("FR")) { reg = ChangeCommand::FR; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("NA")) { reg = ChangeCommand::NA; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("FS")) { reg = ChangeCommand::FS; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("CA")) { reg = ChangeCommand::CA; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("DS")) { reg = ChangeCommand::DS; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("DL")) { reg = ChangeCommand::DL; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("ND")) { reg = ChangeCommand::ND; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("NO")) { reg = ChangeCommand::NO; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("NS")) { reg = ChangeCommand::NS; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("PF")) { reg = ChangeCommand::PF; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("PL")) { reg = ChangeCommand::PL; ccv._byteVal = parseInteger(val, op); } else if (valueString.hasPrefix("PD")) { reg = ChangeCommand::PD; ccv._byteVal = parseInteger(val, op); } return true; }
void parseASMArgs(CMDLINE *cmdline, CMDARGS *arg) { unsigned char tempbuf[256]; int block_option=0; memset(arg->fname,0,512); arg->file = 0; arg->disk = 0; arg->aun = 0; arg->block= 0; arg->level= 0; arg->count= 0; arg->offset=0; while(scanNextWord(cmdline) > 0) { if (compareKeyword(cmdline,"FILE") == 0) block_option = 5; else if (compareKeyword(cmdline,"DISK") == 0) block_option = 2; else if (compareKeyword(cmdline,"AU") == 0) block_option = 3; else if (compareKeyword(cmdline,"BLOCK") == 0) block_option = 4; else if (compareKeyword(cmdline,"LEVEL") == 0) block_option = 6; else if (compareKeyword(cmdline,"COUNT") == 0) block_option = 7; else if (compareKeyword(cmdline,"OFFSET") == 0) block_option = 8; else if (compareKeyword(cmdline,"TO") == 0) block_option = 1; else if (compareKeyword(cmdline,"PATH") == 0) block_option = 1; else { memset(tempbuf,0,256); memcpy(tempbuf,cmdline->buf+cmdline->spos, cmdline->epos - cmdline->spos); tempbuf[cmdline->epos - cmdline->spos]='\0'; switch(block_option) { case 1: memcpy(arg->fname, cmdline->buf+cmdline->spos, MIN(cmdline->epos - cmdline->spos,256)); break; case 2: arg->disk = parseInteger(tempbuf); break; case 3: arg->aun = parseInteger(tempbuf); break; case 4: arg->block = parseInteger(tempbuf); break; case 5: arg->file = parseInteger(tempbuf); break; case 6: arg->level = parseInteger(tempbuf); break; case 7: arg->count = parseInteger(tempbuf); break; case 8: arg->offset = parseInteger(tempbuf); break; } block_option = 0; } } }
void TomlParser::load() { bool formatStrMode = false, rawStrMode = false, escMode = false bool endOfStrMode = false, endOfLine = false; string currLine = ""; string currStr = ""; TomlHash currHash = null; TomlKey currKey = null; int lineNumber = 1; char currChar; for(; !stream.eof(); lineNumber++)//this is the line loop { lineloopstart: endOfLine = false; if(formatStrMode || rawStrMode) { throw new TomlError( "Multiline strings not supported. Use \"\\n\" instead.", lineNumber); } rawStrMode = false; formatStrMode = false; getline(stream, currLine); clipSpaces(currLine); for(int i=1; i<currLine.length(); i++)//this goes over each character { currChar = currLine[i]; if(endOfLine) { throw new TomlError( "What are you trying to do with these random characters?", lineNumber); } else if(formatStrMode) { //parse string } else if(rawStrMode) { if(currChar=='\'') { rawStrMode = false; endOfLine = true; } else { currStr.append(1,currChar); } } else if(endOfStrMode) { goto eos; } else { switch(currChar) { case '#': goto lineloopstart; case '"': formatStrMode = true; break; case '\'': rawStrMode = true; break; case '[': string hashName = ""; while(currChar != ']') { hashName.append(1,currChar); i++; currChar = currLine[i]; } currHash = new TomlHash(hashName, currHash); endOfLine = true; break; default://it's a key eos: if(endOfStrMode) { currKey.type = "STRING"; currKey.value = currStr; break; } string name = ""; while(currChar != '=') { name.append(&currChar); i++; currChar = currLine.at(i); } i++;//we go past the = currChar = currLine.at(i); string valueStr = currLine.substr(i + 1); try { long value = parseInteger(valueStr); currKey = new TomlKey(name, valueStr, "INTEGER", currHash); } catch(int i) { try//This is the only way { bool value = parseBoolean(valueStr); currKey = new TomlKey(name, valueStr, "BOOL", currHash); catch(int i) { try { double value = parseDouble( line.substr(valueStr)); currKey.value = valueStr; currKey = new TomlKey(name, valueStr, "FLOAT", currHash); catch(int i) { //ignore it } } } } }//end try-catch }//end switch }//end else }//end inner for