//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // PBook::EcoSummary(): // Produce a summary from the PBook for the specified ECO code prefix. void PBook::EcoSummary (const char * ecoPrefix, DString * dstr) { uint depth = strLength (ecoPrefix); const char * prevEcoStr = ""; for (uint i=0; i < NodeListCount; i++) { bookNodeT * node = NodeList[i]; if (node == NULL) { continue; } const char * comment = node->data.comment; const char * ecoStr = epd_findOpcode (comment, "eco"); const char * movesStr = epd_findOpcode (comment, "moves"); if (ecoStr != NULL && strIsPrefix (ecoPrefix, ecoStr)) { if (depth < 3 && strPrefix (ecoStr, prevEcoStr) >= depth+1) { continue; } prevEcoStr = ecoStr; while (*ecoStr != '\n' && *ecoStr != 0) { dstr->AddChar (*ecoStr); ecoStr++; } dstr->Append (" "); while (*movesStr != '\n' && *movesStr != 0) { dstr->AddChar (*movesStr); movesStr++; } dstr->AddChar ('\n'); } } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // strContains(): // Returns true if longStr contains an occurrence of keyStr, // case-sensitive and NOT ignoring any characters such as spaces. bool strContains (const char * longStr, const char * keyStr) { while (*longStr) { if (strIsPrefix (keyStr, longStr)) { return true; } longStr++; } return false; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // strContainsIndex(): // Returns the first index if longStr contains an occurrence of keyStr, // case-sensitive and NOT ignoring any characters such as spaces. // Returns -1 if longStr does not contain keyStr int strContainsIndex (const char * longStr, const char * keyStr) { int index = 0; while (*longStr) { if (strIsPrefix (keyStr, longStr)) { return index; } longStr++; index++; } return -1; }
int genLispOption(String opt) { String s; if (strEqual(opt, SOPT_COMMON)) langOpt = GLLANG_COMMON; else if (strEqual(opt, SOPT_SCHEME)) langOpt = GLLANG_SCHEME; else if (strEqual(opt, SOPT_CASE)) glimixedCase = true; else if (s = strIsPrefix(SOPT_FTYPE, opt), s) sxiLispFileType = s; else return -1; return 0; }
inline const char * epd_findOpcode (const char * epdStr, const char * opcode) { const char * s = epdStr; while (*s != 0) { while (*s == ' ' || *s == '\n') { s++; } if (strIsPrefix (opcode, s)) { const char *codeEnd = s + strLength(opcode); if (*codeEnd == ' ') { return codeEnd + 1; } } while (*s != '\n' && *s != 0) { s++; } } return NULL; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // PBook::StripOpcode: // Strips the specified opcode from every position in the book. // Only the first occurrence of an opcode is removed for any position, // but opcodes are not supposed to occur more than once anyway. // Returns the number of positions where an opcode was removed. uint PBook::StripOpcode (const char * opcode) { char * searchCode = new char [strLength(opcode) + 2]; strCopy (searchCode, opcode); strAppend (searchCode, " "); DString dstr; uint countFound = 0; for (uint i=0; i < NodeListCount; i++) { bookNodeT * node = NodeList[i]; if (node == NULL) { continue; } const char * s = node->data.comment; int startIndex = -1; int index = 0; // Look for a line with a matching opcode: while (*s != 0) { while (*s == '\n' || *s == ' ') { s++; index++; } if (strIsPrefix (searchCode, s)) { startIndex = index; countFound++; break; } while (*s != 0 && *s != '\n') { s++; index++; } } if (startIndex > -1) { s = node->data.comment; index = 0; // Add all characters before the line to be stripped: dstr.Clear(); while (index < startIndex) { dstr.AddChar (s[index]); index++; } // Now find the end of this line: s = &(s[startIndex + 1]); while (*s != 0 && *s != '\n') { s++; } if (*s == '\n') { s++; } while (*s != 0) { dstr.AddChar (*s); s++; } delete[] node->data.comment; node->data.comment = strDuplicate (dstr.Data()); } } delete[] searchCode; return countFound; }
local void arRdFormat(Archive ar) { char mag[SARMAGMAX]; ArFmtTag tag; AR_SEEK(ar, int0); FILE_GET_CHARS(ar->file, mag, SARMAGMAX); for (tag = AR_START; tag < AR_LIMIT; tag += 1) if (strIsPrefix(arInfo(tag).str, mag)) break; if (tag == AR_LIMIT) return; ar->format = tag; ar->size = fileSize(ar->name); }
RuntimeCallInfo gen0GetRuntimeCallInfo(Foam decl) { /* !!should cache values */ int i; String name; assert(foamTag(decl) == FOAM_GDecl); name = decl->foamGDecl.id; if (decl->foamGDecl.protocol != FOAM_Proto_Foam) return NULL; for (i = 0; i< NRuntimeCalls; i++) { RuntimeCallInfo info = &runtimeCallInfoTable[i]; if (info->name[0] == name[0] && strEqual(info->name, name)) return info; } if (strIsPrefix(gen0StdLazyNamePrefix(), name)) return &runtimeStdLazyGetterPrefix; return NULL; }