Esempio n. 1
0
static struct lineFile *astLFOpen(char *fileOrUrl)
/* Figure out if fileOrUrl is file or URL and open an lf accordingly. */
{
if (startsWith("http://", fileOrUrl) || startsWith("https://", fileOrUrl) ||
    startsWith("ftp://", fileOrUrl))
    return netLineFileOpen(fileOrUrl);
else
    return lineFileOpen(fileOrUrl, TRUE);
}
Esempio n. 2
0
struct hash *bbiChromSizesFromFile(char *fileName)
/* Read two column file into hash keyed by chrom. */
{
struct hash *hash = hashNew(0);
struct lineFile *lf = netLineFileOpen(fileName);
char *row[2];
while (lineFileRow(lf, row))
    hashAddInt(hash, row[0], sqlUnsigned(row[1]));

lineFileClose(&lf);
return hash;
}
Esempio n. 3
0
File: vcf.c Progetto: bh0085/kent
struct vcfFile *vcfFileMayOpen(char *fileOrUrl, int maxErr, int maxRecords)
/* Parse a VCF file into a vcfFile object.  If maxErr not zero, then
 * continue to parse until this number of error have been reached.  A maxErr
 * less than zero does not stop and reports all errors. */
{
struct lineFile *lf = NULL;
if (startsWith("http://", fileOrUrl) || startsWith("ftp://", fileOrUrl) ||
    startsWith("https://", fileOrUrl))
    lf = netLineFileOpen(fileOrUrl);
else
    lf = lineFileMayOpen(fileOrUrl, TRUE);
struct vcfFile *vcff = vcfFileHeaderFromLineFile(lf, maxErr);
vcfParseData(vcff, maxRecords);
return vcff;
}
Esempio n. 4
0
struct vcfFile *vcfFileMayOpen(char *fileOrUrl, int maxErr, int maxRecords, boolean parseAll)
/* Open fileOrUrl and parse VCF header; return NULL if unable.
 * If parseAll, then read in all lines, parse and store in
 * vcff->records; if maxErr >= zero, then continue to parse until
 * there are maxErr+1 errors.  A maxErr less than zero does not stop
 * and reports all errors. Set maxErr to VCF_IGNORE_ERRS for silence */
{
struct lineFile *lf = NULL;
if (startsWith("http://", fileOrUrl) || startsWith("ftp://", fileOrUrl) ||
    startsWith("https://", fileOrUrl))
    lf = netLineFileOpen(fileOrUrl);
else
    lf = lineFileMayOpen(fileOrUrl, TRUE);
struct vcfFile *vcff = vcfFileHeaderFromLineFile(lf, maxErr);
if (parseAll)
    {
    vcff->records = vcfParseData(vcff, maxRecords);
    lineFileClose(&(vcff->lf)); // Not sure why it is closed.  Angie?
    }
return vcff;
}
Esempio n. 5
0
char *customPpNext(struct customPp *cpp)
/* Return next line. */
{
/* Check first for line to reuse. */
struct slName *reused = cpp->reusedLines;
if (reused)
    {
    /* We need to keep line actually reusing in memory until next
     * call to customPpNext, so we move it to inReuse rather than
     * immediately freeing it. */
    freeMem(cpp->inReuse);   
    cpp->reusedLines = reused->next;
    cpp->inReuse = reused;
    return reused->name;
    }

/* Get next line from file on top of stack.  If at EOF
 * go to next file in stack.  If get a http:// or https:// or ftp:// line
 * open file this references and push it onto stack. Meanwhile
 * squirrel away 'browser' lines. */
struct lineFile *lf;
while ((lf = cpp->fileStack) != NULL)
    {
    char *line;
    if (lineFileNext(lf, &line, NULL))
        {
        // if user pastes just a URL, create a track line automatically
        // also allow a filename from a local directory if it has been allowed via udc.localDir in hg.conf
        bool isLocalFile = cfgOption("udc.localDir")!=NULL && startsWith(cfgOption("udc.localDir"), line);
	if (startsWith("http://", line) || startsWith("https://", line) || startsWith("ftp://", line) ||
            isLocalFile)
	    {
            if (customTrackIsBigData(line))
                line = bigUrlToTrackLine(line);
            else
                {
                lf = netLineFileOpen(line);
                slAddHead(&cpp->fileStack, lf);
    #ifdef PROGRESS_METER
                off_t remoteSize = 0;
                remoteSize = remoteFileSize(line);
                cpp->remoteFileSize = remoteSize;
    #endif
                continue;
                }
	    }
	else if (!cpp->ignoreBrowserLines && startsWith("browser", line))
	    {
	    char afterPattern = line[7];
	    if (isspace(afterPattern) || afterPattern == 0)
	        {
		slNameAddTail(&cpp->browserLines, line);
		continue;
		}
	    }
	return line;
	}
    else
        {
	cpp->fileStack = lf->next;
	lineFileClose(&lf);
	}
    }
return NULL;
}
Esempio n. 6
0
struct meta *metaLoadAll(char *fileName, char *keyTag, char *parentTag,
                         boolean ignoreOtherStanzas, boolean ignoreIndent)
/* Loads in all ra stanzas from file and turns them into a list of meta, some of which
 * may have children.  The keyTag parameter is optional.  If non-null it should be set to
 * the tag name that starts a stanza.   If null, the first tag of the first stanza will be used.
 * The parentTag if non-NULL will be a tag name used to define the parent of a stanza.
 * The ignoreOtherStanzas flag if set will ignore stanzas that start with other tags.
 * If not set the routine will abort on such stanzas.  The ignoreIndent if set will
 * use the parentTag (which must be set) to define the hierarchy.  Otherwise the program
 * will look at the indentation, and if there is a parentTag complain about any
 * disagreements between indentation and parentTag. */
{
    struct lineFile *lf = netLineFileOpen(fileName);
    struct meta *meta, *forest = NULL, *lastMeta = NULL;
    if (ignoreIndent)
    {
        errAbort("Currently metaLoadAll can't ignore indentation, sorry.");
    }
    while ((meta = metaNextStanza(lf)) != NULL)
    {
        struct meta **pList;
        if (forest == NULL)   /* First time. */
        {
            if (meta->indent != 0)
                errAbort("Initial stanza of %s should not be indented", fileName);
            if (keyTag == NULL)
                keyTag = meta->tagList->tag;
            pList = &forest;
        }
        else
        {
            if (!sameString(keyTag, meta->tagList->tag))
            {
                if (ignoreOtherStanzas)
                {
                    metaFree(&meta);
                    continue;
                }
                else
                    errAbort("Stanza beginning with %s instead of %s line %d of %s",
                             meta->tagList->tag, keyTag, lf->lineIx, lf->fileName);
            }
            if (meta->indent > lastMeta->indent)
            {
                pList = &lastMeta->children;
                meta->parent = lastMeta;
            }
            else if (meta->indent == lastMeta->indent)
            {
                if (meta->indent == 0)
                    pList = &forest;
                else
                {
                    pList = &lastMeta->parent->children;
                    meta->parent = lastMeta->parent;
                }
            }
            else /* meta->indent < lastMeta->indent */
            {
                /* Find sibling at same level as us. */
                struct meta *olderSibling;
                for (olderSibling = lastMeta->parent;
                        olderSibling != NULL; olderSibling = olderSibling->parent)
                {
                    if (meta->indent == olderSibling->indent)
                        break;
                }
                if (olderSibling == NULL)
                {
                    warn("Indentation inconsistent in stanza ending line %d of %s.",
                         lf->lineIx, lf->fileName);
                    warn("If you are using tabs, check your tab stop is set to 8.");
                    warn("Otherwise check that when you are reducing indentation in a stanza");
                    warn("that it is the same as the previous stanza at the same level.");
                    noWarnAbort();
                }
                if (olderSibling->parent == NULL)
                    pList = &forest;
                else
                {
                    pList = &olderSibling->parent->children;
                    meta->parent = olderSibling->parent;
                }
            }
        }
        slAddHead(pList, meta);
        lastMeta = meta;
    }
    lineFileClose(&lf);
    forest = rReverseMetaList(forest);
    return forest;
}