Example #1
0
static void
parse_nondirective(char *s)
{
    char *base = s;
    char *t;
    const char *attr0 = Ident_attr;
    const char *attr1 = Ident2_attr;
    char *attr2 = Literal_attr;

    if (FltOptions('c')) {
	t = skip_ident(s = base);
	if (t != s) {
	    int save = *t;

	    /* this parses one of
	     * "name"
	     * "name:class"
	     * "name:color"
	     */
	    parse_keyword(s, 0);

	    *t = 0;
	    attr0 = actual_color(s, abbr_len(s), 0);
	    *t = (char) save;
	}
	if (skip_eqls_ch(&t)) {
	    s = skip_ident(t);
	    if (s != t) {
		attr1 = actual_color(t, (int) (s - t), 1);
	    }
	}
    }

    t = skip_ident(s = base);
    flt_puts(s, (int) (t - s), attr0);
    if (parse_eqls_ch(&t)) {
	s = skip_ident(t);
	if (s != t) {
	    int save = *s;
	    *s = 0;
	    if (!FltOptions('c')) {
		if (*(attr1 = color_of(t, 0)) == '\0')
		    attr1 = Action_attr;
	    }
	    flt_puts(t, (int) strlen(t), attr1);
	    *s = (char) save;
	}
	if (parse_eqls_ch(&s)) {
	    flt_puts(s, (int) strlen(s), attr2);
	} else if (*s) {
	    flt_puts(s, (int) strlen(s), Error_attr);
	}
    } else if (*t) {
	flt_puts(t, (int) strlen(t), Error_attr);
    }
}
Example #2
0
static void
ExecTable(char *param)
{
    char *t;

    VERBOSE(1, ("ExecTable(%s)\n", param));
    if (FltOptions('c')) {
	t = skip_ident(param);
	if (*skip_blanks(t) == '\0') {
	    int save = *t;

	    *t = 0;
	    if (*param) {
		flt_make_symtab(param);
		flt_read_keywords(MY_NAME);
	    } else {
		set_symbol_table(default_table);
	    }
	    *t = (char) save;
	}
    }

    t = skip_ident(param);
    flt_puts(param, (int) (t - param), Literal_attr);
    if (*skip_blanks(t) == '\0') {
	flt_puts(t, (int) strlen(t), "");
    } else {
	flt_error("unexpected tokens");
	flt_puts(t, (int) strlen(t), Error_attr);
    }
}
Example #3
0
static int
color_code(const char *s, const char **t)
{
    int result = 0;
    const char *base = s;

    if (*s != 0) {
	for (;;) {
	    while ((*s != '\0') && strchr("RUBI", *s) != 0)
		++s;
	    if (*s == '\0') {
		result = 1;
		break;
	    } else if (*s++ == 'C') {
		if (isxdigit(CharOf(*s))) {
		    if (*(++s) == 0) {
			result = 1;
		    }
		}
	    } else {
		break;
	    }
	}
	if (result && FltOptions('c')) {
	    *t = base;
	}
    }
    return result;
}
Example #4
0
static const char *
color_of(char *s, int arg)
{
    const char *result = "";
    char *t;
    int quoted = 0;
    int save;

    s = skip_blanks(s);
    t = skip_ident(s);
    if ((save = *t) != 0)
	*t = 0;

    if (is_class(s)) {
	if (FltOptions('c')) {
	    result = keyword_attr(s);
	    if (result == 0)
		result = class_attr(s);
	    if (result == 0)
		result = Ident2_attr;
	} else {
	    result = Ident2_attr;
	}
    } else if (arg && (*s != 0)) {
	char *base = s;

	if (!FltOptions('c'))
	    result = Action_attr;
	while (*s != 0) {
	    if (quoted) {
		if (*s == QUOTE)
		    quoted = 0;
	    } else if (*s == QUOTE) {
		quoted = 1;
		result = Literal_attr;
	    } else if ((s == base) && color_code(s, &result)) {
		break;
	    }
	    s++;
	}
    }
    if (save)
	*t = (char) save;
    return result;
}
Example #5
0
static void
ExecClass(char *param)
{
    char *t = strmalloc(param);
    char *s;
    const char *attr = "";

    parse_keyword(t, 1);
    free(t);
    t = flt_put_blanks(param);
    s = skip_ident(t);
    if (FltOptions('c')) {
	attr = actual_color(param, (int) (s - param), 1);
    } else {
	attr = Ident2_attr;
    }
    flt_puts(param, (int) (s - param), attr);
    if (parse_eqls_ch(&s)) {
	t = s;
	s = skip_ident(t);
	if (FltOptions('c')) {
	    attr = actual_color(t, (int) (s - t), 1);
	} else {
	    if (*(attr = color_of(t, 0)) == '\0')
		attr = Action_attr;
	}
	flt_puts(t, (int) (s - t), attr);
	if (parse_eqls_ch(&s)) {
	    flt_puts(s, (int) strlen(s), Literal_attr);
	} else if (*s) {
	    flt_puts(s, (int) strlen(s), Error_attr);
	}
    } else if (*s) {
	flt_puts(s, (int) strlen(s), Error_attr);
    }
}
Example #6
0
static void
ExecDefault(char *param)
{
    char *s = skip_ident(param);
    const char *t = param;
    const char *attr = Literal_attr;
    int save = *s;

    VERBOSE(1, ("ExecDefault(%s)\n", param));
    *s = 0;
    if (!*t)
	t = NAME_KEYWORD;
    if (is_class(t)) {
	free(default_attr);
	default_attr = strmalloc(t);
    }
    if (FltOptions('c')) {
	attr = actual_color(t, -1, 1);
	VERBOSE(2, ("actual_color(%s) = %s\n", t, attr));
    }
    *s = (char) save;
    flt_puts(param, (int) strlen(param), attr);
}
Example #7
0
/*
 * The "-i" option toggles between case-independent and case-dependent.
 */
const char *
get_keyword_attr(const char *text)
{
    return keyword_attr((FltOptions('i') & 1) ? lowercase_of(text) : text);
}