Exemple #1
0
int dag_parse_variable(struct lexer_book *bk, struct dag_node *n, char *line)
{
	struct dag *d = bk->d;
	char *name = line + (n ? 1 : 0);	/* Node variables require offset of 1 */
	char *value = NULL;
	char *equal = NULL;
	int append = 0;

	equal = strchr(line, '=');
	if((value = strstr(line, "+=")) && value < equal) {
		*value = 0;
		value = value + 2;
		append = 1;
	} else {
		value = equal;
		*value = 0;
		value = value + 1;
	}

	name = string_trim_spaces(name);
	value = string_trim_spaces(value);
	value = string_trim_quotes(value);

	if(strlen(name) == 0) {
		dag_parse_error(bk, "variable name");
		return 0;
	}

	struct hash_table *current_table;
	int nodeid;
	if(n)
	{
		current_table = n->variables;
		nodeid        = n->nodeid;
	}
	else
	{
		current_table = d->variables;
		nodeid        = bk->d->nodeid_counter;
	}

	if(append)
	{
		dag_parse_append_variable(bk, nodeid, n, name, value);
	}
	else
	{
		dag_variable_add_value(name, current_table, nodeid, value);
	}

	dag_parse_process_special_variable(bk, n, nodeid, name, value);

	if(append)
		debug(D_DEBUG, "%s appending to variable name=%s, value=%s", (n ? "node" : "dag"), name, value);
	else
		debug(D_DEBUG, "%s variable name=%s, value=%s", (n ? "node" : "dag"), name, value);

	return 1;
}
Exemple #2
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;
}
Exemple #3
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;
}
Exemple #4
0
char *parse_executable_name(char *command)
{
	command = string_trim_spaces(command);

	char *space = strchr(command, ' ');

	if(space)
		*space = '\0';

	char *executable = command;

	if(space)
		*space = ' ';

	return executable;
}
Exemple #5
0
int dag_parse_node(struct lexer_book *bk, char *line_org)
{
	struct dag *d = bk->d;
	char *line;
	char *outputs = NULL;
	char *inputs = NULL;
	struct dag_node *n;

	n = dag_node_create(bk->d, bk->line_number);

	n->category = bk->category;
	list_push_tail(n->category->nodes, n);

	line = xxstrdup(line_org);

	outputs = line;

	inputs = strchr(line, ':');
	*inputs = 0;
	inputs = inputs + 1;

	inputs = string_trim_spaces(inputs);
	outputs = string_trim_spaces(outputs);

	dag_parse_node_filelist(bk, n, outputs, 0);
	dag_parse_node_filelist(bk, n, inputs, 1);

	int ok;
	char *comment;
	//parse variables and comments
	while((line = dag_parse_readline(bk, n)) != NULL) {
		if(line[0] == '@' && strchr(line, '=')) {
			ok = dag_parse_variable(bk, n, line);
			free(line);

			if(ok) {
				continue;
			} else {
				dag_parse_error(bk, "node variable");
				free(line);
				return 0;
			}
		}

		comment = strchr(line, '#');
		if(comment)
		{
			*comment = '\0';
			int n = strspn(line, " \t");
			int m = strlen(line);
			*comment = '#';


			/* make sure that only spaces and tabs appear before the hash */
			if(n == m) {
				continue;
			}
		}

		/* not a comment or a variable, so we break to parse the command */
		break;
	}

	ok = dag_parse_node_command(bk, n, line);
	free(line);

	if(ok) {
		n->next = d->nodes;
		d->nodes = n;
		itable_insert(d->node_table, n->nodeid, n);
	} else {
		dag_parse_error(bk, "node command");
		return 0;
	}


	debug(D_DEBUG, "Setting resource category '%s' for rule %d.\n", n->category->label, n->nodeid);
	dag_task_fill_resources(n);
	dag_task_print_debug_resources(n);

	return 1;
}