- user-defined config option support implemented

This commit is contained in:
Volker Ruppert 2006-04-05 16:05:11 +00:00
parent 6ce71008f6
commit ba597401a2
3 changed files with 52 additions and 27 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: config.cc,v 1.99 2006-03-29 19:27:31 vruppert Exp $
// $Id: config.cc,v 1.100 2006-04-05 16:05:11 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -3045,9 +3045,9 @@ static Bit32s parse_line_formatted(const char *context, int num_params, char *pa
PARSE_ERR(("ERROR: time0 directive is DEPRECATED, use clock: instead"));
}
// user-defined options handled by registered functions
else if (SIM->is_user_option(params[0]))
else if ((i = SIM->find_user_option(params[0])) >= 0)
{
return SIM->parse_user_option(context, num_params, &params[0]);
return SIM->parse_user_option(i, context, num_params, &params[0]);
}
else
{

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.cc,v 1.134 2006-03-29 19:27:31 vruppert Exp $
// $Id: siminterface.cc,v 1.135 2006-04-05 16:05:11 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// See siminterface.h for description of the siminterface concept.
@ -35,7 +35,7 @@ class bx_real_sim_c : public bx_simulator_interface_c {
const char *registered_ci_name;
config_interface_callback_t ci_callback;
void *ci_callback_data;
unsigned n_user_options;
int n_user_options;
user_option_handler_t user_option_handler[BX_MAX_USER_OPTIONS];
const char *user_option_name[BX_MAX_USER_OPTIONS];
int init_done;
@ -135,9 +135,9 @@ public:
}
virtual bool test_for_text_console();
// user-defined option support
virtual bx_bool register_user_option(char *main_param, user_option_handler_t handler);
virtual bx_bool is_user_option(char *main_param);
virtual Bit32s parse_user_option(const char *context, int num_params, char *params []);
virtual int find_user_option(const char *keyword);
virtual bx_bool register_user_option(const char *keyword, user_option_handler_t handler);
virtual Bit32s parse_user_option(int idx, const char *context, int num_params, char *params []);
};
// recursive function to find parameters from the path
@ -784,24 +784,49 @@ bool bx_real_sim_c::test_for_text_console()
return true;
}
bx_bool bx_real_sim_c::register_user_option(char *main_param, user_option_handler_t handler)
int bx_real_sim_c::find_user_option(const char *keyword)
{
// TODO
return 0;
}
bx_bool bx_real_sim_c::is_user_option(char *main_param)
{
// TODO
return 0;
}
Bit32s bx_real_sim_c::parse_user_option(const char *context, int num_params, char *params [])
{
// TODO
int i = 0;
while (i < n_user_options) {
if (!strcmp(keyword, user_option_name[i])) {
return i;
}
i++;
}
return -1;
}
bx_bool bx_real_sim_c::register_user_option(const char *keyword, user_option_handler_t handler)
{
int idx;
if (n_user_options >= BX_MAX_USER_OPTIONS) {
return 0;
}
idx = find_user_option(keyword);
if (idx >= 0) {
if (handler == user_option_handler[idx]) {
// handler already registered
return 1;
} else {
// keyword already exists
return 0;
}
} else {
user_option_name[n_user_options] = keyword;
user_option_handler[n_user_options++] = handler;
return 1;
}
}
Bit32s bx_real_sim_c::parse_user_option(int idx, const char *context, int num_params, char *params [])
{
if ((idx < 0) || (idx >= n_user_options)) {
return -1;
}
return (*user_option_handler[idx])(context, num_params, params);
}
/////////////////////////////////////////////////////////////////////////
// define methods of bx_param_* and family

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.h,v 1.180 2006-03-29 19:27:31 vruppert Exp $
// $Id: siminterface.h,v 1.181 2006-04-05 16:05:11 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Intro to siminterface by Bryce Denney:
@ -1047,7 +1047,7 @@ enum ci_return_t {
};
typedef int (*config_interface_callback_t)(void *userdata, ci_command_t command);
typedef BxEvent* (*bxevent_handler)(void *theclass, BxEvent *event);
typedef int (*user_option_handler_t)(const char *context, int num_params, char *params[]);
typedef Bit32s (*user_option_handler_t)(const char *context, int num_params, char *params[]);
// bx_gui->set_display_mode() changes the mode between the configuration
// interface and the simulation. This is primarily intended for display
@ -1174,9 +1174,9 @@ public:
virtual void set_display_mode(disp_mode_t newmode) {}
virtual bool test_for_text_console() { return true; }
// user-defined option support
virtual bx_bool register_user_option(char *main_param, user_option_handler_t handler) {return 0;}
virtual bx_bool is_user_option(char *main_param) {return 0;}
virtual Bit32s parse_user_option(const char *context, int num_params, char *params []) {return -1;}
virtual int find_user_option(const char *keyword) {return -1;}
virtual bx_bool register_user_option(const char *keyword, user_option_handler_t handler) {return 0;}
virtual Bit32s parse_user_option(int idx, const char *context, int num_params, char *params []) {return -1;}
};
BOCHSAPI extern bx_simulator_interface_c *SIM;