示例#1
0
boolean maybeTouchFile(char *fileName)
/* If file exists, set its access and mod times to now.  If it doesn't exist, create it.
 * Return FALSE if we have a problem doing so (e.g. when qateam is gdb'ing and code tries 
 * to touch some file owned by www). */
{
if (fileExists(fileName))
    {
    struct utimbuf ut;
    ut.actime = ut.modtime = clock1();
    int ret = utime(fileName, &ut);
    if (ret != 0)
	{
	warn("utime(%s) failed (ownership?)", fileName);
	return FALSE;
	}
    }
else
    {
    FILE *f = fopen(fileName, "w");
    if (f == NULL)
	return FALSE;
    else
	carefulClose(&f);
    }
return TRUE;
}
示例#2
0
文件: clock.cpp 项目: eas/SoftLab
int main()
{
	{ // code block, need it to testing memory leaks
		ClockMessageSystem messageSystem;
		Clock clock1(messageSystem, 200);
		Clock clock2(messageSystem, 700);
		{
			Clock clock3(messageSystem, 900);
			clock3.Post(mds::Message(0, new char(0)), 0);
		}
		clock1.Post(mds::Message(0, NULL), 0);
		clock2.Post(mds::Message(0, NULL), 0);
		messageSystem.Loop();
		//messageSystem.ClearQueue();
	}
	{
		ClockMessageSystem messageSystem;
		TestSend testSend1(messageSystem);
		TestSend testSend2(messageSystem);
		testSend1.Post(mds::Message(0, NULL), 100);
		testSend2.Post(mds::Message(0, NULL), 300);
		messageSystem.Loop();
	}
	_CrtDumpMemoryLeaks();
	return 0;
}
示例#3
0
int getkey (int interval)
{
    int     message;
    double  rem, target;

    // prevent strange behaviour due to programmer mistakes
    if (interval < 0) interval = -1;
        
    switch (interval)
    {
    case -1:
        while (1)
        {
            message = getmessage (-1);
            if (IS_KEY (message) && message > 0) break;
        }
        break;

    case 0:
        while (TRUE)
        {
            message = getmessage (0);
            if (message == 0) break;
            if (IS_KEY (message)) break;
        }
        break;

    default:
        target = clock1 () + ((double)interval)/1000.;
        message = -1;
        while (TRUE)
        {
            rem = target - clock1();
            if (rem <= 0.) break;
            message = getmessage ((int)(rem*1000.));
            if (IS_KEY(message) && message > 0) break;
        }
    }
    
    return message;
}
示例#4
0
struct slName *getTableNames(struct sqlConnection *conn)
/* Return a list of names of tables that have not been excluded by 
 * command line options. */
{
char *query = hoursOld ? "NOSQLINJ show table status" : "NOSQLINJ show tables";
struct sqlResult *sr = sqlGetResult(conn, query);
struct slName *tableList = NULL;
char **row = NULL;
int startTime = clock1();
int ageThresh = hoursOld * 3600;

while((row = sqlNextRow(sr)) != NULL)
    {
    struct slName *tableName = NULL;
    struct slName *pat = NULL;
    boolean gotMatch = FALSE;
    if (hoursOld)
	{
	if (row[11] != NULL)
	    {
	    int tableUpdateTime = sqlDateToUnixTime(row[11]);
	    int ageInSeconds = startTime - tableUpdateTime;
	    if (ageInSeconds > ageThresh)
		continue;
	    }
	else
	    {
	    verbose(2,
		    "Got NULL update time for table %s.%s with hoursOld=%d\n",
		    sqlGetDatabase(conn), row[0], hoursOld);
	    }
	}
    for (pat = excludePatterns;  pat != NULL;  pat=pat->next)
	{
	if (wildMatch(pat->name, row[0]))
	    {
	    gotMatch = TRUE;
	    break;
	    }
	}
    if (gotMatch)
	continue;
    if (verboseLevel() >= 3 || justList)
	fprintf(stderr, "Adding %s\n", row[0]);
    tableName = newSlName(row[0]);
    slAddHead(&tableList, tableName);
    }
sqlFreeResult(&sr);
if (justList)
    exit(0);
slReverse(&tableList);
return tableList;
}
int main(int argc, char *argv[])
{
char *genoListName;
char *otherListName;
char *oocFileName;
char *typeName;
char *outName;
struct patSpace *patSpace;
long startTime, endTime;
char **genoList;
int genoListSize;
char *genoListBuf;
char **otherList;
int otherListSize;
char *otherListBuf;
char *genoName;
int i;
int blockCount = 0;
struct dnaSeq **seqListList = NULL, *seq = NULL;
char *outRoot;
struct sqlConnection *conn;
enum ffStringency stringency = ffCdna;
int seedSize = 10;
FILE *out;
boolean noHead = FALSE;
struct repeatTracker *rt;
struct hash *repeatHash = newHash(10);

hostName = getenv("HOST");
pushWarnHandler(warnHandler);

startTime = clock1();
cgiSpoof(&argc, argv);
minMatch = cgiOptionalInt("minMatch", minMatch);
maxBad = cgiOptionalInt("maxBad", maxBad);
minBases = cgiOptionalInt("minBases", minBases);

dnaUtilOpen();

#ifdef DEBUG
/* Hard wire command line input so don't have to type it in each 
 * time run the stupid Gnu debugger. */

genoListName = "pFoo/geno.lst";
otherListName = "pFoo/bacend.lst";
typeName = "genomic";
oocFileName = "/d/biodata/human/10.ooc";
outName = "pFoo/pFoo.psl";

#else

if (argc != 6 && argc != 7)
    usage();

genoListName = argv[1];
otherListName = argv[2];
typeName = argv[3];
oocFileName = argv[4];
if (sameWord(oocFileName, "none"))
    oocFileName = NULL;
outName = argv[5];
if (argc == 7)
    {
    if (sameWord("noHead", argv[6]))
	noHead = TRUE;
    else
	usage();
    }

#endif 

if (sameWord(typeName, "mRNA") || sameWord(typeName, "cDNA"))
    {
    stringency = ffCdna;
    }
else if (sameWord(typeName, "genomic"))
    {
    stringency = ffTight;
    }
else if (sameWord(typeName, "g2g"))
    {
    stringency = ffTight;
    veryTight = TRUE;
    seedSize = 11;
    }
else if (sameString(typeName, "asm"))
    {
    stringency = ffTight;
    avoidSelfSelf = TRUE;
    }
else
    {
    warn("Unrecognized otherType %s\n", typeName);
    usage();
    }

readAllWordsOrFa(genoListName, &genoList, &genoListSize, &genoListBuf);
filterMissingFiles(genoList, &genoListSize);
if (genoListSize <= 0)
    errAbort("There are no files that exist in %s\n", genoListName);
readAllWordsOrFa(otherListName, &otherList, &otherListSize, &otherListBuf);
if (otherListSize <= 0)
    errAbort("There are no files that exist in %s\n", otherListName);
filterMissingFiles(otherList, &otherListSize);
out = mustOpen(outName, "w");
if (!noHead)
    pslWriteHead(out);

AllocArray(seqListList, genoListSize);
for (i=0; i<genoListSize; ++i)
    {
    genoName = genoList[i];
    if (!startsWith("#", genoName)  )
        seqListList[i] = seq = faReadAllDna(genoName);
    for (;seq != NULL; seq = seq->next)
	{
	int size = seq->size;
	char *name = seq->name;
	struct hashEl *hel;
	AllocVar(rt);
	AllocArray(rt->repBytes, size);
	rt->seq = seq;
	if ((hel = hashLookup(repeatHash, name)) != NULL)
	    errAbort("Duplicate %s in %s\n", name, genoName);
	hashAdd(repeatHash, name, rt);
	}
    storeMasked(repeatHash, genoName);
    }

patSpace = makePatSpace(seqListList, genoListSize, seedSize, oocFileName, minMatch, 2000);
endTime = clock1();
printf("Made index in %ld seconds\n",  (endTime-startTime));
startTime = endTime;

for (i=0; i<otherListSize; ++i)
    {
    FILE *f;
    char *otherName;
    int c;
    int dotCount = 0;
    struct dnaSeq otherSeq;
    ZeroVar(&otherSeq);

    otherName = otherList[i];
    if (startsWith("#", otherName)  )
	continue;
    f = mustOpen(otherName, "r");
    while ((c = fgetc(f)) != EOF)
	if (c == '>')
	    break;
    printf("%s\n", otherName);
    fflush(stdout);
    while (faFastReadNext(f, &otherSeq.dna, &otherSeq.size, &otherSeq.name))
        {
	aliSeqName = otherSeq.name;
	oneStrand(patSpace, repeatHash, &otherSeq, FALSE, stringency, out);
	reverseComplement(otherSeq.dna, otherSeq.size);
	oneStrand(patSpace, repeatHash, &otherSeq, TRUE, stringency, out);
	aliSeqName = NULL;
        }
    fclose(f);
    }
freePatSpace(&patSpace);
endTime = clock1();
printf("Alignment time is %ld sec\n", (endTime-startTime));
startTime = endTime;
fclose(out);
return 0;
}
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&nbsp;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&nbsp;</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&nbsp;</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&nbsp;</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();
}
示例#7
0
int main (int argc, char *argv[])
{
    int res;
    char **list, buffer[8192];
    double t1;
    fastlist_t *fl;
   /* fast_catlist_t *cl; */

    if (argc != 2) error1 ("usage: %s exclude-file\n", argv[0]);

    warning1 ("reading ruleset\n");
    list = read_list (argv[1]);
    if (list == NULL) error1 ("failed to load pattern list from %s\n", argv[1]);

    fl = prepare_fastlist (list);
    /*
    printf ("shortest simple rule: %d\n", fl->shortest);
    for (i=0; i<fl->n_simple; i++)
    {
        printf ("%d %d %s\n",
                fl->rules[fl->simple[i]].type,
                fl->rules[fl->simple[i]].category,
                fl->rules[fl->simple[i]].rule);
    }
    */
    /*
    for (i=0; i<fl->n; i++)
    {
        printf ("%d %d %s\n", fl->rules[i].type, fl->rules[i].category,
                fl->rules[i].rule);
                }
                */
   /* for (i=0; i<fl->n_simple; i++) printf ("SIMPLE: %s\n", fl->simple[i]); */
   /* for (i=0; i<fl->n_complex; i++) printf ("COMPLEX: %s\n", fl->complex[i]); */

   /* cl = prepare_catlist (list); */
    /*
    for (i=0; i<cl->n_simple; i++)
        printf ("SIMPLE: %d.%s\n", cl->simple[i].category, cl->simple[i].rule);
    for (i=0; i<cl->n_coll; i++)
    {
        printf ("COMPLEX: %d (%d rules)\n",
                cl->colls[i].coll_id, cl->colls[i].nrules);
        for (j=0; j<cl->colls[i].nrules; j++)
        {
            printf ("  %s\n", cl->colls[i].rules[j]);
        }
    }
    */
    /*
    printf ("slow:\n");
    t1 = clock1 ();
    res = check_list (list, argv[2]);
    t1 = clock1 () - t1;

    if (res)
        printf ("%s is included (%.3f sec)\n", argv[2], t1);
    else
        printf ("%s is excluded (%.3f sec)\n", argv[2], t1);
        */

    while ((fgets (buffer, sizeof(buffer), stdin) != NULL))
    {
        str_strip (buffer, " \r\n");
        if (normalize_url2 (buffer) < 0)
        {
            printf ("bad url: %s\n", buffer);
            continue;
        }
        t1 = clock1 ();
        res = check_fastlist (fl, buffer);
        t1 = clock1 () - t1;

        if (res)
            printf ("%s is included (%.3f sec)\n", buffer, t1);
        else
            printf ("%s is excluded (%.3f sec)\n", buffer, t1);
    }

    return 0;
}
示例#8
0
文件: web.c 项目: elmargb/kentUtils
static void phoneHome()
{
static boolean beenHere = FALSE;
if (beenHere)  /* one at a time please */
    return;
beenHere = TRUE;

char *expireTime = cfgOptionDefault("browser.cgiExpireMinutes", "20");
unsigned expireMinutes = sqlUnsigned(expireTime);
expireSeconds = expireMinutes * 60;

char trashFile[PATH_LEN];
safef(trashFile, sizeof(trashFile), "%s/registration.txt", trashDir());

/* trashFile does not exist during command line execution */
if(fileExists(trashFile))	/* update access time for trashFile */
    {
    struct utimbuf ut;
    struct stat mystat;
    ZeroVar(&mystat);
    if (stat(trashFile,&mystat)==0)
	{
	ut.actime = clock1();
	ut.modtime = mystat.st_mtime;
	}
    else
	{
	ut.actime = ut.modtime = clock1();
	}
    (void) utime(trashFile, &ut);
    if (expireSeconds > 0)
	{
	(void) signal(SIGALRM, cgiApoptosis);
	(void) alarm(expireSeconds);	/* CGI timeout */
	}
    return;
    }

char *scriptName = cgiScriptName();
char *ip = getenv("SERVER_ADDR");
if (scriptName && ip)  /* will not be true from command line execution */
    {
    FILE *f = fopen(trashFile, "w");
    if (f)		/* rigamarole only if we can get a trash file */
	{
	time_t now = time(NULL);
	char *localTime;
	extern char *tzname[2];
	struct tm *tm = localtime(&now);
	localTime = sqlUnixTimeToDate(&now,FALSE); /* FALSE == localtime */
	fprintf(f, "%s, %s, %s %s, %s\n", scriptName, ip, localTime,
	    tm->tm_isdst ? tzname[1] : tzname[0], trashFile);
	fclose(f);
	chmod(trashFile, 0666);
	pid_t pid0 = fork();
	if (0 == pid0)	/* in child */
	    {
	    close(STDOUT_FILENO); /* do not hang up Apache finish for parent */
	    expireSeconds = 0;	/* no error message from this exit */
	    (void) signal(SIGALRM, cgiApoptosis);
	    (void) alarm(6);	/* timeout here in 6 seconds */
#include "versionInfo.h"
	    char url[1024];
	    safef(url, sizeof(url), "%s%s%s%s%s%s", "http://",
	"genomewiki.", "ucsc.edu/", "cgi-bin/useCount?", "version=browser.v",
		CGI_VERSION);

	    /* 6 second alarm will exit this page fetch if it does not work */
	    (void) htmlPageGetWithCookies(url, NULL); /* ignore return */

	    exit(0);
	    }	/* child of fork has done exit(0) normally or via alarm */
	}		/* trash file open OK */
    if (expireSeconds > 0)
	{
	(void) signal(SIGALRM, cgiApoptosis);
	(void) alarm(expireSeconds);	/* CGI timeout */
	}
    }			/* an actual CGI binary */
}			/* phoneHome()	*/
示例#9
0
int
    sc_main(int argc, char *argv[])
{
    sc_signal<pkt> pkt_in0;
    sc_signal<pkt> pkt_in1;
    sc_signal<pkt> pkt_in2;
    sc_signal<pkt> pkt_in3;
    sc_signal<pkt> pkt_out0;
    sc_signal<pkt> pkt_out1;
    sc_signal<pkt> pkt_out2;
    sc_signal<pkt> pkt_out3;

    sc_signal<sc_int<4> > id0, id1, id2, id3;

    sc_signal<bool> switch_cntrl;

    sc_clock clock1("CLOCK1", 75, SC_NS, 0.5, 0.0, SC_NS);
    sc_clock clock2("CLOCK2", 30, SC_NS, 0.5, 10.0, SC_NS);

    // Module instiatiations follow
    // Note that modules can be connected by hooking up ports 
    // to signals by name or by using a positional notation

    sender sender0("SENDER0");
    // hooking up signals to ports by name
    sender0.pkt_out(pkt_in0);
    sender0.source_id(id0);
    sender0.CLK(clock1);

    sender sender1("SENDER1");
    // hooking up signals to ports by position
    sender1(pkt_in1, id1, clock1);

    sender sender2("SENDER2");
    // hooking up signals to ports by name
    sender2.pkt_out(pkt_in2);
    sender2.source_id(id2);
    sender2.CLK(clock1);

    sender sender3("SENDER3");
    // hooking up signals to ports by position
    sender3( pkt_in3, id3, clock1 );

    switch_clk switch_clk1("SWITCH_CLK");
    // hooking up signals to ports by name
    switch_clk1.switch_cntrl(switch_cntrl);
    switch_clk1.CLK(clock2);

    mcast_pkt_switch switch1("SWITCH");
    // hooking up signals to ports by name
    switch1.switch_cntrl(switch_cntrl);
    switch1.in0(pkt_in0);
    switch1.in1(pkt_in1);
    switch1.in2(pkt_in2);
    switch1.in3(pkt_in3);
    switch1.out0(pkt_out0);
    switch1.out1(pkt_out1);
    switch1.out2(pkt_out2);
    switch1.out3(pkt_out3);

    receiver receiver0("RECEIVER0");
    // hooking up signals to ports by name  
    receiver0.pkt_in(pkt_out0);
    receiver0.sink_id(id0);

    receiver receiver1("RECEIVER1");
    // hooking up signals to ports by position
    receiver1( pkt_out1, id1 );

    receiver receiver2("RECEIVER2");
    // hooking up signals to ports by name
    receiver2.pkt_in(pkt_out2);
    receiver2.sink_id(id2);

    receiver receiver3("RECEIVER3");
    // hooking up signals to ports by position
    receiver3( pkt_out3, id3 );

    sc_start(0, SC_NS);

#if !defined(__SUNPRO_CC)
    id0.write(0); 
    id1.write(1);
    id2.write(2);
    id3.write(3);
#else
    // you cannot do that with SC5.0
    // since it doesn't support member templates
    id0.write(sc_int<4>(0));
    id0.write(sc_int<4>(1));
    id0.write(sc_int<4>(2));
    id0.write(sc_int<4>(3));
#endif
    sc_start();
    return 0;

}
示例#10
0
void doSearchTracks(struct group *groupList)
{
webIncludeResourceFile("ui.dropdownchecklist.css");
jsIncludeFile("ui.dropdownchecklist.js",NULL);
// This line is needed to get the multi-selects initialized
jsIncludeFile("ddcl.js",NULL);

struct group *group;
char *groups[128];
char *labels[128];
int numGroups = 1;
groups[0] = ANYLABEL;
labels[0] = ANYLABEL;
char *nameSearch  = cartOptionalString(cart, TRACK_SEARCH_ON_NAME);
char *typeSearch  = cartUsualString(   cart, TRACK_SEARCH_ON_TYPE,ANYLABEL);
char *simpleEntry = cartOptionalString(cart, TRACK_SEARCH_SIMPLE);
char *descSearch  = cartOptionalString(cart, TRACK_SEARCH_ON_DESCR);
char *groupSearch = cartUsualString(  cart, TRACK_SEARCH_ON_GROUP,ANYLABEL);
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 tracksFound = 0;
boolean searchTermsExist = FALSE;
int cols;
char buf[512];

char *currentTab = cartUsualString(cart, TRACK_SEARCH_CURRENT_TAB, "simpleTab");
enum searchTab selectedTab = (sameString(currentTab, "advancedTab") ? advancedTab : simpleTab);

// NOTE: could support quotes in simple tab by detecting quotes and choosing
//       to use doesNameMatch() || doesDescriptionMatch()
if (selectedTab == simpleTab && !isEmpty(simpleEntry))
    stripChar(simpleEntry, '"');
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.

// Subtrack settings must be removed when composite/view settings are updated
parentChildCartCleanup(trackList,cart,oldVars);

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 id='simpleTable' 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='findTracks.searchButtonsEnable(true);'>\n",
        TRACK_SEARCH_SIMPLE,simpleEntry == NULL ? "" : simpleEntry);
if (selectedTab==simpleTab && simpleEntry)
    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='findTracks.clear();'>\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 id='advancedTable' 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&nbsp;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='findTracks.searchButtonsEnable(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&nbsp;</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='findTracks.searchButtonsEnable(true);' "
        "style='max-width:536px; width:536px; font-size:.9em;'>",
        TRACK_SEARCH_ON_DESCR, descSearch == NULL ? "" : descSearch);
hPrintf("</td></tr>\n");
if (selectedTab==advancedTab && !isEmpty(descSearch))
    searchTermsExist = TRUE;

hPrintf("<tr><td colspan=2></td><td align='right'>and&nbsp;</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 (selectedTab==advancedTab && !isEmpty(groupSearch) && !sameString(groupSearch,ANYLABEL))
    searchTermsExist = TRUE;

// Track Type is (drop down)
hPrintf("<tr><td colspan=2></td><td align='right'>and&nbsp;</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 (selectedTab==advancedTab && !isEmpty(typeSearch) && !sameString(typeSearch,ANYLABEL))
    searchTermsExist = TRUE;

// mdb selects
struct slPair *mdbSelects = NULL;
if (metaDbExists)
    {
    struct slPair *mdbVars = mdbVarsSearchable(conn,TRUE,FALSE); // Tables but not file only objects
    mdbSelects = mdbSelectPairs(cart, mdbVars);
    char *output = mdbSelectsHtmlRows(conn,mdbSelects,mdbVars,cols,FALSE);  // not a fileSearch
    if (output)
        {
        puts(output);
        freeMem(output);
        }
    slPairFreeList(&mdbVars);
    }

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='findTracks.clear();'>\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");

hPrintf("</div>\n");

hPrintf("</form>\n");
hPrintf("</div>"); // Restricts to max-width:1000px;
cgiDown(0.8);

if (measureTiming)
    measureTime("Rendered tabs");

if (doSearch)
    {
    // Now search
    struct slRef *tracks = NULL;
    if (selectedTab==simpleTab && !isEmpty(simpleEntry))
        tracks = simpleSearchForTracksstruct(simpleEntry);
    else if (selectedTab==advancedTab)
        tracks = advancedSearchForTracks(conn,groupList,nameSearch,typeSearch,descSearch,
                                         groupSearch,mdbSelects);

    if (measureTiming)
        measureTime("Searched for tracks");

    // Sort and Print results
    if (selectedTab!=filesTab)
        {
        enum sortBy sortBy = cartUsualInt(cart,TRACK_SEARCH_SORT,sbRelevance);
        tracksFound = slCount(tracks);
        if (tracksFound > 1)
            findTracksSort(&tracks,sortBy);

        displayFoundTracks(cart,tracks,tracksFound,sortBy);

        if (measureTiming)
            measureTime("Displayed found tracks");
        }
    slPairFreeList(&mdbSelects);
    }
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();
}
示例#11
0
/* connect to IPv4 address/port */
int ConnectIP (unsigned long IP, int port)
{
    struct  sockaddr_in conn;
    int     s, rc;
    int     rc1;
    struct  timeval timeout;
    fd_set  wrfds;
    double  target;
#if defined(__MINGW32__)
    unsigned long blk;
#endif    

    /* create socket */
    s = socket (AF_INET, SOCK_STREAM, 0);
    if (s < 0)
    {
        /* warning1 ("cannot create socket\n"); */
        return -2;
    }
    
    memset (&conn, 0, sizeof (conn));
    conn.sin_family = AF_INET;
    conn.sin_port = htons (port);
    conn.sin_addr.s_addr = IP;

    /* set nonblocking mode */
#if !defined(__MINGW32__)
    fcntl (s, F_SETFL, O_NONBLOCK);
#else
    blk = 1;
    ioctlsocket (s, FIONBIO, &blk);
#endif
    rc = connect (s, (struct sockaddr *)&conn, sizeof (struct sockaddr_in));

    if (rc < 0)
    {
        if (errno != EINPROGRESS && errno != EAGAIN)
        {
            Close (s);
            return -3;
        }

        target = clock1 () + timelimit;
        do
        {
            timeout.tv_sec = 0;
            timeout.tv_usec = 100000;
            errno = 0;
            FD_ZERO (&wrfds);
            FD_SET (s, &wrfds);
            rc1 = select (FD_SETSIZE, NULL, &wrfds, NULL, &timeout);
            if (rc1 == 1)
            {
#if !defined(__MINGW32__)
                int rc2;
                /* see if we really got a connection */
                rc2 = connect (s, (struct sockaddr *)&conn, sizeof (struct sockaddr_in));
                if (rc2 < 0 && errno == EISCONN) goto success; /* good! */
                if (rc2 == 0) goto success; /* good for OpenBSD? */
                if (rc2 < 0 && errno != EAGAIN)
                {
                    Close (s);
                    return -3;
                }
#else
                goto success;
#endif
            }
            if (rc1 < 0 && errno == EINTR) continue; /* suspended */
        }
        while (clock1() < target);
        Close (s);
        return -4;
    }

success:
    /* reset nonblocking mode */
#if !defined(__MINGW32__)
    fcntl (s, F_SETFL, 0);
#else
    blk = 0;
    ioctlsocket (s, FIONBIO, &blk);
#endif

    return s;
}