Example #1
0
File: dag.c Project: badi/cctools
struct dag_node *dag_node_create(struct dag *d, int linenum)
{
	struct dag_node *n;

	n = malloc(sizeof(struct dag_node));
	memset(n, 0, sizeof(struct dag_node));
	n->d = d;
	n->linenum = linenum;
	n->state = DAG_NODE_STATE_WAITING;
	n->nodeid = d->nodeid_counter++;
	n->variables = hash_table_create(0, 0);

	n->source_files = list_create(0);
	n->target_files = list_create(0);

	n->remote_names = itable_create(0);
	n->remote_names_inv = hash_table_create(0, 0);

	n->descendants = set_create(0);
	n->ancestors = set_create(0);

	n->ancestor_depth = -1;

	n->resources = make_rmsummary(-1);

	if(verbose_parsing && d->nodeid_counter % PARSING_RULE_MOD_COUNTER == 0)
	{
		fprintf(stdout, "\rRules parsed: %d", d->nodeid_counter + 1);
		fflush(stdout);
	}

	return n;
}
Example #2
0
struct dag_node *dag_node_create(struct dag *d, int linenum)
{
	struct dag_node *n;

	n = malloc(sizeof(struct dag_node));
	memset(n, 0, sizeof(struct dag_node));
	n->d = d;
	n->linenum = linenum;
	n->state = DAG_NODE_STATE_WAITING;
	n->nodeid = d->nodeid_counter++;
	n->variables = hash_table_create(0, 0);

	n->source_files = list_create(0);
	n->target_files = list_create(0);

	n->remote_names = itable_create(0);
	n->remote_names_inv = hash_table_create(0, 0);

	n->descendants = set_create(0);
	n->ancestors = set_create(0);

	n->ancestor_depth = -1;

	n->resources = make_rmsummary(-1);

	return n;
}
Example #3
0
struct dag_task_category *dag_task_category_lookup_or_create(struct dag *d, const char *label)
{
	struct dag_task_category *category;

	category = hash_table_lookup(d->task_categories, label);
	if(!category) {
		category = malloc(sizeof(struct dag_task_category));
		category->label = xxstrdup(label);
		category->nodes = list_create();
		category->variables = hash_table_create(0, 0);
		category->resources = make_rmsummary(-1);
		
		hash_table_insert(d->task_categories, label, category);
	}

	return category;
}
Example #4
0
/* Parse a string for summary fields. Separator is usually '\n' or ',' */
struct rmsummary *rmsummary_parse_from_str(const char *buffer, const char separator)
{
	char key[MAX_LINE], value[MAX_LINE];
	char *token, *saveptr;

	if(!buffer)
		return NULL;

	// strtok does not work with const char.
	char *buffer_copy = xxstrdup(buffer);

	const char delim[] = { separator, '\n', '\0'};

	struct rmsummary *s = make_rmsummary(-1);

	/* if source have no last_error, we do not want the -1 from above */
	s->last_error = 0;

	token = strtok_r(buffer_copy, delim, &saveptr);
	while(token)
	{
		if(sscanf(token, "%[^:]:%*[ \t]%[^\n]", key, value) >= 2)
		{
			char *key_trim   = string_trim_spaces(key);
			char *value_trim = string_trim_spaces(value);

			/* remove units if present */
			if(strcmp("limits_exceeded", key_trim) != 0)
			{
				char *space = strchr(value_trim, ' ');
				if(space)
					*space = '\0';
			}

			rmsummary_assign_field(s, key_trim, value_trim);
		}
		token = strtok_r(NULL, delim, &saveptr);
	}

	free(buffer_copy);

	return s;
}
Example #5
0
struct rmsummary *rmsummary_parse_single(char *buffer, char separator)
{
	char key[MAX_LINE], value[MAX_LINE];
	char *token, *saveptr;

	if(!buffer)
		return NULL;

	buffer = xxstrdup(buffer);

	const char delim[] = { separator, '\n', '\0'}; 

	struct rmsummary *s = make_rmsummary(-1);

	token = strtok_r(buffer, delim, &saveptr);
	while(token)
	{
		if(sscanf(token, "%[^:]:%*[ \t]%[^\n]", key, value) >= 2) 
		{
			char *key_trim   = string_trim_spaces(key);
			char *value_trim = string_trim_spaces(value);

			/* remove units if present */
			if(strcmp("limits_exceeded", key_trim) != 0)
			{
				char *space = strchr(value_trim, ' ');
				if(space)
					*space = '\0';
			}
			
			rmsummary_assign_field(s, key_trim, value_trim);
		}
		token = strtok_r(NULL, delim, &saveptr);
	}

	free(buffer);

	return s;
}