Exemplo n.º 1
0
Arquivo: color.c Projeto: skn/tasknc
int get_colors(const color_object object, task *tsk, const bool selected) /* {{{ */
{
	/* evaluate color rules and return attrset arg */
	short pair = 0;
	int *tskpair;
	color_rule *rule;
	bool done = false;

	/* check for cache if task */
	if (object == OBJECT_TASK)
	{
		if (selected)
			tskpair = &(tsk->selpair);
		else
			tskpair = &(tsk->pair);
		if (*tskpair >= 0)
			return COLOR_PAIR(*tskpair);
	}

	/* iterate through rules */
	rule = color_rules;
	while (rule != NULL)
	{
		/* check for matching object */
		if (object == rule->object)
		{
			switch (object)
			{
				case OBJECT_ERROR:
				case OBJECT_HEADER:
					done = true;
					break;
				case OBJECT_TASK:
					if (eval_rules(rule->rule, tsk, selected))
						pair = rule->pair;
					break;
				default:
					break;
			}
		}
		if (done)
		{
			pair = rule->pair;
			break;
		}
		rule = rule->next;
	}

	/* assign cached color if task object */
	if (object == OBJECT_TASK)
		*tskpair = (int)pair;

	return COLOR_PAIR(pair);
} /* }}} */
Exemplo n.º 2
0
int main(int argc, char ** argv) {

	int count;
	struct life_t life;


	init(&life, &argc, &argv);

	for (count = 0; count < life.generations; count++) {

		copy_bounds(&life);

		eval_rules(&life);

		update_grid(&life);
	}
	cleanup(&life);
	exit(EXIT_SUCCESS);
}
Exemplo n.º 3
0
int main(int argc, char ** argv) {
	int count;
	struct life_t life;

	init(&life, &argc, &argv);

	while (1) {
		if (life.do_display)
			do_draw(&life);

		copy_bounds(&life);

		eval_rules(&life);

		update_grid(&life);

		throttle(&life);

	}

	cleanup(&life);

	exit(EXIT_SUCCESS);
}
Exemplo n.º 4
0
Arquivo: color.c Projeto: skn/tasknc
bool eval_rules(char *rule, const task *tsk, const bool selected) /* {{{ */
{
	/* evaluate a rule set for a task */
	char *regex = NULL, pattern, *tmp;
	int ret, move;
	bool go = false, invert = false;

	/* success if rules are done */
	if (rule == NULL || *rule == 0)
		return true;

	/* skip non-patterns */
	if (*rule != '~')
		return eval_rules(rule+1, tsk, selected);

	/* regex match */
	ret = sscanf(rule, "~%c '%m[^\']'", &pattern, &regex);
	if (ret > 0 && pattern >= 'A' && pattern <= 'Z')
	{
		pattern += 32;
		invert = true;
	}
	if (ret == 1)
	{
		switch (pattern)
		{
			case 's':
				if (!XOR(invert, selected))
					return false;
				else
					return eval_rules(rule+2, tsk, selected);
				break;
			case 't':
				if (!XOR(invert, tsk->start>0))
					return false;
				else
					return eval_rules(rule+2, tsk, selected);
				break;
			default:
				break;
		}
	}
	if (ret == 2)
	{
		move = strlen(regex)+3;
		go = true;
		switch (pattern)
		{
			case 'p':
				if (!XOR(invert, match_string(tsk->project, regex)))
					return false;
				else
					tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "eval_rules: project match - '%s' '%s'", tsk->project, regex);
				break;
			case 'd':
				if (!XOR(invert, match_string(tsk->description, regex)))
					return false;
				else
					tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "eval_rules: description match - '%s' '%s'", tsk->description, regex);
				break;
			case 't':
				if (!XOR(invert, match_string(tsk->tags, regex)))
					return false;
				else
					tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "eval_rules: tag match - '%s' '%s'", tsk->tags, regex);
				break;
			case 'r':
				tmp = calloc(2, sizeof(char));
				*tmp = tsk->priority;
				if (!XOR(invert, match_string(tmp, regex)))
					return false;
				else
					tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "eval_rules: priority match - '%s' '%s'", tmp, regex);
				free(tmp);
				break;
			default:
				go = false;
				break;
		}
		free(regex);
		if (go)
			return eval_rules(rule+move, tsk, selected);
	}

	/* should never get here */
	tnc_fprintf(logfp, LOG_ERROR, "malformed rules - \"%s\"", rule);
	return false;
} /* }}} */