rule.c
// load a rule specified on cmd line or .goomwwmrc
load a rule specified on cmd line or .goomwwmrc
load a rule specified on cmd line or . goomwwmrc
int rule_parse(char *rulestr)
{
	winrule *new = allocate_clear(sizeof(winrule));
	char *str = strdup(rulestr); strtrim(str);
	char *left = str, *right = str;
	while (*right && !isspace(*right)) right++;
	new->pattern = strndup(str, right-left);
	while (*right && isspace(*right)) right++;
	while (*right && !isspace(*right))
	{
		left = right;
		while (*right && !strchr(" ,\t", *right)) right++;
		if (right > left)
		{
			char flag[32]; memset(flag, 0, sizeof(flag));
			strncpy(flag, left, MIN(sizeof(flag)-1, right-left));
			if (regquick("^[0-9]*[%]*x[0-9]*[%]*$", flag))
			{
				new->flags |= RULE_SIZE;
				char *p = flag;
				new->w = strtol(p, &p, 10);
				new->w_is_pct = (*p == '%') ? 1:0;
				if (new->w_is_pct) p++;
				if (*p == 'x') p++;
				new->h = strtol(p, &p, 10);
				new->h_is_pct = (*p == '%') ? 1:0;
			} else
			{
				int i; for (i = 0; i < sizeof(rulemap)/sizeof(winrulemap); i++)
					if (!strcasecmp(flag, rulemap[i].name))
						{ new->flags |= rulemap[i].flag; break; }
			}
		}
		while (*right && strchr(" ,\t", *right)) right++;
	}
	char *pat = new->pattern;
	if (regquick("^(class|name|title):", pat)) pat = strchr(pat, ':')+1;
	int ok = 0;
	if (regcomp(&new->re, pat, REG_EXTENDED|REG_ICASE|REG_NOSUB) == 0)
	{
		new->next = config_rules;
		config_rules = new;
		ok = 1;
	} else
	{
		fprintf(stderr, "failed to compile regex: %s\n", pat);
		free(new->pattern); free(new);
	}
	free(str);
	return ok;
}
int rule_parse ( char * rulestr ) { winrule * new = allocate_clear ( sizeof ( winrule ) ) ; char * str = strdup ( rulestr ) ; strtrim ( str ) ; char * left = str , * right = str ; while ( * right && ! isspace ( * right ) ) right ++ ; new -> pattern = strndup ( str , right - left ) ; while ( * right && isspace ( * right ) ) right ++ ; while ( * right && ! isspace ( * right ) ) { left = right ; while ( * right && ! strchr ( " \t " , * right ) ) right ++ ; if ( right > left ) { char flag [ 32 ] ; memset ( flag , 0 , sizeof ( flag ) ) ; strncpy ( flag , left , MIN ( sizeof ( flag ) - 1 , right - left ) ) ; if ( regquick ( " " , flag ) ) { new -> flags |= RULE_SIZE ; char * p = flag ; new -> w = strtol ( p , & p , 10 ) ; new -> w_is_pct = ( * p == ' ' ) ? 1 : 0 ; if ( new -> w_is_pct ) p ++ ; if ( * p == ' ' ) p ++ ; new -> h = strtol ( p , & p , 10 ) ; new -> h_is_pct = ( * p == ' ' ) ? 1 : 0 ; } else { int i ; for ( i = 0 ; i < sizeof ( rulemap ) / sizeof ( winrulemap ) ; i ++ ) if ( ! strcasecmp ( flag , rulemap [ i ] . name ) ) { new -> flags |= rulemap [ i ] . flag ; break ; } } } while ( * right && strchr ( " \t " , * right ) ) right ++ ; } char * pat = new -> pattern ; if ( regquick ( " " , pat ) ) pat = strchr ( pat , ' ' ) + 1 ; int ok = 0 ; if ( regcomp ( & new -> re , pat , REG_EXTENDED | REG_ICASE | REG_NOSUB ) == 0 ) { new -> next = config_rules ; config_rules = new ; ok = 1 ; } else { fprintf ( stderr , " \n " , pat ) ; free ( new -> pattern ) ; free ( new ) ; } free ( str ) ; return ok ; }
load a rule specified on cmd line or .goomwwmrc
load a rule specified on cmd line or . goomwwmrc
// locate end of pattern // walk over rule flags, space or command delimited // scan for delimiters // check for geometry // check known flags // skip delimiters // prepare pattern regexes