static void process_baud_rate(unsigned int target_baud_rate) { const ParameterList *full_list; ParameterList *user_list; /* create subset of full options */ full_list = Angel_FindParamList(&serpar_options, AP_BAUD_RATE); user_list = Angel_FindParamList(&user_options, AP_BAUD_RATE); if (full_list != NULL && user_list != NULL) { unsigned int i, j; unsigned int def_baud = 0; /* find lower or equal to */ for (i = 0; i < full_list->num_options; ++i) if (target_baud_rate >= full_list->option[i]) { /* copy remaining */ for (j = 0; j < (full_list->num_options - i); ++j) user_list->option[j] = full_list->option[i+j]; user_list->num_options = j; /* check this is not the default */ Angel_FindParam(AP_BAUD_RATE, &serpar_defaults, &def_baud); if ((j == 1) && (user_list->option[0] == def_baud)) { #ifdef DEBUG printf("user selected default\n"); #endif } else { user_options_set = TRUE; #ifdef DEBUG printf("user options are: "); for (j = 0; j < user_list->num_options; ++j) printf("%u ", user_list->option[j]); printf("\n"); #endif } break; /* out of i loop */ } #ifdef DEBUG if (i >= full_list->num_options) printf("couldn't match baud rate %u\n", target_baud_rate); #endif } #ifdef DEBUG else printf("failed to find lists\n"); #endif }
/* * Function: Angel_MatchParams * Purpose: find a configuration from the requested options which is * the best match from the supported options. * * see params.h for details */ const ParameterConfig *Angel_MatchParams( const ParameterOptions *requested, const ParameterOptions *supported ) { static Parameter chosen_params[AP_NUM_PARAMS]; static ParameterConfig chosen_config = { AP_NUM_PARAMS, chosen_params }; unsigned int i; ASSERT( requested != NULL, "requested is NULL" ); ASSERT( requested != NULL, "requested is NULL" ); ASSERT( supported->num_param_lists <= AP_NUM_PARAMS, "supp_num too big" ); if ( requested->num_param_lists > supported->num_param_lists ) { WARN( "req_num exceeds supp_num" ); return NULL; } for ( i = 0; i < requested->num_param_lists; ++i ) { bool match; unsigned int j; const ParameterList *req_list = &requested->param_list[i]; ADP_Parameter req_type = req_list->type; const ParameterList *sup_list = Angel_FindParamList( supported, req_type ); if ( sup_list == NULL ) { #ifdef ASSERTIONS_ENABLED __rt_warning( "option %x not supported\n", req_type ); #endif /* ASSERTIONS_ENABLED */ return NULL; } for ( j = 0, match = FALSE; (j < req_list->num_options) && !match; ++j ) { unsigned int k; for ( k = 0; (k < sup_list->num_options) && !match; ++k ) { if ( req_list->option[j] == sup_list->option[k] ) { #ifdef DEBUG __rt_info( "chose value %d for option %x\n", req_list->option[j], req_type ); #endif /* DEBUG */ match = TRUE; chosen_config.param[i].type = req_type; chosen_config.param[i].value = req_list->option[j]; } } } if ( !match ) { #ifdef ASSERTIONS_ENABLED __rt_warning( "no match found for option %x\n", req_type ); #endif /* ASSERTIONS_ENABLED */ return NULL; } } chosen_config.num_parameters = i; INFO( "match succeeded" ); return &chosen_config; }