4f1b44a9c8959ac7f1528f2d526623117d7ee6a9 max Thu Aug 22 17:41:32 2013 -0700 small changes to limit text diff --git src/hg/hgc/pubs.c src/hg/hgc/pubs.c index d5abca1..02ef5b0 100644 --- src/hg/hgc/pubs.c +++ src/hg/hgc/pubs.c @@ -178,31 +178,35 @@ web2StartDivCI("section", id); web2StartDivC("subheadingBar windowSize"); vprintf(format, args); web2EndDiv("subheadingBar"); va_end(args); } static void web2EndSection() /* end section */ { web2EndDiv("section"); } /* ------ */ - +static void printDebug(char *text) +{ +if (pubsDebug) + printf("%s
", text); +} static char *mangleUrl(char *url) /* add publisher specific parameters to url and return new url*/ { if (!stringIn("sciencedirect.com", url)) return url; // cgi param to add the "UCSC matches" sciverse application to elsevier's sciencedirect char *sdAddParam = "?svAppaddApp=298535"; char *longUrl = catTwoStrings(url, sdAddParam); char *newUrl = replaceChars(longUrl, "article", "svapps"); return newUrl; } static void printPositionAndSize(int start, int end, bool showSize) @@ -290,32 +294,31 @@ if (isNotEmpty(artExtIdFilter)) safef(artFilterSql, sizeof(artFilterSql), " AND extId='%s' ", artExtIdFilter); // no need to check for illegal characters in sectionList sqlSafef(query, sizeof(query), "SELECT distinct %s.articleId, url, title, authors, citation, year, " "pmid FROM %s " //"group_concat(snippet, concat(\" (section: \", section, \")\") SEPARATOR ' (...) ') FROM %s " "JOIN %s USING (articleId) " "WHERE markerId='%s' AND section in (%-s) " "%-s" //"GROUP by articleId " "ORDER BY year DESC " "LIMIT %d", markerTable, markerTable, articleTable, item, sectionList, artFilterSql, itemLimit); -if (pubsDebug) - printf("%s", query); + printDebug(query); struct sqlResult *sr = sqlGetResult(conn, query); return sr; } static struct sqlResult *querySnippets(struct sqlConnection *conn, char *markerTable, \ char *articleId, char *markerId, char *sectionList) /* query marker snippet rows from mysql for an article, markerId combination */ { char query[4000]; sqlSafef(query, sizeof(query), "SELECT section, snippet FROM %s " "WHERE articleId=%s AND markerId='%s' AND section in (%-s) ", markerTable, articleId, markerId, sectionList); struct sqlResult *sr = sqlGetResult(conn, query); @@ -364,31 +367,31 @@ printf("
"); printf("\n"); printf("

\n"); } static void printLimitWarning(struct sqlConnection *conn, char *markerTable, char *item, int itemLimit, char *sectionList) { char query[4000]; // no need to check for illegal characters in sectionList sqlSafef(query, sizeof(query), "SELECT COUNT(*) from %s WHERE markerId='%s' AND section in (%-s) ", markerTable, item, sectionList); if (sqlNeedQuickNum(conn, query) > itemLimit) { printf("This marker is mentioned more than %d times
\n", itemLimit); printf("The results would take too long to load in your browser and are " - "therefore limited to %d articles.

\n", itemLimit); + "therefore limited to the %d most recent articles.

\n", itemLimit); } } static void printAddWbr(char *text, int distance) /* a crazy hack for firefox/mozilla that is unable to break long words in tables * We need to add a tag every x characters in the text to make text breakable. */ { int i; i = 0; char *c; c = text; bool doNotBreak = FALSE; while (*c != 0) { @@ -411,31 +414,31 @@ char *in, *out; char c; in = out = s; for (;;) { c = *in++; if (c == 0) break; if (isupper(c)) *out++ = c; } *out = 0; } -char* printShortArticleInfo(char **row) { +static char* printShortArticleInfo(char **row) { /* print a two-line description of article */ char *articleId = row[0]; char *url = row[1]; char *title = row[2]; char *authors = row[3]; char *citation = row[4]; char *year = row[5]; char *pmid = row[6]; url = mangleUrl(url); printf("%s
", url, title); // cut author string at 40 chars, like scholar printf(""); if (strlen(authors)>40) { authors[60] = 0; @@ -450,31 +453,31 @@ char *journal = words[0]; printf("%s - %s ", year, journal); if (!isEmpty(pmid) && strcmp(pmid, "0")!=0 ) printf(", PMID%s\n", pmid, pmid); printf("\n"); printf("\n"); printf("
\n"); if (pubsDebug) printf("articleId=%s", articleId); return articleId; } -void printSnippets(struct sqlResult *srSnip) +static void printSnippets(struct sqlResult *srSnip) { char **snipRow; struct hash *doneSnips = newHash(0); // avoid printing a sentence twice int snipCount = 0; struct slPair *secSnips = NULL; // add all pairs to the list, remove duplicated snippets (ignore all lowercase chars) while ((snipRow = sqlNextRow(srSnip)) != NULL) { char *section = cloneString(snipRow[0]); char *snippet = cloneString(snipRow[1]); char *snipHash = cloneString(snippet); eraseAllButUpper(snipHash); if (hashLookup(doneSnips, snipHash)!=NULL) { @@ -546,30 +549,31 @@ // better readable if not across the whole screen printf("

\n"); char **row; // loop over articles and print out snippets for each while ((row = sqlNextRow(sr)) != NULL) { char *articleId = printShortArticleInfo(row); struct sqlConnection *snipConn = hAllocConn(database); struct sqlResult *srSnip = querySnippets(snipConn, markerTable, articleId, item, sectionList); printSnippets(srSnip); hFreeConn(&snipConn); printf("
"); } printf("
\n"); + freeMem(sectionList); sqlFreeResult(&sr); } static char *urlToLogoUrl(char *pubsArticleTable, char *articleId, char *urlOrig) /* return a string with relative path of logo for publisher given the url of * fulltext or a table/articleId, has to be freed */ { struct sqlConnection *conn = hAllocConn(database); char *pubCode = NULL; if (hHasField("hgFixed", pubsArticleTable, "publisher")) { char query[4000]; sqlSafef(query, sizeof(query), "SELECT publisher from %s where articleId=%s", @@ -674,32 +678,31 @@ /* return a hash with the sequence IDs for a given chain of BLAT matches */ { if (start==-1) return NULL; char query[512]; /* check first if the column exists (some debugging tables on hgwdev don't have seqIds) */ sqlSafef(query, sizeof(query), "SHOW COLUMNS FROM %s LIKE 'seqIds';", trackTable); char *seqIdPresent = sqlQuickString(conn, query); if (!seqIdPresent) { return NULL; } /* get sequence-Ids for feature that was clicked (item&startPos are unique) and return as hash*/ sqlSafef(query, sizeof(query), "SELECT seqIds,'' FROM %s WHERE name='%s' " "and chrom='%s' and chromStart=%d;", trackTable, item, seqName, start); -if (pubsDebug) - printf("%s
", query); + printDebug(query); // split comma-sep list into parts char *seqIdCoordString = sqlQuickString(conn, query); char *seqIdCoords[1024]; if (isEmpty(seqIdCoordString)) return NULL; int partCount = chopString(seqIdCoordString, ",", seqIdCoords, ArraySize(seqIdCoords)); int i; struct hash *seqIdHash = NULL; seqIdHash = newHash(0); for (i=0; i", seqIdCoords[i]); @@ -829,32 +832,31 @@ * * */ { // get data from mysql // I support two different schemas: new and old. On old tables, there is no fileUrl yet on the annotations // that means that oldQuery just uses an empty string for the fileUrl field. char *oldQuery = "SELECT fileDesc, snippet, locations, annotId, sequence, \"\" FROM %s WHERE articleId='%s'"; char *newQuery = "SELECT fileDesc, snippet, locations, annotId, sequence, fileUrl FROM %s WHERE articleId='%s'"; char *queryTemplate = oldQuery; if (hHasField("hgFixed", pubsSequenceTable, "fileUrl")) queryTemplate = newQuery; char query[4096]; sqlSafef(query, sizeof(query), queryTemplate, pubsSequenceTable, articleId); -if (pubsDebug) - puts(query); +printDebug(query); struct sqlResult *sr = sqlGetResult(conn, query); // construct title for section char *otherFormat = NULL; if (fasta) otherFormat = "table"; else otherFormat = "fasta"; char fullTitle[5000]; safef(fullTitle, sizeof(fullTitle), "%s (%s format)\n", title, cartSidUrlString(cart), cgiOptionalString("o"), cgiOptionalString("t"), cgiString("g"), cgiString("i"), !fasta, otherFormat);