static boolean sameAccession(char *acc1, char *acc2) /* test if an accessions is the same, ignoring optional versions */ { int len1 = lenLessVer(acc1); int len2 = lenLessVer(acc2); return (len1 != len2) ? FALSE : sameStringN(acc1, acc2, len1); }
boolean endsWithWordComma(char *string, char *word) /* Return TRUE if string ends with word possibly followed by a comma, and the beginning * of word within string is the beginning of string or follows a comma. */ { int stringLen = strlen(string); int wordLen = strlen(word); int commaSize = (stringLen > wordLen && string[stringLen-1] == ',') ? 1 : 0; if (stringLen < wordLen + commaSize) return FALSE; int wordOffset = stringLen - commaSize - wordLen; if (sameStringN(string + wordOffset, word, wordLen) && (wordOffset == 0 || string[wordOffset-1] == ',')) return TRUE; return FALSE; }
static char *readHtmlRecursive(char *fileName, char *database) /* Slurp in an html file. Wherever it contains insertHtmlRegex, recursively slurp that in * and replace insertHtmlRegex with the contents. */ { char *html; readInGulp(fileName, &html, NULL); if (isEmpty(html)) return html; regmatch_t substrs[4]; while (regexMatchSubstr(html, insertHtmlRegex, substrs, ArraySize(substrs))) { struct dyString *dy = dyStringNew(0); // All text before the regex match: dyStringAppendN(dy, html, substrs[0].rm_so); // Is there an #if before the #insert ? boolean doInsert = TRUE; if (substrs[1].rm_so != -1 && (! sameStringN(database, html+substrs[2].rm_so, (substrs[2].rm_eo - substrs[2].rm_so)))) doInsert = FALSE; if (doInsert) { // Recursively pull in inserted file contents from relative path, replacing regex match: char dir[PATH_LEN]; splitPath(fileName, dir, NULL, NULL); char insertFileName[PATH_LEN+FILENAME_LEN]; safecpy(insertFileName, sizeof(insertFileName), dir); safencat(insertFileName, sizeof(insertFileName), html+substrs[3].rm_so, (substrs[3].rm_eo - substrs[3].rm_so)); if (!fileExists(insertFileName)) errAbort("readHtmlRecursive: relative path '%s' (#insert'ed in %s) not found", insertFileName, fileName); char *insertedText = readHtmlRecursive(insertFileName, database); dyStringAppend(dy, insertedText); freez(&insertedText); } // All text after the regex match: dyStringAppend(dy, html+substrs[0].rm_eo); freez(&html); html = dyStringCannibalize(&dy); } return html; }