Example #1
0
int main(int argc, char *argv[])
{
    DIR *dirp;
    struct dirent *dp;

    Status *status;
    Status *previous = NULL;

    dirp = opendir("/proc/");

    while ((dp = readdir(dirp)) != NULL) {

        if (isNumericString(dp->d_name)) {

            status = getProcessStatus(atoi(dp->d_name));

            if (status != NULL) {
                insertProcess(previous, status);
                previous = status;
            }

        }

    }

    draw(status);

    freeAll(previous);
    closedir(dirp);

    exit(EXIT_SUCCESS);
}
Example #2
0
int
id3tag_set_textinfo_ucs2(lame_global_flags * gfp, char const *id, unsigned short const *text)
{
    uint32_t const t_mask = FRAME_ID('T', 0, 0, 0);
    uint32_t const frame_id = toID3v2TagId(id);
    if (frame_id == 0) {
        return -1;
    }
    if ((frame_id & t_mask) == t_mask) {
        if (isNumericString(frame_id)) {
            return -2;  /* must be Latin-1 encoded */
        }
        if (text == 0) {
            return 0;
        }
        if (!hasUcs2ByteOrderMarker(text[0])) {
            return -3;  /* BOM missing */
        }
        if (gfp != 0) {
            if (frame_id == ID_TXXX) {
                return id3tag_set_userinfo_ucs2(gfp->internal_flags, text);
            }
            return id3v2_add_ucs2(gfp->internal_flags, frame_id, 0, 0, text);
        }
    }
    return -255;        /* not supported by now */
}
Example #3
0
int getScopeId(const std::string& scopedName)
{
  std::string scope = getScope(scopedName);

  if (!isNumericString(scope)) {
    throw "Cannot provide scope Id for non-numeric scope";
  }

  int result = atoi(scope.c_str());
  return result;
}
Example #4
0
static struct bed4 *parseRegionInput(char *db, char *inputString, int maxRegions, int maxErrs,
                                     struct dyString *dyWarn)
/* scan the user region definition, turn into a bed list */
{
int regionCount = 0;
int errCount = 0;
struct bed4 *bedList = NULL;
struct lineFile *lf = lineFileOnString("userData", TRUE, inputString);
char *line = NULL;
while (lineFileNextReal(lf, &line))
    {
    char *chromName = NULL;
    int chromStart = 0;
    int chromEnd = 0;
    char *regionName = NULL;
    // Chop a copy of line so we can display line if there's an error.
    char copy[strlen(line)+1];
    safecpy(copy, sizeof(copy), line);
    char *words[5];
    int wordCount = chopByWhite(copy, words, ArraySize(words));
    boolean badFormat = FALSE;
    boolean gotError = FALSE;
    /*	might be something of the form: chrom:start-end optionalRegionName */
    if (((1 == wordCount) || (2 == wordCount)) &&
	    hgParseChromRange(NULL, words[0], &chromName,
		&chromStart, &chromEnd))
	{
	if (2 == wordCount)
	    regionName = cloneString(words[1]);
	}
    else if (!((3 == wordCount) || (4 == wordCount)))
	{
	dyStringPrintf(dyWarn, "line %d: '%s': "
                       "unrecognized format.  Please enter 3- or 4-column BED or "
                       "a chr:start-end position range optionally followed by a name.\n",
                       lf->lineIx, line);
        badFormat = TRUE;
        gotError = TRUE;
	}
    else
	{
	chromName = words[0];
        // Make sure chromStart and chromEnd are numbers
        if (!isNumericString(words[1]))
            {
            dyStringPrintf(dyWarn, "line %d: '%s': chromStart must be a number but is '%s'\n",
                           lf->lineIx, line, words[1]);
            gotError = TRUE;
            }
        if (!isNumericString(words[2]))
            {
            dyStringPrintf(dyWarn, "line %d: '%s': chromEnd must be a number but is '%s'\n",
                           lf->lineIx, line, words[2]);
            gotError = TRUE;
            }
        if (! gotError)
            {
            chromStart = atoi(words[1]);
            chromEnd = atoi(words[2]);
            if (wordCount > 3)
                regionName = cloneString(words[3]);
            }
	}
    char *officialChromName = chromName ? hgOfficialChromName(db, chromName) : NULL;
    if (! badFormat)
        {
        if (NULL == officialChromName)
            {
            dyStringPrintf(dyWarn,
                           "line %d: '%s': chrom name '%s' not recognized in this assembly\n",
                           lf->lineIx, line, chromName ? chromName : words[0]);
            gotError = TRUE;
            }
        else if (illegalCoordinate(db, officialChromName, chromStart, chromEnd, line, lf->lineIx,
                                   dyWarn))
            {
            gotError = TRUE;
            }
        }
    if (gotError)
        {
        errCount++;
        if (errCount > maxErrs && maxErrs > 0)
            {
            dyStringPrintf(dyWarn, "Exceeded maximum number of errors (%d), quitting\n", maxErrs);
            break;
            }
        else
            continue;
        }
    ++regionCount;
    if (regionCount > maxRegions && maxRegions > 0)
	{
	dyStringPrintf(dyWarn,
                       "line %d: limit of %d region definitions exceeded, skipping the rest\n",
                       lf->lineIx, maxRegions);
	break;
	}
    struct bed4 *bedEl = bed4New(officialChromName, chromStart, chromEnd, regionName);
    slAddHead(&bedList, bedEl);
    }
lineFileClose(&lf);
// Keep regions in same order as user entered them:
slReverse(&bedList);
return (bedList);
}
Example #5
0
int main(int argc, char *argv[])
{
	DIR *proc_dp;
	DIR *fd_dp;

	Status *status;

	struct dirent *pid_dir;
	struct dirent *fd_dir;

	char pathname[PATH_MAX] = {0};
	char fd_pathname[PATH_MAX] = {0};
	char content[CONTENT_MAX] = {0};

	if (argc != 2) {
		usageErr("./program filename\n");
	}

	proc_dp = opendir("/proc/");

	while ((pid_dir = readdir(proc_dp)) != NULL) {

		if (isNumericString(pid_dir->d_name)) {

			snprintf(pathname, PATH_MAX, "/proc/%s/fd/", pid_dir->d_name);

			fd_dp = opendir(pathname);

			if (!fd_dp) {
				cleanup(NULL, pathname, NULL);
				continue;
			}

			while ((fd_dir = readdir(fd_dp)) != NULL) {

				snprintf(fd_pathname, PATH_MAX, "/proc/%s/fd/%s",
					pid_dir->d_name,
					fd_dir->d_name
				);

				if (readlink(fd_pathname, content, CONTENT_MAX - 1) == -1) {
					cleanup(NULL, NULL, fd_pathname);
					continue;
				}

				status = getProcessStatus(atoi(pid_dir->d_name));
				if (status == NULL) {
					continue;
				}

				if (endswith(content, argv[1])) {
					printf("%s (%ld)\n", status->comm, (long)status->pid);
				}

				free(status);
				cleanup(content, NULL, fd_pathname);
			}

			cleanup(NULL, pathname, NULL);
		}
	}

	closedir(proc_dp);
	closedir(fd_dp);

	exit(EXIT_SUCCESS);
}
Example #6
0
void webTableBuildQuery(struct cart *cart, char *from, char *initialWhere, 
    char *varPrefix, char *fields, boolean withFilters, 
    struct dyString **retQuery, struct dyString **retWhere)
/* Construct select, from and where clauses in query, keeping an additional copy of where 
 * Returns the SQL query and the SQL where expression as two dyStrings (need to be freed)  */
{
struct dyString *query = dyStringNew(0);
struct dyString *where = dyStringNew(0);
struct slName *field, *fieldList = commaSepToSlNames(fields);
boolean gotWhere = FALSE;
sqlDyStringPrintf(query, "%s", ""); // TODO check with Galt on how to get reasonable checking back.
dyStringPrintf(query, "select %s from %s", fields, from);
if (!isEmpty(initialWhere))
    {
    dyStringPrintf(where, " where ");
    sqlSanityCheckWhere(initialWhere, where);
    gotWhere = TRUE;
    }

/* If we're doing filters, have to loop through the row of filter controls */
if (withFilters)
    {
    for (field = fieldList; field != NULL; field = field->next)
        {
	char varName[128];
	safef(varName, sizeof(varName), "%s_f_%s", varPrefix, field->name);
	char *val = trimSpaces(cartUsualString(cart, varName, ""));
	if (!isEmpty(val))
	    {
	    if (gotWhere)
		dyStringPrintf(where, " and ");
	    else
		{
	        dyStringPrintf(where, " where ");
		gotWhere = TRUE;
		}
	    if (anyWild(val))
	         {
		 char *converted = sqlLikeFromWild(val);
		 char *escaped = makeEscapedString(converted, '"');
		 dyStringPrintf(where, "%s like \"%s\"", field->name, escaped);
		 freez(&escaped);
		 freez(&converted);
		 }
	    else if (val[0] == '>' || val[0] == '<')
	         {
		 char *remaining = val+1;
		 if (remaining[0] == '=')
		     remaining += 1;
		 remaining = skipLeadingSpaces(remaining);
		 if (isNumericString(remaining))
		     dyStringPrintf(where, "%s %s", field->name, val);
		 else
		     {
		     warn("Filter for %s doesn't parse:  %s", field->name, val);
		     dyStringPrintf(where, "%s is not null", field->name); // Let query continue
		     }
		 }
	    else
	         {
		 char *escaped = makeEscapedString(val, '"');
		 dyStringPrintf(where, "%s = \"%s\"", field->name, escaped);
		 freez(&escaped);
		 }
	    }
	}
    }
dyStringAppend(query, where->string);

/* We do order here so as to keep order when working with tables bigger than a page. */
char orderVar[256];
safef(orderVar, sizeof(orderVar), "%s_order", varPrefix);
char *orderFields = cartUsualString(cart, orderVar, "");
if (!isEmpty(orderFields))
    {
    if (orderFields[0] == '-')
	dyStringPrintf(query, " order by %s desc", orderFields+1);
    else
	dyStringPrintf(query, " order by %s", orderFields);
    }

// return query and where expression
*retQuery = query;
*retWhere = where;
}