コード例 #1
0
ファイル: dyOut.c プロジェクト: andrelmartins/bigWig
void dyOutTest()
// Tests of dyOut functions
{
printf("Plain printf\n");
dyOutPrintf("1 dyOutPrintf unopened\n");

int token1 = dyOutOpen(0);
dyOutPrintf("2 dyOutOpen:1\n");
dyOutFlush(token1);
dyOutPrintf("3^10   1:%d after flush\n",dyOutStackDepth());
int token2 = dyOutOpen(256);
dyOutPrintf("4 dsOpen:2 len1:%d  len2:%d  lenAll:%d\n",
         dyOutSize(token1),dyOutSize(token2),dyOutSizeAll());
dyOutRegisterAltStream(stderr);
dyOutFlush(token2);
dyOutUnregisterAltStream(stderr);
dyOutPrintf("5      2:%d After flush  len1:%d  len2:%d  lenAll:%d\n",
         dyOutStackDepth(),dyOutSize(token1),dyOutSize(token2),dyOutSizeAll());
dyOutFlushAndClose(token2);
dyOutPrintf("6      1:%d After flushAndClose:2  len1:%d\n",dyOutStackDepth(),dyOutSize(token1));
token2 = dyOutOpen(256);
dyOutPrintf("7 dyOutOpen:2 reopen:2  WILL ABANDON CONTENT\n");
char *content = cloneString(dyOutContent(token2));
dyOutAbandonContent(token2);
dyOutPrintf("8x7    2:%d len1:%d len2:%d lenAll:%d isEmpty2:%s\n",
         dyOutStackDepth(),dyOutSize(token1),dyOutSize(token2),dyOutSizeAll(),
         (dyOutIsEmpty(token2) ? "EMPTY":"NOT_EMPTY"));
strSwapChar(content,'\n','~');  // Replace newline before printing.
dyOutPrintf("9      2:%d No flush yet   len1:%d  len2:%d  lenAll:%d  prev7:[%s]\n",
         dyOutStackDepth(),dyOutSize(token1),dyOutSize(token2),dyOutSizeAll(),content);
freez(&content);
int token3 = dyOutOpen(256);
dyOutPuts("10  Open:3 Line doubled and out of turn due to dyOutPrintDirectly()");
dyOutPrintDirectly(token3,stdout);
dyOutPrintf("11     3:%d Just prior to closing all.  len1:%d  len2:%d  len3:%d  lenAll:%d",
         dyOutStackDepth(),
         dyOutSize(token1),dyOutSize(token2),dyOutSize(token3),dyOutSizeAll());
int token4 = dyOutOpen(256);
dyOutPrintf("12  Open:4 Opened  stack:%d  WILL ABANDON\n",dyOutStackDepth());
dyOutAbandon(token4);
dyOutPutc('\n');
dyOutPuts("13  Puts:  Added last '\\n' with dsPutc(), this with dsPuts().");
dyOutPrintf("14     3:%d Last line!  Expect 7 & 12 missing, 10 dupped.  lenAll:%d  Bye.\n",
         dyOutStackDepth(),dyOutSizeAll());
dyOutFlushAndCloseAll();
assert(dyOutStack == NULL);
int ix = 0;
for (;ix<20;ix++) // tested to 1000
    {
    dyOutOpen(32); // Don't even care about tokens!
    if (ix == 0)
        dyOutPrintf("CannibalizeAndCloseAll():");
    dyOutPrintf(" %d",dyOutStackDepth());
    }
content = dyOutCannibalizeAndCloseAll();
printf("\n[%s]\n",content);
freez(&content);
}
コード例 #2
0
ファイル: errabort.c プロジェクト: JimKent/linearSat
void warnWithBackTrace(char *format, ...)
/* Issue a warning message and append backtrace. */
{
va_list args;
va_start(args, format);
struct dyString *dy = newDyString(255);
dyStringAppend(dy, format);

#define STACK_LIMIT 20
char **strings = NULL;
int count = 0;

// developer: this is an occasionally useful means of getting stack info without crashing
// however, it is not supported on cygwin.  Conditionally compile this in when desired.
// The define is at top to include execinfo.h
#ifdef BACKTRACE_EXISTS
void *buffer[STACK_LIMIT];
count = backtrace(buffer, STACK_LIMIT);
strings = backtrace_symbols(buffer, count);
#endif///def BACKTRACE_EXISTS

if (strings == NULL)
    dyStringAppend(dy,"\nno backtrace_symbols available in errabort::warnWithBackTrace().");
else
    {
    int ix = 1;
    dyStringAppend(dy,"\nBACKTRACE (use on cmdLine):");
    if (strings[1] != NULL)
        {
        strSwapChar(strings[1],' ','\0');
        dyStringPrintf(dy,"\naddr2line -Cfise %s",strings[1]);
        strings[1] += strlen(strings[1]) + 1;
        }
    for (; ix < count && strings[ix] != NULL; ix++)
        {
        strings[ix] = skipBeyondDelimit(strings[ix],'[');
        strSwapChar(strings[ix],']','\0');
        dyStringPrintf(dy," %s",strings[ix]);
        }

    free(strings);
    }
vaWarn(dyStringCannibalize(&dy), args);
va_end(args);
}
コード例 #3
0
int trackHubCrawl(char *hubUrl)
/* Crawl a track data hub and output strings useful in a search */
{
struct errCatch *errCatch = errCatchNew();
struct trackHub *hub = NULL;
int retVal = 0;

if (errCatchStart(errCatch))
    {
    hub = trackHubOpen(hubUrl, "hub_0");
    }
errCatchEnd(errCatch);
if (errCatch->gotError)
    {
    retVal = 1;
    fprintf(stderr, "%s\n", errCatch->message->string);
    }
errCatchFree(&errCatch);

if (hub == NULL)
    return 1;

FILE *searchFp =stdout;
struct trackHubGenome *genomeList = hub->genomeList;

for(; genomeList ; genomeList = genomeList->next)
    fprintf(searchFp, "%s\t%s\n",hub->url,  trackHubSkipHubName(genomeList->name));
fprintf(searchFp, "%s\t%s\t%s\n",hub->url, hub->shortLabel, hub->longLabel);

if (hub->descriptionUrl != NULL)
    {
    char *html = netReadTextFileIfExists(hub->descriptionUrl);
    char *stripHtml =htmlTextStripTags(html);
    strSwapChar(stripHtml, '\n', ' ');
    strSwapChar(stripHtml, '\t', ' ');
    strSwapChar(stripHtml, '\015', ' ');
    strSwapChar(stripHtml, ')', ' ');
    strSwapChar(stripHtml, '(', ' ');
    strSwapChar(stripHtml, '[', ' ');
    strSwapChar(stripHtml, ']', ' ');
    fprintf(searchFp, "%s\t%s\n",hub->url,  stripHtml);
    }

trackHubClose(&hub);
return retVal;
}
コード例 #4
0
ファイル: search.c プロジェクト: davidhoover/kent
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.
{
if (tdb->html == NULL)
    return (wordList != NULL);

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;
}
コード例 #5
0
int documentLink(struct hash *ra, char *term, char *docTerm,char *dir,
                 char *title,boolean genericDoc)
// Compare controlled vocab based on term value
{
boolean docsPrinted = 0;
char *s;
if (title == NULL)
    title = docTerm;

//can use hg.conf to direct links back to main UCSC server if a mirror doesn't
//want all the PDFs
char *baseUrl = cfgOptionDefault("hgEncodeVocabDocBaseUrl", "");
// add links to protocol doc if it exists
char docUrl[PATH_LEN];
char docFile[PATH_LEN];
// parse setting
s = hashFindVal(ra,docTerm);
if (s != NULL)
    {
    if (sameWord(s,"missing"))
        printf("&nbsp;<em>missing</em>\n");
    else
        {
        char *docSetting = cloneString(s);
        char *settings=docSetting;
        int count=0;
        while ((s = nextWord(&settings)) != NULL)
            {
            char *docTitle = NULL;
            char *fileName = NULL;
            if (strchr(s,':')) // lab Specific setting
                {
                docTitle = strSwapChar(s,':',0);
                fileName = docTitle + strlen(docTitle) + 1;
                }
            else
                {
                docTitle = title;
                fileName = s;
                }
            if (count>0)
                printf("<BR>");
            count++;
            docTitle = htmlEncode(strSwapChar(docTitle,'_',' '));
            if (sameWord(fileName,"missing"))
                printf("%s<em>missing</em>\n",docTitle);
            else
                {
                safef(docUrl,  sizeof(docUrl),  "%s%s%s", baseUrl, dir, fileName);
                safef(docFile, sizeof(docFile), "%s%s", hDocumentRoot(), docUrl);
                printf(" <A TARGET=_BLANK HREF=%s>%s</A>\n", docUrl,docTitle);
                docsPrinted++;
                }
            freeMem(docTitle);
            }
        freeMem(docSetting);
        }
    }
else if (genericDoc)
    { // generate a standard name
    safef(docUrl,  sizeof(docUrl),  "%s%s%s_protocol.pdf", baseUrl, dir, term);
    safef(docFile, sizeof(docFile), "%s%s", hDocumentRoot(), docUrl);
    if (fileExists(docFile))
        {
        printf(" <A TARGET=_BLANK HREF=%s>%s</A>\n", docUrl,title);
        docsPrinted++;
        }
    }
return docsPrinted;
}
コード例 #6
0
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;
}