Пример #1
0
int main(int argc, char *argv[]) {

	// init

	util_init();
	my_random_init(); // for opening book

	printf(
		"Gambit Fruit based on Fruit 2.1 and Toga by Ryan Benitez, Thomas Gaksch and Fabien Letouzey\nEdit by Evgeniy Zheltonozhskiy\n");

	// early initialisation (the rest is done after UCI options are parsed in protocol.cpp)

	option_init();

	square_init();
	piece_init();
	pawn_init_bit();
	value_init();
	vector_init();
	attack_init();
	move_do_init();

	random_init();
	hash_init();

	trans_init(Trans);
	book_init();

	// loop
	loop();

	return EXIT_SUCCESS;
}
Пример #2
0
int main(int argc, char * argv[]) {

   // init

   util_init();
   my_random_init(); // for opening book

   printf("Toga II 1.2.1a UCI based on Fruit 2.1 by Thomas Gaksch and Fabien Letouzey. Settings by Dieter Eberle\n");

   // early initialisation (the rest is done after UCI options are parsed in protocol.cpp)

   option_init();

   square_init();
   piece_init();
   pawn_init_bit();
   value_init();
   vector_init();
   attack_init();
   move_do_init();

   random_init();
   hash_init();

   trans_init(Trans);
   book_init();

   // loop

   loop();

   return EXIT_SUCCESS;
}
Пример #3
0
int main(void) {

	// Initialize the OSS-7 Stack
	system_init();

	// Currently we address the Transport Layer, this should go to an upper layer once it is working.
	trans_init();
	trans_set_tx_callback(&tx_callback);
	// The initial Tca for the CSMA-CA in
	trans_set_initial_t_ca(200);

	event.next_event = SEND_INTERVAL_MS;
	event.f = &start_tx;

	log_print_string("endpoint started");

	timer_add_event(&event);

	// Log the device id
	log_print_data(device_id, 8);

	system_watchdog_init(WDTSSEL0, 0x03);
	system_watchdog_timer_start();

	while(1)
	{
		if (add_tx_event)
		{
			add_tx_event = false;
			timer_add_event(&event);
		}

		system_lowpower_mode(3,1);
	}
}
Пример #4
0
/**
 * @brief Upgrade a specified list of packages.
 *
 * @param targets a list of packages (as strings) to upgrade
 *
 * @return 0 on success, 1 on failure
 */
int pacman_upgrade(alpm_list_t *targets)
{
	alpm_list_t *i;
	alpm_siglevel_t level = alpm_option_get_default_siglevel(config->handle);

	if(targets == NULL) {
		pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
		return 1;
	}

	/* Check for URL targets and process them
	 */
	for(i = targets; i; i = alpm_list_next(i)) {
		if(strstr(i->data, "://")) {
			char *str = alpm_fetch_pkgurl(config->handle, i->data);
			if(str == NULL) {
				pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n",
						(char *)i->data, alpm_strerror(alpm_errno(config->handle)));
				return 1;
			} else {
				free(i->data);
				i->data = str;
			}
		}
	}

	/* Step 1: create a new transaction */
	if(trans_init(config->flags, 1) == -1) {
		return 1;
	}

	printf(_("loading packages...\n"));
	/* add targets to the created transaction */
	for(i = targets; i; i = alpm_list_next(i)) {
		char *targ = alpm_list_getdata(i);
		alpm_pkg_t *pkg;

		if(alpm_pkg_load(config->handle, targ, 1, level, &pkg) != 0) {
			pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n",
					targ, alpm_strerror(alpm_errno(config->handle)));
			trans_release();
			return 1;
		}
		if(alpm_add_pkg(config->handle, pkg) == -1) {
			pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n",
					targ, alpm_strerror(alpm_errno(config->handle)));
			alpm_pkg_free(pkg);
			trans_release();
			return 1;
		}
		config->explicit_adds = alpm_list_add(config->explicit_adds, pkg);
	}

	/* now that targets are resolved, we can hand it all off to the sync code */
	return sync_prepare_execute();
}
Пример #5
0
/**
 * @brief Modify the 'local' package database.
 *
 * @param targets a list of packages (as strings) to modify
 *
 * @return 0 on success, 1 on failure
 */
int pacman_database(alpm_list_t *targets)
{
	alpm_list_t *i;
	alpm_db_t *db_local;
	int retval = 0;
	alpm_pkgreason_t reason;

	if(targets == NULL) {
		pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
		return 1;
	}

	if(config->flags & ALPM_TRANS_FLAG_ALLDEPS) { /* --asdeps */
		reason = ALPM_PKG_REASON_DEPEND;
	} else if(config->flags & ALPM_TRANS_FLAG_ALLEXPLICIT) { /* --asexplicit */
		reason = ALPM_PKG_REASON_EXPLICIT;
	} else {
		pm_printf(ALPM_LOG_ERROR, _("no install reason specified (use -h for help)\n"));
		return 1;
	}

	/* Lock database */
	if(trans_init(0, 0) == -1) {
		return 1;
	}

	db_local = alpm_option_get_localdb(config->handle);
	for(i = targets; i; i = alpm_list_next(i)) {
		char *pkgname = i->data;
		alpm_pkg_t *pkg = alpm_db_get_pkg(db_local, pkgname);
		if(!pkg || alpm_db_set_pkgreason(config->handle, pkg, reason)) {
			pm_printf(ALPM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"),
							pkgname, alpm_strerror(alpm_errno(config->handle)));
			retval = 1;
		} else {
			if(reason == ALPM_PKG_REASON_DEPEND) {
				printf(_("%s: install reason has been set to 'installed as dependency'\n"), pkgname);
			} else {
				printf(_("%s: install reason has been set to 'explicitly installed'\n"), pkgname);
			}
		}
	}

	/* Unlock database */
	if(trans_release() == -1) {
		return 1;
	}
	return retval;
}
Пример #6
0
void
lrt_start(void)
{  
  uart_write(uart_addr, "In int\n", 7);
  
  lrt_mem_init();

  lrt_trans_init();

  trans_init();

  struct testObj **id = (struct testObj **)EBBIdAlloc();
  EBBIdBind((EBBId)id, testMissFunc, 0);

  EBBId_DREF(id)->ft->foo(EBBId_DREF(id));

  uart_write(uart_addr, "In int\n", 7);
}
Пример #7
0
void main()
{
	// Initialize RobotNet stack
	hal_init();
	mac_init();
	trans_init();

	// Main loop
	while (1)
	{
		// Keep stack rolling
		mac_FSM();

		// Deal with newly frame?
		if ( trans_frm_avail() )
		{
			trans_frm_parse();
		}
	}
}
Пример #8
0
int main(void) {
	// Initialize the OSS-7 Stack
	system_init();

	// Currently we address the Transport Layer for RX, this should go to an upper layer once it is working.
	trans_init();
	trans_set_query_rx_callback(&rx_callback);
	trans_set_tx_callback(&tx_callback);
	// The initial Tca for the CSMA-CA in
	trans_set_initial_t_ca(200);

	start_channel_scan = true;

	log_print_string("gateway started");

	// Log the device id
	log_print_data(device_id, 8);

	// configure blinking led event
	dim_led_event.next_event = 50;
	dim_led_event.f = &dim_led;

	system_watchdog_init(WDTSSEL0, 0x03);
	system_watchdog_timer_start();

	blink_led();

	while(1)
	{
		if (start_channel_scan)
		{
			start_rx();
		}

		// Don't know why but system reboots when LPM > 1 since ACLK is uses for UART
		system_lowpower_mode(0,1);
	}
}
Пример #9
0
/**
 * Initialize the CDiameterPeer from a configuration file.
 * The file is kept as dtd. See configdtd.h for the DTD and ConfigExample.xml.
 * @param cfg_filename - file with the configuration
 * @returns 1 on success, 0 on error
 */
int diameter_peer_init(char *cfg_filename)
{	
	pid_list_t *i,*j;

	config = parse_dp_config(cfg_filename);
	if (!config) {
		LOG(L_ERR,"ERROR:init_diameter_peer(): Error loading configuration file. Aborting...\n");
		goto error;
	}
	log_dp_config(L_INFO,config);
	
	dp_first_pid = shm_malloc(sizeof(pid_t));
	if (!dp_first_pid){
		LOG_NO_MEM("shm",sizeof(pid_t));
		goto error;
	}
	*dp_first_pid = getpid();
	
	shutdownx = shm_malloc(sizeof(int));
	if (!shutdownx){
		LOG_NO_MEM("shm",sizeof(int));
		goto error;
	}
	*shutdownx = 0;
	
	shutdownx_lock = lock_alloc();
	if (!shutdownx_lock){
		LOG_NO_MEM("shm",sizeof(gen_lock_t));
		goto error;
	}
	shutdownx_lock = lock_init(shutdownx_lock);

	handlers_lock = lock_alloc();
	if (!handlers_lock){
		LOG_NO_MEM("shm",sizeof(gen_lock_t));
		goto error;
	}
	handlers_lock = lock_init(handlers_lock);

	handlers = shm_malloc(sizeof(handler_list));
	if (!handlers){
		LOG_NO_MEM("shm",sizeof(handler_list));
		goto error;
	}
	handlers->head=0;
	handlers->tail=0;

	/* init the pid list */
	pid_list = shm_malloc(sizeof(pid_list_head_t));
	pid_list_lock = lock_alloc();
	pid_list_lock = lock_init(pid_list_lock);

	/* init shared mem pointers before forking */
	timer_cdp_init();
	worker_init();

	/* init the peer manager */
	peer_manager_init(config);
	
	/* init the msg_handler */
	//msg_timer_init();
	
	/* init the session */
	if (!session_init()) goto error;
	
#ifdef CDP_FOR_SER
	/* init diameter transactions */
	trans_init();
	
	/* add callback for messages - used to implement the API */
	cb_add(api_callback,0);
		
#endif

/***********
Added by Vitalis to initialize the transactions

**********/
	/* init diameter transactions */
	trans_init();
	
	/* add callback for messages - used to implement the API */
	cb_add(api_callback,0);

/*******End of addition ***********/

	
	return 1;
	
error:
	if (shutdownx) shm_free(shutdownx);
	if (config) free_dp_config(config);
	i = pid_list->head;
	while(i){
		j = i->next;
		shm_free(i);
		i = j;
	}
	shm_free(pid_list);
	lock_get(pid_list_lock);
	lock_destroy(pid_list_lock);
	lock_dealloc((void*)pid_list_lock);
	return 0;	

}
Пример #10
0
/**
 * Main routine, start of the program execution.
 * \param argc the number of arguments
 * \param argv pointer to the arguments array
 * \return don't return on sucess, -1 on error
 * \see main_loop
 */
int main(int argc, char** argv)
{
    /* configure by default logging to syslog */
    int cfg_log_stderr = 0;
    FILE* cfg_stream;
    int c,r;
    char *tmp;
    int tmp_len;
    int port;
    int proto;
    char *options;
    int ret;
    unsigned int seed;
    int rfd;

    /*init*/
    ret=-1;
    my_argc=argc;
    my_argv=argv;

    /* process pkg mem size from command line */
    opterr=0;
    options="f:cCm:M:b:l:n:N:rRvdDFETSVhw:t:u:g:P:G:W:o:";

    while((c=getopt(argc,argv,options))!=-1) {
        switch(c) {
        case 'M':
            pkg_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
            if (tmp &&(*tmp)) {
                LM_ERR("bad pkgmem size number: -m %s\n", optarg);
                goto error00;
            };

            break;
        }
    }
    /*init pkg mallocs (before parsing cfg but after parsing cmd line !)*/
    if (init_pkg_mallocs()==-1)
        goto error00;

    init_route_lists();

    /* process command line (get port no, cfg. file path etc) */
    /* first reset getopt */
    optind = 1;
    while((c=getopt(argc,argv,options))!=-1) {
        switch(c) {
        case 'f':
            cfg_file=optarg;
            break;
        case 'C':
            config_check |= 2;
        case 'c':
            if (config_check==3)
                break;
            config_check |= 1;
            cfg_log_stderr=1; /* force stderr logging */
            break;
        case 'm':
            shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
            if (tmp &&(*tmp)) {
                LM_ERR("bad shmem size number: -m %s\n", optarg);
                goto error00;
            };

            break;
        case 'M':
            /* ignoring it, parsed previously */

            break;
        case 'b':
            maxbuffer=strtol(optarg, &tmp, 10);
            if (tmp &&(*tmp)) {
                LM_ERR("bad max buffer size number: -b %s\n", optarg);
                goto error00;
            }
            break;
        case 'l':
            if (parse_phostport(optarg, strlen(optarg), &tmp, &tmp_len,
                                &port, &proto)<0) {
                LM_ERR("bad -l address specifier: %s\n", optarg);
                goto error00;
            }
            tmp[tmp_len]=0; /* null terminate the host */
            /* add a new addr. to our address list */
            if (add_cmd_listener(tmp, port, proto)!=0) {
                LM_ERR("failed to add new listen address\n");
                goto error00;
            }
            break;
        case 'n':
            children_no=strtol(optarg, &tmp, 10);
            if ((tmp==0) ||(*tmp)) {
                LM_ERR("bad process number: -n %s\n", optarg);
                goto error00;
            }
            break;
        case 'v':
            check_via=1;
            break;
        case 'r':
            received_dns|=DO_DNS;
            break;
        case 'R':
            received_dns|=DO_REV_DNS;
        case 'd':
            (*debug)++;
            break;
        case 'D':
            dont_fork=1;
            break;
        case 'F':
            no_daemon_mode=1;
            break;
        case 'E':
            cfg_log_stderr=1;
            break;
        case 'N':
            tcp_children_no=strtol(optarg, &tmp, 10);
            if ((tmp==0) ||(*tmp)) {
                LM_ERR("bad process number: -N %s\n", optarg);
                goto error00;
            }
            break;
        case 'W':
            io_poll_method=get_poll_type(optarg);
            if (io_poll_method==POLL_NONE) {
                LM_ERR("bad poll method name: -W %s\ntry "
                       "one of %s.\n", optarg, poll_support);
                goto error00;
            }
            break;
        case 'V':
            printf("version: %s\n", version);
            printf("flags: %s\n", flags );
            print_ct_constants();
            printf("%s compiled on %s with %s\n", __FILE__,
                   compiled, COMPILER );

            exit(0);
            break;
        case 'h':
            printf("version: %s\n", version);
            printf("%s",help_msg);
            exit(0);
            break;
        case 'w':
            working_dir=optarg;
            break;
        case 't':
            chroot_dir=optarg;
            break;
        case 'u':
            user=optarg;
            break;
        case 'g':
            group=optarg;
            break;
        case 'P':
            pid_file=optarg;
            break;
        case 'G':
            pgid_file=optarg;
            break;
        case 'o':
            if (add_arg_var(optarg) < 0)
                LM_ERR("cannot add option %s\n", optarg);
            break;
        case '?':
            if (isprint(optopt))
                LM_ERR("Unknown option `-%c`.\n", optopt);
            else
                LM_ERR("Unknown option character `\\x%x`.\n", optopt);
            goto error00;
        case ':':
            LM_ERR("Option `-%c` requires an argument.\n", optopt);
            goto error00;
        default:
            abort();
        }
    }

    log_stderr = cfg_log_stderr;

    /* fill missing arguments with the default values*/
    if (cfg_file==0) cfg_file=CFG_FILE;

    /* load config file or die */
    cfg_stream=fopen (cfg_file, "r");
    if (cfg_stream==0) {
        LM_ERR("loading config file(%s): %s\n", cfg_file,
               strerror(errno));
        goto error00;
    }

    /* seed the prng, try to use /dev/urandom if possible */
    /* no debugging information is logged, because the standard
       log level prior the config file parsing is L_NOTICE */
    seed=0;
    if ((rfd=open("/dev/urandom", O_RDONLY))!=-1) {
try_again:
        if (read(rfd, (void*)&seed, sizeof(seed))==-1) {
            if (errno==EINTR) goto try_again; /* interrupted by signal */
            LM_WARN("could not read from /dev/urandom (%d)\n", errno);
        }
        LM_DBG("initialize the pseudo random generator from "
               "/dev/urandom\n");
        LM_DBG("read %u from /dev/urandom\n", seed);
        close(rfd);
    } else {
        LM_WARN("could not open /dev/urandom (%d)\n", errno);
        LM_WARN("using a unsafe seed for the pseudo random number generator");
    }
    seed+=getpid()+time(0);
    LM_DBG("seeding PRNG with %u\n", seed);
    srand(seed);
    LM_DBG("test random number %u\n", rand());

    /*register builtin  modules*/
    register_builtin_modules();

    if (preinit_black_lists()!=0) {
        LM_CRIT("failed to alloc black list's anchor\n");
        goto error00;
    }

    /* init avps */
    if (init_global_avps() != 0) {
        LM_ERR("error while initializing avps\n");
        goto error;
    }

    /* used for parser debugging */
#ifdef DEBUG_PARSER
    yydebug = 1;
#endif

    /*
     * initializes transport interfaces - we initialize them here because we
     * can have listening interfaces declared in the command line
     */
    if (trans_init() < 0) {
        LM_ERR("cannot initialize transport interface\n");
        goto error;
    }

    /* parse the config file, prior to this only default values
       e.g. for debugging settings will be used */
    yyin=cfg_stream;
    if ((yyparse()!=0)||(cfg_errors)) {
        LM_ERR("bad config file (%d errors)\n", cfg_errors);
        goto error00;
    }

    if (config_check>1 && check_rls()!=0) {
        LM_ERR("bad function call in config file\n");
        return ret;
    }
#ifdef EXTRA_DEBUG
    print_rl();
#endif

    if (no_daemon_mode+dont_fork > 1) {
        LM_ERR("cannot use -D (fork=no) and -F together\n");
        return ret;
    }

    /* init the resolver, before fixing the config */
    resolv_init();

    fix_poll_method( &io_poll_method );

    /* fix temporary listeners added in the cmd line */
    if (fix_cmd_listeners() < 0) {
        LM_ERR("cannot add temproray listeners\n");
        return ret;
    }

    /* load transport protocols */
    if (trans_load() < 0) {
        LM_ERR("cannot load transport protocols\n");
        goto error;
    }

    /* fix parameters */
    if (working_dir==0) working_dir="/";

    /* get uid/gid */
    if (user) {
        if (user2uid(&uid, &gid, user)<0) {
            LM_ERR("bad user name/uid number: -u %s\n", user);
            goto error00;
        }
    }
    if (group) {
        if (group2gid(&gid, group)<0) {
            LM_ERR("bad group name/gid number: -u %s\n", group);
            goto error00;
        }
    }
    if (fix_all_socket_lists()!=0) {
        LM_ERR("failed to initialize list addresses\n");
        goto error00;
    }
    /* print all the listen addresses */
    printf("Listening on \n");
    print_all_socket_lists();
    printf("Aliases: \n");
    /*print_aliases();*/
    print_aliases();
    printf("\n");

    if (dont_fork) {
        LM_WARN("no fork mode %s\n",
                (protos[PROTO_UDP].listeners)?(
                    (protos[PROTO_UDP].listeners->next)?" and more than one listen"
                    " address found(will use only the first one)":""
                ):"and no udp listen address found" );
    }
    if (config_check) {
        LM_NOTICE("config file ok, exiting...\n");
        return 0;
    }

    time(&startup_time);

    /*init shm mallocs
     *  this must be here
     *     -to allow setting shm mem size from the command line
     *       => if shm_mem should be settable from the cfg file move
     *       everything after
     *     -it must be also before init_timer and init_tcp
     *     -it must be after we know uid (so that in the SYSV sems case,
     *        the sems will have the correct euid)
     * --andrei */
    if (init_shm_mallocs()==-1)
        goto error;

    /* Init statistics */
    if (init_stats_collector()<0) {
        LM_ERR("failed to initialize statistics\n");
        goto error;
    }

    init_shm_statistics();

    /*init UDP networking layer*/
    if (udp_init()<0) {
        LM_CRIT("could not initialize tcp, exiting...\n");
        goto error;
    }
    /*init TCP networking layer*/
    if (tcp_init()<0) {
        LM_CRIT("could not initialize tcp, exiting...\n");
        goto error;
    }

    /* init_daemon? */
    if (!dont_fork) {
        if ( daemonize((log_name==0)?argv[0]:log_name, &own_pgid) <0 )
            goto error;
    }

    /* install signal handlers */
    if (install_sigs() != 0) {
        LM_ERR("could not install the signal handlers\n");
        goto error;
    }

    if (disable_core_dump) set_core_dump(0, 0);
    else set_core_dump(1, shm_mem_size+pkg_mem_size+4*1024*1024);
    if (open_files_limit>0) {
        if(increase_open_fds(open_files_limit)<0) {
            LM_ERR("ERROR: error could not increase file limits\n");
            goto error;
        }
    }

    /* print OpenSIPS version to log for history tracking */
    LM_NOTICE("version: %s\n", version);

    /* print some data about the configuration */
    LM_INFO("using %ld Mb shared memory\n", ((shm_mem_size/1024)/1024));
    LM_INFO("using %ld Mb private memory per process\n",
            ((pkg_mem_size/1024)/1024));

    /* init timer */
    if (init_timer()<0) {
        LM_CRIT("could not initialize timer, exiting...\n");
        goto error;
    }

    /* init serial forking engine */
    if (init_serialization()!=0) {
        LM_ERR("failed to initialize serialization\n");
        goto error;
    }
    /* Init MI */
    if (init_mi_core()<0) {
        LM_ERR("failed to initialize MI core\n");
        goto error;
    }

    /* Register core events */
    if (evi_register_core() != 0) {
        LM_ERR("failed register core events\n");
        goto error;
    }

    /* init black list engine */
    if (init_black_lists()!=0) {
        LM_CRIT("failed to init blacklists\n");
        goto error;
    }
    /* init resolver's blacklist */
    if (resolv_blacklist_init()!=0) {
        LM_CRIT("failed to create DNS blacklist\n");
        goto error;
    }

    /* init modules */
    if (init_modules() != 0) {
        LM_ERR("error while initializing modules\n");
        goto error;
    }

    /* register route timers */
    if(register_route_timers() < 0) {
        LM_ERR("Failed to register timer\n");
        goto error;
    }

    /* check pv context list */
    if(pv_contextlist_check() != 0) {
        LM_ERR("used pv context that was not defined\n");
        goto error;
    }

    /* init query list now in shm
     * so all processes that will be forked from now on
     * will have access to it
     *
     * if it fails, give it a try and carry on */
    if (init_ql_support() != 0) {
        LM_ERR("failed to initialise buffering query list\n");
        query_buffer_size = 0;
        *query_list = NULL;
    }

    /* init multi processes support */
    if (init_multi_proc_support()!=0) {
        LM_ERR("failed to init multi-proc support\n");
        goto error;
    }

#ifdef PKG_MALLOC
    /* init stats support for pkg mem */
    if (init_pkg_stats(counted_processes)!=0) {
        LM_ERR("failed to init stats for pkg\n");
        goto error;
    }
#endif

    /* init avps */
    if (init_extra_avps() != 0) {
        LM_ERR("error while initializing avps\n");
        goto error;
    }

    /* fix routing lists */
    if ( (r=fix_rls())!=0) {
        LM_ERR("failed to fix configuration with err code %d\n", r);
        goto error;
    };

    ret=main_loop();

error:
    /*kill everything*/
    kill_all_children(SIGTERM);
    /*clean-up*/
    cleanup(0);
error00:
    return ret;
}
Пример #11
0
/**
 * @brief Upgrade a specified list of packages.
 *
 * @param targets a list of packages (as strings) to upgrade
 *
 * @return 0 on success, 1 on failure
 */
int pacman_upgrade(alpm_list_t *targets)
{
	alpm_list_t *i, *data = NULL;
	pgp_verify_t check_sig = alpm_option_get_default_sigverify(config->handle);
	int retval = 0;

	if(targets == NULL) {
		pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
		return 1;
	}

	/* Check for URL targets and process them
	 */
	for(i = targets; i; i = alpm_list_next(i)) {
		if(strstr(i->data, "://")) {
			char *str = alpm_fetch_pkgurl(config->handle, i->data);
			if(str == NULL) {
				pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
						(char *)i->data, alpm_strerror(alpm_errno(config->handle)));
				return 1;
			} else {
				free(i->data);
				i->data = str;
			}
		}
	}

	/* Step 1: create a new transaction */
	if(trans_init(config->flags) == -1) {
		return 1;
	}

	/* add targets to the created transaction */
	for(i = targets; i; i = alpm_list_next(i)) {
		char *targ = alpm_list_getdata(i);
		pmpkg_t *pkg;

		if(alpm_pkg_load(config->handle, targ, 1, check_sig, &pkg) != 0) {
			pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
					targ, alpm_strerror(alpm_errno(config->handle)));
			trans_release();
			return 1;
		}
		if(alpm_add_pkg(config->handle, pkg) == -1) {
			pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
					targ, alpm_strerror(alpm_errno(config->handle)));
			alpm_pkg_free(pkg);
			trans_release();
			return 1;
		}
	}

	/* Step 2: "compute" the transaction based on targets and flags */
	/* TODO: No, compute nothing. This is stupid. */
	if(alpm_trans_prepare(config->handle, &data) == -1) {
		enum _pmerrno_t err = alpm_errno(config->handle);
		pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
		        alpm_strerror(err));
		switch(err) {
			case PM_ERR_PKG_INVALID_ARCH:
				for(i = data; i; i = alpm_list_next(i)) {
					char *pkg = alpm_list_getdata(i);
					printf(_(":: package %s does not have a valid architecture\n"), pkg);
				}
				break;
			case PM_ERR_UNSATISFIED_DEPS:
				for(i = data; i; i = alpm_list_next(i)) {
					pmdepmissing_t *miss = alpm_list_getdata(i);
					char *depstring = alpm_dep_compute_string(miss->depend);

					/* TODO indicate if the error was a virtual package or not:
					 *		:: %s: requires %s, provided by %s
					 */
					printf(_(":: %s: requires %s\n"), miss->target, depstring);
					free(depstring);
				}
				break;
			case PM_ERR_CONFLICTING_DEPS:
				for(i = data; i; i = alpm_list_next(i)) {
					pmconflict_t *conflict = alpm_list_getdata(i);
					if(strcmp(conflict->package1, conflict->reason) == 0 ||
							strcmp(conflict->package2, conflict->reason) == 0) {
						printf(_(":: %s and %s are in conflict\n"),
								conflict->package1, conflict->package2);
					} else {
						printf(_(":: %s and %s are in conflict (%s)\n"),
								conflict->package1, conflict->package2, conflict->reason);
					}
				}
				break;
			default:
				break;
		}
		trans_release();
		FREELIST(data);
		return 1;
	}

	/* Step 3: perform the installation */
	alpm_list_t *packages = alpm_trans_get_add(config->handle);

	if(config->print) {
		print_packages(packages);
		trans_release();
		return 0;
	}

	/* print targets and ask user confirmation */
	if(packages == NULL) { /* we are done */
		printf(_(" there is nothing to do\n"));
		trans_release();
		return retval;
	}
	display_targets(alpm_trans_get_remove(config->handle), 0);
	display_targets(alpm_trans_get_add(config->handle), 1);
	printf("\n");
	int confirm = yesno(_("Proceed with installation?"));
	if(!confirm) {
		trans_release();
		return retval;
	}

	if(alpm_trans_commit(config->handle, &data) == -1) {
		enum _pmerrno_t err = alpm_errno(config->handle);
		pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
				alpm_strerror(err));
		switch(err) {
			case PM_ERR_FILE_CONFLICTS:
				for(i = data; i; i = alpm_list_next(i)) {
					pmfileconflict_t *conflict = alpm_list_getdata(i);
					switch(conflict->type) {
						case PM_FILECONFLICT_TARGET:
							printf(_("%s exists in both '%s' and '%s'\n"),
									conflict->file, conflict->target, conflict->ctarget);
							break;
						case PM_FILECONFLICT_FILESYSTEM:
							printf(_("%s: %s exists in filesystem\n"),
									conflict->target, conflict->file);
							break;
					}
				}
				break;
			case PM_ERR_PKG_INVALID:
			case PM_ERR_DLT_INVALID:
				for(i = data; i; i = alpm_list_next(i)) {
					char *filename = alpm_list_getdata(i);
					printf(_("%s is invalid or corrupted\n"), filename);
				}
				break;
			default:
				break;
		}
		FREELIST(data);
		trans_release();
		return 1;
	}

	if(trans_release() == -1) {
		retval = 1;
	}
	return retval;
}
Пример #12
0
/**
 * @brief Upgrade a specified list of packages.
 *
 * @param targets a list of packages (as strings) to upgrade
 *
 * @return 0 on success, 1 on failure
 */
int pacman_upgrade(alpm_list_t *targets)
{
	int retval = 0;
	alpm_list_t *i, *j, *remote = NULL;

	if(targets == NULL) {
		pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
		return 1;
	}

	/* Check for URL targets and process them
	 */
	for(i = targets; i; i = alpm_list_next(i)) {
		int *r = malloc(sizeof(int));

		if(strstr(i->data, "://")) {
			char *str = alpm_fetch_pkgurl(config->handle, i->data);
			if(str == NULL) {
				pm_printf(ALPM_LOG_ERROR, "'%s': %s\n",
						(char *)i->data, alpm_strerror(alpm_errno(config->handle)));
				retval = 1;
			} else {
				free(i->data);
				i->data = str;
				*r = 1;
			}
		} else {
			*r = 0;
		}

		remote = alpm_list_add(remote, r);
	}

	if(retval) {
		return retval;
	}

	/* Step 1: create a new transaction */
	if(trans_init(config->flags, 1) == -1) {
		return 1;
	}

	printf(_("loading packages...\n"));
	/* add targets to the created transaction */
	for(i = targets, j = remote; i; i = alpm_list_next(i), j = alpm_list_next(j)) {
		const char *targ = i->data;
		alpm_pkg_t *pkg;
		alpm_siglevel_t level;

		if(*(int *)j->data) {
			level = alpm_option_get_remote_file_siglevel(config->handle);
		} else {
			level = alpm_option_get_local_file_siglevel(config->handle);
		}

		if(alpm_pkg_load(config->handle, targ, 1, level, &pkg) != 0) {
			pm_printf(ALPM_LOG_ERROR, "'%s': %s\n",
					targ, alpm_strerror(alpm_errno(config->handle)));
			retval = 1;
			continue;
		}
		if(alpm_add_pkg(config->handle, pkg) == -1) {
			pm_printf(ALPM_LOG_ERROR, "'%s': %s\n",
					targ, alpm_strerror(alpm_errno(config->handle)));
			alpm_pkg_free(pkg);
			retval = 1;
			continue;
		}
		config->explicit_adds = alpm_list_add(config->explicit_adds, pkg);
	}

	FREELIST(remote);

	if(retval) {
		trans_release();
		return retval;
	}

	/* now that targets are resolved, we can hand it all off to the sync code */
	return sync_prepare_execute();
}
Пример #13
0
/**
 * @brief Upgrade a specified list of packages.
 *
 * @param targets a list of packages (as strings) to upgrade
 *
 * @return 0 on success, 1 on failure
 */
int pacman_upgrade(alpm_list_t *targets)
{
    int retval = 0, *file_is_remote;
    alpm_list_t *i;
    unsigned int n, num_targets;

    if(targets == NULL) {
        pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
        return 1;
    }

    num_targets = alpm_list_count(targets);

    /* Check for URL targets and process them */
    file_is_remote = malloc(num_targets * sizeof(int));
    if(file_is_remote == NULL) {
        pm_printf(ALPM_LOG_ERROR, _("memory exhausted\n"));
        return 1;
    }

    for(i = targets, n = 0; i; i = alpm_list_next(i), n++) {
        if(strstr(i->data, "://")) {
            char *str = alpm_fetch_pkgurl(config->handle, i->data);
            if(str == NULL) {
                pm_printf(ALPM_LOG_ERROR, "'%s': %s\n",
                          (char *)i->data, alpm_strerror(alpm_errno(config->handle)));
                retval = 1;
            } else {
                free(i->data);
                i->data = str;
                file_is_remote[n] = 1;
            }
        } else {
            file_is_remote[n] = 0;
        }
    }

    if(retval) {
        goto fail_free;
    }

    /* Step 1: create a new transaction */
    if(trans_init(config->flags, 1) == -1) {
        retval = 1;
        goto fail_free;
    }

    printf(_("loading packages...\n"));
    /* add targets to the created transaction */
    for(i = targets, n = 0; i; i = alpm_list_next(i), n++) {
        const char *targ = i->data;
        alpm_pkg_t *pkg;
        int siglevel;

        if(file_is_remote[n]) {
            siglevel = alpm_option_get_remote_file_siglevel(config->handle);
        } else {
            siglevel = alpm_option_get_local_file_siglevel(config->handle);
        }

        if(alpm_pkg_load(config->handle, targ, 1, siglevel, &pkg) != 0) {
            pm_printf(ALPM_LOG_ERROR, "'%s': %s\n",
                      targ, alpm_strerror(alpm_errno(config->handle)));
            retval = 1;
            continue;
        }
        if(alpm_add_pkg(config->handle, pkg) == -1) {
            pm_printf(ALPM_LOG_ERROR, "'%s': %s\n",
                      targ, alpm_strerror(alpm_errno(config->handle)));
            alpm_pkg_free(pkg);
            retval = 1;
            continue;
        }
        config->explicit_adds = alpm_list_add(config->explicit_adds, pkg);
    }

    if(retval) {
        goto fail_release;
    }

    free(file_is_remote);

    /* now that targets are resolved, we can hand it all off to the sync code */
    return sync_prepare_execute();

fail_release:
    trans_release();
fail_free:
    free(file_is_remote);

    return retval;
}
Пример #14
0
/**
 * @brief Remove a specified list of packages.
 *
 * @param targets a list of packages (as strings) to remove from the system
 *
 * @return 0 on success, 1 on failure
 */
int pacman_remove(alpm_list_t *targets)
{
    int retval = 0;
    alpm_list_t *i, *data = NULL;

    if(targets == NULL) {
        pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
        return(1);
    }

    /* Step 0: create a new transaction */
    if(trans_init(PM_TRANS_TYPE_REMOVE, config->flags) == -1) {
        return(1);
    }

    /* Step 1: add targets to the created transaction */
    for(i = targets; i; i = alpm_list_next(i)) {
        char *targ = alpm_list_getdata(i);
        if(alpm_trans_addtarget(targ) == -1) {
            if(pm_errno == PM_ERR_PKG_NOT_FOUND) {
                printf(_("%s not found, searching for group...\n"), targ);
                pmgrp_t *grp = alpm_db_readgrp(db_local, targ);
                if(grp == NULL) {
                    pm_fprintf(stderr, PM_LOG_ERROR, _("'%s': not found in local db\n"), targ);
                    retval = 1;
                    goto cleanup;
                } else {
                    alpm_list_t *p, *pkgnames = NULL;
                    /* convert packages to package names */
                    for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
                        pmpkg_t *pkg = alpm_list_getdata(p);
                        pkgnames = alpm_list_add(pkgnames, (void *)alpm_pkg_get_name(pkg));
                    }
                    printf(_(":: group %s:\n"), targ);
                    list_display("   ", pkgnames);
                    int all = yesno(1, _("    Remove whole content?"));
                    for(p = pkgnames; p; p = alpm_list_next(p)) {
                        char *pkgn = alpm_list_getdata(p);
                        if(all || yesno(1, _(":: Remove %s from group %s?"), pkgn, targ)) {
                            if(alpm_trans_addtarget(pkgn) == -1) {
                                pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ,
                                           alpm_strerrorlast());
                                retval = 1;
                                alpm_list_free(pkgnames);
                                goto cleanup;
                            }
                        }
                    }
                    alpm_list_free(pkgnames);
                }
            } else {
                pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast());
                retval = 1;
                goto cleanup;
            }
        }
    }

    /* Step 2: prepare the transaction based on its type, targets and flags */
    if(alpm_trans_prepare(&data) == -1) {
        pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
                   alpm_strerrorlast());
        switch(pm_errno) {
        case PM_ERR_UNSATISFIED_DEPS:
            for(i = data; i; i = alpm_list_next(i)) {
                pmdepmissing_t *miss = alpm_list_getdata(i);
                pmdepend_t *dep = alpm_miss_get_dep(miss);
                char *depstring = alpm_dep_get_string(dep);
                printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
                       depstring);
                free(depstring);
            }
            FREELIST(data);
            break;
        default:
            break;
        }
        retval = 1;
        goto cleanup;
    }

    /* Warn user in case of dangerous operation */
    if(config->flags & PM_TRANS_FLAG_RECURSE ||
            config->flags & PM_TRANS_FLAG_CASCADE) {
        /* list transaction targets */
        alpm_list_t *pkglist = alpm_trans_get_pkgs();

        display_targets(pkglist, 0);
        printf("\n");

        /* get confirmation */
        if(yesno(1, _("Do you want to remove these packages?")) == 0) {
            retval = 1;
            goto cleanup;
        }
    }

    /* Step 3: actually perform the removal */
    if(alpm_trans_commit(NULL) == -1) {
        pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
                   alpm_strerrorlast());
        retval = 1;
    }

    /* Step 4: release transaction resources */
cleanup:
    if(trans_release() == -1) {
        retval = 1;
    }
    return(retval);
}
Пример #15
0
int main(int argc, char * argv[])
{
	const char *BoolValue[2] = { "false", "true" };
    printf("Mars V0.3 UCCI based on Fruit 2.1 by Fabien Letouzey\n");
	printf("作者:顾剑辉\n");
    printf("网站:www.jsmaster.com\n");
	printf("请键入ucci指令......\n");
    //position fen rnbakab2/9/2c1c1n2/p1p1p3p/6p2/2PN3r1/P3P1P1P/1C2C1N2/9/1RBAKAB1R w - - 0 7   
	//position fen 1rbakab2/9/1cn5n/pR4p1p/2p1p4/4c1P2/P1P4rP/2N1C1NC1/4A4/2B1KABR1 w - - 0 10
	//9/3ka4/3R5/5r2p/p5p2/4N4/P5P1P/9/4A2c1/2BK2B2 b - - 0 36
	CommEnum IdleComm;
	CommDetail Command;
	int move,n;
	undo_t undo[1];
 
	if(BootLine() == e_CommUcci)
	{

		zobrist_gen();
	    pre_move_gen();
	    trans_init(Trans);
	    trans_alloc(Trans);
        material_init();
        material_alloc(); 
		OutFile = stdout;
        board_from_fen("rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR r - - 0 1");
		//board_from_fen("3k5/9/9/9/9/4c4/9/9/4n4/4K4 r - - 0 1");
		//board_from_fen("3k5/9/9/9/9/4c4/3C5/2n1n4/4K4/9 r - - 0 1");
		printf("position fen rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR r - - 0 1\n\n");
		print_board();
		printf("\n");
		printf("id name Mars v0.3\n");
		fflush(stdout);
		printf("id copyright 版权所有(C) 2005-2008\n");
		fflush(stdout);
		printf("id author 顾剑辉\n");
		fflush(stdout);
		printf("id user 未知\n\n");
		fflush(stdout);
/*
				printf("option batch type check default %s\n", BoolValue[ThisSearch.bBatch]);
		fflush(stdout);

		// option debug 让引擎输出详细的搜索信息,并非真正的调试模式。
		printf("option debug type check default %s\n", BoolValue[ThisSearch.Debug]);
		fflush(stdout);

		// 指定开局库文件的名称,可指定多个开局库文件,用分号“;”隔开,如不让引擎使用开局库,可以把值设成空
		ThisSearch.bUseOpeningBook = ThisSearch.m_Hash.LoadBook(BookFile);
		if(ThisSearch.bUseOpeningBook)
			printf("option bookfiles type string default %s\n", BookFile);
		else
			printf("option bookfiles type string default %s\n", 0);
		fflush(stdout);

		// 残局库名称
		printf("option egtbpaths type string default null\n");
		fflush(stdout);

		// 显示Hash表的大小
		printf("option hashsize type spin default %d MB\n", ThisSearch.m_Hash.nHashSize*2*sizeof(CHashRecord)/1024/1024);
		fflush(stdout);

		// 引擎的线程数
		printf("option threads type spin default %d\n", 0);
		fflush(stdout);

		// 引擎达到自然限着的半回合数
		printf("option drawmoves type spin default %d\n", ThisSearch.NaturalBouts);
		fflush(stdout);

		// 棋规
		printf("option repetition type spin default %d 1999年版《中国象棋竞赛规则》\n", e_RepetitionChineseRule);
		fflush(stdout);

		// 空着裁减是否打开
		printf("option pruning type check %d\n", ThisSearch);
		fflush(stdout);

		// 估值函数的使用情况
		printf("option knowledge type check %d\n", ThisSearch);
		fflush(stdout);

		// 指定选择性系数,通常有0,1,2,3四个级别。给估值函数加减一定范围内的随机数,让引擎每次走出不相同的棋。
		printf("option selectivity type spin min 0 max 3 default %d\n", ThisSearch.nSelectivity);
		fflush(stdout);

		// 指定下棋的风格,通常有solid(保守)、normal(均衡)和risky(冒进)三种
		printf("option style type combo var solid var normal var risky default %s\n", ChessStyle[ThisSearch.nStyle]);
		fflush(stdout);		
*/
		// copyprotection 显示版权检查信息(正在检查,版权信息正确或版权信息错误)。 
		printf("copyprotection ok\n\n");
		fflush(stdout);

		// ucciok 这是ucci指令的最后一条反馈信息,表示引擎已经进入用UCCI协议通讯的状态。
		printf("ucciok\n\n");
		fflush(stdout);
        
		//FILE * out=fopen("info.txt","w+");
		do 
		{
			IdleComm = IdleLine(Command, 0);
			switch (IdleComm) 
			{
				// isready 检测引擎是否处于就绪状态,其反馈信息总是readyok,该指令仅仅用来检测引擎的“指令接收缓冲区”是否能正常容纳指令。
				// readyok 表明引擎处于就绪状态(即可接收指令的状态),不管引擎处于空闲状态还是思考状态。
				case e_CommIsReady:
					//fprintf(out,"readyok\n");
					printf("readyok\n");
					fflush(stdout);
					break;

				// stop 中断引擎的思考,强制出着。后台思考没有命中时,就用该指令来中止思考,然后重新输入局面。
				case e_CommStop:
					//ThisSearch.bStopThinking = 1;
					printf("nobestmove\n");
					printf("score 0\n");
					fflush(stdout);
					break;

				// position fen 设置“内置棋盘”的局面,用fen来指定FEN格式串,moves后面跟的是随后走过的着法
				case e_CommPosition:
					// 将界面传来的Fen串转化为棋局信息
					// board_clear();
					//fprintf(out,"%s\n",Command.Position.FenStr);
                    //fprintf(out,"%d",Command.Position.MoveNum);
					//fprintf(out,"%s\n",Command.Position.CoordList);
					 //trans_clear(Trans);
					 board_from_fen(Command.Position.FenStr);
					 print_board();
					 for(n=0; n<Command.Position.MoveNum; n++)
					{
						move = move_from_string(Command.Position.CoordList[n]);
						//fprintf(out,"%x ",move);
						if( !move )
							break;

						move_do(move,undo);
						//ThisSearch.StepRecords[ThisSearch.nCurrentStep-1] |= ThisSearch.Checking(ThisSearch.Player) << 24;
					}
					// 将局面走到当前,主要是为了更新着法记录,用于循环检测。
					break;

				// banmoves 为当前局面设置禁手,以解决引擎无法处理的长打问题。当出现长打局面时,棋手可以操控界面向引擎发出禁手指令。
				case e_CommBanMoves:
					break;

				// setoption 设置引擎各种参数
				case e_CommSetOption:
					switch(Command.Option.Type) 
					{
						// setoption batch %d
						case e_OptionBatch:
							batch=(Command.Option.Value.Check == e_CheckTrue);
							printf("option batch type check default %s\n", BoolValue[batch]);
							fflush(stdout);
							break;

						// setoption debug %d 让引擎输出详细的搜索信息,并非真正的调试模式。
						case e_OptionDebug:
							
							break;

						// setoption bookfiles %s  指定开局库文件的名称,可指定多个开局库文件,用分号“;”隔开,如不让引擎使用开局库,可以把值设成空
						case e_OptionBookFiles:
							
							break;

						// setoption egtbpaths %s  指定残局库文件的名称,可指定多个残局库路径,用分号“;”隔开,如不让引擎使用残局库,可以把值设成空
						case e_OptionEgtbPaths:
							// 引擎目前不支持开局库
							
							break;

						// setoption hashsize %d  以MB为单位规定Hash表的大小,-1表示让引擎自动分配Hash表。1~1024MB
						// 象堡界面有个Bug,每次设置引擎时,这个命令应在开局库的前面
						case e_OptionHashSize:
							// -1MB(自动), 0MB(自动), 1MB(16), 2MB(17), 4MB(18), 8MB(19), 16MB(20), 32MB(21), 64MB(22), 128MB(23), 256MB(24), 512MB(25), 1024MB(26)
							if( Command.Option.Value.Spin <= 0)
								n = 22;		// 缺省情况下,引擎自动分配(1<<22)*16=64MB,红与黑两各表,双方各一半。
							else
							{
								n = 15;											// 0.5 MB = 512 KB 以此为基数
								while( Command.Option.Value.Spin > 0 )
								{
									Command.Option.Value.Spin >>= 1;			// 每次除以2,直到为0
									n ++;
								}
							}								

							break;

						// setoption threads %d	      引擎的线程数,为多处理器并行运算服务
						case e_OptionThreads:
							// ThisSearch.nThreads = Command.Option.Value.Spin;		// 0(auto),1,2,4,8,16,32
							printf("option drawmoves type spin default %d\n", 0);
							fflush(stdout);
							break;

						// setoption drawmoves %d	  达到自然限着的回合数:50,60,70,80,90,100,象堡已经自动转化为半回合数
						case e_OptionDrawMoves:
							
							break;

						// setoption repetition %d	  处理循环的棋规,目前只支持“中国象棋棋规1999”
						case e_OptionRepetition:
							// ThisSearch.nRepetitionStyle = Command.Option.Value.Repetition;
							// e_RepetitionAlwaysDraw  不变作和
							// e_RepetitionCheckBan    禁止长将
							// e_RepetitionAsianRule   亚洲规则
							// e_RepetitionChineseRule 中国规则(缺省)
							
							break;

						// setoption pruning %d,“空着向前裁剪”是否打开
						case e_OptionPruning:
							//ThisSearch.bPruning = Command.Option.Value.Scale;
							//printf("option pruning type check %d\n", ThisSearch);
							//fflush(stdout);
							break;

						// setoption knowledge %d,估值函数的使用
						case e_OptionKnowledge:
							//ThisSearch.bKnowledge = Command.Option.Value.Scale;
							//printf("option knowledge type check %d\n", ThisSearch);
							//fflush(stdout);
							break;

						// setoption selectivity %d  指定选择性系数,通常有0,1,2,3四个级别
						case e_OptionSelectivity:
							/*switch (Command.Option.Value.Scale)
							{
								case e_ScaleNone:
									ThisSearch.SelectMask = 0;
									break;
								case e_ScaleSmall:
									ThisSearch.SelectMask = 1;
									break;
								case e_ScaleMedium:
									ThisSearch.SelectMask = 3;
									break;
								case e_ScaleLarge:
									ThisSearch.SelectMask = 7;
									break;
								default:
									ThisSearch.SelectMask = 0;
									break;
							}
							printf("option selectivity type spin min 0 max 3 default %d\n", ThisSearch.SelectMask);
							fflush(stdout);*/
							break;

						// setoption style %d  指定下棋的风格,通常有solid(保守)、normal(均衡)和risky(冒进)三种
						case e_OptionStyle:
							//ThisSearch.nStyle = Command.Option.Value.Style;
							//printf("option style type combo var solid var normal var risky default %s\n", ChessStyle[Command.Option.Value.Style]);
							//fflush(stdout);
							break;						

						// setoption loadbook  UCCI界面ElephantBoard在每次新建棋局时都会发送这条指令
						case e_OptionLoadBook:
							/*ThisSearch.m_Hash.ClearHashTable();
							ThisSearch.bUseOpeningBook = ThisSearch.m_Hash.LoadBook(BookFile);
							
							if(ThisSearch.bUseOpeningBook)
								printf("option loadbook succeed. %s\n", BookFile);		// 成功
							else
								printf("option loadbook failed! %s\n", "Not found file BOOK.DAT");				// 没有开局库
							fflush(stdout);
							printf("\n\n");
							fflush(stdout);
							*/
							break;

						default:
							break;
					}
					break;

				// Prepare timer strategy according to "go depth %d" or "go ponder depth %d" command
				case e_CommGo:
				case e_CommGoPonder:
					switch (Command.Search.Mode)
					{
						// 固定深度Command.Search.DepthTime.Depth
						case e_TimeDepth:
							ponder = 2;
							search(Command.Search.DepthTime.Depth,0,0);
							break;

						// 时段制: 分配时间 = 剩余时间 / 要走的步数
						case e_TimeMove:
							ponder = (IdleComm == e_CommGoPonder ? 1 : 0);
							search(32,Command.Search.DepthTime.Time * 1000 / Command.Search.TimeMode.MovesToGo, Command.Search.DepthTime.Time * 1000);
						//	ThisSearch.Ponder = (IdleComm == e_CommGoPonder ? 1 : 0);
						//	printf("%d\n", Command.Search.TimeMode.MovesToGo);
						//	ThisSearch.MainSearch(127, Command.Search.DepthTime.Time * 1000 / Command.Search.TimeMode.MovesToGo, Command.Search.DepthTime.Time * 1000);
							break;

						// 加时制: 分配时间 = 每步增加的时间 + 剩余时间 / 20 (即假设棋局会在20步内结束)
						case e_TimeInc:
                            ponder = (IdleComm == e_CommGoPonder ? 1 : 0);
							search(32,(Command.Search.DepthTime.Time + Command.Search.TimeMode.Increment * 20) * 1000 / 20, Command.Search.DepthTime.Time * 1000);
						 //	ThisSearch.Ponder = (IdleComm == e_CommGoPonder ? 1 : 0);
						 //	ThisSearch.MainSearch(127, (Command.Search.DepthTime.Time + Command.Search.TimeMode.Increment * 20) * 1000 / 20, Command.Search.DepthTime.Time * 1000);
							break;

						default:
							break;
					}
					break;
			}
		} while (IdleComm != e_CommQuit);
        //fprintf(out,"bye");
		//fclose(out);
		printf("bye\n");
		fflush(stdout);
		//getchar();
	}
Пример #16
0
void c4_init()
{
  trans_init();
}
Пример #17
0
/**
 * @brief Remove a specified list of packages.
 *
 * @param targets a list of packages (as strings) to remove from the system
 *
 * @return 0 on success, 1 on failure
 */
int pacman_remove(alpm_list_t *targets)
{
	int retval = 0;
	alpm_list_t *i, *data = NULL;

	if(targets == NULL) {
		pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
		return 1;
	}

	/* Step 0: create a new transaction */
	if(trans_init(config->flags, 0) == -1) {
		return 1;
	}

	/* Step 1: add targets to the created transaction */
	for(i = targets; i; i = alpm_list_next(i)) {
		char *target = i->data;
		if(strncmp(target, "local/", 6) == 0) {
			target += 6;
		}
		if(remove_target(target) == -1) {
			retval = 1;
		}
	}

	if(retval == 1) {
		goto cleanup;
	}

	/* Step 2: prepare the transaction based on its type, targets and flags */
	if(alpm_trans_prepare(config->handle, &data) == -1) {
		alpm_errno_t err = alpm_errno(config->handle);
		pm_printf(ALPM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
		        alpm_strerror(err));
		switch(err) {
			case ALPM_ERR_UNSATISFIED_DEPS:
				for(i = data; i; i = alpm_list_next(i)) {
					alpm_depmissing_t *miss = i->data;
					char *depstring = alpm_dep_compute_string(miss->depend);
					colon_printf(_("%s: requires %s\n"), miss->target, depstring);
					free(depstring);
					alpm_depmissing_free(miss);
				}
				break;
			default:
				break;
		}
		alpm_list_free(data);
		retval = 1;
		goto cleanup;
	}

	/* Search for holdpkg in target list */
	int holdpkg = 0;
	for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) {
		alpm_pkg_t *pkg = i->data;
		if(alpm_list_find(config->holdpkg, alpm_pkg_get_name(pkg), fnmatch_cmp)) {
			pm_printf(ALPM_LOG_WARNING, _("%s is designated as a HoldPkg.\n"),
							alpm_pkg_get_name(pkg));
			holdpkg = 1;
		}
	}
	if(holdpkg && (noyes(_("HoldPkg was found in target list. Do you want to continue?")) == 0)) {
		retval = 1;
		goto cleanup;
	}

	/* Step 3: actually perform the removal */
	alpm_list_t *pkglist = alpm_trans_get_remove(config->handle);
	if(pkglist == NULL) {
		printf(_(" there is nothing to do\n"));
		goto cleanup; /* we are done */
	}

	if(config->print) {
		print_packages(pkglist);
		goto cleanup;
	}

	/* print targets and ask user confirmation */
	display_targets();
	printf("\n");
	if(yesno(_("Do you want to remove these packages?")) == 0) {
		retval = 1;
		goto cleanup;
	}

	if(alpm_trans_commit(config->handle, &data) == -1) {
		pm_printf(ALPM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
		        alpm_strerror(alpm_errno(config->handle)));
		retval = 1;
	}

	FREELIST(data);

	/* Step 4: release transaction resources */
cleanup:
	if(trans_release() == -1) {
		retval = 1;
	}
	return retval;
}
Пример #18
0
void
l0_start(uintptr_t startInfo)
{
  trans_init();
  EBB_init(startInfo);
}