void wsplayer_t::delegate_step()
{
    incer_t<int> hld_thinking(thinking);

	field=game().field();
	root=item_ptr(new item_t(*this,field.back()));

	ObjectProgress::log_generator lg(true);

	init_states();

	try
	{
		root->process_deep_common();
	}
	catch(e_cancel&)
	{
		lg<<"canceled";
        hld_thinking.reset();
        throw;
	}

	if(!root->get_wins().empty())
	{
		unsigned int depth=root->get_chain_depth()-1;
		std::string chain=print_chain(root->get_wins().get_best());
		lg<<"wsplayer_t::delegate_step(): find win chain_depth="<<depth<<": "<<chain;
	}
	if(!root->get_fails().empty() && root->get_neitrals().empty())lg<<"wsplayer_t::delegate_step(): find fail chain_depth="<<(root->get_chain_depth()-1)
		<<": "<<print_chain(root->get_fails().get_best());

	point p=*root->get_next_step();
    game().OnNextStep(*this,p);
}
Exemple #2
0
static cl_error_t post(int fd, int result, const char *virname, void *context)
{
    struct clamscan_cb_data *d = context;
    struct metachain *c;
    char str[128];

    UNUSEDPARAM(fd);
    UNUSEDPARAM(result);

    if (d != NULL)
        c = d->chain;

    if (c && c->nchains) {
        print_chain(c, str, sizeof(str));

        if (c->level == c->lastadd && !virname)
            free(c->chains[--c->nchains]);

        if (virname && !c->lastvir)
            c->lastvir = c->level;
    }

    if (c)
        c->level--;

    return CL_CLEAN;
}
Exemple #3
0
int main ()
{
    freopen ("aplusb.in", "rt", stdin);
    freopen ("aplusb.out", "wt", stdout);

    chain a, b, c;
    read_chain (a);
    read_chain (b);

    double x = eval_chain (a);
    double y = eval_chain (b);
    if (x < 0 || y < 0)
    {
        printf ("Impossible");
        return 0;
    }
    x += y;
    for (c.n = 1; c.n <= 7; c.n++)
    {
        for (c.k = 0; c.k < c.n; c.k++)
        {
            for (int i = 0; i <= c.n; i++)
                c.d[i] = 1;
            while (true)
            {
                double r = eval_chain (c);
                if (r < x - EPS)
                {
                    int v = isint (x - r);
                    if (v >= 0)
                    {
                        c.d[0] += v;
                        print_chain (c);
                        return 0;
                    }
                }
                int cur = c.n;
                while (cur > 0 && c.d[cur] == 10)
                    c.d[cur] = 1, cur--;
                if (cur <= 0)
                    break;
                c.d[cur]++;
            }
        }
    }
    printf ("Impossible");

    return 0;
}
Exemple #4
0
static cl_error_t post(int fd, int result, const char *virname, void *context)
{
    struct metachain *c = context;
    if (c && c->n) {
	char str[128];
	int toolong = print_chain(c, str, sizeof(str));
	if (c->level == c->lastadd && !virname)
	    free(c->chains[--c->n]);
	if (virname && !c->lastvir)
	    c->lastvir = c->level;
    }
    if (c)
	c->level--;
    return CL_CLEAN;
}
int init_module()
{
  nfho.hook = hook_func;
  nfho.hooknum = NF_INET_PRE_ROUTING;
  nfho.pf = PF_INET;
  nfho.priority = NF_IP_PRI_FIRST;
 
  udp_capture_chain_head = create_chain(buffer_len); 
  
  udp_capture_chain_cur = udp_capture_chain_head;
  
  print_chain(udp_capture_chain_head); 
 
  nf_register_hook(&nfho);

  file1 = debugfs_create_file("mmap_example", 0644, NULL, NULL, &my_fops);
       
  return 0;
}
Exemple #6
0
static cl_error_t meta(const char* container_type, unsigned long fsize_container, const char *filename,
		       unsigned long fsize_real,  int is_encrypted, unsigned int filepos_container, void *context)
{
    int na = 0;
    char prev[128];
    struct metachain *c = context;
    const char *type = !strncmp(container_type,"CL_TYPE_",8) ? container_type + 8 : container_type;
    unsigned n = strlen(type) + 1 + strlen(filename) + 1;
    char *chain;
    char **chains;
    int toolong;

    if (!c)
	return CL_CLEAN;
    chain = malloc(n);
    if (!chain)
	return CL_CLEAN;
    if (!strcmp(type, "ANY"))
	snprintf(chain, n,"%s", filename);
    else
	snprintf(chain, n,"%s:%s", type, filename);
    if (c->lastadd != c->level) {
	n = c->n + 1;
	chains = realloc(c->chains, n * sizeof(*chains));
	if (!chains) {
	    free(chain);
	    return CL_CLEAN;
	}
	c->chains = chains;
	c->n = n;
	c->lastadd = c->level;
    } else {
	free(c->chains[c->n-1]);
    }
    c->chains[c->n-1] = chain;
    toolong = print_chain(c, prev, sizeof(prev));
    logg("*Scanning %s%s!%s\n", prev,toolong ? "..." : "", chain);
    return CL_CLEAN;
}
Exemple #7
0
static void consensus(args_t *args)
{
    htsFile *fasta = hts_open(args->ref_fname, "rb");
    if ( !fasta ) error("Error reading %s\n", args->ref_fname);
    kstring_t str = {0,0,0};
    while ( hts_getline(fasta, KS_SEP_LINE, &str) > 0 )
    {
        if ( str.s[0]=='>' )
        {
            // new sequence encountered, apply all chached variants
            while ( args->vcf_rbuf.n )
            {
                if (args->chain) {
                    print_chain(args);
                    destroy_chain(args);
                }
                bcf1_t *rec = args->vcf_buf[args->vcf_rbuf.f];
                if ( rec->rid!=args->rid || ( args->fa_end_pos && rec->pos > args->fa_end_pos ) ) break;
                int i = rbuf_shift(&args->vcf_rbuf);
                apply_variant(args, args->vcf_buf[i]);
            }
            flush_fa_buffer(args, 0);
            init_region(args, str.s+1);
            continue;
        }
        args->fa_length  += str.l;
        args->fa_src_pos += str.l;

        // determine if uppercase or lowercase is used in this fasta file
        if ( args->fa_case==-1 ) args->fa_case = toupper(str.s[0])==str.s[0] ? 1 : 0;

        if ( args->mask && args->rid>=0) mask_region(args, str.s, str.l);
        kputs(str.s, &args->fa_buf);

        bcf1_t **rec_ptr = NULL;
        while ( args->rid>=0 && (rec_ptr = next_vcf_line(args)) )
        {
            bcf1_t *rec = *rec_ptr;

            // still the same chr and the same region? if not, fasta buf can be flushed
            if ( rec->rid!=args->rid || ( args->fa_end_pos && rec->pos > args->fa_end_pos ) )
            {
                // save the vcf record until next time and flush
                unread_vcf_line(args, rec_ptr);
                rec_ptr = NULL;
                break;
            }

            // is the vcf record well beyond cached fasta buffer? if yes, the buf can be flushed
            if ( args->fa_ori_pos + args->fa_buf.l - args->fa_mod_off <= rec->pos )
            {
                unread_vcf_line(args, rec_ptr);
                rec_ptr = NULL;
                break;
            }

            // is the cached fasta buffer full enough? if not, read more fasta, no flushing
            if ( args->fa_ori_pos + args->fa_buf.l - args->fa_mod_off < rec->pos + rec->rlen )
            {
                unread_vcf_line(args, rec_ptr);
                break;
            }
            apply_variant(args, rec);
        }
        if ( !rec_ptr ) flush_fa_buffer(args, 60);
    }
    if (args->chain) {
        print_chain(args);
        destroy_chain(args);
    }
    flush_fa_buffer(args, 0);
    hts_close(fasta);
    free(str.s);
}
Exemple #8
0
static void scanfile(const char *filename, struct cl_engine *engine, const struct optstruct *opts, unsigned int options)
{
    int ret = 0, fd, included;
    unsigned i;
    const struct optstruct *opt;
    const char *virname;
    STATBUF sb;
    struct metachain chain;
    struct clamscan_cb_data data;

    if((opt = optget(opts, "exclude"))->enabled) {
        while(opt) {
            if(match_regex(filename, opt->strarg) == 1) {
                if(!printinfected)
                    logg("~%s: Excluded\n", filename);

                return;
            }

            opt = opt->nextarg;
        }
    }

    if((opt = optget(opts, "include"))->enabled) {
        included = 0;

        while(opt) {
            if(match_regex(filename, opt->strarg) == 1) {
                included = 1;
                break;
            }

            opt = opt->nextarg;
        }

        if(!included) {
            if(!printinfected)
                logg("~%s: Excluded\n", filename);

            return;
        }
    }

    /* argh, don't scan /proc files */
    if(CLAMSTAT(filename, &sb) != -1) {
#ifdef C_LINUX
        if(procdev && sb.st_dev == procdev) {
            if(!printinfected)
                logg("~%s: Excluded (/proc)\n", filename);

            return;
        }
#endif    
        if(!sb.st_size) {
            if(!printinfected)
                logg("~%s: Empty file\n", filename);

            return;
        }

        info.rblocks += sb.st_size / CL_COUNT_PRECISION;
    }

#ifndef _WIN32
    if(geteuid()) {
        if(checkaccess(filename, NULL, R_OK) != 1) {
            if(!printinfected)
                logg("~%s: Access denied\n", filename);

            info.errors++;
            return;
        }
    }
#endif

    memset(&chain, 0, sizeof(chain));
    if(optget(opts, "archive-verbose")->enabled) {
        chain.chains = malloc(sizeof(char **));
        if (chain.chains) {
            chain.chains[0] = strdup(filename);
            if (!chain.chains[0]) {
                free(chain.chains);
                logg("Unable to allocate memory in scanfile()\n");
                info.errors++;
                return;
            }
            chain.nchains = 1;
        }
    }

    logg("*Scanning %s\n", filename);

    if((fd = safe_open(filename, O_RDONLY|O_BINARY)) == -1) {
        logg("^Can't open file %s: %s\n", filename, strerror(errno));
        info.errors++;
        return;
    }

    data.chain = &chain;
    data.filename = filename;
    if((ret = cl_scandesc_callback(fd, &virname, &info.blocks, engine, options, &data)) == CL_VIRUS) {
        if(optget(opts, "archive-verbose")->enabled) {
            if (chain.nchains > 1) {
                char str[128];
                int toolong = print_chain(&chain, str, sizeof(str));

                logg("~%s%s!(%llu)%s: %s FOUND\n", str, toolong ? "..." : "", (long long unsigned)(chain.lastvir-1), chain.chains[chain.nchains-1], virname);
            } else if (chain.lastvir) {
                logg("~%s!(%llu): %s FOUND\n", filename, (long long unsigned)(chain.lastvir-1), virname);
            }
        }
        info.files++;
        info.ifiles++;

        if(bell)
            fprintf(stderr, "\007");
    } else if(ret == CL_CLEAN) {
        if(!printinfected && printclean)
            mprintf("~%s: OK\n", filename);

        info.files++;
    } else {
        if(!printinfected)
            logg("~%s: %s ERROR\n", filename, cl_strerror(ret));

        info.errors++;
    }

    for (i=0;i<chain.nchains;i++)
        free(chain.chains[i]);

    free(chain.chains);
    close(fd);

    if(ret == CL_VIRUS && action)
        action(filename);
}
Exemple #9
0
static cl_error_t meta(const char* container_type, unsigned long fsize_container, const char *filename,
    unsigned long fsize_real,  int is_encrypted, unsigned int filepos_container, void *context)
{
    char prev[128];
    struct metachain *c;
    struct clamscan_cb_data *d;
    const char *type;
    size_t n;
    char *chain;
    char **chains;
    int toolong;

    UNUSEDPARAM(fsize_container);
    UNUSEDPARAM(fsize_real);
    UNUSEDPARAM(is_encrypted);
    UNUSEDPARAM(filepos_container);

    if (!(context))
        return CL_CLEAN;
    d = (struct clamscan_cb_data *)context;

    c = d->chain;
    type = (strncmp(container_type, "CL_TYPE_", 8) == 0 ? container_type + 8 : container_type);
    n = strlen(type) + strlen(filename) + 2;

    if (!c)
        return CL_CLEAN;

    chain = malloc(n);

    if (!chain)
        return CL_CLEAN;

    if (!strcmp(type, "ANY"))
        snprintf(chain, n,"%s", filename);
    else
        snprintf(chain, n,"%s:%s", type, filename);

    if (c->lastadd != c->level) {
        n = c->nchains + 1;

        chains = realloc(c->chains, n * sizeof(*chains));
        if (!chains) {
            free(chain);
            return CL_CLEAN;
        }

        c->chains = chains;
        c->nchains = n;
        c->lastadd = c->level;
    } else {
        if (c->nchains > 0)
            free(c->chains[c->nchains-1]);
    }

    if (c->nchains > 0) {
        c->chains[c->nchains-1] = chain;
        toolong = print_chain(c, prev, sizeof(prev));
        logg("*Scanning %s%s!%s\n", prev,toolong ? "..." : "", chain);
    } else {
        free(chain);
    }

    return CL_CLEAN;
}
Exemple #10
0
/* print hash table contents */
void print(FILE* outfp, struct hash_table *table )
{
  int i;
  for( i = 0; i < table->size; i++ )
    print_chain(outfp, table->chain[i] );
}