const PHPDocProperty::Tuple_t& PHPDocProperty::ParseParams() { m_params.clear(); wxArrayString lines = ::wxStringTokenize(m_comment, "\n\r", wxTOKEN_STRTOK); for(size_t i = 0; i < lines.size(); ++i) { const wxString& line = lines.Item(i); size_t offset = 0; wxString word; while(NextWord(line, offset, word)) { if(!word.IsEmpty() && word.StartsWith("@property")) { wxString stype, sname, sdesc; if(NextWord(line, offset, word)) { stype = word; if(NextWord(line, offset, word)) { sname = word; // The remainder is the description sdesc = line.Mid(offset); m_params.push_back(std::make_tuple(m_sourceFile.MakeIdentifierAbsolute(stype), sname, sdesc)); } } } } } return m_params; }
bool Assembler::ParseLine(string& line, int linecount, Assembly& assembly, LabelVector& labels) { string op; int i = NextWord(line, op); // skip commented and empty lines if(i == -1 || op == "//" || op == ";") return true; // this is a a very slow way of doing things, but then this code will only // be used during development and for debugging OpDesc *opcode; int codecount = sizeof(opcodes)/sizeof(OpDesc); int j = 0; for(; j < codecount; j ++) { if(stricmp(opcodes[j].name, op.c_str()) == 0) { opcode = &opcodes[j]; break; } } // is this a label? if(j == codecount) { size_t k = op.length() - 1; if(op.find_first_of(":") == k) { string name = op.substr(0, k); labels.at(AddLabel(name, labels)).pos = assembly.curpos; return true; } else return false; } else { assembly.WriteDword(opcode->code); string param; i = NextWord(line, param, i); if(IsJumpOp(opcode->code)) { // write the label index, we'll later replace this with the code position assembly.WriteDword(AddLabel(param, labels)); } else { if(i == -1) { assembly.WriteDword(0); if(opcode->paramcount > 0) return false; // if we need more params, bail } else assembly.WriteDword(StringToOperand(param, opcode)); } } return true; }
void SpellCheck::OnClickedAdd() { // Check for invalid characters bool invalid = false; for (int i = 0; i < m_currentBadWord.GetLength(); i++) { if (m_currentBadWord[i] > 255) invalid = true; } if (invalid) { CString msg; msg.Format( "Cannot add the word to the dictionary, as it contains characters\n" "outside of the dictionary's character set, %s.",spell->get_dic_encoding()); MessageBox(msg,INFORM_TITLE,MB_ICONERROR|MB_OK); return; } // Add the word if it is not already in the dictionary CString word = TextFormat::UnicodeToLatin1(m_currentBadWord); if (spell->spell(word) == 0) spell->add(word); NextWord(); }
int CManageObject::WordRemove(int wordid) { if(_bBuilt == false) return 0; if(wordid == _stCacheRec.m_iID) { return NextWord(); } TScoreMap::iterator it = _mapScore.begin(); while(it != _mapScore.end()) { TRecordList::iterator i = it->second.begin(); while(i != it->second.end()) { if(i->m_iID == wordid) { it->second.erase(i); if(it->second.size() == 0) { UpdateScoreVector(it->first, false); _mapScore.erase(it); } return 0; } ++ i; } ++ it; } return 0; }
/* seek next PARAM element content: "<PARAM ... >" (delimiters excluded) and return next trailing stream */ static char * NextParam(char *stream, NString *param) { NString element, word; do { stream = NextElement(stream, &element); if (element.length) /* get element name */ (void) NextWord(element.ptr + 1, element.ptr + element.length - 1, &word); else { /* no more elements stop here */ param->ptr = 0; param->length = 0; return stream; } /* check if it's a PARAM element */ } while(word.length != 5 && memcmp("PARAM", word.ptr, 5) != 0 && *stream); param->ptr = word.ptr + word.length; param->length = element.length - word.length - 1; /* delimiters excluded */ return stream; }
int CManageObject::NextWord(int offset) { if(_iCacheScore != -1) { if(PushWord(_iCacheScore, _stCacheRec, offset) != 0) return -1; } return NextWord(); }
/* Checks if the cursor can move through comments and white spaces to the end of * line or file. If so, it updates the position of cursor and returns TRUE. */ __regargs BOOL EndOfLine(char **data) { char *str = *data; if (NextWord(&str)) return FALSE; *data = str; return TRUE; }
size_t FileUtils::SplitWords(const wxString& str, wxStringSet_t& outputSet, bool makeLower) { size_t offset = 0; wxString word; outputSet.clear(); while(NextWord(str, offset, word, makeLower)) { outputSet.insert(word); } return outputSet.size(); }
bool FileUtils::FuzzyMatch(const wxString& needle, const wxString& haystack) { wxString word; size_t offset = 0; wxString lcHaystack = haystack.Lower(); while(NextWord(needle, offset, word, true)) { if(!lcHaystack.Contains(word)) { return false; } } return true; }
/* Moves cursor to the first character of next line. If there's no next line * moves cursor to '\0' character. */ __regargs void SkipLine(char **data) { char *str = *data; while (NextWord(&str)) SkipWord(&str); if (*str == '\n') str++; *data = str; }
// ------------------------------------------------------------------------ bool S4::Interpreter::Step() { Lexeme l; if (!NextWord(&l)) { printf(".step:\tthinking it is end of input\n\t-->%s\n", programCounter); return false; } Word *word; switch (l.kind) { case Lexeme::endOfInput: printf(".step:\tendOfInput\n"); return false; case Lexeme::integer: if (IsCompileMode()) { return true; } printf(".push:\tinteger %d\n", l.data.integer); dataStack.push(CellFromInteger(l.data.integer)); return true; case Lexeme::number: if (IsCompileMode()) { return true; } printf(".push:\tnumber %g\n", l.data.number); dataStack.push(CellFromNumber(l.data.number)); return true; case Lexeme::symbol: printf(".eval:\tsymbol %s\n", l.data.symbol); word = dictionary->Lookup(l.data.symbol); if (!word) { printf("error:\tundefined word '%s'\n", l.data.symbol); return false; } if (IsCompileMode()) { return word->Compile(this); } return word->Execute(this); case Lexeme::text: if (IsCompileMode()) { return true; } printf(".push:\ttext %s\n", l.data.text); dataStack.push(CellFromText(l.data.text)); return true; } printf("panic:\tunknown lexeme %d\n", l.kind); exit(2); // NOT REACHED return false; }
/* Moves cursor to next word of a non-empty line. Returns FALSE if there's no * next line. */ __regargs BOOL NextLine(char **data) { char *str = *data; while (!NextWord(&str)) { if (*str == '\n') str++; if (*str == '\0') break; } *data = str; return *str; }
/* void next (in wstring text, in long length, in long pos, out boolean hasMoreUnits, out long begin, out long end); */ NS_IMETHODIMP nsSemanticUnitScanner::Next(const char16_t *text, int32_t length, int32_t pos, bool isLastBuffer, int32_t *begin, int32_t *end, bool *_retval) { // xxx need to bullet proff and check input pointer // make sure begin, end and _retval is not nullptr here // if we reach the end, just return if (pos >= length) { *begin = pos; *end = pos; *_retval = false; return NS_OK; } uint8_t char_class = nsSampleWordBreaker::GetClass(text[pos]); // if we are in chinese mode, return one han letter at a time // we should not do this if we are in Japanese or Korean mode if (kWbClassHanLetter == char_class) { *begin = pos; *end = pos+1; *_retval = true; return NS_OK; } int32_t next; // find the next "word" next = NextWord(text, (uint32_t) length, (uint32_t) pos); // if we don't have enough text to make decision, return if (next == NS_WORDBREAKER_NEED_MORE_TEXT) { *begin = pos; *end = isLastBuffer ? length : pos; *_retval = isLastBuffer; return NS_OK; } // if what we got is space or punct, look at the next break if ((char_class == kWbClassSpace) || (char_class == kWbClassPunct)) { // if the next "word" is not letters, // call itself recursively with the new pos return Next(text, length, next, isLastBuffer, begin, end, _retval); } // for the rest, return *begin = pos; *end = next; *_retval = true; return NS_OK; }
Static void addStyle(Char *S) { style_index0 sn; Char STR1[256]; sn = findStyle(NextWord(STR1, S, colon_, dummy)); if (sn > 0) { strcpy(known_style[sn-1], S); return; } if (known_styles < max_styles) { known_styles++; strcpy(known_style[known_styles-1], S); } else error("Can't add another style - table full", print); }
__regargs BOOL ReadInt(char **data, LONG *numptr) { char *str = *data; char c; LONG num = 0; BOOL minus = FALSE; BOOL hex = FALSE; /* Skip white spaces. */ if (!NextWord(&str)) return FALSE; /* Read optional sign character. */ if (*str == '-') str++, minus = TRUE; if (*str == '$') str++, hex = TRUE; /* Read at least one digit. */ c = *str; if (hex) { if (!isxdigit(c)) return FALSE; while (isxdigit(c)) { num = num * 16 + xdigit(c); c = *(++str); } } else { if (!isdigit(c)) return FALSE; while (isdigit(c)) { num = num * 10 + digit(c); c = *(++str); } } *data = str; if (numptr) *numptr = minus ? -num : num; return TRUE; }
//----------------------------------------------------------------------------- bool TestCommandHandle::Parse(const char* params) { static const std::string argCount = "count"; static const std::string argDepth = "depth"; static const std::string argFile = "file"; static const std::string argGain = "gain"; static const std::string argNoClear = "noclear"; static const std::string argPrint = "print"; static const std::string argSkip = "skip"; static const std::string argTime = "time"; noClear = false; printBoard = false; maxCount = 0; maxDepth = 0; minGain = 0; skipCount = 0; maxTime = 0; fileName = ""; bool invalid = false; while (!invalid && params && *NextWord(params)) { if (HasParam(argNoClear, noClear, params) || HasParam(argPrint, printBoard, params) || NumberParam(argCount, maxCount, params, invalid) || NumberParam(argDepth, maxDepth, params, invalid) || NumberParam(argGain, minGain, params, invalid) || NumberParam(argSkip, skipCount, params, invalid) || NumberParam(argTime, maxTime, params, invalid) || StringParam(argFile, fileName, params, invalid)) { continue; } Output() << "Unexpected token: " << params; return false; } if (invalid) { Output() << "usage: " << Usage(); return false; } if (fileName.empty()) { fileName = _TEST_FILE; } return true; }
__regargs WORD ReadString(char **data, char *buf, WORD buflen) { char *str = *data; BOOL escape = FALSE; BOOL quote = FALSE; WORD n = 0; char c; if (!NextWord(&str)) return 0; if (*str == '"') str++, quote = TRUE; while ((c = *str) && n < buflen - 1) { if (!escape) { if (c == '#') break; else if (c == '\\') escape = TRUE; else if (c == '"' && quote) { str++; break; } else if (isspace(c) && !quote) break; else *buf++ = c, n++; } else { escape = FALSE; if (c != '\n') { if (c == 't') c = '\t'; if (c == 'n') c = '\n'; if (c == 'r') c = '\r'; if (c == '0') c = '\0'; *buf++ = c, n++; } } str++; } if (n == buflen) return -1; *buf = '\0'; *data = str; return n; }
//----------------------------------------------------------------------------- //! \brief Perform [q]perft search, \p params format = 'D<depth> <leafs>' //! \param[in] params The parameter string //! \param[out] count Incremented by the number of perft nodes visited //! \param[out] nodes Incremented by the number of nodes visited //! \param[out] qnodes Incremented by the number of quiescence nodes visited //! \return false if count does not match expected count //----------------------------------------------------------------------------- bool PerftCommandHandle::Process(const char* params, uint64_t& count, uint64_t& nodes, uint64_t& qnodes) { const char* p = (params + 1); int depth = 0; while (*p && isdigit(*p)) { depth = ((10 * depth) + (*p++ - '0')); if (depth < 0) { Output() << "invalid depth: " << params; return true; } } if (!depth || (maxDepth && (depth > maxDepth))) { return true; } NextWord(p); uint64_t expected = 0; while (*p && isdigit(*p)) { expected = ((10 * expected) + (*p++ - '0')); } if (!expected || (maxLeafs && (expected > maxLeafs))) { return true; } Output() << "--- " << depth << " => " << expected; uint64_t perft_count = qperft ? engine->QPerft(depth) : engine->Perft(depth); uint64_t node_count = 0; uint64_t qnode_count = 0; engine->GetStats(NULL, NULL, &node_count, &qnode_count); count += perft_count; nodes += node_count; qnodes += qnode_count; if (!qperft && (perft_count != expected)) { Output() << "--- " << perft_count << " != " << expected; return false; } return true; }
// Get the next token NNT Lexer::Next() { restart: // Delegate based on the next character in the file stream if (ifs.eof()) { RETURN_NNT("", eof, 0); } else if (IsAlphaOrUnderscore(*cursor)) { return NextWord(); } else if (IsDigit(*cursor)) { return NextNumber(); } switch (*cursor) { case '\t': case ' ': IncrementCursor(); goto restart; // Explicit TCO case '\0': IncrementCursor(); RETURN_NNT("", newline, 0); default: return NextOperator(); } }
__regargs BOOL ReadFloat(char **data, FLOAT *numptr) { char *str = *data; char c; LONG p = 0, q = 1; BOOL minus = FALSE, dot = FALSE; /* Skip white spaces. */ if (!NextWord(&str)) return FALSE; /* Read optional sign character. */ if (*str == '-') str++, minus = TRUE; /* Read at least one digit. */ c = *str; if (!isdigit(c)) return FALSE; while (1) { if (!dot && c == '.') { dot = TRUE; } else if (!isdigit(c)) { break; } else { p = p * 10 + digit(c); if (dot) q *= 10; } c = *(++str); } *data = str; if (numptr) *numptr = SPDiv(SPFlt(q), SPFlt(minus ? -p : p)); return TRUE; }
//----------------------------------------------------------------------------- bool PerftCommandHandle::Parse(const char* params) { static const std::string argCount = "count"; static const std::string argDepth = "depth"; static const std::string argEpd = "epd"; static const std::string argFile = "file"; static const std::string argLeafs = "leafs"; static const std::string argSkip = "skip"; count = 0; skip = 0; maxDepth = 0; maxLeafs = 0; fileName = ""; bool epd = false; bool invalid = false; while (!invalid && params && *NextWord(params)) { if (HasParam(argEpd, epd, params) || NumberParam(argCount, count, params, invalid) || NumberParam(argSkip, skip, params, invalid) || NumberParam(argDepth, maxDepth, params, invalid) || NumberParam(argLeafs, maxLeafs, params, invalid) || StringParam(argFile, fileName, params, invalid)) { continue; } Output() << "Unexpected token: " << params; return false; } if (invalid) { Output() << "usage: " << Usage(); return false; } if (epd && fileName.empty()) { fileName = _TEST_FILE; } return true; }
/* Moves cursor to first white space character after next word. Understands * escape character '\'. */ __regargs void SkipWord(char **data) { char *str = *data; BOOL escape = FALSE; if (NextWord(&str)) { char c; while ((c = *str)) { if (escape) { escape = FALSE; } else if (c == '\\') { escape = TRUE; } else if (isspace(c)) { break; } str++; } *data = str; } }
Static boolean isControlParagraph(Char (*P)[256], paragraph_index para_len) { paragraph_index0 commands = 0, labels = 0, voices = 0, guff = 0; paragraph_index0 i; Char w[256]; /* p2c: prepmx.pas: Note: Eliminated unused assignment statement [338] */ for (i = 0; i <= para_len - 1; i++) { if (!startsWith(P[i], "%")) { NextWord(w, P[i], ' ', ':'); if (!endsWith(w, ":")) guff++; else if (strlen(w) < 3 || findVoice(w) > 0) voices++; else if (isCommand(w)) commands++; else labels++; } } if (voices + guff > commands) return false; return true; }
void SpellCheck::OnClickedReplace() { // Get the replacement text CStringW replace; if (m_suggestions.IsWindowEnabled()) { int sel = m_suggestions.GetCurSel(); if (sel == -1) { MessageBox("There is no suggestion selected to replace the word with.", INFORM_TITLE,MB_ICONERROR|MB_OK); return; } CString replaceA; m_suggestions.GetText(sel,replaceA); replace = replaceA; } else m_badWord.GetWindowText(replace); // Replace the selection, then move to the next word m_edit->ReplaceSelect(replace); NextWord(); }
void text_wrapper::ChunkText(void) { int c_st = -1, c_en = -1; for (int i = 0; i < glyph_length; i++) { int g_st = glyph_text[i].uni_st, g_en = glyph_text[i].uni_en; glyph_text[i].char_start = false; glyph_text[i].word_start = false; glyph_text[i].para_start = false; // boundaries depend on the directionality // letter boundaries correspond to the glyphs starting one letter when you read them left to right (always) // because that's the order they are stored into in the glyph_text array if ( glyph_text[i].uni_dir == 0 ) { if ( IsBound(bnd_char, g_st, c_st) ) { // check if there is a charcater (=letter in pango speak) at this position // can be a 'start' boundary or a 'end' boundary, doesn't matter, as long // as you get from one letter to the next at this position if ( g_st == bounds[c_st].uni_pos ) glyph_text[i].char_start = true; } if ( IsBound(bnd_word, g_st, c_st) ) { if ( g_st == bounds[c_st].uni_pos ) glyph_text[i].word_start = true; } if ( IsBound(bnd_para, g_st, c_st) ) { if ( g_st == bounds[c_st].uni_pos ) glyph_text[i].para_start = true; } } else { if ( IsBound(bnd_char, g_en, c_en) ) { if ( g_en == bounds[c_en].uni_pos ) glyph_text[i].char_start = true; } if ( IsBound(bnd_word, g_en, c_en) ) { if ( g_en == bounds[c_en].uni_pos ) glyph_text[i].word_start = true; } if ( IsBound(bnd_para, g_en, c_en) ) { if ( g_en == bounds[c_en].uni_pos ) glyph_text[i].para_start = true; } } } if ( glyph_length > 0 ) { glyph_text[glyph_length].char_start = true; glyph_text[glyph_length].word_start = true; glyph_text[glyph_length].para_start = true; } { // doing little boxes int g_st = -1, g_en = -1; while ( NextWord(g_st, g_en) ) { // check uniformity of fonts if ( g_st < g_en ) { int n_st = g_st; int n_en = g_st; bool first = true; do { n_st = n_en; PangoFont *curPF = glyph_text[n_st].font; do { n_en++; } while ( n_en < g_en && glyph_text[n_en].font == curPF ); if ( nbBox >= maxBox ) { maxBox = 2 * nbBox + 1; one_box *newdata = static_cast<one_box*>(realloc(boxes, maxBox * sizeof(one_box))); if (newdata != NULL) { boxes = newdata; } else { g_warning("Failed to reallocate boxes"); } } boxes[nbBox].g_st = n_st; boxes[nbBox].g_en = n_en; boxes[nbBox].word_start = first; boxes[nbBox].word_end = (n_en >= g_en); nbBox++; first = false; } while ( n_en < g_en ); } } } { // doing little paras int g_st = -1, g_en = -1; while ( NextPara(g_st, g_en) ) { int b_st = 0; while ( b_st < nbBox && boxes[b_st].g_st < g_st ) b_st++; if ( b_st < nbBox && boxes[b_st].g_st == g_st ) { int b_en = b_st; while ( b_en < nbBox && boxes[b_en].g_en < g_en ) b_en++; if ( b_en < nbBox && boxes[b_en].g_en == g_en ) { if ( nbPara >= maxPara ) { maxPara = 2 * nbPara + 1; one_para *newdata = static_cast<one_para*>(realloc(paras, maxPara * sizeof(one_para))); if (newdata != NULL) { paras = newdata; } else { g_warning("Failed to reallocate paras"); } } paras[nbPara].b_st = b_st; paras[nbPara].b_en = b_en; nbPara++; } } } } }
//--------------------------------------------------------------------------- UnicodeString WrapText(const UnicodeString & Line, intptr_t MaxWidth) { UnicodeString Result; intptr_t LenBuffer = 0; intptr_t SpaceLeft = MaxWidth; if (MaxWidth == 0) { MaxWidth = 78; } if (MaxWidth < 5) { MaxWidth = 5; } /* two passes through the input. the first pass updates the buffer length. * the second pass creates and populates the buffer */ while (Result.Length() == 0) { intptr_t LineCount = 0; if (LenBuffer) { /* second pass, so create the wrapped buffer */ Result.SetLength(LenBuffer + 1); if (Result.Length() == 0) { break; } } wchar_t * w = const_cast<wchar_t *>(Result.c_str()); /* for each Word in Text if Width(Word) > SpaceLeft insert line break before Word in Text SpaceLeft := LineWidth - Width(Word) else SpaceLeft := SpaceLeft - Width(Word) + SpaceWidth */ const wchar_t * s = NextWord(Line.c_str()); while (*s) { SpaceLeft = MaxWidth; /* force the first word to always be completely copied */ while (*s) { if (Result.Length() == 0) { ++LenBuffer; } else { *(w++) = *s; } --SpaceLeft; ++s; } if (!*s) { s = NextWord(nullptr); } /* copy as many words as will fit onto the current line */ while (*s && static_cast<intptr_t>(wcslen(s) + 1) <= SpaceLeft) { if (Result.Length() == 0) { ++LenBuffer; } --SpaceLeft; /* then copy the word */ while (*s) { if (Result.Length() == 0) { ++LenBuffer; } else { *(w++) = *s; } --SpaceLeft; ++s; } if (!*s) { s = NextWord(nullptr); } } if (!*s) { s = NextWord(nullptr); } if (*s) { /* add a new line here */ if (Result.Length() == 0) { ++LenBuffer; } else { *(w++) = L'\n'; } // Skip whitespace before first word on new line while (iswspace(*s)) { ++s; } } ++LineCount; } LenBuffer += 2; if (w) { *w = 0; } } return Result; }
void ReadMaterialComp() { char *input, fname[MAX_STR], word[MAX_STR], pname[MAX_STR], **params; long loc0, loc1, mat, mat0, iso, iso0, nuc, i0, i, np, j, n, line, r, g, b; double val, sum; FILE *fp; /* Get pointer to file list */ if ((loc0 = (long)RDB[DATA_PTR_COMP_FILE]) < VALID_PTR) return; fprintf(out, "Overriding initial material compositions...\n"); /* Reset previous pointer */ mat0 = -1; /* Reset counters for line number calculation */ WDB[DATA_LINE_NUM_N0] = 0.0; WDB[DATA_LINE_NUM_NL0] = 1.0; /* Loop over list */ while (RDB[loc0] > VALID_PTR) { /* Get file name */ sprintf(fname, "%s", GetText(loc0)); /* Check that file exists */ if ((fp = fopen(fname, "r")) != NULL) fclose(fp); else { /* File not found */ Error(0, "Material composition file \"%s\" does not exist", fname); } /* Read input file */ input = ReadTextFile(fname); /* Avoid compiler warning */ params = NULL; /* Loop over file */ i0 = 0; while ((i = NextWord(&input[i0], word)) > 0) { /* update pointer */ i0 = i0 + i; /* Get line number for error messages */ line = GetLineNumber(input, i0); /* Look for material definition */ if (!strcasecmp(word, "mat")) { /* Copy parameter name */ strcpy (pname, word); /* Read parameters */ params = GetParams(word, input, &np, &i0, 4, 4*MAX_ISOTOPES + 8, fname); /* Read data */ j = 0; /* Find material (try starting from previous) */ mat = mat0; while (mat > VALID_PTR) { /* Compare */ if (!strcmp(params[j], GetText(mat + MATERIAL_PTR_NAME))) break; /* Next */ mat = NextItem(mat); } /* Find material (start from beginning) */ if (mat < VALID_PTR) { mat = (long)RDB[DATA_PTR_M0]; while (mat > VALID_PTR) { /* Compare */ if (!strcmp(params[j], GetText(mat + MATERIAL_PTR_NAME))) break; /* Next */ mat = NextItem(mat); } } /* Check */ if (mat < VALID_PTR) Error(-1, pname, fname, line, "Material %s is not defined", params[j]); else j++; /* Remember previous */ mat0 = NextItem(mat); /* Material density */ if (!strcmp(params[j], "sum")) { /* Set value to -inf to calculate sum from composition */ WDB[mat + MATERIAL_ADENS] = -INFTY; j++; } else { /* Read value */ WDB[mat + MATERIAL_ADENS] = TestParam(pname, fname, line, params[j++], PTYPE_REAL, -1000.0, 1000.0); } /* Reset sum */ sum = 0.0; /* Reset previous pointer */ iso0 = -1; /* Loop over parameters */ while (j < np) { /* Check parameter */ if (!strcmp(params[j], "tmp")) { /***** Temperature for Doppler-breadening **************/ j++; /* Get temperature */ WDB[mat + MATERIAL_DOPPLER_TEMP] = TestParam(pname, fname, line, params[j++], PTYPE_REAL, 0.0, 100000.0); /* Set option */ WDB[DATA_USE_DOPPLER_PREPROCESSOR] = (double)YES; /*******************************************************/ } if (!strcmp(params[j], "tms") || !strcmp(params[j], "ettm")) { /***** Temperature for TMS *****************************/ j++; /* Get temperature */ WDB[mat + MATERIAL_TMS_TMIN] = TestParam(pname, fname, line, params[j++], PTYPE_REAL, 0.0, 100000.0); /* Copy to maximum */ WDB[mat + MATERIAL_TMS_TMAX] = RDB[mat + MATERIAL_TMS_TMIN]; /* Set mode */ WDB[DATA_TMS_MODE] = (double)TMS_MODE_CE; WDB[mat + MATERIAL_TMS_MODE] = (double)YES; /*******************************************************/ } else if (!strcmp(params[j], "rgb")) { /***** Material colour *********************************/ j++; /* Get r, b and g */ r = TestParam(pname, fname, line, params[j++], PTYPE_INT, 0, 255); g = TestParam(pname, fname, line, params[j++], PTYPE_INT, 0, 255); b = TestParam(pname, fname, line, params[j++], PTYPE_INT, 0, 255); /* Set color */ WDB[mat + MATERIAL_RGB] = b + 1000.0*g + 1000000.0*r; /*******************************************************/ } else if (!strcmp(params[j], "vol")) { /***** Material volume *********************************/ j++; /* Get volume */ WDB[mat + MATERIAL_VOLUME_GIVEN] = TestParam(pname, fname, line, params[j++], PTYPE_REAL, 0.0, INFTY); /*******************************************************/ } else if (!strcmp(params[j], "fix")) { /***** Default library ID and temperature***************/ j++; /* Get default ID and temperature */ WDB[mat + MATERIAL_DEFAULT_PTR_LIB_ID] = PutText(params[j++]); WDB[mat + MATERIAL_DEFAULT_TMP] = TestParam(pname, fname, line, params[j++], PTYPE_REAL, 0.0, INFTY); /*******************************************************/ } else if (!strcmp(params[j], "mass")) { /***** Material mass ***********************************/ j++; /* Get mass */ WDB[mat + MATERIAL_MASS_GIVEN] = TestParam(pname, fname, line, params[j++], PTYPE_REAL, 0.0, INFTY); /*******************************************************/ } else if (!strcmp(params[j], "burn")) { /***** Burnable material *******************************/ j++; /* Set burn flag */ SetOption(mat + MATERIAL_OPTIONS, OPT_BURN_MAT); /* Set burn sort flag and materials flag */ WDB[mat + MATERIAL_BURN_SORT_FLAG] = 1.0; WDB[DATA_BURN_MATERIALS_FLAG] = (double)YES; /* Get number of rings */ WDB[mat + MATERIAL_BURN_RINGS] = (double)TestParam(pname, fname, line, params[j++], PTYPE_INT, 0, 10000000); /*******************************************************/ } else if (!strcmp(params[j], "moder")) { /***** Thermal scattering data *************************/ j++; /* Check number of parameters */ if (j > np - 3) Error(mat, "Invalid number of parameters"); /* Create new item (use the same structure as with */ /* the therm card) */ WDB[mat + MATERIAL_PTR_SAB] = NULLPTR; loc1 = NewItem(mat + MATERIAL_PTR_SAB, THERM_BLOCK_SIZE); /* Read name */ WDB[loc1 + THERM_PTR_ALIAS] = (double)PutText(params[j++]); /* Read ZA */ WDB[loc1 + THERM_ZA] = (double)TestParam(pname, fname, line, params[j++], PTYPE_INT, 1001, 120000); /*******************************************************/ } else if (!strcmp(params[j], "tft")) { /***** Minimum and maximum temperatures for TMS ********/ j++; /* Get minimum temperature */ WDB[mat + MATERIAL_TMS_TMIN] = TestParam(pname, fname, line, params[j++], PTYPE_REAL, 0.0, 100000.0); /* Get maximum temperature */ WDB[mat + MATERIAL_TMS_TMAX] = TestParam(pname, fname, line, params[j++], PTYPE_REAL, RDB[mat + MATERIAL_TMS_TMIN], 100000.0); /* Set mode */ WDB[DATA_TMS_MODE] = (double)TMS_MODE_CE; WDB[mat + MATERIAL_TMS_MODE] = (double)YES; /*******************************************************/ } else { /***** Composition *************************************/ /* Find nuclide in composition (start from previous) */ iso = iso0; while (iso > VALID_PTR) { /* Pointer to nuclide data */ nuc = (long)RDB[iso + COMPOSITION_PTR_NUCLIDE]; CheckPointer(FUNCTION_NAME, "(nuc)", DATA_ARRAY,nuc); /* Compare */ if (!strcmp(GetText(nuc + NUCLIDE_PTR_NAME), params[j])) break; /* Next */ iso = NextItem(iso); } /* Find nuclide in composition (start from beginning) */ if (iso < VALID_PTR) { iso = (long)RDB[mat + MATERIAL_PTR_COMP]; while (iso > VALID_PTR) { /* Pointer to nuclide data */ nuc = (long)RDB[iso + COMPOSITION_PTR_NUCLIDE]; CheckPointer(FUNCTION_NAME, "(nuc)", DATA_ARRAY,nuc); /* Compare */ if (!strcmp(GetText(nuc + NUCLIDE_PTR_NAME), params[j])) break; /* Next */ iso = NextItem(iso); } } /* Check pointer */ if (iso < VALID_PTR) Error(-1, pname, fname, line, "Material %s has no nuclide %s in composition", GetText(mat + MATERIAL_PTR_NAME), params[j]); else j++; /* Remember pointer */ iso0 = iso; /* Read fraction */ val = TestParam(pname, fname, line, params[j++], PTYPE_REAL, -100.0, 1E+25); /* Put value */ WDB[iso + COMPOSITION_ADENS] = val; /* Add to sum */ sum = sum + val; /*******************************************************/ } } /* Set density if sum */ if (RDB[mat + MATERIAL_ADENS] == -INFTY) WDB[mat + MATERIAL_ADENS] = sum; /* Calculate normalized fractions */ IsotopeFractions(mat); } /* Free parameter list */ if (np > 0) for (n = 0; n < np + 1; n++) Mem(MEM_FREE, params[n]); } /* Free memory */ Mem(MEM_FREE, input); /* Next file */ loc0++; } /* This must be called to get the divided compositions into material */ /* structures */ SumDivCompositions(); fprintf(out, "OK.\n\n"); }
//----------------------------------------------------------------------------- void TestCommandHandle::Execute() { if (!engine) { Output() << "Engine not set for 'test' command"; return; } if (fileName.empty()) { Output() << "FileName not set for 'test' command"; return; } char fen[16384]; int depth = 0; int line = 0; int maxSearchDepth = 0; int maxSeldepth = 0; int minSearchDepth = -1; int minSeldepth = -1; int passed = 0; int positions = 0; int seldepth = 0; int tested = 0; int totalDepth = 0; int totalSeldepth = 0; uint64_t nodes = 0; uint64_t qnodes = 0; uint64_t time = 0; uint64_t totalNodes = 0; uint64_t totalQnodes = 0; uint64_t totalTime = 0; FILE* fp = NULL; try { MoveFinder moveFinder; if (!(fp = fopen(fileName.c_str(), "r"))) { Output() << "Cannot open '" << fileName << "': " << strerror(errno); return; } engine->ClearStopFlags(); engine->ResetStatsTotals(); while (fgets(fen, sizeof(fen), fp)) { line++; char* f = fen; if (!*NextWord(f) || (*f == '#')) { continue; } positions++; if (skipCount && (positions <= skipCount)) { continue; } Output() << "--- Test " << (++tested) << " at line " << line << ' ' << f; NormalizeString(f); const char* next = engine->SetPosition(f); if (!next || !moveFinder.LoadFEN(f)) { break; } f += (next - f); // consume 'am' and 'bm' parameters std::set<std::string> avoid; std::set<std::string> best; while (f && *NextWord(f)) { // null terminate this parameter (parameters end with ; or end of line) char* end = strchr(f, ';'); if (end) { *end = 0; } if (!strncmp(f, "am ", 3)) { f += 3; while (*NextWord(f)) { std::string coord = moveFinder.ToCoordinates(f); if (coord.size()) { avoid.insert(coord); } else { break; } } } else if (!strncmp(f, "bm ", 3)) { f += 3; while (*NextWord(f)) { std::string coord = moveFinder.ToCoordinates(f); if (coord.size()) { best.insert(coord); } else { break; } } } // move 'f' to beginning of next parameter if (end) { f = (end + 1); continue; } break; } if (avoid.empty() && best.empty()) { Output() << "error at line " << line << ", no best or avoid moves specified"; break; } if (!noClear) { engine->ClearSearchData(); } if (printBoard) { engine->PrintBoard(); } const std::string bestmove = engine->Go(maxDepth, 0, maxTime); Output(Output::NoPrefix) << "bestmove " << bestmove; engine->GetStats(&depth, &seldepth, &nodes, &qnodes, &time); if (bestmove.empty() || (best.size() && !best.count(bestmove)) || (avoid.size() && avoid.count(bestmove))) { Output() << "--- FAILED! line " << line << " (" << Percent(passed, tested) << "%) " << f; } else { passed++; Output() << "--- Passed. line " << line << " (" << Percent(passed, tested) << "%) " << f; } if (depth > maxSearchDepth) { maxSearchDepth = depth; } if ((minSearchDepth < 0) || (depth < minSearchDepth)) { minSearchDepth = depth; } if (seldepth > maxSeldepth) { maxSeldepth = seldepth; } if ((minSeldepth < 0) || (seldepth < minSeldepth)) { minSeldepth = seldepth; } totalDepth += depth; totalNodes += nodes; totalQnodes += qnodes; totalSeldepth += seldepth; totalTime += time; if (engine->StopRequested() || (maxCount && (tested >= maxCount))) { break; } } Output() << "--- Completed " << tested << " test positions"; Output() << "--- Passed " << passed << " passed (" << Percent(passed, tested) << "%)"; Output() << "--- Time " << totalTime << " (" << Average(totalTime, static_cast<uint64_t>(tested)) << " avg)"; Output() << "--- Nodes " << totalNodes << ", " << Rate((totalNodes / 1000), totalTime) << " KNodes/sec"; Output() << "--- QNodes " << totalQnodes << " (" << Percent(totalQnodes, totalNodes) << "%)"; Output() << "--- Depth " << minSearchDepth << " min, " << static_cast<int>(Average(totalDepth, tested)) << " avg, " << maxSearchDepth << " max"; Output() << "--- SelDepth " << minSeldepth << " min, " << static_cast<int>(Average(totalSeldepth, tested)) << " avg, " << maxSeldepth << " max"; engine->ShowStatsTotals(); } catch (const std::exception& e) { Output() << "ERROR: " << e.what(); } catch (...) { Output() << "Unknown error!"; } if (fp) { fclose(fp); fp = NULL; } }
//----------------------------------------------------------------------------- bool GoCommandHandle::Parse(const char* params) { static const std::string argBinc = "binc"; static const std::string argBtime = "btime"; static const std::string argDepth = "depth"; static const std::string argInfinite = "infinite"; static const std::string argMovestogo = "movestogo"; static const std::string argMovetime = "movetime"; static const std::string argNodes = "nodes"; static const std::string argPonder = "ponder"; static const std::string argSearchmoves = "searchmoves"; static const std::string argWinc = "winc"; static const std::string argWtime = "wtime"; infinite = false; ponder = false; depth = 0; movestogo = 0; binc = 0; btime = 0; movetime = 0; nodes = 0; winc = 0; wtime = 0; bool invalid = false; while (!invalid && params && *NextWord(params)) { if (ParamMatch(argSearchmoves, params)) { Output() << "searchmoves not implemented!"; // TODO break; } if (HasParam(argInfinite, infinite, params) || HasParam(argPonder, ponder, params) || NumberParam(argDepth, depth, params, invalid) || NumberParam(argMovestogo, movestogo, params, invalid) || NumberParam(argBinc, binc, params, invalid) || NumberParam(argBtime, btime, params, invalid) || NumberParam(argMovetime, movetime, params, invalid) || NumberParam(argNodes, nodes, params, invalid) || NumberParam(argWinc, winc, params, invalid) || NumberParam(argWtime, wtime, params, invalid)) { continue; } Output() << "Unexpected token: " << params; return false; } if (invalid) { Output() << "usage: " << Usage(); return false; } if (infinite || ponder) { depth = 0; movestogo = 0; binc = 0; btime = 0; movetime = 0; nodes = 0; winc = 0; wtime = 0; } return true; }
//----------------------------------------------------------------------------- void PerftCommandHandle::Execute() { if (!engine) { Output() << "Engine not set for '" << command << "' command"; return; } engine->ClearStopFlags(); if (fileName.empty()) { if (qperft) { engine->QPerft(maxDepth); } else { engine->Perft(maxDepth); } return; } FILE* fp = NULL; try { if (!(fp = fopen(fileName.c_str(), "r"))) { Output() << "Cannot open '" << fileName << "': " << strerror(errno); return; } const uint64_t start = Now(); uint64_t pcount = 0; uint64_t nodes = 0; uint64_t qnodes = 0; bool done = false; char fen[16384]; int positions = 0; for (int line = 1; !done && fgets(fen, sizeof(fen), fp); ++line) { char* f = fen; if (!*NextWord(f) || (*f == '#')) { continue; } positions++; if ((skip > 0) && (positions <= skip)) { continue; } Output() << fileName << " line " << line << ' ' << f; NormalizeString(f); if (!(f = const_cast<char*>(engine->SetPosition(f)))) { break; } while (f && *f) { // null terminate this parameter (parameters end with ; or end of line) char* end = strchr(f, ';'); if (end) { *end = 0; } // process "D<depth> <leafs>" parameters (e.g. D5 4865609) if ((*NextWord(f) == 'D') && isdigit(f[1])) { if (!Process(f, pcount, nodes, qnodes)) { done = true; break; } } // move 'f' to beginning of next parameter if (end) { f = (end + 1); continue; } break; } if ((count > 0) && (positions >= count)) { break; } } const uint64_t time = (Now() - start); if (qperft) { Output() << "Total QPerft " << pcount << ' ' << Rate((pcount / 1000), time) << " KNodes/sec"; Output() << "Total Snodes " << (nodes - qnodes) << ", Qnodes " << qnodes << " (" << Percent(qnodes, pcount) << "%)"; } else { Output() << "Total Perft " << pcount << ' ' << Rate((pcount / 1000), time) << " KLeafs/sec"; Output() << "Total Nodes " << nodes << ' ' << Rate((nodes / 1000), time) << " KNodes/sec"; } } catch (const std::exception& e) { Output() << "ERROR: " << e.what(); } catch (...) { Output() << "Unknown error!"; } if (fp) { fclose(fp); fp = NULL; } }