Exemple #1
0
/* SYNTAX: HILIGHT [-nick | -word | -line] [-mask | -full | -regexp]
                   [-color <color>] [-actcolor <color>] [-level <level>]
		   [-network <network>] [-channels <channels>] <text> */
static void cmd_hilight(const char *data)
{
    GHashTable *optlist;
    HILIGHT_REC *rec;
    char *colorarg, *actcolorarg, *levelarg, *priorityarg, *chanarg, *text, *servertag;
    char **channels;
    void *free_arg;

    g_return_if_fail(data != NULL);

    if (*data == '\0') {
        cmd_hilight_show();
        return;
    }

    if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
                        PARAM_FLAG_GETREST, "hilight", &optlist, &text))
        return;

    chanarg = g_hash_table_lookup(optlist, "channels");
    levelarg = g_hash_table_lookup(optlist, "level");
    priorityarg = g_hash_table_lookup(optlist, "priority");
    colorarg = g_hash_table_lookup(optlist, "color");
    actcolorarg = g_hash_table_lookup(optlist, "actcolor");
    servertag = g_hash_table_lookup(optlist, "network");

    if (*text == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

    channels = (chanarg == NULL || *chanarg == '\0') ? NULL :
               g_strsplit(chanarg, ",", -1);

    rec = hilight_find(text, channels);
    if (rec == NULL) {
        rec = g_new0(HILIGHT_REC, 1);

        /* default to nick/word hilighting */
        rec->nick = TRUE;
        rec->word = TRUE;

        rec->text = g_strdup(text);
        rec->channels = channels;
    } else {
        g_strfreev(channels);
    }

    rec->level = (levelarg == NULL || *levelarg == '\0') ? 0 :
                 level2bits(replace_chars(levelarg, ',', ' '), NULL);
    rec->priority = priorityarg == NULL ? 0 : atoi(priorityarg);

    if (g_hash_table_lookup(optlist, "line") != NULL) {
        rec->word = FALSE;
        rec->nick = FALSE;
    }

    if (g_hash_table_lookup(optlist, "word") != NULL) {
        rec->word = TRUE;
        rec->nick = FALSE;
    }

    if (g_hash_table_lookup(optlist, "nick") != NULL)
        rec->nick = TRUE;

    rec->nickmask = g_hash_table_lookup(optlist, "mask") != NULL;
    rec->fullword = g_hash_table_lookup(optlist, "full") != NULL;
    rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL;

    if (colorarg != NULL) {
        g_free_and_null(rec->color);
        if (*colorarg != '\0')
            rec->color = g_strdup(colorarg);
    }
    if (actcolorarg != NULL) {
        g_free_and_null(rec->act_color);
        if (*actcolorarg != '\0')
            rec->act_color = g_strdup(actcolorarg);
    }
    if (servertag != NULL) {
        g_free_and_null(rec->servertag);
        if (*servertag != '\0')
            rec->servertag = g_strdup(servertag);
    }

    hilight_create(rec);

    hilight_print(g_slist_index(hilights, rec)+1, rec);
    cmd_params_free(free_arg);

    reset_cache();
}
Exemple #2
0
/* SYNTAX: HILIGHT [-nick | -nonick] [-mask | -regexp | -word]
                   [-color <color>] [-level <level>]
		   [-channels <channels>] <text> */
static void cmd_hilight(const char *data)
{
        GHashTable *optlist;
	HILIGHT_REC *rec;
	char *colorarg, *levelarg, *chanarg, *text;
	char **channels;
	void *free_arg;

	g_return_if_fail(data != NULL);

	if (*data == '\0') {
		cmd_hilight_show();
		return;
	}

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
			    PARAM_FLAG_GETREST, "hilight", &optlist, &text))
		return;

	chanarg = g_hash_table_lookup(optlist, "channels");
	levelarg = g_hash_table_lookup(optlist, "level");
	colorarg = g_hash_table_lookup(optlist, "color");

	if (*text == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	channels = (chanarg == NULL || *chanarg == '\0') ? NULL :
		g_strsplit(replace_chars(chanarg, ',', ' '), " ", -1);

	rec = hilight_find(text, channels);
	if (rec == NULL) {
		rec = g_new0(HILIGHT_REC, 1);

		rec->text = g_strdup(text);
		rec->channels = channels;
	} else {
                g_free_and_null(rec->color);
		g_strfreev(channels);

                hilight_remove_config(rec);
		hilights = g_slist_remove(hilights, rec);
	}

	rec->level = (levelarg == NULL || *levelarg == '\0') ? 0 :
		level2bits(replace_chars(levelarg, ',', ' '));
	rec->nick = settings_get_bool("hilight_only_nick") &&
		(rec->level == 0 || (rec->level & DEFAULT_HILIGHT_LEVEL) == rec->level) ?
		g_hash_table_lookup(optlist, "nonick") == NULL :
		g_hash_table_lookup(optlist, "nick") != NULL;
	rec->nickmask = g_hash_table_lookup(optlist, "mask") != NULL;
	rec->fullword = g_hash_table_lookup(optlist, "word") != NULL;
	rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL;

	if (colorarg != NULL && *colorarg != '\0')
		rec->color = g_strdup(colorarg);

	hilights = g_slist_append(hilights, rec);
	hilight_add_config(rec);

	hilight_print(g_slist_index(hilights, rec)+1, rec);
        cmd_params_free(free_arg);
}