コード例 #1
0
ファイル: filtering.c プロジェクト: vifm/vifm
/* Changes *matcher to have the value of the expr.  The operation is assumed to
 * succeed, but it's not guaranteed. */
static void
replace_matcher(matcher_t **matcher, const char expr[])
{
	char *error;

	matcher_free(*matcher);
	*matcher = matcher_alloc(expr, FILTER_DEF_CASE_SENSITIVITY, 0, "", &error);
	free(error);
}
コード例 #2
0
/* Frees data structures of the color scheme that are related to filename
 * specific highlight. */
static void
free_color_scheme_highlights(col_scheme_t *cs)
{
	int i;

	for(i = 0; i < cs->file_hi_count; ++i)
	{
		file_hi_t *const hi = &cs->file_hi[i];
		matcher_free(hi->matcher);
	}

	free(cs->file_hi);

	cs->file_hi = NULL;
	cs->file_hi_count = 0;
}
コード例 #3
0
ファイル: tabs.c プロジェクト: phantasea/vifm
/* Clones one view into another.  Path specifies location of active pane and can
 * be NULL.  The destination view is assumed to not own any resources. */
static void
clone_view(view_t *dst, view_t *src, const char path[])
{
	strcpy(dst->curr_dir, path == NULL ? flist_get_dir(src) : path);
	dst->timestamps_mutex = src->timestamps_mutex;
	dst->win = src->win;
	dst->title = src->title;

	flist_init_view(dst);
	dst->dir_entry[0].origin = src->curr_dir;

	clone_local_options(src, dst, 1);
	matcher_free(dst->manual_filter);
	dst->manual_filter = matcher_clone(src->manual_filter);
	filter_assign(&dst->auto_filter, &src->auto_filter);
	dst->prev_invert = src->prev_invert;
	dst->invert = src->invert;

	/* Clone current entry even though we populate file list later to give
	 * reloading reference point for cursor. */
	replace_dir_entries(dst, &dst->dir_entry, &dst->list_rows,
			get_current_entry(src), 1);
	dst->list_pos = 0;
	/* Clone viewport configuration. */
	dst->curr_line = src->curr_line;
	dst->top_line = src->top_line;
	dst->window_rows = src->window_rows;
	dst->window_cols = src->window_cols;
	dst->window_cells = src->window_cells;

	flist_hist_resize(dst, cfg.history_len);
	flist_hist_clone(dst, src);
	if(path != NULL && !flist_custom_active(src))
	{
		/* Record location we're leaving. */
		flist_hist_save(dst, src->curr_dir, get_current_file_name(src),
				src->list_pos - src->top_line);
	}

	(void)populate_dir_list(dst, path == NULL);
	/* XXX: do we need to update origins or is this a leftover from before list
	 *      population was introduced? */
	flist_update_origins(dst, &dst->curr_dir[0], &src->curr_dir[0]);

	/* Record new location. */
	flist_hist_save(dst, NULL, NULL, -1);
}
コード例 #4
0
ファイル: tabs.c プロジェクト: acklinr/vifm
/* Clones one view into another.  The destination view is assumed to not own any
 * resources. */
static void
clone_view(view_t *dst, view_t *src)
{
	strcpy(dst->curr_dir, flist_get_dir(src));
	dst->timestamps_mutex = src->timestamps_mutex;
	dst->win = src->win;
	dst->title = src->title;

	flist_init_view(dst);
	dst->dir_entry[0].origin = src->curr_dir;

	clone_local_options(src, dst, 1);
	matcher_free(dst->manual_filter);
	dst->manual_filter = matcher_clone(src->manual_filter);
	filter_assign(&dst->auto_filter, &src->auto_filter);
	dst->prev_invert = src->prev_invert;
	dst->invert = src->invert;

	/* Clone current entry even though we populate file list later to give
	 * reloading reference point for cursor. */
	replace_dir_entries(dst, &dst->dir_entry, &dst->list_rows,
			get_current_entry(src), 1);
	dst->list_pos = 0;
	/* Clone viewport configuration. */
	dst->curr_line = src->curr_line;
	dst->top_line = src->top_line;
	dst->window_rows = src->window_rows;
	dst->window_cols = src->window_cols;
	dst->window_cells = src->window_cells;

	flist_hist_resize(dst, cfg.history_len);
	flist_hist_clone(dst, src);

	(void)populate_dir_list(dst, 1);
	flist_update_origins(dst, &dst->curr_dir[0], &src->curr_dir[0]);
}
コード例 #5
0
ファイル: filetype.c プロジェクト: lowtalker/vifm
static void
free_assoc(assoc_t *assoc)
{
	matcher_free(assoc->matcher);
	ft_assoc_records_free(&assoc->records);
}
コード例 #6
0
ファイル: cr-coder.c プロジェクト: raedwulf/comprox
void lzencode(data_block_t* ib, data_block_t* ob, int print_information) {
    matcher_t matcher;
    uint32_t  match_len;
    uint32_t  i;
    uint32_t  pos;
    uint32_t  counter[256] = {0};
    int       esc = 0;

    lzmatch_thread_param_pack_t thread_args;
    pthread_t thread;
    uint32_t  match_retindex = 0;
    uint32_t  match_retn = 0;
    uint32_t  match_nextpos = 0;
    uint32_t  match_lens[2][M_match_rets_size];

    if(print_information) {
        fprintf(stderr, "%s\n", "-> running LZP/ARI encoding...");
    }

    /* reserve space for block header */
    data_block_resize(ob, sizeof(block_header));
    if(ib->m_size < 16) {
        goto CannotCompress_nojoin_nofree;
    }
    for(pos = 0; pos < 9; pos++) {
        block_header.m_firstbytes[pos] = ib->m_data[pos];
    }

    /* find escape */
    for(i = 0; i < ib->m_size; i++) {
        counter[ib->m_data[i]]++;
    }
    for(i = 1; i < 256; i++) {
        if(counter[esc] > counter[i]) {
            esc = i;
        }
    }
    block_header.m_esc = esc;

    matcher_init(&matcher);
    range_encoder_init(&coder);

    /* start thread (matching first block) */
    match_nextpos = pos;
    thread_args.m_pos = &match_nextpos;
    thread_args.m_iblock = ib;
    thread_args.m_matcher = &matcher;
    thread_args.m_lens = match_lens[0]; lzmatch_thread(&thread_args);
    thread_args.m_lens = match_lens[1]; pthread_create(&thread, 0, (void*)lzmatch_thread, &thread_args);

    while(pos < ib->m_size) {
        if(print_information) {
            update_progress(pos, ib->m_size);
        }

        /* find match */
        if(match_retindex >= M_match_rets_size) { /* start the next matching thread */
            pthread_join(thread, 0);
            thread_args.m_lens = match_lens[match_retn];
            pthread_create(&thread, 0, (void*)lzmatch_thread, &thread_args);
            match_retindex = 0;
            match_retn = 1 - match_retn;
        }
        match_len = match_lens[match_retn][match_retindex++];

        /* encode a (esc+len) or a single literal */
        if(match_len > 1) {
            ppm_encode(&coder, &m.ppm_model, esc, ob);
            ppm_update_context(&m.ppm_model, esc);
            ppm_encode(&coder, &m.ppm_model, match_len, ob);

        } else {
            ppm_encode(&coder, &m.ppm_model, ib->m_data[pos], ob);
            if(ib->m_data[pos] == esc) {
                ppm_update_context(&m.ppm_model, esc);
                ppm_encode(&coder, &m.ppm_model, 0, ob);
            }
        }

        while(match_len > 0) { /* update context */
            ppm_update_context(&m.ppm_model, ib->m_data[pos]);
            pos++;
            match_len--;
        }

        if(ob->m_size >= ib->m_size) { /* cannot compress */
            goto CannotCompress;
        }
    }
    pthread_join(thread, 0);
    matcher_free(&matcher);
    range_encoder_flush(&coder, ob);

    /* set block header */
    block_header.m_compressed = 1;
    block_header.m_original_size = ib->m_size;
    memcpy(ob->m_data, &block_header, sizeof(block_header));
    return;

CannotCompress:
    pthread_join(thread, NULL);
    matcher_free(&matcher);

CannotCompress_nojoin_nofree:
    data_block_resize(ob, sizeof(block_header) + ib->m_size);
    memset(ob->m_data, 0, sizeof(block_header));
    for(i = 0; i < ib->m_size; i++) {
        ob->m_data[sizeof(block_header) + i] = ib->m_data[i];
    }
    return;
}