Ejemplo n.º 1
0
void set_option(char *line)
{
    char name[64];
    char value[64];
    char *find_value;

    strip(line);
    if( strlen(line) > 64 ) return;

    strcpy(name, line+15);
    find_value = strstr(line, " value ");
    if(find_value)
    {
        strcpy(value, find_value+7);
        name[strlen(line+15)-strlen(value)-7] = '\0';
    }
    else
    {
        value[0] = '\0';
    }

    if(strcmp(name, "Personality") == 0)
    {
        set_personality_name( value );
    }
    else if(strcmp(name, "Min Time") == 0)
    {
        set_min_time( value );
    }
    else if(strcmp(name, "Max Time") == 0)
    {
        set_max_time( value );
    }
    else if(strcmp(name, "Hash") == 0)
    {
        set_hash( value );
    }
    /* setoption name <id> [value <x>]
    	this is sent to the engine when the user wants to change the internal parameters
    	of the engine. For the "button" type no value is needed.
    	One string will be sent for each parameter and this will only be sent when the engine is waiting.
    	The name and value of the option in <id> should not be case sensitive and can inlude spaces.
    	The substrings "value" and "name" should be avoided in <id> and <x> to allow unambiguous parsing,
    	for example do not use <name> = "draw value".
    	Here are some strings for the example below:
    	   "setoption name Nullmove value true\n"
           "setoption name Selectivity value 3\n"
    	   "setoption name Style value Risky\n"
    	   "setoption name Clear Hash\n"
    	   "setoption name NalimovPath value c:\chess\tb\4;c:\chess\tb\5\n"
    */
}
Ejemplo n.º 2
0
bool tdata_io_v4_load(tdata_t *td, char *filename) {
    tdata_header_t h;
    tdata_header_t *header = &h;

    int fd = open(filename, O_RDONLY);
    if (fd == -1) {
        fprintf(stderr, "The input file %s could not be found.\n", filename);
        return false;
    }

    if (read (fd, header, sizeof(tdata_header_t)) != sizeof(tdata_header_t)) {
        goto fail_close_fd;
    }

    td->base = NULL;
    td->size = 0;

    if( strncmp("TTABLEV4", header->version_string, 8) ) {
        fprintf(stderr, "The input file %s does not appear to be a timetable or is of the wrong version.\n", filename);
        goto fail_close_fd;
    }

    /* More input validation in the dynamic loading case. */
    if ( !( header->n_stop_points < ((spidx_t) -2) &&
            header->n_stop_areas < ((spidx_t) -2) &&
            header->n_stop_point_attributes < ((spidx_t) -2) &&
            header->n_stop_point_coords < ((spidx_t) -2) &&
            header->n_stop_area_coords < ((spidx_t) -2) &&
            header->n_journey_patterns < ((jpidx_t) -1) &&
            header->n_journey_pattern_points < (UINT32_MAX) &&
            header->n_journey_pattern_point_attributes < (UINT32_MAX) &&
            header->n_journey_pattern_point_headsigns < (UINT32_MAX) &&
            header->n_stop_times < (UINT32_MAX) &&
            header->n_vjs < (UINT32_MAX) &&
            header->n_journey_patterns_at_stop < (UINT32_MAX) &&
            header->n_transfer_target_stops < (UINT32_MAX) &&
            header->n_transfer_durations < (UINT32_MAX) &&
            header->n_vj_active < (UINT32_MAX) &&
            header->n_journey_pattern_active < (UINT32_MAX) &&
            header->n_platformcodes < (UINT32_MAX) &&
            header->n_stop_point_nameidx < ((spidx_t) -2) &&
            header->n_stop_area_nameidx < ((spidx_t) -2) &&
            header->n_operator_ids < (UINT8_MAX) &&
            header->n_operator_names < (UINT8_MAX) &&
            header->n_operator_urls < (UINT8_MAX) &&
            header->n_string_pool < (UINT32_MAX) &&
            header->n_line_codes < (UINT16_MAX) &&
            header->n_commercial_mode_ids < (UINT16_MAX) &&
            header->n_commercial_mode_names < (UINT16_MAX) &&
            header->n_commercial_mode_for_jp < (UINT32_MAX) &&
            header->n_physical_mode_ids < (UINT16_MAX) &&
            header->n_physical_mode_names < (UINT16_MAX) &&
            header->n_physical_mode_for_line < (UINT16_MAX) &&
            header->n_stop_point_waittime < ((rtime_t) -2) &&
            header->n_vehicle_journey_transfers_backward < (UINT32_MAX) &&
            header->n_vehicle_journey_transfers_forward < (UINT32_MAX) &&
            header->n_line_ids < (UINT32_MAX) &&
            header->n_line_colors < (UINT32_MAX) &&
            header->n_line_colors_text < (UINT32_MAX) &&
            header->n_line_names < (UINT32_MAX) &&
            header->n_line_for_route < (UINT16_MAX) &&
            header->n_operator_for_line < (UINT16_MAX) &&
            header->n_stop_point_ids < ((spidx_t) -2) &&
            header->n_stop_area_ids < ((spidx_t) -2) &&
            header->n_vj_ids < (UINT32_MAX) ) &&
            header->n_vj_time_offsets < (UINT32_MAX) ) {

        fprintf(stderr, "The input file %s does not appear to be a valid timetable.\n", filename);
        goto fail_close_fd;
    }

    td->timezone = header->timezone;
    td->calendar_start_time = header->calendar_start_time;
    td->utc_offset = header->utc_offset;
    td->n_days = header->n_days;
    td->n_stop_areas = header->n_stop_areas;

    load_dynamic (fd, stop_points, stop_point_t);
    load_dynamic (fd, stop_point_attributes, uint8_t);
    load_dynamic (fd, stop_point_coords, latlon_t);
    load_dynamic (fd, stop_area_coords, latlon_t);
    load_dynamic (fd, stop_area_for_stop_point, spidx_t);
    load_dynamic (fd, journey_patterns, journey_pattern_t);
    load_dynamic (fd, journey_pattern_points, spidx_t);
    load_dynamic (fd, journey_pattern_point_attributes, uint8_t);
    load_dynamic (fd, journey_pattern_point_headsigns, uint32_t);
    load_dynamic (fd, stop_times, stoptime_t);
    load_dynamic (fd, vjs, vehicle_journey_t);
    load_dynamic (fd, journey_patterns_at_stop, jpidx_t);
    load_dynamic (fd, transfer_target_stops, spidx_t);
    load_dynamic (fd, transfer_durations, rtime_t);
    load_dynamic (fd, stop_point_waittime, rtime_t);
    load_dynamic (fd, vehicle_journey_transfers_backward, vehicle_journey_ref_t);
    load_dynamic (fd, vehicle_journey_transfers_forward, vehicle_journey_ref_t);
    load_dynamic (fd, vj_active, calendar_t);
    load_dynamic (fd, journey_pattern_active, calendar_t);
    load_dynamic (fd, string_pool, char);
    load_dynamic (fd, stop_point_nameidx, uint32_t);
    load_dynamic (fd, stop_area_nameidx, uint32_t);
    load_dynamic (fd, line_for_route, uint16_t);
    load_dynamic (fd, operator_for_line, uint8_t);
    load_dynamic (fd, commercial_mode_for_jp, uint16_t);
    load_dynamic (fd, physical_mode_for_line, uint16_t);
    load_dynamic (fd, line_codes, uint32_t);
    load_dynamic (fd, line_colors, uint32_t);
    load_dynamic (fd, line_colors_text, uint32_t);
    load_dynamic (fd, line_names, uint32_t);
    load_dynamic (fd, operator_ids, uint32_t);
    load_dynamic (fd, operator_names, uint32_t);
    load_dynamic (fd, operator_urls, uint32_t);
    load_dynamic (fd, commercial_mode_ids, uint32_t);
    load_dynamic (fd, commercial_mode_names, uint32_t);
    load_dynamic (fd, physical_mode_ids, uint32_t);
    load_dynamic (fd, physical_mode_names, uint32_t);
    load_dynamic (fd, platformcodes, uint32_t);
    load_dynamic (fd, line_ids, uint32_t);
    load_dynamic (fd, stop_point_ids, uint32_t);
    load_dynamic (fd, stop_area_ids, uint32_t);
    load_dynamic (fd, stop_area_timezones, uint32_t);
    load_dynamic (fd, vj_ids, uint32_t);
    load_dynamic (fd, vj_time_offsets, int8_t);

    set_max_time(td);
    close (fd);

    return true;

fail_close_fd:
    close (fd);

    return false;
}