예제 #1
0
struct slName *listDirRegEx(char *dir, char *regEx, int flags)
/* Return an alphabetized list of all files that match 
 * the regular expression pattern in directory.
 * See REGCOMP(3) for flags (e.g. REG_ICASE)  */
{
struct slName *list = NULL, *name;
struct dirent *de;
DIR *d;
regex_t re;
int err = regcomp(&re, regEx, flags | REG_NOSUB);
if(err)
    errAbort("regcomp failed; err: %d", err);

if ((d = opendir(dir)) == NULL)
    return NULL;
while ((de = readdir(d)) != NULL)
    {
    char *fileName = de->d_name;
    if (differentString(fileName, ".") && differentString(fileName, ".."))
	{
	if (!regexec(&re, fileName, 0, NULL, 0))
	    {
	    name = newSlName(fileName);
	    slAddHead(&list, name);
	    }
	}
    }
closedir(d);
regfree(&re);
slNameSort(&list);
return list;
}
예제 #2
0
struct slName *listDir(char *dir, char *pattern)
/* Return an alphabetized list of all files that match 
 * the wildcard pattern in directory. */
{
struct slName *list = NULL, *name;
struct dirent *de;
DIR *d;

if ((d = opendir(dir)) == NULL)
    return NULL;
while ((de = readdir(d)) != NULL)
    {
    char *fileName = de->d_name;
    if (differentString(fileName, ".") && differentString(fileName, ".."))
	{
	if (pattern == NULL || wildMatch(pattern, fileName))
	    {
	    name = newSlName(fileName);
	    slAddHead(&list, name);
	    }
	}
    }
closedir(d);
slNameSort(&list);
return list;
}
void writeHashToFile(struct hash *countHash, char *outputFile)
/* Make an slPair list out of a hashEl list, sort it, output it. */
{
FILE *f = mustOpen(outputFile, "w");
struct hashEl *el, *list = hashElListHash(countHash);
slNameSort((struct slName **)&list);
for (el = list; el != NULL; el = el->next)
    fprintf(f, "%s\t%d\n", el->name, ptToInt(el->val));
carefulClose(&f);
hashElFreeList(&list);
}
struct slName *hashToList(struct hash *wordHash)
/* convert the hash back to a list. */
{
struct hashEl *elList = hashElListHash(wordHash);
struct slName *list = NULL;
struct hashEl *cur;
for (cur = elList; cur != NULL; cur = cur->next)
    slNameAddHead(&list, cur->name);
slNameSort(&list);
hashElFreeList(&elList);
return list;
}
예제 #5
0
struct slName *lsSnpPdbChimeraGetSnpPdbs(struct sqlConnection *conn,
                                         char *snpId)
/* get list of PDBs to which snpId is mapped.  */
{
if (!sqlTableExists(conn, "lsSnpPdb"))
    return NULL;
char query[256];
sqlSafef(query, sizeof(query), "SELECT distinct pdbId FROM lsSnpPdb WHERE (snpId = \"%s\")",
      snpId);
struct slName *pdbIds = sqlQuickList(conn, query);
slNameSort(&pdbIds);
return pdbIds;
}
예제 #6
0
struct slName *cartTrackDbTablesForTrack(char *db, struct trackDb *track, boolean useJoiner)
/* Return list of all tables associated with track.  If useJoiner, the result can include
 * non-positional tables that are related to track by all.joiner. */
{
static struct joiner *allJoiner = NULL;
struct hash *uniqHash = newHash(8);
struct slName *name, *nameList = NULL;
char *trackTable = track->table;

hashAdd(uniqHash, trackTable, NULL);
if (useJoiner)
    {
    if (allJoiner == NULL)
        allJoiner = joinerRead("all.joiner");
    struct joinerPair *jpList, *jp;
    jpList = joinerRelate(allJoiner, db, trackTable);
    for (jp = jpList; jp != NULL; jp = jp->next)
	{
	struct joinerDtf *dtf = jp->b;
	if (cartTrackDbIsAccessDenied(dtf->database, dtf->table))
	    continue;
	char buf[256];
	char *s;
	if (sameString(dtf->database, db))
	    s = dtf->table;
	else
	    {
	    safef(buf, sizeof(buf), "%s.%s", dtf->database, dtf->table);
	    s = buf;
	    }
	if (!hashLookup(uniqHash, s))
	    {
	    hashAdd(uniqHash, s, NULL);
	    name = slNameNew(s);
	    slAddHead(&nameList, name);
	    }
	}
    slNameSort(&nameList);
    }
/* suppress for parent tracks -- only the subtracks have tables */
if (track->subtracks == NULL)
    {
    name = slNameNew(trackTable);
    slAddHead(&nameList, name);
    }
addTablesAccordingToTrackType(db, &nameList, uniqHash, track);
hashFree(&uniqHash);
return nameList;
}
예제 #7
0
파일: pslSets.c 프로젝트: blumroy/kentUtils
struct slName *pslSetsQueryNames(struct pslSets *ps)
/* get list of all query names in all tables. slFree when done */
{
struct slName *qNames = NULL;
struct hash *qNameHash = hashNew(21);
int iSet;
struct hashCookie hc;
struct hashEl *hel;

for (iSet = 0; iSet < ps->numSets; iSet++)
    addQueryNames(qNameHash, ps->sets[iSet]);

/* copy to a list */
hc = hashFirst(qNameHash);
while ((hel = hashNext(&hc)) != NULL)
    slSafeAddHead(&qNames, slNameNew(hel->name));
hashFree(&qNameHash);
slNameSort(&qNames);
return qNames;
}
예제 #8
0
void dropDownAdvFilterControls(struct column *col, struct sqlConnection *conn)
/* Print out controls for dropdown list filter. */
{
struct sqlResult *sr;
char **row;
char query[256];
struct slName *list=NULL, *el;

sqlSafef(query, sizeof(query),
    "select distinct %s from gisaidSubjInfo", col->name);
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
    {
    char *val = row[0];
    if (col->remap)
    	val = hashFindVal(col->remap,val);
    slNameAddHead(&list, val);
    }
sqlFreeResult(&sr);

slNameSort(&list);

hPrintf("choose: ");
hPrintf("<SELECT NAME=\"%s\"", "countVarName");
hPrintf(">\n");
hPrintf("<OPTION VALUE=\"\">");

for (el = list; el; el = el->next)
    {
    hPrintf("<OPTION VALUE=\"%s\"", el->name);
    if (sameString(el->name, "displayCountString"))
	hPrintf(" SELECTED");
    hPrintf(">%s\n", el->name);
    }

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

slFreeList(&list);

}
예제 #9
0
파일: oswin9x.c 프로젝트: JinfengChen/pblat
struct slName *listDir(char *dir, char *pattern)
/* Return an alphabetized list of all files that match 
 * the wildcard pattern in directory. */
{
long hFile;
struct _finddata_t fileInfo;
struct slName *list = NULL, *name;
boolean otherDir = FALSE;
char *currentDir;

if (dir == NULL || sameString(".", dir) || sameString("", dir))
    dir = "";
else
    {
    currentDir = getCurrentDir();
    setCurrentDir(dir);
    otherDir = TRUE;
    }

if (pattern == NULL)
    pattern = *;
if( (hFile = _findfirst( pattern, &fileInfo)) == -1L )
    return NULL;

do
    {
    if (!sameString(".", fileInfo.name) && !sameString("..", fileInfo.name))
        {
        name = newSlName(fileInfo.name);
        slAddHead(&list, name);
        }
    }
while( _findnext( hFile, &fileInfo) == 0 );
_findclose( hFile );
if (otherDir)
    setCurrentDir(currentDir);
slNameSort(&list);
return list;
}
예제 #10
0
struct slName *valsForVar(char *varName, struct taggedFile *tfList)
/* Return all values for given variable. */
{
struct slName *list = NULL;
struct hash *uniqHash = hashNew(7);
struct taggedFile *tf;
for (tf = tfList; tf != NULL; tf = tf->next)
    {
    char *val = metaTagValFindVal(tf->tagList, varName);
    if (val != NULL)
        {
	if (hashLookup(uniqHash, val) == NULL)
	    {
	    hashAdd(uniqHash, val, NULL);
	    slNameAddHead(&list, val);
	    }
        }
    }
hashFree(&uniqHash);
slNameSort(&list);
return list;
}
void statsOnSubsets(struct nearTest *list, int subIx, FILE *f)
/* Report tests of certain subtype. */
{
struct nearTest *test;
struct hash *hash = newHash(0);
struct slName *typeList = NULL, *type;

fprintf(f, "\n%s subtotals\n", nearTestInfoTypes[subIx]);

/* Get list of all types in this field. */
for (test = list; test != NULL; test = test->next)
    {
    char *info = test->info[subIx];
    if (!hashLookup(hash, info))
       {
       type = slNameNew(info);
       hashAdd(hash, info, type);
       slAddHead(&typeList, type);
       }
    }
slNameSort(&typeList);
hashFree(&hash);

for (type = typeList; type != NULL; type = type->next)
    {
    struct qaStatistics *stats;
    AllocVar(stats);
    for (test = list; test != NULL; test = test->next)
        {
	if (sameString(type->name, test->info[subIx]))
	    {
	    qaStatisticsAdd(stats, test->status);
	    }
	}
    qaStatisticsReport(stats, type->name, f);
    freez(&stats);
    }
}
예제 #12
0
void showListOfFilterValues(struct column *col, struct sqlConnection *conn)
/* Print out list of values availabe for filter. */
{
struct sqlResult *sr;
char **row;
char query[256];
struct slName *list=NULL, *el;

sqlSafef(query, sizeof(query),
    "select distinct %s from gisaidSubjInfo", col->name);
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
    {
    char *val = row[0];
    if (col->remap)
    	val = hashFindVal(col->remap,val);
    slNameAddHead(&list, val);
    }
sqlFreeResult(&sr);

slNameSort(&list);

hPrintf("<BR>\n");
hPrintf("<B>Available Values:</B><BR>\n");
hPrintf("<TABLE>\n");

for (el = list; el; el = el->next)
    {
    hPrintf("<TR><TD>%s</TD></TR>\n", el->name);
    }

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

slFreeList(&list);

}
예제 #13
0
int hubSettingsCheckInit(struct trackHub *hub,  struct trackHubCheckOptions *options, 
                        struct dyString *errors)
{
int retVal = 0;

if (hub->version != NULL && options->version == NULL)
    options->version = hub->version;

struct trackHubSettingSpec *hubLevel = NULL;
int level = 0;
if (hub->version != NULL)
    {
    AllocVar(hubLevel);
    if ((level = trackHubSettingLevel(hubLevel)) < 0)
        {
        dyStringPrintf(errors, "Unknown hub support level: %s. Defaulting to 'all'.\n",
                                hub->level);
        retVal = 1;
        }
    else
        options->level = hub->level;
    }
verbose(2, "Checking hub '%s'", hub->longLabel);
if (options->level)
    verbose(2, " for compliance to level '%s' (use -settings to view)", options->level);
verbose(2, "\n");

struct errCatch *errCatch = errCatchNew();
if (errCatchStart(errCatch))
    {
    /* make hash of settings for this version, saving in options */
    struct trackHubSettingSpec *setting, *settings = 
                trackHubSettingsForVersion(options->specHost, options->version);
    options->settings = newHash(0);
    options->suggest = NULL;
    for (setting = settings; setting != NULL; setting = setting->next)
        {
        hashAdd(options->settings, setting->name, setting);
        slNameAddHead(&options->suggest, setting->name);
        }
    /* TODO: ? also need to check settings not in this list (other tdb fields) */

    // TODO: move extra file handling here (out of hubCheck)
    if (options->extra != NULL)
        {
        struct hashCookie cookie = hashFirst(options->extra);
        struct hashEl *hel;
        while ((hel = hashNext(&cookie)) != NULL)
            slNameAddHead(&options->suggest, hel->name);
        }
    slNameSort(&options->suggest);
    verbose(3, "Suggest list has %d settings\n", slCount(options->suggest));
    }
errCatchEnd(errCatch);
if (errCatch->gotError)
    {
    retVal = 1;
    dyStringPrintf(errors, "%s", errCatch->message->string);
    }
errCatchFree(&errCatch);
return retVal;
}
void gitReports()
/* Generate code-review reports from git repo */
{
int totalChangedLines = 0;
int totalChangedFiles = 0;

int userChangedLines = 0;
int userChangedFiles = 0;

tempMakeDiffName = cloneString(rTempName("/tmp", "makeDiff", ".tmp"));

/* read the commits */
struct commit *commits = getCommits(), *c = NULL;
/* make the user list */
for(c = commits; c; c = c->next)
    {
    
    if (!hashLookup(userHash, c->author))
	{
	hashStore(userHash, c->author);
	struct slName *name = newSlName(c->author);
	slAddHead(&users, name);
	}
    }
slNameSort(&users);

/* create prefix dir */
char path[256];
safef(path, sizeof(path), "%s/%s", outDir, outPrefix);
makeMyDir(path);

/* create file dir */
safef(path, sizeof(path), "%s/%s/%s", outDir, outPrefix, "file");
makeMyDir(path);

/* create user dir */
safef(path, sizeof(path), "%s/%s/%s", outDir, outPrefix, "user");
makeMyDir(path);


char usersPath[1024];
safef(usersPath, sizeof(usersPath), "%s/%s/%s/index.html", outDir, outPrefix, "user");

FILE *h = mustOpen(usersPath, "w");
fprintf(h, "<html>\n<head>\n<title>Changes By User</title>\n</head>\n</body>\n");
fprintf(h, "<h1>Changes By User</h1>\n");

fprintf(h, "<h2>%s to %s (%s to %s) %s</h2>\n", startTag, endTag, startDate, endDate, title);

fprintf(h, "<ul>\n");



struct slName*u;
for(u = users; u; u = u->next)
    {
    printf("user: %s\n", u->name);

    /* create user/name dir */
    safef(path, sizeof(path), "%s/%s/%s/%s", outDir, outPrefix, "user", u->name);
    makeMyDir(path);

    /* create user/name/context dir */
    safef(path, sizeof(path), "%s/%s/%s/%s/%s", outDir, outPrefix, "user", u->name, "context");
    makeMyDir(path);

    /* create user/name/full dir */
    safef(path, sizeof(path), "%s/%s/%s/%s/%s", outDir, outPrefix, "user", u->name, "full");
    makeMyDir(path);

    userChangedLines = 0;
    userChangedFiles = 0;

    /* make user's reports */
    doUserCommits(u->name, commits, &userChangedLines, &userChangedFiles);

    doUserFiles(u->name, commits);

    char relPath[1024];
    safef(relPath, sizeof(relPath), "%s/index.html", u->name);
    fprintf(h, "<li> <A href=\"%s\">%s</A> - changed lines: %d, files: %d</li>\n", relPath, u->name, userChangedLines, userChangedFiles);

    totalChangedLines += userChangedLines;
    totalChangedFiles += userChangedFiles;  

    }

fprintf(h, "</ul>\n");
if (u)
    {
    fprintf(h, "switch to <A href=\"index.html\">commits view</A>, <A href=\"../index.html\">user index</A>");
    }
else
    {
    fprintf(h, "<ul>\n");
    fprintf(h, "<li>  lines changed: %d</li>\n", totalChangedLines);
    fprintf(h, "<li>  files changed: %d</li>\n", totalChangedFiles);
    fprintf(h, "</ul>\n");
    }
fprintf(h, "</body>\n</html>\n");

fclose(h);

// make index of all files view
doUserFiles(NULL, commits);

// make main index page
doMainIndex();

// tidying up
unlink(tempMakeDiffName);
freez(&tempMakeDiffName);
}
예제 #15
0
int main(int argc, char *argv[])
/* Process command line. */
{
optionInit(&argc, argv, options);

if ((argc != 1) || optionExists("-help"))
    usage();

char *hgdbConf = getenv("HGDB_CONF");
if (hgdbConf)
    printf("\nHGDB_CONF = %s\n\n", hgdbConf);

// go through the list of cfgNames found to assemble a list of configs
struct slName *cfgName = NULL, *cfgNameList = NULL, *configList = NULL, *config = NULL;
cfgNameList = cfgNames();
slNameSort(&cfgNameList);
for (cfgName = cfgNameList; cfgName; cfgName = cfgName->next)
    {
    //printf("%s\n", cfgName->name);
    if (endsWith(cfgName->name, ".user"))
	{
	char *base = cloneString(cfgName->name);
	base[strlen(base)-5] = 0;
	/* get connection info */
	//char *database = getCfgOption(base, "db"      );  apparently this can be optional on customtracks?
	char *host     = getCfgOption(base, "host"    );
	char *user     = getCfgOption(base, "user"    );
	char *password = getCfgOption(base, "password");
	if (/*database &&*/ host && user && password)
	    {
    	    //printf("%s\n", base);
	    slAddHead(&configList, slNameNew(base));
	    }
	}
    }
slReverse(&configList);
printf("Configs found:\n\n");
int problemsFound = 0;
for (config = configList; config; config = config->next)
    {
    printf("Config %s\n", config->name);
    printf("%s.host=%s\n", config->name, getCfgOption(config->name, "host"));
    printf("%s.user=%s\n", config->name, getCfgOption(config->name, "user"));
    boolean problemFound = mysqlCheckSecurityOfConfig(config->name);
    if (problemFound)
	{
	++problemsFound;
	printf("!!! Problem found in config %s !!!\n", config->name);
	}
    else
	{
	printf("Config %s is protected from mysql database access.\n", config->name);
	}
    printf("\n");
    }
printf("\nProblems Found in %d out of %d Configs\n\n", problemsFound, slCount(configList));

if (problemsFound > 1)
    return 1;

return 0;  
}
예제 #16
0
static void parseDbXrefs()
/* Parse the db_xref entries for various features to build a single dbx entry
 * in the kvt and to obtain the locus and mim ids for the kvt */
{
static char* LOCUS_ID = "LocusID:";
static char* GENE_ID = "GeneID:";
static char* MIM_ID = "MIM:";
struct slName* head = NULL, *xref, *prevXref;
struct keyVal* dbXrefKv = NULL;
struct keyVal* locusLinkIdKv = NULL;
struct keyVal* geneIdKv = NULL;
struct keyVal* omimIdKv = NULL;
if (dbXrefBuf == NULL)
    dbXrefBuf = dyStringNew(256);
dyStringClear(dbXrefBuf);
if (omimIdBuf == NULL)
    omimIdBuf = dyStringNew(256);
dyStringClear(omimIdBuf);
locusLinkId[0] = '\0';

/* split into a list and sort so we can remove dups */
if (gbCdsDbxField->val->stringSize > 0)
    head = slCat(head, parseDbXrefStr(gbCdsDbxField->val->string));
if (gbGeneDbxField->val->stringSize > 0)
    head = slCat(head, parseDbXrefStr(gbGeneDbxField->val->string));
slNameSort(&head);

xref = head;
prevXref = NULL;
while (xref != NULL)
    {
    /* skip if dup of previous */
    if ((prevXref == NULL) || !sameString(prevXref->name, xref->name))
        {
        if (dbXrefBuf->stringSize > 0)
            dyStringAppendC(dbXrefBuf, ' ');
        dyStringAppend(dbXrefBuf, xref->name);
        updateKvt(&dbXrefKv, "dbx", dbXrefBuf->string);

        /* find number in db_xref like LocusID:27 or GeneID:27 */
        if (startsWith(LOCUS_ID, xref->name))
            {
            safef(locusLinkId, sizeof(locusLinkId), "%s",
                  xref->name+strlen(LOCUS_ID));
            updateKvt(&locusLinkIdKv, "loc", locusLinkId);
            }
        else if (startsWith(GENE_ID, xref->name))
            {
            safef(geneId, sizeof(geneId), "%s",
                  xref->name+strlen(GENE_ID));
            updateKvt(&geneIdKv, "gni", geneId);
            }
        else if (startsWith(MIM_ID, xref->name))
            {
            if (omimIdBuf->stringSize > 0)
                dyStringAppendC(omimIdBuf, ' ');
            dyStringAppend(omimIdBuf, xref->name+strlen(MIM_ID));
            updateKvt(&omimIdKv, "mim", omimIdBuf->string);
            }
        }
    prevXref = xref;
    xref = xref->next;
    }
slFreeList(&head);
}