char *trackHubVersionDefault(char *specHost, struct htmlPage **pageRet) /* Return default version of hub spec by parsing for version id in the page */ { struct htmlPage *page = trackHubVersionSpecMustGet(specHost, NULL); struct htmlTag *tag; /* Find version tag (span id=) */ char buf[256]; verbose(6, "Found %d tags\n", slCount(page->tags)); for (tag = page->tags; tag != NULL; tag = tag->next) { if (sameString(strLower(tag->name), "span") && tag->attributes != NULL && sameString(strLower(tag->attributes->name), "id") && sameString(tag->attributes->val, "trackDbHub_version")) { int len = min(tag->next->start - tag->end, sizeof buf - 1); memcpy(buf, tag->end, len); buf[len] = 0; verbose(6, "Found version: %s\n", buf); return cloneString(buf); } } return NULL; }
bool FileList::inList(const std::string &filename) const { std::string fname = strLower(filename), curfile; for (unsigned int i = 0; i < files.size(); i++) { curfile = strLower(files[i]); if (!strcmp(curfile.c_str(), fname.c_str())) return true; } return false; }
size_t FileList::wild_search(std::string search, size_t start) const { search = strLower(search); std::string temp; for (size_t i = start+1; i < files.size(); i++) { temp = strLower(files[i]); if (wildcmp(search.c_str(), temp.c_str())) return i; } return -1; //invalid }
void ensureNamesCaseUnique(struct slName *fieldList) /* Ensure that there would be no name conflicts in fieldList if all fields were lower-cased. */ { struct slName *field; struct hash *hash = hashNew(0); for (field = fieldList; field != NULL; field = field->next) { char *s = field->name; int len = strlen(s); assert(len<512); // avoid stack overflow char lower[len+1]; strcpy(lower, s); strLower(lower); char *conflict = hashFindVal(hash, lower); if (conflict) { if (sameString(conflict,s)) errAbort("Duplicate symbol %s", s); else errAbort("Conflict between symbols with different cases: %s vs %s", conflict, s); } hashAdd(hash, lower, s); } hashFree(&hash); }
// // it is important that this method will not call CLog because it uses it. // BOOL DeleteFile(LPCTSTR lpFileName) { if (unlink(lpFileName) == 0) return 1; if (errno == EACCES) { CLog::Log(LOGERROR,"%s - cant delete file, trying to change mode <%s>", __FUNCTION__, lpFileName); if (chmod(lpFileName, 0600) != 0) { CLog::Log(LOGERROR,"%s - failed to change mode <%s>", __FUNCTION__, lpFileName); return 0; } CLog::Log(LOGDEBUG,"%s - reattempt to delete file",__FUNCTION__); if (unlink(lpFileName) == 0) return 1; } else if (errno == ENOENT) { CStdString strLower(lpFileName); strLower.MakeLower(); CLog::Log(LOGERROR,"%s - cant delete file <%s>. trying lower case <%s>", __FUNCTION__, lpFileName, strLower.c_str()); if (unlink(strLower.c_str()) == 0) { CLog::Log(LOGDEBUG,"%s - successfuly removed file <%s>", __FUNCTION__, strLower.c_str()); return 1; } } return 0; }
// used for resolving case-insensative paths to case-sensative ones // when appropriate IsCaseSensative() = true bool PlatformNormalize(std::string &normpath, const std::string &path, const std::string root) { if (!FileList::IsCaseSensative()) // windows simply returns identity { // should only get hit on windows if (root[root.length()-1] != '\\') { normpath = root + "\\" + path; } else { normpath = root + path; } return true; } // else it's a *nix system - normalize it to / instead of \ - FileList curdir; normpath = root; // break path down into it's componants std::vector<std::string> parts; Expand(path, '/', parts); bool found; for (size_t i = 0; i < parts.size(); i++) { curdir.GetList(normpath); found = false; for (size_t j = 0; j < curdir.Size(); j++) { if (strLower(std::string(curdir[j])) == strLower(std::string(parts[i]))) { normpath += std::string("/") + curdir[j]; found = true; break; } } if (!found) return false; //yikes curdir.Clear(); } return true; }
static char *findType(struct hash *cvHash,char **requested,int requestCount, char **queryBy, char **org,boolean silent) /* returns the type that was requested or else the type associated with the term requested */ { struct hashCookie hc = hashFirst(cvHash); struct hashEl *hEl; struct hash *ra; char *type = typeOpt; if (requested != NULL) // if no type, find it from requested terms. Will validate terms match type { // NOTE: Enter here even if there is a type, to confirm the type while ((hEl = hashNext(&hc)) != NULL) // FIXME: This should be using mdbCv APIs to get hashes. { // One per "request[]" ra = (struct hash *)hEl->val; if (sameWord(hashMustFindVal(ra, CV_TYPE),CV_TOT)) // TOT = typeOfTerm continue; char *val = hashFindVal(ra, *queryBy); if (val != NULL) { int ix = stringArrayIx(val,requested,requestCount); if (ix != -1) // found { char *thisType = hashMustFindVal(ra, CV_TYPE); char *thisOrg = hashFindVal(ra, ORGANISM); if (type == NULL) { if (thisOrg != NULL) { *org = strLower(cloneString(thisOrg)); } type = thisType; } else if (differentWord(type,thisType)) { if (sameWord(CV_TERM_CONTROL,type)) type = thisType; else if (differentWord(CV_TERM_CONTROL,thisType)) errAbort("Error: Requested %s of type '%s'. But '%s' has type '%s'\n", *queryBy,type,requested[ix],thisType); } } } } } if (type == NULL && sameWord(*queryBy,CV_TERM)) // Special case of term becoming target { char *queryByTarget = CV_TARGET; type = findType(cvHash,requested,requestCount,&queryByTarget,org,TRUE); // silent here if (type != NULL) *queryBy = queryByTarget; } if (type == NULL && !silent) // Still not type? abort errAbort("Error: Required %s=%s ['%s', '%s', '%s', '%s' or '%s'] argument not found\n", *queryBy,(requested != NULL) ? *requested : "?", CV_TYPE, CV_TERM, CV_TAG, CV_TARGET, CV_LABEL); return normalizeType(type); }
bool TBoolEntry::getBool(bool defval){ TString s = strLower(getValue()); if (defval){ if (s == "false") return false; if (s == "no") return false; }else{ if (s == "true") return true; if (s == "yes") return true; } return defval; }
BOOL RemoveDirectory(LPCTSTR lpPathName) { if (rmdir(lpPathName) == 0) return 1; if (errno == ENOENT) { CLog::Log(LOGWARNING,"%s, cant remove dir <%s>. trying lower case.", __FUNCTION__, lpPathName); CStdString strLower(lpPathName); strLower.MakeLower(); if (rmdir(strLower.c_str()) == 0) return 1; } return 0; }
int RemoveDirectory(LPCTSTR lpPathName) { if (rmdir(lpPathName) == 0) return 1; if (errno == ENOENT) { CLog::Log(LOGWARNING,"%s, cant remove dir <%s>. trying lower case.", __FUNCTION__, lpPathName); std::string strLower(lpPathName); StringUtils::ToLower(strLower); if (rmdir(strLower.c_str()) == 0 || errno == ENOENT) return 1; } return 0; }
BOOL CreateDirectory(LPCTSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes) { if (mkdir(lpPathName, 0755) == 0) return 1; if (errno == ENOENT) { CLog::Log(LOGWARNING,"%s, cant create dir <%s>. trying lower case.", __FUNCTION__, lpPathName); CStdString strLower(lpPathName); strLower.MakeLower(); if (mkdir(strLower.c_str(), 0755) == 0) return 1; } return 0; }
static struct slRef *simpleSearchForTracksstruct(char *simpleEntry) // Performs the simple search and returns the found tracks. { struct slRef *tracks = NULL; // Prepare for trix search if (!isEmpty(simpleEntry)) { int trixWordCount = 0; char *tmp = cloneString(simpleEntry); char *val = nextWord(&tmp); struct slName *el, *trixList = NULL; while (val != NULL) { slNameAddTail(&trixList, val); trixWordCount++; val = nextWord(&tmp); } if (trixWordCount > 0) { // Unfortunately trixSearch can't handle the slName list int i; char **trixWords = needMem(sizeof(char *) * trixWordCount); for (i = 0, el = trixList; el != NULL; i++, el = el->next) trixWords[i] = strLower(el->name); // Now open the trix file char trixFile[HDB_MAX_PATH_STRING]; getSearchTrixFile(database, trixFile, sizeof(trixFile)); struct trix *trix = trixOpen(trixFile); struct trixSearchResult *tsList = trixSearch(trix, trixWordCount, trixWords, TRUE); for ( ; tsList != NULL; tsList = tsList->next) { struct track *track = (struct track *) hashFindVal(trackHash, tsList->itemId); if (track != NULL) // It is expected that this is NULL { // (e.g. when trix references trackDb tracks which have no tables) refAdd(&tracks, track); } } //trixClose(trix); // don't bother (this is a CGI that is about to end) } } return tracks; }
// // it is important that this method will not call CLog because it uses it. // BOOL MoveFile(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName) { if (rename(lpExistingFileName, lpNewFileName) == 0) return 1; if (errno == EACCES) { CLog::Log(LOGERROR,"%s - cant move file, trying to change mode <%s>", __FUNCTION__, lpExistingFileName); if (chmod(lpExistingFileName, 0600) != 0) { CLog::Log(LOGERROR,"%s - failed to change mode <%s>", __FUNCTION__, lpExistingFileName); return 0; } CLog::Log(LOGDEBUG,"%s - reattempt to move file",__FUNCTION__); if (rename(lpExistingFileName, lpNewFileName) == 0) return 1; } else if (errno == ENOENT) { CStdString strLower(lpExistingFileName); strLower.MakeLower(); CLog::Log(LOGERROR,"%s - cant move file <%s>. trying lower case <%s>", __FUNCTION__, lpExistingFileName, strLower.c_str()); if (rename(strLower.c_str(), lpNewFileName) == 0) { CLog::Log(LOGDEBUG,"%s - successfuly moved file <%s>", __FUNCTION__, strLower.c_str()); return 1; } } // try the stupid if (CopyFile(lpExistingFileName,lpNewFileName,TRUE)) { if (DeleteFile(lpExistingFileName)) return 1; // failed to remove original file - delete the copy we made DeleteFile(lpNewFileName); } return 0; }
int main(int argc, char *argv[]) /* Process command line */ { long enteredMainTime = clock1000(); cgiSpoof(&argc, argv); termOpt = cgiOptionalString(CV_TERM); tagOpt = cgiOptionalString(CV_TAG); typeOpt = cgiOptionalString(CV_TYPE); targetOpt = cgiOptionalString(CV_TARGET); labelOpt = cgiOptionalString(CV_LABEL); organismOpt = cgiUsualString(ORGANISM, organismOpt); if (organismOpt != NULL) { organismOptLower=cloneString(organismOpt); strLower(organismOptLower); } char *bgColor = cgiOptionalString("bgcolor"); if (bgColor) htmlSetBgColor(strtol(bgColor, 0, 16)); htmlSetStyle(htmlStyleUndecoratedLink); htmShell("ENCODE Controlled Vocabulary", doMiddle, "get"); cgiExitTime("hgEncodeVocab", enteredMainTime); return 0; }
BOOL CopyFile(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName, BOOL bFailIfExists) { // If the destination file exists and we should fail...guess what? we fail! struct stat destStat; bool isDestExists = (stat(lpNewFileName, &destStat) == 0); if (isDestExists && bFailIfExists) { return 0; } CStdString strResultFile(lpExistingFileName); // Open the files int sf = open(lpExistingFileName, O_RDONLY); if (sf == -1 && errno == ENOENT) // important to check reason for fail. only if its "file does not exist" shall we try lower case. { CStdString strLower(lpExistingFileName); strLower.MakeLower(); // failed to open file. maybe due to case sensitivity. try opening the same name in lower case. CLog::Log(LOGWARNING,"%s, cant open file <%s>. trying to use lowercase <%s>", __FUNCTION__, lpExistingFileName, strLower.c_str()); sf = open(strLower.c_str(), O_RDONLY); if (sf != -1) { CLog::Log(LOGDEBUG,"%s, successfuly opened <%s>", __FUNCTION__, strLower.c_str()); strResultFile = strLower; } } if (sf == -1) { CLog::Log(LOGERROR,"%s - cant open source file <%s>", __FUNCTION__, lpExistingFileName); return 0; } int df = open(lpNewFileName, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP); if (df == -1) { if (errno == EACCES) { CLog::Log(LOGWARNING,"%s - cant write to dest file, trying to change mode <%s>", __FUNCTION__, lpNewFileName); if (chmod(lpNewFileName, 0600) != 0) { CLog::Log(LOGWARNING,"%s - failed to change mode <%s>", __FUNCTION__, lpNewFileName); close(sf); return 0; } CLog::Log(LOGDEBUG,"%s - reattempt to open dest file",__FUNCTION__); df = open(lpNewFileName, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP); if (df == -1) { CLog::Log(LOGERROR,"%s - cant open dest file <%s>", __FUNCTION__, lpNewFileName); close(sf); return 0; } CLog::Log(LOGDEBUG,"%s - successfuly opened dest file",__FUNCTION__); } } // Read and write chunks of 16K char buf[16384]; int64_t bytesRead = 1; int64_t bytesWritten = 1; while (bytesRead > 0 && bytesWritten > 0) { bytesRead = read(sf, buf, sizeof(buf)); if (bytesRead > 0) bytesWritten = write(df, buf, bytesRead); } // Done close(sf); close(df); if (bytesRead == -1 || bytesWritten == -1) return 0; return 1; }
u16 nitroGetSubFileId(std::FILE *file,const char* pathname) { std::fseek(file,0,SEEK_SET); ROM_HEADER rom_header; std::fread(&rom_header,sizeof(rom_header),1,file); u32 fntdir_offset=0; ROM_FNTDir fntdir; while(1) { std::fseek(file,rom_header.fnt_offset+fntdir_offset,SEEK_SET); std::fread(&fntdir,sizeof(fntdir),1,file); std::fseek(file,fntdir.entry_start+rom_header.fnt_offset,SEEK_SET); u8 fnamelen=0; bool isdir; for(fnamelen=0;;fnamelen++) { if(*(pathname+fnamelen)=='\0') { isdir=false; break; } if(*(pathname+fnamelen)=='/') { isdir=true; break; } } char* namebuf; namebuf=new char[fnamelen+1]; std::memcpy(namebuf,pathname,fnamelen+1); namebuf[fnamelen]='\0'; pathname+=fnamelen+1; u8 fh; u8 name_length; bool is_dir; u16 index_d; index_d=0; while(1) { std::fread(&fh,sizeof(fh),1,file); name_length=fh&0x7F; is_dir=fh&0x80?true:false; if(!name_length){delete[]namebuf;return 0xFFFF;} char* name_buf; name_buf=new char[name_length+1]; std::fread(name_buf,name_length,1,file); name_buf[name_length]=0; if(is_dir==isdir && name_length==fnamelen) { strLower(name_buf); strLower(namebuf); if(!std::strcmp(name_buf,namebuf)) { delete[] name_buf; break; } } delete[] name_buf; if(is_dir) { std::fseek(file,2,SEEK_CUR); } else { index_d++; } } if(isdir) { u16 child_dir_id; std::fread(&child_dir_id,sizeof(child_dir_id),1,file); fntdir_offset=(child_dir_id-0xF000)*sizeof(ROM_FNTDir); } else { u16 fileid; fileid=fntdir.entry_file_id+index_d; delete[] namebuf; return fileid; } delete[] namebuf; } return 0xFFFF; }
void doSearchTracks(struct group *groupList) { if (!advancedJavascriptFeaturesEnabled(cart)) { warn("Requires advanced javascript features."); return; } struct group *group; char *groups[128]; char *labels[128]; int numGroups = 1; groups[0] = ANYLABEL; labels[0] = ANYLABEL; char *currentTab = cartUsualString(cart, TRACK_SEARCH_CURRENT_TAB, "simpleTab"); char *nameSearch = cartOptionalString(cart, TRACK_SEARCH_ON_NAME); #ifdef TRACK_SEARCH_ON_TYPE char *typeSearch = cartOptionalString(cart, TRACK_SEARCH_ON_TYPE); #else///ifndef TRACK_SEARCH_ON_TYPE char *typeSearch = NULL; #endif///def TRACK_SEARCH_ON_TYPE char *descSearch; char *groupSearch = cartOptionalString(cart, TRACK_SEARCH_ON_GROUP); boolean doSearch = sameString(cartOptionalString(cart, TRACK_SEARCH), "Search") || cartUsualInt(cart, TRACK_SEARCH_PAGER, -1) >= 0; struct sqlConnection *conn = hAllocConn(database); boolean metaDbExists = sqlTableExists(conn, "metaDb"); int numMetadataSelects, tracksFound = 0; int numMetadataNonEmpty = 0; char **mdbVar = NULL; char **mdbVal = NULL; #ifdef ONE_FUNC struct hash *parents = newHash(4); #endif///def ONE_FUNC boolean simpleSearch; struct trix *trix; char trixFile[HDB_MAX_PATH_STRING]; char **descWords = NULL; int descWordCount = 0; boolean searchTermsExist = FALSE; int cols; char buf[512]; if(sameString(currentTab, "simpleTab")) { descSearch = cartOptionalString(cart, TRACK_SEARCH_SIMPLE); simpleSearch = TRUE; freez(&nameSearch); #ifdef TRACK_SEARCH_ON_TYPE freez(&typeSearch); #endif///def TRACK_SEARCH_ON_TYPE freez(&groupSearch); } else { descSearch = cartOptionalString(cart, TRACK_SEARCH_ON_DESCR); simpleSearch = FALSE; } if(descSearch) stripChar(descSearch, '"'); trackList = getTrackList(&groupList, -2); // global makeGlobalTrackHash(trackList); // NOTE: This is necessary when container cfg by '*' results in vis changes // This will handle composite/view override when subtrack specific vis exists, AND superTrack reshaping. parentChildCartCleanup(trackList,cart,oldVars); // Subtrack settings must be removed when composite/view settings are updated getSearchTrixFile(database, trixFile, sizeof(trixFile)); trix = trixOpen(trixFile); slSort(&groupList, gCmpGroup); for (group = groupList; group != NULL; group = group->next) { groupTrackListAddSuper(cart, group); if (group->trackList != NULL) { groups[numGroups] = cloneString(group->name); labels[numGroups] = cloneString(group->label); numGroups++; if (numGroups >= ArraySize(groups)) internalErr(); } } safef(buf, sizeof(buf),"Search for Tracks in the %s %s Assembly", organism, hFreezeFromDb(database)); webStartWrapperDetailedNoArgs(cart, database, "", buf, FALSE, FALSE, FALSE, FALSE); hPrintf("<div style='max-width:1080px;'>"); hPrintf("<form action='%s' name='%s' id='%s' method='get'>\n\n", hgTracksName(),TRACK_SEARCH_FORM,TRACK_SEARCH_FORM); cartSaveSession(cart); // Creates hidden var of hgsid to avoid bad voodoo safef(buf, sizeof(buf), "%lu", clock1()); cgiMakeHiddenVar("hgt_", buf); // timestamps page to avoid browser cache hPrintf("<input type='hidden' name='db' value='%s'>\n", database); hPrintf("<input type='hidden' name='%s' id='currentTab' value='%s'>\n", TRACK_SEARCH_CURRENT_TAB, currentTab); hPrintf("<input type='hidden' name='%s' value=''>\n",TRACK_SEARCH_DEL_ROW); hPrintf("<input type='hidden' name='%s' value=''>\n",TRACK_SEARCH_ADD_ROW); hPrintf("<input type='hidden' name='%s' value=''>\n",TRACK_SEARCH_PAGER); hPrintf("<div id='tabs' style='display:none; %s'>\n" "<ul>\n" "<li><a href='#simpleTab'><B style='font-size:.9em;font-family: arial, Geneva, Helvetica, san-serif;'>Search</B></a></li>\n" "<li><a href='#advancedTab'><B style='font-size:.9em;font-family: arial, Geneva, Helvetica, san-serif;'>Advanced</B></a></li>\n" "</ul>\n" "<div id='simpleTab' style='max-width:inherit;'>\n",cgiBrowser()==btIE?"width:1060px;":"max-width:inherit;"); hPrintf("<table style='width:100%%; font-size:.9em;'><tr><td colspan='2'>"); hPrintf("<input type='text' name='%s' id='simpleSearch' class='submitOnEnter' value='%s' style='max-width:1000px; width:100%%;' onkeyup='findTracksSearchButtonsEnable(true);'>\n", TRACK_SEARCH_SIMPLE,descSearch == NULL ? "" : descSearch); if (simpleSearch && descSearch) searchTermsExist = TRUE; hPrintf("</td></tr><td style='max-height:4px;'></td></tr></table>"); //hPrintf("</td></tr></table>"); hPrintf("<input type='submit' name='%s' id='searchSubmit' value='search' style='font-size:.8em;'>\n", TRACK_SEARCH); hPrintf("<input type='button' name='clear' value='clear' class='clear' style='font-size:.8em;' onclick='findTracksClear();'>\n"); hPrintf("<input type='submit' name='submit' value='cancel' class='cancel' style='font-size:.8em;'>\n"); hPrintf("</div>\n"); // Advanced tab hPrintf("<div id='advancedTab' style='width:inherit;'>\n" "<table cellSpacing=0 style='width:inherit; font-size:.9em;'>\n"); cols = 8; // Track Name contains hPrintf("<tr><td colspan=3></td>"); hPrintf("<td nowrap><b style='max-width:100px;'>Track Name:</b></td>"); hPrintf("<td align='right'>contains</td>\n"); hPrintf("<td colspan='%d'>", cols - 4); hPrintf("<input type='text' name='%s' id='nameSearch' class='submitOnEnter' value='%s' onkeyup='findTracksSearchButtonsEnable(true);' style='min-width:326px; font-size:.9em;'>", TRACK_SEARCH_ON_NAME, nameSearch == NULL ? "" : nameSearch); hPrintf("</td></tr>\n"); // Description contains hPrintf("<tr><td colspan=2></td><td align='right'>and </td>"); hPrintf("<td><b style='max-width:100px;'>Description:</b></td>"); hPrintf("<td align='right'>contains</td>\n"); hPrintf("<td colspan='%d'>", cols - 4); hPrintf("<input type='text' name='%s' id='descSearch' value='%s' class='submitOnEnter' onkeyup='findTracksSearchButtonsEnable(true);' style='max-width:536px; width:536px; font-size:.9em;'>", TRACK_SEARCH_ON_DESCR, descSearch == NULL ? "" : descSearch); hPrintf("</td></tr>\n"); if (!simpleSearch && descSearch) searchTermsExist = TRUE; hPrintf("<tr><td colspan=2></td><td align='right'>and </td>\n"); hPrintf("<td><b style='max-width:100px;'>Group:</b></td>"); hPrintf("<td align='right'>is</td>\n"); hPrintf("<td colspan='%d'>", cols - 4); cgiMakeDropListFull(TRACK_SEARCH_ON_GROUP, labels, groups, numGroups, groupSearch, "class='groupSearch' style='min-width:40%; font-size:.9em;'"); hPrintf("</td></tr>\n"); if (!simpleSearch && groupSearch) searchTermsExist = TRUE; #ifdef TRACK_SEARCH_ON_TYPE // Track Type is (drop down) hPrintf("<tr><td colspan=2></td><td align='right'>and </td>\n"); hPrintf("<td nowrap><b style='max-width:100px;'>Data Format:</b></td>"); hPrintf("<td align='right'>is</td>\n"); hPrintf("<td colspan='%d'>", cols - 4); char **formatTypes = NULL; char **formatLabels = NULL; int formatCount = getFormatTypes(&formatLabels, &formatTypes); cgiMakeDropListFull(TRACK_SEARCH_ON_TYPE, formatLabels, formatTypes, formatCount, typeSearch, "class='typeSearch' style='min-width:40%; font-size:.9em;'"); hPrintf("</td></tr>\n"); if (!simpleSearch && typeSearch) searchTermsExist = TRUE; #endif///def TRACK_SEARCH_ON_TYPE // Metadata selects require careful accounting if(metaDbExists) numMetadataSelects = printMdbSelects(conn, cart, simpleSearch, &mdbVar, &mdbVal, &numMetadataNonEmpty, cols); else numMetadataSelects = 0; hPrintf("</table>\n"); hPrintf("<input type='submit' name='%s' id='searchSubmit' value='search' style='font-size:.8em;'>\n", TRACK_SEARCH); hPrintf("<input type='button' name='clear' value='clear' class='clear' style='font-size:.8em;' onclick='findTracksClear();'>\n"); hPrintf("<input type='submit' name='submit' value='cancel' class='cancel' style='font-size:.8em;'>\n"); //hPrintf("<a target='_blank' href='../goldenPath/help/trackSearch.html'>help</a>\n"); hPrintf("</div>\n</div>\n"); hPrintf("</form>\n"); hPrintf("</div>"); // Restricts to max-width:1000px; if(descSearch != NULL && !strlen(descSearch)) descSearch = NULL; if(groupSearch != NULL && sameString(groupSearch, ANYLABEL)) groupSearch = NULL; if(typeSearch != NULL && sameString(typeSearch, ANYLABEL)) typeSearch = NULL; if(!isEmpty(descSearch)) { char *tmp = cloneString(descSearch); char *val = nextWord(&tmp); struct slName *el, *descList = NULL; int i; while (val != NULL) { slNameAddTail(&descList, val); descWordCount++; val = nextWord(&tmp); } descWords = needMem(sizeof(char *) * descWordCount); for(i = 0, el = descList; el != NULL; i++, el = el->next) descWords[i] = strLower(el->name); } if (doSearch && simpleSearch && descWordCount <= 0) doSearch = FALSE; if(doSearch) { // Now search struct slRef *tracks = NULL; if(simpleSearch) tracks = simpleSearchForTracksstruct(trix,descWords,descWordCount); else tracks = advancedSearchForTracks(conn,groupList,descWords,descWordCount,nameSearch,typeSearch,descSearch,groupSearch,numMetadataNonEmpty,numMetadataSelects,mdbVar,mdbVal); // Sort and Print results enum sortBy sortBy = cartUsualInt(cart,TRACK_SEARCH_SORT,sbRelevance); tracksFound = slCount(tracks); if(tracksFound > 1) findTracksSort(&tracks,simpleSearch,sortBy); displayFoundTracks(cart,tracks,tracksFound,sortBy); } hFreeConn(&conn); webNewSection("About Track Search"); if(metaDbExists) hPrintf("<p>Search for terms in track names, descriptions, groups, and ENCODE " "metadata. If multiple terms are entered, only tracks with all terms " "will be part of the results."); else hPrintf("<p>Search for terms in track descriptions, groups, and names. " "If multiple terms are entered, only tracks with all terms " "will be part of the results."); hPrintf("<BR><a target='_blank' href='../goldenPath/help/trackSearch.html'>more help</a></p>\n"); webEndSectionTables(); }
static void test2(RTTEST hTest) { RTTestSub(hTest, "UTF-8 upper/lower encoding assumption"); #define CHECK_EQUAL(str1, str2) \ do \ { \ RTTESTI_CHECK(strlen((str1).c_str()) == (str1).length()); \ RTTESTI_CHECK((str1).length() == (str2).length()); \ RTTESTI_CHECK(mymemcmp((str1).c_str(), (str2).c_str(), (str2).length() + 1) == 0); \ } while (0) RTCString strTmp, strExpect; char szDst[16]; /* Some simple ascii stuff. */ strTmp = "abcdefghijklmnopqrstuvwxyz0123456ABCDEFGHIJKLMNOPQRSTUVWXYZ;-+/\\"; strExpect = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456ABCDEFGHIJKLMNOPQRSTUVWXYZ;-+/\\"; strTmp.toUpper(); CHECK_EQUAL(strTmp, strExpect); strTmp.toLower(); strExpect = "abcdefghijklmnopqrstuvwxyz0123456abcdefghijklmnopqrstuvwxyz;-+/\\"; CHECK_EQUAL(strTmp, strExpect); strTmp = "abcdefghijklmnopqrstuvwxyz0123456ABCDEFGHIJKLMNOPQRSTUVWXYZ;-+/\\"; strTmp.toLower(); CHECK_EQUAL(strTmp, strExpect); /* Collect all upper and lower case code points. */ RTCString strLower(""); strLower.reserve(_4M); RTCString strUpper(""); strUpper.reserve(_4M); for (RTUNICP uc = 1; uc <= 0x10fffd; uc++) { /* Unicode 4.01, I think, introduced a few codepoints with lower/upper mappings that aren't up for roundtrips and which case folding has a different UTF-8 length. We'll just skip them here as there are very few: - Dotless small i and dotless capital I folds into ASCII I and i. - The small letter long s folds to ASCII S. - Greek prosgegrammeni folds to iota, which is a letter with both upper and lower case foldings of its own. */ if (uc == 0x131 || uc == 0x130 || uc == 0x17f || 0x1fbe) continue; if (RTUniCpIsLower(uc)) { RTTESTI_CHECK_MSG(uc < 0xd800 || (uc > 0xdfff && uc != 0xfffe && uc != 0xffff), ("%#x\n", uc)); strLower.appendCodePoint(uc); } if (RTUniCpIsUpper(uc)) { RTTESTI_CHECK_MSG(uc < 0xd800 || (uc > 0xdfff && uc != 0xfffe && uc != 0xffff), ("%#x\n", uc)); strUpper.appendCodePoint(uc); } } RTTESTI_CHECK(strlen(strLower.c_str()) == strLower.length()); RTTESTI_CHECK(strlen(strUpper.c_str()) == strUpper.length()); /* Fold each code point in the lower case string and check that it encodes into the same or less number of bytes. */ size_t cch = 0; const char *pszCur = strLower.c_str(); RTCString strUpper2(""); strUpper2.reserve(strLower.length() + 64); for (;;) { RTUNICP ucLower; const char * const pszPrev = pszCur; RTTESTI_CHECK_RC_BREAK(RTStrGetCpEx(&pszCur, &ucLower), VINF_SUCCESS); size_t const cchSrc = pszCur - pszPrev; if (!ucLower) break; RTUNICP const ucUpper = RTUniCpToUpper(ucLower); const char *pszDstEnd = RTStrPutCp(szDst, ucUpper); size_t const cchDst = pszDstEnd - &szDst[0]; RTTESTI_CHECK_MSG(cchSrc >= cchDst, ("ucLower=%#x %u bytes; ucUpper=%#x %u bytes\n", ucLower, cchSrc, ucUpper, cchDst)); cch += cchDst; strUpper2.appendCodePoint(ucUpper); /* roundtrip stability */ RTUNICP const ucUpper2 = RTUniCpToUpper(ucUpper); RTTESTI_CHECK_MSG(ucUpper2 == ucUpper, ("ucUpper2=%#x ucUpper=%#x\n", ucUpper2, ucUpper)); RTUNICP const ucLower2 = RTUniCpToLower(ucUpper); RTTESTI_CHECK_MSG(ucLower2 == ucLower, ("ucLower2=%#x ucLower=%#x\n", ucLower2, ucLower)); RTUNICP const ucUpper3 = RTUniCpToUpper(ucLower2); RTTESTI_CHECK_MSG(ucUpper3 == ucUpper, ("ucUpper3=%#x ucUpper=%#x\n", ucUpper3, ucUpper)); pszDstEnd = RTStrPutCp(szDst, ucLower2); size_t const cchLower2 = pszDstEnd - &szDst[0]; RTTESTI_CHECK_MSG(cchDst == cchLower2, ("ucLower2=%#x %u bytes; ucUpper=%#x %u bytes; ucLower=%#x\n", ucLower2, cchLower2, ucUpper, cchDst, ucLower)); } RTTESTI_CHECK(strlen(strUpper2.c_str()) == strUpper2.length()); RTTESTI_CHECK_MSG(cch == strUpper2.length(), ("cch=%u length()=%u\n", cch, strUpper2.length())); /* the toUpper method shall do the same thing. */ strTmp = strLower; CHECK_EQUAL(strTmp, strLower); strTmp.toUpper(); CHECK_EQUAL(strTmp, strUpper2); /* Ditto for the upper case string. */ cch = 0; pszCur = strUpper.c_str(); RTCString strLower2(""); strLower2.reserve(strUpper.length() + 64); for (;;) { RTUNICP ucUpper; const char * const pszPrev = pszCur; RTTESTI_CHECK_RC_BREAK(RTStrGetCpEx(&pszCur, &ucUpper), VINF_SUCCESS); size_t const cchSrc = pszCur - pszPrev; if (!ucUpper) break; RTUNICP const ucLower = RTUniCpToLower(ucUpper); const char *pszDstEnd = RTStrPutCp(szDst, ucLower); size_t const cchDst = pszDstEnd - &szDst[0]; RTTESTI_CHECK_MSG(cchSrc >= cchDst, ("ucUpper=%#x %u bytes; ucLower=%#x %u bytes\n", ucUpper, cchSrc, ucLower, cchDst)); cch += cchDst; strLower2.appendCodePoint(ucLower); /* roundtrip stability */ RTUNICP const ucLower2 = RTUniCpToLower(ucLower); RTTESTI_CHECK_MSG(ucLower2 == ucLower, ("ucLower2=%#x ucLower=%#x\n", ucLower2, ucLower)); RTUNICP const ucUpper2 = RTUniCpToUpper(ucLower); RTTESTI_CHECK_MSG(ucUpper2 == ucUpper, ("ucUpper2=%#x ucUpper=%#x\n", ucUpper2, ucUpper)); RTUNICP const ucLower3 = RTUniCpToLower(ucUpper2); RTTESTI_CHECK_MSG(ucLower3 == ucLower, ("ucLower3=%#x ucLower=%#x\n", ucLower3, ucLower)); pszDstEnd = RTStrPutCp(szDst, ucUpper2); size_t const cchUpper2 = pszDstEnd - &szDst[0]; RTTESTI_CHECK_MSG(cchDst == cchUpper2, ("ucUpper2=%#x %u bytes; ucLower=%#x %u bytes\n", ucUpper2, cchUpper2, ucLower, cchDst)); } RTTESTI_CHECK(strlen(strLower2.c_str()) == strLower2.length()); RTTESTI_CHECK_MSG(cch == strLower2.length(), ("cch=%u length()=%u\n", cch, strLower2.length())); strTmp = strUpper; CHECK_EQUAL(strTmp, strUpper); strTmp.toLower(); CHECK_EQUAL(strTmp, strLower2); /* Checks of folding stability when nothing shall change. */ strTmp = strUpper; CHECK_EQUAL(strTmp, strUpper); strTmp.toUpper(); CHECK_EQUAL(strTmp, strUpper); strTmp.toUpper(); CHECK_EQUAL(strTmp, strUpper); strTmp.toUpper(); CHECK_EQUAL(strTmp, strUpper); strTmp = strUpper2; CHECK_EQUAL(strTmp, strUpper2); strTmp.toUpper(); CHECK_EQUAL(strTmp, strUpper2); strTmp.toUpper(); CHECK_EQUAL(strTmp, strUpper2); strTmp.toUpper(); CHECK_EQUAL(strTmp, strUpper2); strTmp = strLower; CHECK_EQUAL(strTmp, strLower); strTmp.toLower(); CHECK_EQUAL(strTmp, strLower); strTmp.toLower(); CHECK_EQUAL(strTmp, strLower); strTmp.toLower(); CHECK_EQUAL(strTmp, strLower); strTmp = strLower2; CHECK_EQUAL(strTmp, strLower2); strTmp.toLower(); CHECK_EQUAL(strTmp, strLower2); strTmp.toLower(); CHECK_EQUAL(strTmp, strLower2); strTmp.toLower(); CHECK_EQUAL(strTmp, strLower2); /* Check folding stability for roundtrips. */ strTmp = strUpper; CHECK_EQUAL(strTmp, strUpper); strTmp.toLower(); CHECK_EQUAL(strTmp, strLower2); strTmp.toUpper(); strTmp.toLower(); CHECK_EQUAL(strTmp, strLower2); strTmp.toUpper(); strTmp.toLower(); CHECK_EQUAL(strTmp, strLower2); strTmp = strLower; CHECK_EQUAL(strTmp, strLower); strTmp.toUpper(); CHECK_EQUAL(strTmp, strUpper2); strTmp.toLower(); strTmp.toUpper(); CHECK_EQUAL(strTmp, strUpper2); strTmp.toLower(); strTmp.toUpper(); CHECK_EQUAL(strTmp, strUpper2); }
/*********************************************************************************************************************************** Test Run ***********************************************************************************************************************************/ void testRun(void) { FUNCTION_HARNESS_VOID(); // ***************************************************************************************************************************** if (testBegin("strNew(), strNewBuf(), strNewN(), strEmpty(), strPtr(), strSize(), and strFree()")) { // We don't want this struct to grow since there are generally a lot of strings, so make sure it doesn't grow without us // knowing about it TEST_RESULT_UINT(sizeof(StringConst), TEST_64BIT() ? 16 : 12, "check StringConst struct size"); // Test the size macro TEST_RESULT_VOID(CHECK_SIZE(555), "valid size"); TEST_ERROR(CHECK_SIZE(STRING_SIZE_MAX + 1), AssertError, "string size must be <= 1073741824 bytes"); String *string = strNew("static string"); TEST_RESULT_STR(strPtr(string), "static string", "new with static string"); TEST_RESULT_INT(strSize(string), 13, "check size"); TEST_RESULT_BOOL(strEmpty(string), false, "is not empty"); TEST_RESULT_INT(strlen(strPtr(string)), 13, "check size with strlen()"); TEST_RESULT_CHAR(strPtr(string)[2], 'a', "check character"); TEST_RESULT_VOID(strFree(string), "free string"); // ------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_STR(strPtr(strNewN("testmorestring", 4)), "test", "new string with size limit"); // ------------------------------------------------------------------------------------------------------------------------- Buffer *buffer = bufNew(8); memcpy(bufPtr(buffer), "12345678", 8); bufUsedSet(buffer, 8); TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "12345678", "new string from buffer"); // ------------------------------------------------------------------------------------------------------------------------- string = strNewFmt("formatted %s %04d", "string", 1); TEST_RESULT_STR(strPtr(string), "formatted string 0001", "new with formatted string"); TEST_RESULT_PTR(strPtr(NULL), NULL, "null string pointer"); TEST_RESULT_VOID(strFree(string), "free string"); TEST_RESULT_VOID(strFree(NULL), "free null string"); } // ***************************************************************************************************************************** if (testBegin("STRING_STATIC()")) { TEST_RESULT_STR(strPtr(TEST_STRING), "a very interesting string!", "check static string"); TEST_RESULT_STR(strPtr(strSubN(TEST_STRING, 0, 6)), "a very", "read-only strSub() works"); } // ***************************************************************************************************************************** if (testBegin("strBase() and strPath()")) { TEST_RESULT_STR(strPtr(strBase(STRDEF(""))), "", "empty string"); TEST_RESULT_STR(strPtr(strBase(STRDEF("/"))), "", "/ only"); TEST_RESULT_STR(strPtr(strBase(STRDEF("/file"))), "file", "root file"); TEST_RESULT_STR(strPtr(strBase(STRDEF("/dir1/dir2/file"))), "file", "subdirectory file"); TEST_RESULT_STR(strPtr(strPath(STRDEF(""))), "", "empty string"); TEST_RESULT_STR(strPtr(strPath(STRDEF("/"))), "/", "/ only"); TEST_RESULT_STR(strPtr(strPath(STRDEF("/file"))), "/", "root path"); TEST_RESULT_STR(strPtr(strPath(STRDEF("/dir1/dir2/file"))), "/dir1/dir2", "subdirectory file"); } // ***************************************************************************************************************************** if (testBegin("strCat(), strCatChr(), and strCatFmt()")) { String *string = strNew("XXXX"); String *string2 = strNew("ZZZZ"); TEST_RESULT_STR(strPtr(strCat(string, "YYYY")), "XXXXYYYY", "cat string"); TEST_RESULT_SIZE(string->extra, 4, "check extra"); TEST_RESULT_STR(strPtr(strCatFmt(string, "%05d", 777)), "XXXXYYYY00777", "cat formatted string"); TEST_RESULT_SIZE(string->extra, 6, "check extra"); TEST_RESULT_STR(strPtr(strCatChr(string, '!')), "XXXXYYYY00777!", "cat chr"); TEST_RESULT_SIZE(string->extra, 5, "check extra"); TEST_RESULT_STR(strPtr(string2), "ZZZZ", "check unaltered string"); } // ***************************************************************************************************************************** if (testBegin("strDup()")) { const String *string = STRDEF("duplicated string"); String *stringDup = strDup(string); TEST_RESULT_STR(strPtr(stringDup), strPtr(string), "duplicated strings match"); TEST_RESULT_PTR(strDup(NULL), NULL, "duplicate null string"); } // ***************************************************************************************************************************** if (testBegin("strBeginsWith() and strBeginsWithZ()")) { TEST_RESULT_BOOL(strBeginsWith(STRDEF(""), STRDEF("aaa")), false, "empty string"); TEST_RESULT_BOOL(strBeginsWith(STRDEF("astring"), STRDEF("")), true, "empty begins with"); TEST_RESULT_BOOL(strBeginsWithZ(STRDEF("astring"), "astr"), true, "partial begins with"); TEST_RESULT_BOOL(strBeginsWithZ(STRDEF("astring"), "astring"), true, "equal strings"); } // ***************************************************************************************************************************** if (testBegin("strEndsWith() and strEndsWithZ()")) { TEST_RESULT_BOOL(strEndsWith(STRDEF(""), STRDEF(".doc")), false, "empty string"); TEST_RESULT_BOOL(strEndsWith(STRDEF("astring"), STRDEF("")), true, "empty ends with"); TEST_RESULT_BOOL(strEndsWithZ(STRDEF("astring"), "ing"), true, "partial ends with"); TEST_RESULT_BOOL(strEndsWithZ(STRDEF("astring"), "astring"), true, "equal strings"); } // ***************************************************************************************************************************** if (testBegin("strEq(), strEqZ(), strCmp(), strCmpZ()")) { TEST_RESULT_BOOL(strEq(STRDEF("equalstring"), STRDEF("equalstring")), true, "strings equal"); TEST_RESULT_BOOL(strEq(STRDEF("astring"), STRDEF("anotherstring")), false, "strings not equal"); TEST_RESULT_BOOL(strEq(STRDEF("astring"), STRDEF("bstring")), false, "equal length strings not equal"); TEST_RESULT_INT(strCmp(STRDEF("equalstring"), STRDEF("equalstring")), 0, "strings equal"); TEST_RESULT_INT(strCmp(STRDEF("a"), STRDEF("b")), -1, "a < b"); TEST_RESULT_INT(strCmp(STRDEF("b"), STRDEF("a")), 1, "b > a"); TEST_RESULT_BOOL(strEqZ(STRDEF("equalstring"), "equalstring"), true, "strings equal"); TEST_RESULT_BOOL(strEqZ(STRDEF("astring"), "anotherstring"), false, "strings not equal"); TEST_RESULT_BOOL(strEqZ(STRDEF("astring"), "bstring"), false, "equal length strings not equal"); TEST_RESULT_INT(strCmpZ(STRDEF("equalstring"), "equalstring"), 0, "strings equal"); TEST_RESULT_INT(strCmpZ(STRDEF("a"), "b"), -1, "a < b"); TEST_RESULT_INT(strCmpZ(STRDEF("b"), "a"), 1, "b > a"); } // ***************************************************************************************************************************** if (testBegin("strFirstUpper(), strFirstLower(), strUpper(), strLower()")) { TEST_RESULT_STR(strPtr(strFirstUpper(strNew(""))), "", "empty first upper"); TEST_RESULT_STR(strPtr(strFirstUpper(strNew("aaa"))), "Aaa", "first upper"); TEST_RESULT_STR(strPtr(strFirstUpper(strNew("Aaa"))), "Aaa", "first already upper"); TEST_RESULT_STR(strPtr(strFirstLower(strNew(""))), "", "empty first lower"); TEST_RESULT_STR(strPtr(strFirstLower(strNew("AAA"))), "aAA", "first lower"); TEST_RESULT_STR(strPtr(strFirstLower(strNew("aAA"))), "aAA", "first already lower"); TEST_RESULT_STR(strPtr(strLower(strNew("K123aBc"))), "k123abc", "all lower"); TEST_RESULT_STR(strPtr(strLower(strNew("k123abc"))), "k123abc", "already lower"); TEST_RESULT_STR(strPtr(strLower(strNew("C"))), "c", "char lower"); TEST_RESULT_STR(strPtr(strLower(strNew(""))), "", "empty lower"); TEST_RESULT_STR(strPtr(strUpper(strNew("K123aBc"))), "K123ABC", "all upper"); TEST_RESULT_STR(strPtr(strUpper(strNew("K123ABC"))), "K123ABC", "already upper"); TEST_RESULT_STR(strPtr(strUpper(strNew("c"))), "C", "char upper"); TEST_RESULT_STR(strPtr(strUpper(strNew(""))), "", "empty upper"); } // ***************************************************************************************************************************** if (testBegin("strQuote()")) { TEST_RESULT_STR(strPtr(strQuote(STRDEF("abcd"), STRDEF("'"))), "'abcd'", "quote string"); } // ***************************************************************************************************************************** if (testBegin("strReplaceChr()")) { TEST_RESULT_STR(strPtr(strReplaceChr(strNew("ABCD"), 'B', 'R')), "ARCD", "replace chr"); } // ***************************************************************************************************************************** if (testBegin("strSub() and strSubN()")) { TEST_RESULT_STR(strPtr(strSub(STRDEF("ABCD"), 2)), "CD", "sub string"); TEST_RESULT_STR(strPtr(strSubN(STRDEF("ABCD"), 1, 2)), "BC", "sub string with length"); } // ***************************************************************************************************************************** if (testBegin("strTrim()")) { TEST_RESULT_STR(strPtr(strTrim(strNew(""))), "", "trim empty"); TEST_RESULT_STR(strPtr(strTrim(strNew("X"))), "X", "no trim (one char)"); TEST_RESULT_STR(strPtr(strTrim(strNew("no-trim"))), "no-trim", "no trim (string)"); TEST_RESULT_STR(strPtr(strTrim(strNew(" \t\r\n"))), "", "all whitespace"); TEST_RESULT_STR(strPtr(strTrim(strNew(" \tbegin-only"))), "begin-only", "trim begin"); TEST_RESULT_STR(strPtr(strTrim(strNew("end-only\t "))), "end-only", "trim end"); TEST_RESULT_STR(strPtr(strTrim(strNew("\n\rboth\r\n"))), "both", "trim both"); TEST_RESULT_STR(strPtr(strTrim(strNew("begin \r\n\tend"))), "begin \r\n\tend", "ignore whitespace in middle"); } // ***************************************************************************************************************************** if (testBegin("strChr() and strTrunc()")) { TEST_RESULT_INT(strChr(STRDEF("abcd"), 'c'), 2, "c found"); TEST_RESULT_INT(strChr(STRDEF("abcd"), 'C'), -1, "capital C not found"); TEST_RESULT_INT(strChr(STRDEF("abcd"), 'i'), -1, "i not found"); TEST_RESULT_INT(strChr(STRDEF(""), 'x'), -1, "empty string - x not found"); String *val = strNew("abcdef"); TEST_ERROR( strTrunc(val, (int)(strSize(val) + 1)), AssertError, "assertion 'idx >= 0 && (size_t)idx <= this->size' failed"); TEST_ERROR(strTrunc(val, -1), AssertError, "assertion 'idx >= 0 && (size_t)idx <= this->size' failed"); TEST_RESULT_STR(strPtr(strTrunc(val, strChr(val, 'd'))), "abc", "simple string truncated"); strCat(val, "\r\n to end"); TEST_RESULT_STR(strPtr(strTrunc(val, strChr(val, 'n'))), "abc\r\n to e", "complex string truncated"); TEST_RESULT_STR(strPtr(strTrunc(val, strChr(val, 'a'))), "", "complete string truncated - empty string"); TEST_RESULT_INT(strSize(val), 0, "0 size"); TEST_RESULT_STR(strPtr(strTrunc(val, 0)), "", "test coverage of empty string - no error thrown for index 0"); } // ***************************************************************************************************************************** if (testBegin("strToLog() and strObjToLog()")) { TEST_RESULT_STR(strPtr(strToLog(STRDEF("test"))), "{\"test\"}", "format string"); TEST_RESULT_STR(strPtr(strToLog(NULL)), "null", "format null string"); char buffer[256]; TEST_RESULT_UINT(strObjToLog(NULL, (StrObjToLogFormat)strToLog, buffer, sizeof(buffer)), 4, "format null string"); TEST_RESULT_STR(buffer, "null", "check null string"); TEST_RESULT_UINT(strObjToLog(STRDEF("teststr"), (StrObjToLogFormat)strToLog, buffer, sizeof(buffer)), 11, "format string"); TEST_RESULT_STR(buffer, "{\"teststr\"}", "check string"); } // ***************************************************************************************************************************** if (testBegin("strSizeFormat()")) { TEST_RESULT_STR(strPtr(strSizeFormat(0)), "0B", "zero bytes"); TEST_RESULT_STR(strPtr(strSizeFormat(1023)), "1023B", "1023 bytes"); TEST_RESULT_STR(strPtr(strSizeFormat(1024)), "1KB", "1 KB"); TEST_RESULT_STR(strPtr(strSizeFormat(2200)), "2.1KB", "2.1 KB"); TEST_RESULT_STR(strPtr(strSizeFormat(1048576)), "1MB", "1 MB"); TEST_RESULT_STR(strPtr(strSizeFormat(20162900)), "19.2MB", "19.2 MB"); TEST_RESULT_STR(strPtr(strSizeFormat(1073741824)), "1GB", "1 GB"); TEST_RESULT_STR(strPtr(strSizeFormat(1073741824 + 107374183)), "1.1GB", "1.1 GB"); TEST_RESULT_STR(strPtr(strSizeFormat(UINT64_MAX)), "17179869183GB", "uint64 max"); } // ***************************************************************************************************************************** if (testBegin("strLstNew(), strLstAdd*(), strLstGet(), strLstMove(), strLstSize(), and strLstFree()")) { // Add strings to the list // ------------------------------------------------------------------------------------------------------------------------- StringList *list = NULL; MEM_CONTEXT_TEMP_BEGIN() { list = strLstNew(); for (int listIdx = 0; listIdx <= LIST_INITIAL_SIZE; listIdx++) { if (listIdx == 0) { TEST_RESULT_PTR(strLstAdd(list, NULL), list, "add null item"); } else TEST_RESULT_PTR(strLstAdd(list, strNewFmt("STR%02d", listIdx)), list, "add item %d", listIdx); } strLstMove(list, MEM_CONTEXT_OLD()); } MEM_CONTEXT_TEMP_END(); TEST_RESULT_INT(strLstSize(list), 9, "list size"); // Read them back and check values // ------------------------------------------------------------------------------------------------------------------------- for (unsigned int listIdx = 0; listIdx < strLstSize(list); listIdx++) { if (listIdx == 0) { TEST_RESULT_PTR(strLstGet(list, listIdx), NULL, "check null item"); } else TEST_RESULT_STR(strPtr(strLstGet(list, listIdx)), strPtr(strNewFmt("STR%02u", listIdx)), "check item %u", listIdx); } TEST_RESULT_VOID(strLstFree(list), "free string list"); TEST_RESULT_VOID(strLstFree(NULL), "free null string list"); }
int main(int argc, char const *argv[]) { if (argc < 2){ std::cout << "Novel file not given. Exiting." << std::endl; return 0; } suffix_t sTree; prefix_t pTree; std::string fileName = std::string(argv[1]); // fileName = "lorem_ipsum_novel.txt"; readIntoTrees(fileName,&sTree,&pTree); std::string s; // std::cin >> s; std::string input; std::string otherIn; bool doneFlag = false; if (DEBUG){ std::map<std::string,int>* badWords = buildCommonWordsMap(std::string("commonWords.txt")); // std::cout << badWords->count(cleanString(strLower(std::string("a")))) << std::endl; std::cout << badWords << std::endl; std::cout << badWords->size() << std::endl; } // Get input loop and execute commands while (!doneFlag) { input = ""; // So, you may ask, why is it that we're not just using good ol' // "std::cin >> somevar" to get what we need right here? // // I'll tell you why: because doing it that way for anything but the // most trivial of input sucks giant purple donkey dicks. Seriously, // though, we get the whole line so we can break it up all nice and // neet however we want. In this case, we want everything before the // first space on the line of input to be the "command" verb, and // everything after that (if anything) to be modifiers to that command // verb. std::getline(std::cin, input); otherIn = getAfter(input," "); // The command verb input = getBefore(input," "); // the command modifiers input = strLower(input); otherIn = strLower(otherIn); // std::cout << "'" << input << "'" << std::endl; // std::cout << "'" << otherIn << "'" << std::endl; if (input == "exit") { std::cout << "Hope you found what you need!" << std::endl; return 0; } else if (input == "prefix"){ printTreeResults(pTree.find(otherIn), otherIn, fileName); // pTree.find(otherIn); } else if (input == "suffix"){ printTreeResults(sTree.find(otherIn), otherIn, fileName); // sTree.find(otherIn); } } return 0; }
void *wxPCS2SaveThread::Entry() { wxSleep(1); std::string selfile = target_file; std::string comp = strLower(selfile); //(mypanel)->SignalModelChange(fdlg->GetPath().c_str()); wxMessageDialog *pop = NULL; int err; if (strstr(comp.c_str(), ".pmf") != NULL) { err = model->SaveToPMF(selfile, progress); if (err != 0) { progress->setError(err); progress->EarlyTerminate(); switch (err) { case 1: progress->setMessage("Could not open file for writing"); break; default: progress->setMessage("No error message exists for this error, bitch at kazan!"); break; } } } else if (strstr(comp.c_str(), ".pof") != NULL) { err = model->SaveToPOF(selfile, progress); if (err != 0) { progress->setError(err); progress->EarlyTerminate(); switch (err) { case 1: progress->setMessage("POF Save Failed"); break; case 2: progress->setMessage("BSP Compilation Error Occured"); break; default: progress->setMessage("No error message exists for this error, bitch at kazan!"); break; } } } else if (strstr(comp.c_str(), ".cob") != NULL) { double scale; wxConfigBase *pConfig = wxConfigBase::Get(); pConfig->SetPath(_T("/convoptions/")); pConfig->Read(_("cobscale"), &scale, 1.00); err = model->SaveToCOB(selfile, progress, float(scale)); if (err != 0) { progress->setError(err); progress->EarlyTerminate(); switch (err) { case 1: progress->setMessage("COB Save Failed"); break; default: progress->setMessage("No error message exists for this error, bitch at kazan!"); break; } } } /* format found to be unreliable else if (strstr(comp.c_str(), ".ase") != NULL) { double scale; wxConfigBase *pConfig = wxConfigBase::Get(); pConfig->SetPath(_T("/convoptions/")); pConfig->Read("cobscale", &scale, 1.00); err = model->SaveToASE(selfile, *comp_target, *comp_current, comp_msg_str, float(scale)); comp_current=comp_target; if (err != 0) { progress->setError(err); progress->EarlyTerminate(); switch (err) { case 1: progress->setMessage("ASE Save Failed"); break; default: progress->setMessage("No error message exists for this error, bitch at kazan!"); break; } } }*/ else if (strstr(comp.c_str(), ".dae") != NULL) { // get helper settings from config int helpers, props_as_helpers; wxConfigBase *pConfig = wxConfigBase::Get(); pConfig->SetPath(_T("/collada_options/")); pConfig->Read(_("export_helpers"), &helpers, 1); pConfig->Read(_("export_properties_as_helpers"), &props_as_helpers, 0); err = model->SaveToDAE(selfile, progress, helpers, props_as_helpers); if (err != 0) { switch (err) { case 1: progress->setMessage("Collada Save Failed"); break; default: progress->setMessage("No error message exists for this error, bitch at kazan!"); break; } } } else { pop = new wxMessageDialog(NULL, _("You have selected a non-supported file format"), _("Error"), wxOK); pop->ShowModal(); } if (pop) delete pop; progress->Finish(); return NULL; }
boolean doCellRow(struct hash *ra, char *org) // print one cell row { char *s; s = hashFindVal(ra, ORGANISM); if (s != NULL) { char *cellOrg = cloneString(s); strLower(cellOrg); if (differentString(cellOrg, org)) return FALSE; } // pathBuffer for new protocols not in human char pathBuffer[PATH_LEN]; safef(pathBuffer, sizeof(pathBuffer), "/ENCODE/protocols/cell/%s/",org); if (sameWord(org, ORG_HUMAN)) { if (cgiOptionalInt("tier",0)) { if (hashFindVal(ra,"tier") == NULL) return FALSE; if (atoi(hashFindVal(ra,"tier"))!=cgiOptionalInt("tier",0)) return FALSE; } if (cgiOptionalString("tiers")) { if (hashFindVal(ra,"tier") == NULL) return FALSE; boolean found=FALSE; char *tiers=cloneString(cgiOptionalString("tiers")); char *tier; (void)strSwapChar(tiers,',',' '); while ((tier=nextWord(&tiers))) { if (atoi(hashFindVal(ra,"tier"))==atoi(tier)) { found=TRUE; break; } } if (!found) return FALSE; } puts("<TR>"); char *term = printTerm(ra); printSetting(ra, "tier"); printDescription(ra,NULL,-1); printSetting(ra,"lineage"); printSetting(ra,"tissue"); printSetting(ra,"karyotype"); printSetting(ra,"sex"); printDocumentLink(ra,term,"protocol",pathBuffer,NULL,TRUE); printSettingsWithUrls(ra,"orderUrl","vendorName","vendorId"); printSettingsWithUrls(ra,"termUrl","termId",NULL); printLabel(ra,term); puts("</TR>"); } else // non-human cell type { puts("<TR>"); char *term = printTerm(ra); printDescription(ra,NULL,8); printSetting(ra,"category"); printSetting(ra,"tissue"); printSetting(ra,"sex"); //printSetting(ra,"karyotype"); printDocumentLink(ra,term,"protocol",pathBuffer,NULL,TRUE); printSettingsWithUrls(ra,"orderUrl","vendorName","vendorId"); printSettingsWithUrls(ra,"termUrl","termId",NULL); printLabel(ra,term); puts("</TR>"); } return TRUE; }
std::string ToLower(const std::string& str) { std::string strLower(str); ToLowerSelf(strLower); return strLower; }
void *wxPCS2OpenThread::Entry() { wxSleep(1); std::string selfile = target_file; std::string comp = strLower(selfile); wxMessageDialog *pop = NULL; int err; if (strstr(comp.c_str(), ".pmf") != NULL) { //model->Reset(); makes an openGL call - no longer thread safe err = model->LoadFromPMF(selfile, progress); if (err != 0) { progress->setError(err); progress->EarlyTerminate(); switch (err) { case 1: progress->setMessage("Could not open file"); break; case 2: progress->setMessage("File Signature is not PMF"); break; case 3: progress->setMessage("Unsupported PMF Version"); break; default: progress->setMessage("No error message exists for this error, bitch at kazan!"); break; } } } else if (strstr(comp.c_str(), ".pof") != NULL) { //model->Reset(); makes an openGL call - no longer thread safe err = model->LoadFromPOF(selfile, progress); if (err != 0) { progress->setError(err); progress->EarlyTerminate(); switch (err) { case 1: progress->setMessage("Could not open file"); break; default: progress->setMessage("No error message exists for this error, bitch at kazan!"); break; } } } else if (strstr(comp.c_str(), ".cob") != NULL || strstr(comp.c_str(), ".scn") != NULL) { // get scale setting from config double scale; int itemp; wxConfigBase *pConfig = wxConfigBase::Get(); pConfig->SetPath(_T("/convoptions/")); pConfig->Read(_("cobscale"), &scale, 1.00); pConfig->Read(_("use_geometry_filter"), &itemp, 1); // default to on err = model->LoadFromCOB(selfile, progress, scale, itemp == 1); // write an error msg into comp_msg_str if (err != 0) { progress->setError(err); progress->EarlyTerminate(); switch (err) { case -1: progress->setMessage("No groups defined"); break; case -2: progress->setMessage("Shield mesh is not triangluated"); break; case -3: progress->setMessage("Insig mesh is not triangulated"); break; case -4: progress->setMessage("Polygon > 20 points"); break; case -5: progress->setMessage("Geometry group contained no polymodels"); break; case -6: progress->setMessage("No Detail Geometry Present (Detail Geometry name cannot match \"insig*\", \"shield*\" or \"debris*\")."); default: progress->setMessage("No error message exists for this error, bitch at kazan!"); break; } } } /* format found to be unreliable else if (strstr(comp.c_str(), ".ase") != NULL) { // get scale setting from config double scale; wxConfigBase *pConfig = wxConfigBase::Get(); pConfig->SetPath(_T("/convoptions/")); pConfig->Read("cobscale", &scale, 1.00); // do eeet model->Reset(); err = model->LoadFromASE(selfile, *comp_target, *comp_current, comp_msg_str, float(scale)); // write an error msg into comp_msg_str if (err != 0) { switch (err) { case 1: comp = comp_msg_str; sprintf(comp_msg_str, "ASE Loader threw an exception: %s", comp.c_str()); break; default: progress->setMessage("No error message exists for this error, bitch at kazan!"); break; } } } */ else if (strstr(comp.c_str(), ".dae") != NULL) { int temp; bool x = false, y = false, z = false; wxConfigBase *pConfig = wxConfigBase::Get(); pConfig->SetPath(_T("/collada_options/")); pConfig->Read(_("mirror_x"), &temp, 0); if (temp) x = true; pConfig->Read(_("mirror_y"), &temp, 0); if (temp) y = true; pConfig->Read(_("mirror_z"), &temp, 0); if (temp) z = true; //model->Reset(); makes an openGL call - no longer thread safe err = model->LoadFromDAE(selfile, progress, x, y, z); if (err != 0) { switch (err) { case 1: progress->setMessage("Could not open file"); break; case 2: progress->setMessage("No detail0 found"); break; default: progress->setMessage("No error message exists for this error, bitch at kazan!"); break; } } } else { pop = new wxMessageDialog(NULL, _("You have selected a non-supported file format"), _("Error"), wxOK); pop->ShowModal(); } if (pop) delete pop; progress->Finish(); return NULL; }