static ESExpResult *
func_regex_raw (struct _ESExp *f,
                gint argc,
                struct _ESExpResult **argv,
                gpointer data)
{
	SearchContext *ctx = data;

	return entry_compare (ctx, f, argc, argv, regex_raw_helper);
}
static ESExpResult *
func_eqphone_short (struct _ESExp *f,
                    gint argc,
                    struct _ESExpResult **argv,
                    gpointer data)
{
	SearchContext *ctx = data;

	return entry_compare (ctx, f, argc, argv, eqphone_short_helper);
}
static ESExpResult *
func_beginswith (struct _ESExp *f,
                 gint argc,
                 struct _ESExpResult **argv,
                 gpointer data)
{
	SearchContext *ctx = data;

	return entry_compare (ctx, f, argc, argv, beginswith_helper);
}
Exemplo n.º 4
0
int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
{
	int ret = 0;
	struct name_entry *entry = xmalloc(n*sizeof(*entry));

	for (;;) {
		unsigned long mask = 0;
		unsigned long dirmask = 0;
		int i, last;

		last = -1;
		for (i = 0; i < n; i++) {
			if (!t[i].size)
				continue;
			entry_extract(t+i, entry+i);
			if (last >= 0) {
				int cmp = entry_compare(entry+i, entry+last);

				/*
				 * Is the new name bigger than the old one?
				 * Ignore it
				 */
				if (cmp > 0)
					continue;
				/*
				 * Is the new name smaller than the old one?
				 * Ignore all old ones
				 */
				if (cmp < 0)
					mask = 0;
			}
			mask |= 1ul << i;
			if (S_ISDIR(entry[i].mode))
				dirmask |= 1ul << i;
			last = i;
		}
		if (!mask)
			break;
		dirmask &= mask;

		/*
		 * Clear all the unused name-entries.
		 */
		for (i = 0; i < n; i++) {
			if (mask & (1ul << i))
				continue;
			entry_clear(entry + i);
		}
		ret = info->fn(n, mask, dirmask, entry, info);
		if (ret < 0)
			break;
		if (ret)
			mask &= ret;
		ret = 0;
		for (i = 0; i < n; i++) {
			if (mask & (1ul << i))
				update_tree_entry(t + i);
		}
	}
	free(entry);
	return ret;
}
Exemplo n.º 5
0
void
key_table_diff(key_table_t old_key_table,
	       char **old_key_names,
	       int old_key_count,
	       key_table_t new_key_table,
	       char **new_key_names,
	       int new_key_count,
	       int is_for_notify,
	       elvin_keys_t *keys_to_add_out,
	       elvin_keys_t *keys_to_remove_out)
{
    elvin_keys_t keys_to_add = NULL;
    elvin_keys_t keys_to_remove = NULL;
    key_entry_t *old_entries;
    key_entry_t *new_entries;
    int old_count, new_count;
    int old_index, new_index;
    int result;

    /* Look up the old keys and sort them */
    get_sorted_entries(
        old_key_table,
        old_key_names,
        old_key_count,
        0,
        &old_entries,
        &old_count);

    /* Look up the new keys and sort them */
    get_sorted_entries(
        new_key_table,
        new_key_names,
        new_key_count,
        1,
        &new_entries,
        &new_count);

    /* Walk the two tables and find differences */
    old_index = 0;
    new_index = 0;
    while (old_index < old_count && new_index < new_count) {
        result = entry_compare(old_entries + old_index,
                               new_entries + new_index);
        if (result < 0) {
            DPRINTF((2, "removing key: \"%s\"\n",
                     old_entries[old_index]->name));
            ensure_keys(&keys_to_remove);
            key_entry_add_to_keys(
                old_entries[old_index++],
                is_for_notify,
                keys_to_remove, NULL);
        } else if (result > 0) {
            DPRINTF((2, "adding key: \"%s\"\n",
                     new_entries[new_index]->name));
            ensure_keys(&keys_to_add);
            key_entry_add_to_keys(
                new_entries[new_index++],
                is_for_notify,
                keys_to_add, NULL);
        } else {
            if (old_entries[old_index]->is_private ==
                new_entries[old_index]->is_private) {
                DPRINTF((2, "keeping key: \"%s\" -> \"%s\"\n",
                         old_entries[old_index]->name,
                         new_entries[new_index]->name));
            } else if (old_entries[old_index]->is_private) {
                DPRINTF((2, "demoting key: \"%s\" -> \"%s\"\n",
                         old_entries[old_index]->name,
                         new_entries[new_index]->name));
                ensure_keys(&keys_to_remove);
                key_entry_promote(old_entries[old_index],
                                  is_for_notify,
                                  keys_to_remove, NULL);
            } else if (new_entries[new_index]->is_private) {
                DPRINTF((2, "promoting key: \"%s\" -> \"%s\"\n",
                         old_entries[old_index]->name,
                         new_entries[new_index]->name));
                ensure_keys(&keys_to_add);
                key_entry_promote(new_entries[new_index],
                                  is_for_notify,
                                  keys_to_add, NULL);
            }

            old_index++;
            new_index++;
        }
    }

    while (old_index < old_count) {
        DPRINTF((2, "removing key: \"%s\"\n", old_entries[old_index]->name));
        ensure_keys(&keys_to_remove);
        key_entry_add_to_keys(
            old_entries[old_index++],
            is_for_notify,
            keys_to_remove, NULL);
    }

    while (new_index < new_count) {
        DPRINTF((2, "adding key: \"%s\"\n", new_entries[new_index]->name));
        ensure_keys(&keys_to_add);
        key_entry_add_to_keys(
            new_entries[new_index++],
            is_for_notify,
            keys_to_add, NULL);
    }

    DPRINTF((2, "---\n"));

    free(old_entries);
    free(new_entries);

    if (keys_to_add_out) {
        *keys_to_add_out = keys_to_add;
    } else if (keys_to_add) {
        elvin_keys_free(keys_to_add, NULL);
    }

    if (keys_to_remove_out) {
        *keys_to_remove_out = keys_to_remove;
    } else if (keys_to_remove) {
        elvin_keys_free(keys_to_remove, NULL);
    }
}