errorT PBook::FindSummary (Position * pos, DString * target) { const char * comment = NULL; errorT err = Find (pos, &comment); if (err != OK) { return ERROR_NotFound; } const char * s = epd_findOpcode (comment, "ce"); if (s != NULL) { int ce = strGetInteger (s); if (pos->GetToMove() == BLACK) { ce = -ce; } char temp[20]; sprintf (temp, "%+.2f", ((double) ce) / 100.0); target->Append (temp); return OK; } static const char * opcodes[] = { "eco", "nic", "pv", "pm", "bm", "id", NULL }; for (const char ** opcode = opcodes; *opcode != NULL; opcode++) { s = epd_findOpcode (comment, *opcode); if (s != NULL) { while (*s != 0 && *s != '\n') { target->AddChar (*s); s++; } return OK; } } return ERROR_NotFound; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // strGetIntegers: // Extracts the specified number of signed integers in a // whitespace-separated string to an array. void strGetIntegers (const char * str, int * results, uint nResults) { for (uint i=0; i < nResults; i++) { while (*str != 0 && isspace(*str)) { str++; } results[i] = strGetInteger (str); while (*str != 0 && !isspace(*str)) { str++; } } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // strCompareRound(): // String comparison function for round names. Sorts by the integer // number at the start of each string first. int strCompareRound (const char * sleft, const char * sright) { int ileft = strGetInteger (sleft); int iright = strGetInteger (sright); int diff = ileft - iright; if (diff != 0) { return diff; } // Now check if both strings are equal up to the first dot. // If so, do an integer comparison after the ".": bool equalUpToDot = false; const char * templeft = sleft; const char * tempright = sright; while (true) { char leftc = *templeft; char rightc = *tempright; if (leftc == 0 || rightc == 0) { break; } if (leftc != rightc) { break; } if (leftc == '.' && rightc == '.') { equalUpToDot = true; break; } templeft++; tempright++; } if (equalUpToDot) { templeft++; tempright++; // Now templeft and tempright point to the first character // after each dot. ileft = strGetInteger (templeft); iright = strGetInteger(tempright); diff = ileft - iright; if (diff != 0) { return diff; } } // Give up on integer comparisons and do a regular string comparison: return strCompare (sleft, sright); }