コード例 #1
0
ファイル: obscure.c プロジェクト: andrelmartins/bigWig
struct slName *stringToSlNames(char *string)
/* Convert string to a list of slNames separated by
 * white space, but allowing multiple words in quotes.
 * Quotes if any are stripped.  */
{
struct slName *list = NULL, *name;
char *dupe = cloneString(string);
char c, *s = dupe, *e;

for (;;)
    {
    if ((s = skipLeadingSpaces(s)) == NULL)
        break;
    if ((c = *s) == 0)
        break;
    if (c == '\'' || c == '"')
        {
	if (!parseQuotedString(s, s, &e))
	    errAbort("missing closing %c in %s", c, string);
	}
    else
        {
	e = skipToSpaces(s);
	if (e != NULL) *e++ = 0;
	}
    name = slNameNew(s);
    slAddHead(&list, name);
    s = e;
    }
freeMem(dupe);
slReverse(&list);
return list;
}
コード例 #2
0
struct hash *readInfoFile(char *fileName)
/* Read in 'info' file into hash keyed by gene field and
 * containing a partial sanger22extra. */
{
    struct hash *infoHash = newHash(0);
    struct lineFile *lf = lineFileOpen(fileName, TRUE);
    char *line, *type, *val;
    struct dyString *dy = newDyString(512);
    struct sanger22extra *sx = NULL;

    while (lineFileNext(lf, &line, NULL))
    {
        line = skipLeadingSpaces(line);
        if (line[0] == 0)
        {
            finishRecord(sx, dy);
            sx = NULL;
        }
        else
        {
            if (sx == NULL)
                AllocVar(sx);
            type = nextWord(&line);
            val = strchr(line, '"');
            if (val == NULL)
                errAbort("No quoted value line %d of %s\n", lf->lineIx, lf->fileName);
            parseQuotedString(val, val, &line);
            if (sameString("Gene", type))
            {
                sx->name = cloneString(val);
                hashAdd(infoHash, val, sx);
            }
            else if (sameString("Remark", type))
            {
                dyStringAppend(dy, val);
                dyStringAppend(dy, ". ");
            }
        }
    }
    finishRecord(sx, dy);
    lineFileClose(&lf);
    return infoHash;
}
コード例 #3
0
ファイル: obscure.c プロジェクト: andrelmartins/bigWig
struct hash *hashThisEqThatLine(char *line, int lineIx, boolean firstStartsWithLetter)
/* Return a symbol table from a line of form:
 *   1-this1=val1 2-this='quoted val2' var3="another val" 
 * If firstStartsWithLetter is true, then the left side of the equals must start with
 * a letter. */
{
char *dupe = cloneString(line);
char *s = dupe, c;
char *var, *val;
struct hash *hash = newHash(8);

for (;;)
    {
    if ((var = skipLeadingSpaces(s)) == NULL)
        break;

    if ((c = *var) == 0)
        break;
    if (firstStartsWithLetter && !isalpha(c))
	errAbort("line %d of custom input: variable needs to start with letter '%s'", lineIx, var);
    val = strchr(var, '=');
    if (val == NULL)
        {
        errAbort("line %d of var %s in custom input: %s \n missing = in var/val pair", lineIx, var, line);
        }
    *val++ = 0;
    c = *val;
    if (c == '\'' || c == '"')
        {
	if (!parseQuotedString(val, val, &s))
	    errAbort("line %d of input: missing closing %c", lineIx, c);
	}
    else
	{
	s = skipToSpaces(val);
	if (s != NULL) *s++ = 0;
	}
    hashAdd(hash, var, cloneString(val));
    }
freez(&dupe);
return hash;
}
コード例 #4
0
ファイル: hgSanger22.c プロジェクト: elmargb/kentUtils
char *findVal(struct lineFile *lf, char *group, char *key)
/* Return value that matches key in group or NULL. */
{
char *s, *var, *val;
static char buf[512];

if (strlen(group) >= sizeof(buf))
    errAbort("Line too long line %d of %s", lf->lineIx, lf->fileName);
strcpy(buf, group);
s = buf;
for (;;)
    {
    var = nextWord(&s);
    if (var == NULL)
        return "";
    s = skipLeadingSpaces(s);
    if (s == NULL || s[0] == 0)
        errAbort("Unmatched key/val pair in group line %d of %s", lf->lineIx, lf->fileName);
    val = s;
    if (s[0] == '\'' || s[0] == '"')
	{
        if (!parseQuotedString(val, val, &s))
	    errAbort("Unmatched quote line %d of %s", lf->lineIx, lf->fileName);
	}
    else
        {
	int end;
	val = nextWord(&s);
	end = strlen(val) - 1;
	if (val[end] == ';')
	     val[end] = 0;
	}
    s = skipLeadingSpaces(s);
    if (s != NULL && s[0] == ';')
        s += 1;
    if (sameString(key, var))
	{
	subChar(val, '\t', ' ');
        return val;
	}
    }
}
コード例 #5
0
ファイル: obscure.c プロジェクト: Puneet-Shivanand/zinba
struct hash *hashVarLine(char *line, int lineIx)
/* Return a symbol table from a line of form:
 *   var1=val1 var2='quoted val2' var3="another val" */
{
char *dupe = cloneString(line);
char *s = dupe, c;
char *var, *val;
struct hash *hash = newHash(8);

for (;;)
    {
    if ((var = skipLeadingSpaces(s)) == NULL)
        break;

    if ((c = *var) == 0)
        break;
    if (!isalpha(c))
	errAbort("line %d of custom input: variable needs to start with letter '%s'", lineIx, var);
    val = strchr(var, '=');
    if (val == NULL)
        {
        errAbort("line %d of var %s in custom input: %s \n missing = in var/val pair", lineIx, var, line);
        }
    *val++ = 0;
    c = *val;
    if (c == '\'' || c == '"')
        {
	if (!parseQuotedString(val, val, &s))
	    errAbort("line %d of input: missing closing %c", lineIx, c);
	}
    else
	{
	s = skipToSpaces(val);
	if (s != NULL) *s++ = 0;
	}
    hashAdd(hash, var, cloneString(val));
    }
freez(&dupe);
return hash;
}
コード例 #6
0
ファイル: obscure.c プロジェクト: andrelmartins/bigWig
char *nextQuotedWord(char **pLine)
/* Generalization of nextWord.  Returns next quoted
 * string or if no quotes next word.  Updates *pLine
 * to point past word that is returned. Does not return
 * quotes. */
{
char *line, c;
line = skipLeadingSpaces(*pLine);
if (line == NULL || line[0] == 0)
    return NULL;
c = *line;
if (c == '"' || c == '\'')
    {
    if (!parseQuotedString(line, line, pLine))
        return NULL;
    return line;
    }
else
    {
    return nextWord(pLine);
    }
}
コード例 #7
0
ファイル: AppendToFile.c プロジェクト: jgrossmann/security3
/*
	Parses the data string to make sure it is valid
*/
char *parseData(char *data) {
	int isQuoted = quotedString(data);
	if(isQuoted == -1) {
		printf("Error: Data string not closed\n");
		return NULL;
	}
	
	char *newData = NULL;
	char *temp = NULL;
	if(isQuoted) {
		temp = removeQuotes(data);
		newData = parseQuotedString(temp);
		return newData;
	}else {
		newData = parseString(data);
		if(newData == NULL) {
			return NULL;
		}
		temp = (char *) malloc((strlen(newData) + 1) * sizeof(char));
		strncpy(temp, newData, strlen(newData) + 1);
		return temp;
	}
}
コード例 #8
0
ファイル: gff.c プロジェクト: JinfengChen/pblat
static void readQuotedString(char *fileName, int lineIx, char *in, char *out, char **retNext)
/* Parse quoted string and abort on error. */
{
if (!parseQuotedString(in, out, retNext))
    errAbort("Line %d of %s\n", lineIx, fileName);
}
コード例 #9
0
ファイル: hgYeastRegCode.c プロジェクト: blumroy/kentUtils
struct hash *makeProbeBed(char *inGff, char *outBed)
/* Convert probe location GFF file to BED. */
{
struct lineFile *lf = lineFileOpen(inGff, TRUE);
char *row[9];
struct hash *hash = newHash(16);
FILE *f = mustOpen(outBed, "w");
while (lineFileNextRowTab(lf, row, ArraySize(row)))
    {
    int chromIx = romanToArabicChrom(row[0], lf);
    int start = lineFileNeedNum(lf, row, 3) - 1;
    int end = lineFileNeedNum(lf, row, 4);
    char *s = row[8];
    char *probe, *orf, *note; 
    char *boundAt = "Bound at ";
    struct tfBinding *tfbList = NULL, *tfb;
    if (!startsWith("Probe ", s))
        errAbort("Expecting 9th column to start with 'Probe ' line %d of %s",
		lf->lineIx, lf->fileName);
    probe = nextWord(&s);
    orf = nextWord(&s);
    chopOff(orf, ';');
    note = nextWord(&s);
    if (!sameWord("Note", note))
        errAbort("Expecting 'note' in 9th column line %d of %s", 
		lf->lineIx, lf->fileName);
    s = skipLeadingSpaces(s);
    if (!parseQuotedString(s, s, NULL))
        errAbort("Expecting quoted string in 9th column line %d of %s",
		lf->lineIx, lf->fileName);
    if (startsWith("Bad Probe", s))
        continue;
    else if (startsWith("Not bound", s))
        {
	/* Ok, we do nothing. */
	}
    else if (startsWith(boundAt, s))
	{
	while (s != NULL && startsWith(boundAt, s))
	    {
	    char *word, *by;
	    double binding;
	    s += strlen(boundAt);
	    word = nextWord(&s);
	    binding = atof(word);
	    by = nextWord(&s);
	    if (!sameString("by:", by))
	        errAbort("Expecting by: line %d of %s", lf->lineIx, lf->fileName);
	    while ((word = nextWord(&s)) != NULL)
		{
		char lastChar = 0, *e;
		e = word + strlen(word) - 1;
		lastChar = *e;
		if (lastChar == ';' || lastChar == ',')
		     *e = 0;
		AllocVar(tfb);
		tfb->binding = binding;
		tfb->tf = cloneString(word);
		slAddHead(&tfbList, tfb);
		if (lastChar == ';')
		     break;
		}
	    s = skipLeadingSpaces(s);
	    }
	slReverse(&tfbList);
	}
    else
        {
	errAbort("Expecting %s in note line %d of %s", boundAt, 
		lf->lineIx, lf->fileName);
	}
    fprintf(f, "chr%d\t%d\t%d\t", chromIx+1, start, end);
    fprintf(f, "%s\t%d\t", orf, slCount(tfbList));
    for (tfb = tfbList; tfb != NULL; tfb = tfb->next)
	fprintf(f, "%s,", tfb->tf);
    fprintf(f, "\t");
    for (tfb = tfbList; tfb != NULL; tfb = tfb->next)
        fprintf(f, "%4.3f,", tfb->binding);
    fprintf(f, "\n");
    hashAdd(hash, orf, NULL);
    }
lineFileClose(&lf);
carefulClose(&f);
return hash;
}
コード例 #10
0
ファイル: AppendToFile.c プロジェクト: jgrossmann/security3
/*
	Takes a string path and collapses it to find the
	absolute path without "." or ".."
*/
node *collapseFilePath(char *path) {
	
	int isQuoted = quotedString(path);
	if(isQuoted == -1) {
		printf("Error: File Path string not closed\n");
		return NULL;
	}
	
	node *currentNode = NULL;
	
	char *checkedStr = NULL;
	if(!isQuoted) {
		currentNode = getCurrentPath();
		checkedStr = parseString(path);
		if(checkedStr == NULL) {
			freePathReverse(currentNode);
			return NULL;
		}
		
		char *temp = (char *) malloc(strlen(checkedStr) + 8);
		if(temp == NULL) {
			printf("ERROR: No memory left to append uni to file path\n");
			freePathReverse(currentNode);
			return NULL;
		}
		strncpy(temp, checkedStr, strlen(checkedStr) + 1);
		strncat(temp, ".jg3538", 8);
		currentNode = insertNode(currentNode, temp);
		free(temp);
	}else {
	
		if(path[1] != '/') {
			currentNode = getCurrentPath();
		}
	
		path = removeQuotes(path);
		char temp[strlen(path)+1];
		strncpy(temp, path, strlen(path)+1);
		char *base = basename(temp);
		if(strncmp(base, "..", 3) == 0 && strlen(base) == 2) {
			path = (char *) realloc(path, strlen(path) + 9);
			if(path == NULL) {
				printf("ERROR: No memory left to append uni to file path\n");
				freePathReverse(currentNode);
				return NULL;
			}
			strncat(path, "/.jg3538", 8);
		}else {
			path = (char *) realloc(path, strlen(path) + 8);
			if(path == NULL) {
				printf("ERROR: No memory left to append uni to file path\n");
				freePathReverse(currentNode);
				return NULL;
			}
			strncat(path, ".jg3538", 8);
		}
		
		char *token = strtok(path, "/");
	
		while(token != NULL) {
			checkedStr = parseQuotedString(token);
		
			if(checkedStr == NULL) {
				freePathReverse(currentNode);
				free(path);
				return NULL;
			}
		
			currentNode = insertNode(currentNode, checkedStr);
			free(checkedStr);
			token = strtok(NULL, "/");
		}
		
		free(path);
	}

	while(currentNode->prev != NULL) {
		currentNode = currentNode->prev;
	}
	
	return currentNode;
}