예제 #1
0
void fetch_param_bool( struct param *p )
{
    const char *str_val;
    int val;
    bool_t no_val = False;

    check_assertion( p->type == PARAM_BOOL, 
		     "configuration parameter type mismatch" );

    str_val = Tcl_GetVar( g_game.tcl_interp, p->name, TCL_GLOBAL_ONLY );
    
    if ( str_val == NULL ) {
	no_val = True;
    } else if ( string_cmp_no_case( str_val, "false" ) == 0 ) {
	p->val.bool_val = False;
    } else if ( string_cmp_no_case( str_val, "true" ) == 0 ) {
	p->val.bool_val = True;
    } else if ( Tcl_GetInt( g_game.tcl_interp, str_val, &val) == TCL_ERROR ) {
	no_val = True;
    } else {
	p->val.bool_val = (val == 0) ? False : True ;
    }

    if ( no_val ) {
	p->val.bool_val = p->deflt.bool_val;
    }

    p->loaded = True;
}
예제 #2
0
/* Parse the debug parameter, fill in the debug_setting array */
void init_debug()
{
    char *debug_str, *tmp_str;
    char *p;
    int i;
    bool_t new_setting;

    for ( i=0; i<NUM_DEBUG_MODES; i++ ) {
	debug_setting[i] = False;
    }

    debug_str = getparam_debug();
    tmp_str = debug_str;

    while ( (p = strtok( tmp_str, " " )) != NULL ) {
	tmp_str = NULL;

	new_setting = True;

	if ( *p == '-' ) {
	    p++;
	    new_setting = False;

	    if ( *p == '\0' ) {
		print_warning( CONFIGURATION_WARNING, 
			       "solitary `-' in debug parameter -- ignored." );
		continue;
	    }
	}

	if ( *p == '\0' ) {
	    continue;
	}


	if ( string_cmp_no_case( p, "all" ) == 0 ) {
	    for (i=0; i<NUM_DEBUG_MODES; i++) {
		debug_setting[i] = new_setting;
	    }
	} else {
	    for ( i=0; i<NUM_DEBUG_MODES; i++ ) {
		if ( string_cmp_no_case( p, debug_desc[i] ) == 0 ) {
		    debug_setting[i] = new_setting;
		    break;
		}
	    }

	    if ( i == NUM_DEBUG_MODES ) {
		print_warning( CONFIGURATION_WARNING,
			       "unrecognized debug mode `%s'", p );
	    }
	}
    }
}
예제 #3
0
/*!
 Creates a race_data_t object from a Tcl string.
 \return  New race_data_t object if successful, or NULL if error
 \author  jfpatry
 \date    Created:  2000-09-19
 \date    Modified: 2000-09-19
 */
static
race_data_t* create_race_data ( Tcl_Interp *ip, const char *string, char **err_msg )
{
    const char **argv = NULL;
    const char **orig_argv = NULL;
    int argc = 0;

    char *course = NULL;
    char *name = NULL;
    char *description = NULL;

    int      herring_req[DIFFICULTY_NUM_LEVELS];
    bool_t   herring_req_init = False;
    scalar_t time_req[DIFFICULTY_NUM_LEVELS];
    bool_t   time_req_init = False;
    int score_req[DIFFICULTY_NUM_LEVELS];
    bool_t   score_req_init = False;

    bool_t   mirrored = False;
    race_conditions_t conditions = RACE_CONDITIONS_SUNNY;
    bool_t   windy = False;
    bool_t   snowing = False;

    race_data_t *race_data = NULL;

    if ( Tcl_SplitList( ip, string, &argc, &argv ) == TCL_ERROR ) {
        *err_msg = "race data is not a list";
        goto bail_race_data;
    }

    orig_argv = argv;

    while ( *argv != NULL ) {
        if ( strcmp( *argv, "-course" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -course in race data";
                goto bail_race_data;
            }

            course = string_copy( *argv );
        } else if ( strcmp( *argv, "-name" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -name in race data";
                goto bail_race_data;
            }

            name = string_copy( *argv );
        } else if ( strcmp( *argv, "-description" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -description in race data";
                goto bail_race_data;
            }

            description = string_copy( *argv );
        } else if ( strcmp( *argv, "-herring" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -herring in race data";
                goto bail_race_data;
            }

            if ( get_tcl_int_tuple(
                        ip, *argv, herring_req,
                        sizeof(herring_req)/sizeof(herring_req[0]) ) == TCL_ERROR )
            {
                *err_msg = "Value for -herring is not a list or has "
                           "the wrong number of elements";
                goto bail_race_data;
            }

            herring_req_init = True;
        } else if ( strcmp( *argv, "-time" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -time in race data" ;
                goto bail_race_data;
            }

            if ( get_tcl_tuple( ip, *argv, time_req,
                                sizeof(time_req)/sizeof(time_req[0]) )
                    == TCL_ERROR )
            {
                *err_msg = "Value for -time is not a list or hsa the "
                           "wrong number of elements";
                goto bail_race_data;
            }

            time_req_init = True;
        } else if ( strcmp( *argv, "-score" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -score in race data";
                goto bail_race_data;
            }

            if ( get_tcl_int_tuple( ip, *argv, score_req,
                                    sizeof(score_req)/sizeof(score_req[0]) )
                    == TCL_ERROR )
            {
                *err_msg = "Value for -score is not a list or has the "
                           "wrong number of elements";
                goto bail_race_data;
            }

            score_req_init = True;
        } else if ( strcmp( *argv, "-mirrored" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -mirrored in race data";
                goto bail_race_data;
            }

            if ( string_cmp_no_case( *argv, "yes" ) == 0 ) {
                mirrored = True;
            } else {
                mirrored = False;
            }
        } else if ( strcmp( *argv, "-conditions" ) == 0 ) {
            int i;
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -conditions in race data";
                goto bail_race_data;
            }

            for ( i=0; i<RACE_CONDITIONS_NUM_CONDITIONS; i++ ) {
                if ( string_cmp_no_case( race_condition_names[i],
                                         *argv ) == 0 )
                {
                    break;
                }
            }

            if ( i == RACE_CONDITIONS_NUM_CONDITIONS ) {
                *err_msg = "Invalid value for -conditions in race data";
                goto bail_race_data;
            }

            conditions = (race_conditions_t)i;
        } else if ( strcmp( *argv, "-windy" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -windy in race data";
                goto bail_race_data;
            }

            if ( string_cmp_no_case( *argv, "yes" ) == 0 ) {
                windy = True;
            } else {
                windy = False;
            }
        } else if ( strcmp( *argv, "-snowing" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -snowing in race data";
                goto bail_race_data;
            }

            if ( string_cmp_no_case( *argv, "yes" ) == 0 ) {
                snowing = True;
            } else {
                snowing = False;
            }
        } else {
            sprintf( err_buff, "unrecognized option `%s' in race data",
                     *argv );
            *err_msg = err_buff;
            goto bail_race_data;
        }

        NEXT_ARG;
    }

    /* Check mandatory arguments */
    if ( course == NULL ) {
        *err_msg = "No course specified in race data";
        goto bail_race_data;
    }

    if ( !herring_req_init ||
            !time_req_init ||
            !score_req_init )
    {
        *err_msg = "Must specify requirement for herring, time, and score.";
        goto bail_race_data;
    }

    /* Create new race_data_t object */

    race_data = (race_data_t*) malloc( sizeof(race_data_t) );
    check_assertion( race_data != NULL, "out of memory" );

    race_data->course = course;
    race_data->name = name;
    race_data->description = description;

    memcpy( race_data->herring_req, herring_req, sizeof(herring_req) );
    memcpy( race_data->time_req, time_req, sizeof(time_req) );
    memcpy( race_data->score_req, score_req, sizeof(score_req) );

    race_data->mirrored = mirrored;
    race_data->conditions = conditions;
    race_data->windy = windy;
    race_data->snowing = snowing;

    Tcl_Free( (char*) orig_argv );

    return race_data;

bail_race_data:

    if ( orig_argv ) {
        Tcl_Free( (char*) orig_argv );
    }

    if ( course ) {
        free( course );
    }

    if ( name ) {
        free( name );
    }

    if ( description ) {
        free( description );
    }

    if ( race_data ) {
        free( race_data );
    }

    return NULL;
}
예제 #4
0
/*!
 Creates an open_course_data_t object from a Tcl string.
 \author  jfpatry
 \date    Created:  2000-09-21
 \date    Modified: 2000-09-21
 */
open_course_data_t* create_open_course_data( Tcl_Interp *ip, const char *string,
        char **err_msg )
{
    const char **argv = NULL;
    const char **orig_argv = NULL;
    int argc = 0;

    char *course = NULL;
    char *name = NULL;
    char *description = NULL;
    race_conditions_t conditions = RACE_CONDITIONS_SUNNY;
    scalar_t par_time = 120;
    bool_t speed = True;
    bool_t score = True;

    open_course_data_t *open_course_data = NULL;

    if ( Tcl_SplitList( ip, string, &argc, &argv ) == TCL_ERROR ) {
        *err_msg = "open course data is not a list";
        goto bail_open_course_data;
    }

    orig_argv = argv;

    while ( *argv != NULL ) {
        if ( strcmp( *argv, "-course" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -course in open course data";
                goto bail_open_course_data;
            }

            course = string_copy( *argv );
        } else if ( strcmp( *argv, "-name" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -name in open course data";
                goto bail_open_course_data;
            }

            name = string_copy( *argv );
        } else if ( strcmp( *argv, "-description" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -description in open course data";
                goto bail_open_course_data;
            }

            description = string_copy( *argv );
        } else if ( strcmp( *argv, "-par_time" ) == 0 ) {
            NEXT_ARG;

            if ( *argv == NULL ) {
                par_time = 120.0;
                print_warning( PEDANTIC_WARNING,
                               "No data supplied for -par_time in open course "
                               "data.  Using %g seconds.", par_time );
            } else if ( Tcl_GetDouble( ip, *argv, &par_time ) != TCL_OK ) {
                *err_msg = "Invalid value for -par_time in open course data";
                goto bail_open_course_data;
            }
        } else if ( strcmp( *argv, "-conditions" ) == 0 ) {
            int i;
            NEXT_ARG;

            if ( *argv == NULL ) {
                *err_msg = "No data supplied for -conditions in open course data";
                goto bail_open_course_data;
            }

            for ( i=0; i<RACE_CONDITIONS_NUM_CONDITIONS; i++ ) {
                if ( string_cmp_no_case( race_condition_names[i],
                                         *argv ) == 0 )
                {
                    break;
                }
            }

            if ( i == RACE_CONDITIONS_NUM_CONDITIONS ) {
                *err_msg = "Invalid value for -conditions in race data";
                goto bail_open_course_data;
            }

            conditions = (race_conditions_t)i;

        } else if ( strcmp( *argv, "-no_speed" ) == 0 ) {
            speed = False;
        } else if ( strcmp( *argv, "-no_score" ) == 0 ) {
            score = False;
        }
        else {
            sprintf( err_buff, "unrecognized option `%s' in open course data",
                     *argv );
            *err_msg = err_buff;
            goto bail_open_course_data;
        }

        NEXT_ARG;
    }

    /* Check mandatory arguments */
    if ( course == NULL ) {
        *err_msg = "No course specified in open course data";
        goto bail_open_course_data;
    }

    if ( name == NULL ) {
        *err_msg = "No name specified in open course data";
        goto bail_open_course_data;
    }


    /* Create new open_course_data_t object */
    open_course_data = (open_course_data_t*) malloc( sizeof(open_course_data_t) );
    check_assertion( open_course_data != NULL, "out of memory" );

    open_course_data->course = course;
    open_course_data->name = name;
    open_course_data->description = description;
    open_course_data->par_time = par_time;
    open_course_data->conditions = conditions;
    open_course_data->speed = speed;
    open_course_data->score = score;

    Tcl_Free( (char*) orig_argv );

    return open_course_data;

bail_open_course_data:

    if ( orig_argv ) {
        Tcl_Free( (char*) orig_argv );
    }

    if ( course ) {
        free( course );
    }

    if ( name ) {
        free( name );
    }

    if ( description ) {
        free( description );
    }

    if ( open_course_data ) {
        free( open_course_data );
    }

    return NULL;
}