981ef07d25e4560559dae28d3e316913569944d7 tdreszer Fri Jul 6 17:51:06 2012 -0700 Next batch of many checkins as dictated by Jim. Formatting space after if and limiting lines to 100 chars. Changes limited to lines last touched by tdreszer (git blame) so as not to ruin history. None of these changes should affect executables in any way. diff --git src/hg/lib/search.c src/hg/lib/search.c index eed16fd..19dfd81 100644 --- src/hg/lib/search.c +++ src/hg/lib/search.c @@ -17,67 +17,70 @@ struct subText *subList = subTextNew("$db", database); subTextStatic(subList, trixPath, buf, len); } boolean isSearchTracksSupported(char *database, struct cart *cart) // Return TRUE if searchTracks is supported for this database and javascript is supported too { char trixFile[HDB_MAX_PATH_STRING]; getSearchTrixFile(database, trixFile, sizeof(trixFile)); return fileExists(trixFile); } struct slPair *fileFormatSearchWhiteList() // Gets the whitelist of approved file formats that is allowed for search { -char *crudeTypes[] = { +char *crudeTypes[] = + { "bam", // "bam.bai" is now alway selected with bam, "tagAlign", "bed.gz", "bigBed", "broadPeak", "narrowPeak", "fastq", "bigWig", "wig" // TODO: Add "other" category. TODO: make into multi-select }; -char *nicerTypes[] = { +char *nicerTypes[] = + { "Alignment binary (bam) - binary SAM", // "Alignment binary index (bai) - binary SAM index", "Alignment tags (tagAlign)", "bed - browser extensible data", "bigBed - self index, often remote bed format", "Peaks Broad (broadPeak) - ENCODE large region peak format", "Peaks Narrow (narrowPeak) - ENCODE small region peak format", "Raw Sequence (fastq) - High throughput sequence format", "Signal (bigWig) - self index, often remote wiggle format", "Signal (wig) - wiggle format" }; struct slPair *fileTypes = NULL; int ix = 0, count = sizeof(crudeTypes)/sizeof(char *); for(ix=0;ix<count;ix++) - slPairAdd(&fileTypes, crudeTypes[ix],cloneString(nicerTypes[ix])); // Name gets cloned while adding + slPairAdd(&fileTypes, crudeTypes[ix],cloneString(nicerTypes[ix])); return fileTypes; } char *fileFormatSelectHtml(char *name, char *selected, char *extraHtml) // returns an allocated string of HTML for the fileType select drop down { struct slPair *fileTypes = fileFormatSearchWhiteList(); if (slCount(fileTypes) > 0) { - char *dropDownHtml = cgiMakeSingleSelectDropList(name,fileTypes,selected,ANYLABEL,NULL,extraHtml); + char *dropDownHtml = cgiMakeSingleSelectDropList(name,fileTypes,selected, + ANYLABEL,NULL,extraHtml); slPairFreeList(&fileTypes); return dropDownHtml; } return NULL; } struct slPair *mdbSelectPairs(struct cart *cart, struct slPair *mdbVars) // Returns the current mdb vars and vals in the table of drop down selects { // figure out how many metadata selects are visible. int numMetadataSelects = 0; struct slPair *mdbSelectPairs = NULL; if (mdbVars == NULL) return 0; @@ -157,115 +160,140 @@ safef(buf, sizeof(buf), "%s%d", METADATA_VALUE_PREFIX, numMetadataSelects + 1); cartRemove(cart, buf); } } else { // create defaults slPairAdd(&mdbSelectPairs,"cell", NULL); slPairAdd(&mdbSelectPairs,"antibody",NULL); } slReverse(&mdbSelectPairs); return mdbSelectPairs; } -char *mdbSelectsHtmlRows(struct sqlConnection *conn,struct slPair *mdbSelects,struct slPair *mdbVars,int cols,boolean fileSearch) -// genereates the html for the table rows containing mdb var and val selects. Assume tableSearch unless fileSearch +char *mdbSelectsHtmlRows(struct sqlConnection *conn,struct slPair *mdbSelects, + struct slPair *mdbVars,int cols,boolean fileSearch) +// genereates the html for the table rows containing mdb var and val selects. +// Assume tableSearch unless fileSearch { struct dyString *output = dyStringNew(1024); -dyStringPrintf(output,"<tr><td colspan='%d' align='right' class='lineOnTop' style='height:20px; max-height:20px;'><em style='color:%s; width:200px;'>ENCODE terms</em></td></tr>\n", cols,COLOR_DARKGREY); +dyStringPrintf(output,"<tr><td colspan='%d' align='right' class='lineOnTop' style='height:20px; " + "max-height:20px;'><em style='color:%s; width:200px;'>ENCODE terms</em>" + "</td></tr>\n", cols,COLOR_DARKGREY); struct slPair *mdbSelect = mdbSelects; int row = 0; for(;mdbSelect != NULL; mdbSelect = mdbSelect->next) { char buf[256]; char *dropDownHtml = NULL; #ifdef BUTTONS_BY_CSS - #define BUTTON_PM "<span class='pmButton' id='%sButton%d' title='%s' onclick='findTracks.mdbSelectPlusMinus(this,%d)'>%c</span>" - #define ADD_PM_BUTTON(type,num,value) dyStringPrintf(output,BUTTON_PM, (type), (num), ((value) == '+' ? "add another row after":"delete"), (num), (value)) + #define BUTTON_PM "<span class='pmButton' id='%sButton%d' title='%s' " \ + "onclick='findTracks.mdbSelectPlusMinus(this,%d)'>%c</span>" + #define ADD_PM_BUTTON(type,num,value) dyStringPrintf(output,BUTTON_PM, (type), (num), " \ + "((value) == '+' ? "add another row after":"delete"), (num), (value)) #else///ifndef BUTTONS_BY_CSS - #define PLUS_MINUS_BUTTON "<input type='button' id='%sButton%d' value='%c' style='font-size:.7em;' title='%s' onclick='findTracks.mdbSelectPlusMinus(this,%d)'>" - #define ADD_PM_BUTTON(type,num,value) dyStringPrintf(output,PLUS_MINUS_BUTTON, (type), (num), (value), ((value) == '+' ? "add another row after":"delete"), (num)) + #define PLUS_MINUS_BUTTON "<input type='button' id='%sButton%d' value='%c' " \ + "style='font-size:.7em;' title='%s' " \ + "onclick='findTracks.mdbSelectPlusMinus(this,%d)'>" + #define ADD_PM_BUTTON(type,num,value) \ + dyStringPrintf(output,PLUS_MINUS_BUTTON, (type), (num), (value), \ + ((value) == '+' ? "add another row after":"delete"), (num)) #endif///def BUTTONS_BY_CSS dyStringAppend(output,"<tr valign='top' class='mdbSelect'><td nowrap>\n"); row++; if(slCount(mdbSelects) > 2 || row > 2) ADD_PM_BUTTON("minus", row, '-'); else dyStringAppend(output," "); ADD_PM_BUTTON("plus", row, '+'); dyStringAppend(output,"</td><td>and </td><td colspan=3 nowrap>\n"); safef(buf, sizeof(buf), "%s%i", METADATA_NAME_PREFIX, row); // Left side select of vars - dropDownHtml = cgiMakeSingleSelectDropList(buf, mdbVars,mdbSelect->name, NULL,"mdbVar","style='font-size:.9em;' onchange='findTracks.mdbVarChanged(this);'"); + dropDownHtml = cgiMakeSingleSelectDropList(buf, mdbVars,mdbSelect->name, NULL,"mdbVar", + "style='font-size:.9em;' onchange='findTracks.mdbVarChanged(this);'"); if (dropDownHtml) { dyStringAppend(output,dropDownHtml); freeMem(dropDownHtml); } // Right side select of vals safef(buf, sizeof(buf), "%s%i", METADATA_VALUE_PREFIX, row); enum cvSearchable searchBy = cvSearchMethod(mdbSelect->name); if (searchBy == cvSearchBySingleSelect || searchBy == cvSearchByMultiSelect) { - dyStringPrintf(output,"</td>\n<td align='right' id='isLike%i' style='width:10px; white-space:nowrap;'>is%s</td>\n<td nowrap id='%s' style='max-width:600px;'>\n", + dyStringPrintf(output,"</td>\n<td align='right' id='isLike%i' style='width:10px; " + "white-space:nowrap;'>is%s</td>\n<td nowrap id='%s' " + "style='max-width:600px;'>\n", row,(searchBy == cvSearchByMultiSelect?" among":""),buf); - struct slPair *pairs = mdbValLabelSearch(conn, mdbSelect->name, MDB_VAL_STD_TRUNCATION, FALSE, !fileSearch, fileSearch); // not tags, either a file or table search + struct slPair *pairs = mdbValLabelSearch(conn, mdbSelect->name, MDB_VAL_STD_TRUNCATION, + FALSE, !fileSearch, fileSearch); + // not tags, either a file or table search if (slCount(pairs) > 0) { char *dropDownHtml = cgiMakeSelectDropList((searchBy == cvSearchByMultiSelect), - buf, pairs,mdbSelect->val, ANYLABEL,"mdbVal","style='min-width:200px; font-size:.9em;' onchange='findTracks.mdbValChanged(this);'"); + buf, pairs,mdbSelect->val, ANYLABEL,"mdbVal", + "style='min-width:200px; font-size:.9em;' " + "onchange='findTracks.mdbValChanged(this);'"); if (dropDownHtml) { dyStringAppend(output,dropDownHtml); freeMem(dropDownHtml); } slPairFreeList(&pairs); } } else if (searchBy == cvSearchByFreeText) { - dyStringPrintf(output,"</td><td align='right' id='isLike%i' style='width:10px; white-space:nowrap;'>contains</td>\n<td nowrap id='%s' style='max-width:600px;'>\n", - row,buf); - dyStringPrintf(output,"<input type='text' name='%s' value='%s' class='mdbVal freeText' style='max-width:310px; width:310px; font-size:.9em;' onchange='findTracks.mdbVarChanged(true);'>\n", + dyStringPrintf(output,"</td><td align='right' id='isLike%i' style='width:10px; " + "white-space:nowrap;'>contains</td>\n<td nowrap id='%s' " + "style='max-width:600px;'>\n",row,buf); + dyStringPrintf(output,"<input type='text' name='%s' value='%s' class='mdbVal freeText' " + "style='max-width:310px; width:310px; font-size:.9em;' " + "onchange='findTracks.mdbVarChanged(true);'>\n", buf,(mdbSelect->val ? (char *)mdbSelect->val: "")); } else if (searchBy == cvSearchByWildList) { - dyStringPrintf(output,"</td><td align='right' id='isLike%i' style='width:10px; white-space:nowrap;'>is among</td>\n<td nowrap id='%s' style='max-width:600px;'>\n", - row,buf); - dyStringPrintf(output,"<input type='text' name='%s' value='%s' class='mdbVal wildList' title='enter comma separated list of values' style='max-width:310px; width:310px; font-size:.9em;' onchange='findTracks.mdbVarChanged(true);'>\n", + dyStringPrintf(output,"</td><td align='right' id='isLike%i' style='width:10px; " + "white-space:nowrap;'>is among</td>\n<td nowrap id='%s' " + "style='max-width:600px;'>\n",row,buf); + dyStringPrintf(output,"<input type='text' name='%s' value='%s' class='mdbVal wildList' " + "title='enter comma separated list of values' " + "style='max-width:310px; width:310px; font-size:.9em;' " + "onchange='findTracks.mdbVarChanged(true);'>\n", buf,(mdbSelect->val ? (char *)mdbSelect->val: "")); } //else if (searchBy == cvSearchByDateRange || searchBy == cvSearchByIntegerRange) // { // // TO BE IMPLEMENTED // } dyStringPrintf(output,"<span id='helpLink%i'> </span></td>\n", row); dyStringPrintf(output,"</tr>\n"); } - dyStringPrintf(output,"<tr><td colspan='%d' align='right' style='height:10px; max-height:10px;'> </td></tr>", cols); + dyStringPrintf(output,"<tr><td colspan='%d' align='right' style='height:10px; " + "max-height:10px;'> </td></tr>", cols); return dyStringCannibalize(&output); } static boolean searchMatchToken(char *string, char *token) { // do this with regex ? Would require all sorts of careful parsing for ()., etc. if (string == NULL) return (token == NULL); if (token == NULL) return TRUE; if (!strchr(token,'*') && !strchr(token,'?')) return (strcasestr(string,token) != NULL); @@ -285,32 +313,33 @@ struct slName *word = wordList; for(; word != NULL; word = word->next) { if (!searchMatchToken(tdb->shortLabel,word->name) && !searchMatchToken(tdb->longLabel, word->name)) return FALSE; } return TRUE; } boolean searchDescriptionMatches(struct trackDb *tdb, struct slName *wordList) // returns TRUE if all words in preparsed list matches html description page. // A "word" can be "multiple words" (parsed from quoteed string). // Because description contains html, quoted string match has limits. -// DANGER: this will alter html of tdb struct (replacing \n with ' ', so the html should not be displayed after. +// DANGER: this will alter html of tdb struct (replacing \n with ' ', +// so the html should not be displayed after. { if (tdb->html == NULL) return (wordList != NULL); -if (strchr(tdb->html,'\n')) - strSwapChar(tdb->html,'\n',' '); // DANGER: don't own memory. However, this CGI will use html for no other purpose +if (strchr(tdb->html,'\n')) // DANGER: don't own memory. + strSwapChar(tdb->html,'\n',' '); // However, this CGI will use html for no other purpose struct slName *word = wordList; for(; word != NULL; word = word->next) { if (!searchMatchToken(tdb->html,word->name)) return FALSE; } return TRUE; }