コード例 #1
0
ファイル: huge.c プロジェクト: lucab/gtk-gnutella
	if (alt != NULL) {
		dmesh_collect_fw_hosts(sha1, alt);
	}
}

/**
 * Initialize the HUGE layer.
 */
void
huge_init(void)
{
	sha1_cache = hikset_create(		/* Keys are atoms */
		offsetof(struct sha1_cache_entry, file_name), HASH_KEY_SELF, 0);
	sha1_read_cache();
	has_http_urls = pattern_compile("http://");
}

/**
 * Free SHA1 cache entry.
 */
static void
cache_free_entry(void *v, void *unused_udata)
{
	struct sha1_cache_entry *e = v;

	(void) unused_udata;

	atom_str_free_null(&e->file_name);
	atom_sha1_free_null(&e->sha1);
	atom_tth_free_null(&e->tth);
コード例 #2
0
ファイル: search.c プロジェクト: megabajt/poldek
static int search(struct cmdctx *cmdctx)
{
    struct poclidek_ctx   *cctx = NULL;
    tn_array               *pkgs = NULL;
    tn_array               *matched_pkgs = NULL;
    int                    i, err = 0, display_bar = 0, bar_v;
    int                    term_height;
    struct pattern         *pt;
    unsigned               flags;
    
    if ((pt = cmdctx->_data) == NULL) {
        logn(LOGERR, _("search: no pattern given"));
        err++;
        goto l_end;
    }
    cmdctx->_data = NULL;            /* we'll free pattern myself */

    cctx = cmdctx->cctx;
    
    flags = cmdctx->_flags;
    flags &= ~OPT_NO_SEARCHSW;
    if (flags == 0)
        cmdctx->_flags |= OPT_SEARCH_DEFAULT;
    
    init_pcre();
    if (!pattern_compile(pt, poldek_ts_get_arg_count(cmdctx->ts))) {
        err++;
        goto l_end;
    }

    poclidek_load_packages(cmdctx->cctx, POCLIDEK_LOAD_ALL);
    if (poldek_ts_get_arg_count(cmdctx->ts) == 0) {
        pkgs = poclidek_get_dent_packages(cctx, NULL);
        
    } else {
        pkgs = poclidek_resolve_packages(NULL, cctx, cmdctx->ts, 0);
    }
    
    if (pkgs == NULL)
        return 0;
    
    matched_pkgs = n_array_new(32, NULL, NULL);

    if (n_array_size(pkgs) > 5 && (cmdctx->_flags & OPT_SEARCH_HDD)) {
        display_bar = 1;
        msg(0, _("Searching packages..."));
    }
    bar_v = 0;
    
    for (i=0; i < n_array_size(pkgs); i++) {
        struct pkg *pkg = n_array_nth(pkgs, i);
        
        if (pkg_match(pkg, pt, cmdctx->_flags)) 
            n_array_push(matched_pkgs, pkg);
        
        if (display_bar) {
            int v, j;
            
            v = i * 40 / n_array_size(pkgs);
            for (j = bar_v; j < v; j++)
                msg(0, "_.");
            bar_v = v;
        }
        
        if (sigint_reached()) {
            msgn(0, _("_interrupted."));
            goto l_end;
        }
    }
    
    if (display_bar) 
        msgn(0, _("_done."));

    term_height = poldek_term_get_height();
    if (n_array_size(matched_pkgs) == 0) 
        cmdctx_printf_c(cmdctx, PRCOLOR_YELLOW, "!No package matches '%s'\n",
                        pt->regexp);
    
    else if (n_array_size(matched_pkgs) < term_height)
        cmdctx_printf_c(cmdctx, PRCOLOR_YELLOW, "!%d package(s) found:\n",
                        n_array_size(matched_pkgs));
    
        
    for (i=0; i<n_array_size(matched_pkgs); i++) {
        struct pkg *pkg;

        pkg = n_array_nth(matched_pkgs, i);
        cmdctx_addtoresult(cmdctx, pkg);
        cmdctx_printf(cmdctx, "%s\n", pkg_id(pkg));
    }

    if (n_array_size(matched_pkgs) >= term_height)
        cmdctx_printf_c(cmdctx, PRCOLOR_YELLOW, "!%d package(s) found.\n",
                        n_array_size(matched_pkgs));
        
l_end:

    if (pkgs)
        n_array_free(pkgs);
    
    if (matched_pkgs)
        n_array_free(matched_pkgs);
    
    if (cmdctx->_data)
        cmdctx->_data = NULL;
    
    if (pt)
        pattern_free(pt);
    return 1;
}