From 65eacd8063174b8800170986b5d42fbab054d680 Mon Sep 17 00:00:00 2001 From: Volker Ruppert Date: Tue, 6 Jan 2009 20:35:39 +0000 Subject: [PATCH] - unlimited number of user options after rewrite (now using a chain similar to the plugin device code) - minor updates --- bochs/PARAM_TREE.txt | 4 +- bochs/config.cc | 8 +-- bochs/gui/siminterface.cc | 113 ++++++++++++++++++++++---------------- bochs/gui/siminterface.h | 6 +- 4 files changed, 75 insertions(+), 56 deletions(-) diff --git a/bochs/PARAM_TREE.txt b/bochs/PARAM_TREE.txt index 982445aa0..c56754daf 100644 --- a/bochs/PARAM_TREE.txt +++ b/bochs/PARAM_TREE.txt @@ -1,4 +1,4 @@ -$Id: PARAM_TREE.txt,v 1.18 2009-01-04 21:46:20 vruppert Exp $ +$Id: PARAM_TREE.txt,v 1.19 2009-01-06 20:35:38 vruppert Exp $ Starting from Bochs 2.3 the parameters are organized in a tree structure instead of a huge flat list. The parameter tree was required for implementing @@ -239,4 +239,4 @@ wxdebug user (subtree for user-defined options) -(updated Oct 8, 2006 by vruppert) +(updated Jan 6, 2008 by vruppert) diff --git a/bochs/config.cc b/bochs/config.cc index 1e6799def..a667e7db7 100755 --- a/bochs/config.cc +++ b/bochs/config.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: config.cc,v 1.147 2009-01-04 21:46:20 vruppert Exp $ +// $Id: config.cc,v 1.148 2009-01-06 20:35:38 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -22,7 +22,7 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA #include "bochs.h" #include "iodev/iodev.h" @@ -3212,9 +3212,9 @@ static int parse_line_formatted(const char *context, int num_params, char *param } #endif // user-defined options handled by registered functions - else if ((i = SIM->find_user_option(params[0])) >= 0) + else if (SIM->is_user_option(params[0])) { - return SIM->parse_user_option(i, context, num_params, ¶ms[0]); + return SIM->parse_user_option(context, num_params, ¶ms[0]); } else { diff --git a/bochs/gui/siminterface.cc b/bochs/gui/siminterface.cc index e7a8e3b7d..306799a3d 100644 --- a/bochs/gui/siminterface.cc +++ b/bochs/gui/siminterface.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: siminterface.cc,v 1.186 2009-01-05 21:15:17 vruppert Exp $ +// $Id: siminterface.cc,v 1.187 2009-01-06 20:35:39 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // See siminterface.h for description of the siminterface concept. @@ -14,8 +14,6 @@ logfunctions *siminterface_log = NULL; bx_list_c *root_param = NULL; #define LOG_THIS siminterface_log-> -#define BX_MAX_USER_OPTIONS 16 - // bx_simulator_interface just defines the interface that the Bochs simulator // and the gui will use to talk to each other. None of the methods of // bx_simulator_interface are implemented; they are all virtual. The @@ -29,10 +27,11 @@ bx_list_c *root_param = NULL; // bx_keyboard.s.internal_buffer[4] (or whatever) directly. -Bryce // -typedef struct { +typedef struct _user_option_t { const char *name; user_option_parser_t parser; user_option_save_t savefn; + struct _user_option_t *next; } user_option_t; class bx_real_sim_c : public bx_simulator_interface_c { @@ -41,8 +40,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; - int n_user_options; - user_option_t user_option[BX_MAX_USER_OPTIONS]; + user_option_t *user_options; int init_done; int enabled; // save context to jump to if we must quit unexpectedly @@ -143,10 +141,10 @@ public: } virtual bx_bool test_for_text_console(); // user-defined option support - virtual int find_user_option(const char *keyword); virtual bx_bool register_user_option(const char *keyword, user_option_parser_t parser, user_option_save_t save_func); virtual bx_bool unregister_user_option(const char *keyword); - virtual Bit32s parse_user_option(int idx, const char *context, int num_params, char *params []); + virtual bx_bool is_user_option(const char *keyword); + virtual Bit32s parse_user_option(const char *context, int num_params, char *params []); virtual Bit32s save_user_options(FILE *fp); // save/restore support @@ -294,7 +292,7 @@ bx_real_sim_c::bx_real_sim_c() quit_context = NULL; exit_code = 0; param_id = BXP_NEW_PARAM_ID; - n_user_options = 0; + user_options = NULL; } void bx_real_sim_c::reset_all_param() @@ -777,69 +775,90 @@ bx_bool bx_real_sim_c::test_for_text_console() return 1; } -int bx_real_sim_c::find_user_option(const char *keyword) +bx_bool bx_real_sim_c::is_user_option(const char *keyword) { - int i = 0; - while (i < n_user_options) { - if (!strcmp(keyword, user_option[i].name)) { - return i; - } - i++; + user_option_t *user_option; + + for (user_option = user_options; user_option; user_option = user_option->next) { + if (!strcmp(user_option->name, keyword)) return 1; } - return -1; + return 0; } bx_bool bx_real_sim_c::register_user_option(const char *keyword, user_option_parser_t parser, user_option_save_t save_func) { - if (n_user_options >= BX_MAX_USER_OPTIONS) { + user_option_t *user_option; + + user_option = (user_option_t *)malloc(sizeof(user_option_t)); + if (user_option == NULL) { + BX_PANIC(("can't allocate user_option_t")); return 0; } - int idx = find_user_option(keyword); - if (idx >= 0) { - if (parser == user_option[idx].parser) { - // parse handler already registered - return 1; - } else { - // keyword already exists - return 0; - } + + user_option->name = keyword; + user_option->parser = parser; + user_option->savefn = save_func; + user_option->next = NULL; + + if (user_options == NULL) { + user_options = user_option; } else { - idx = n_user_options++; - user_option[idx].name = keyword; - user_option[idx].parser = parser; - user_option[idx].savefn = save_func; - return 1; + user_option_t *temp = user_options; + + while (temp->next) { + if (!strcmp(temp->name, keyword)) { + free(user_option); + return 0; + } + temp = temp->next; + } + temp->next = user_option; } + return 1; } bx_bool bx_real_sim_c::unregister_user_option(const char *keyword) { - int idx = find_user_option(keyword); - if (idx >= 0) { - for (int i = idx; i < n_user_options; i++) { - user_option[i] = user_option[i+1]; + user_option_t *user_option, *prev = NULL; + + for (user_option = user_options; user_option; user_option = user_option->next) { + if (!strcmp(user_option->name, keyword)) { + if (prev == NULL) { + user_options = user_option->next; + } else { + prev->next = user_option->next; + } + free(user_option); + return 1; + } else { + prev = user_option; } - n_user_options--; - return 1; - } else { - return 0; } + return 0; } -Bit32s bx_real_sim_c::parse_user_option(int idx, const char *context, int num_params, char *params []) +Bit32s bx_real_sim_c::parse_user_option(const char *context, int num_params, char *params []) { - if (idx < 0 || idx >= n_user_options) { - return -1; + user_option_t *user_option; + + for (user_option = user_options; user_option; user_option = user_option->next) { + if ((!strcmp(user_option->name, params[0])) && + (user_option->parser != NULL)) { + return (*user_option->parser)(context, num_params, params); + } } - return (*user_option[idx].parser)(context, num_params, params); + return -1; + } Bit32s bx_real_sim_c::save_user_options(FILE *fp) { - for (int i = 0; i < n_user_options; i++) { - if (user_option[i].savefn != NULL) { - (*user_option[i].savefn)(fp); + user_option_t *user_option; + + for (user_option = user_options; user_option; user_option = user_option->next) { + if (user_option->savefn != NULL) { + (*user_option->savefn)(fp); } } return 0; diff --git a/bochs/gui/siminterface.h b/bochs/gui/siminterface.h index 1080c8f90..469502c20 100644 --- a/bochs/gui/siminterface.h +++ b/bochs/gui/siminterface.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: siminterface.h,v 1.221 2009-01-04 21:46:20 vruppert Exp $ +// $Id: siminterface.h,v 1.222 2009-01-06 20:35:39 vruppert Exp $ ///////////////////////////////////////////////////////////////////////// // // Intro to siminterface by Bryce Denney: @@ -1217,10 +1217,10 @@ public: virtual void set_display_mode(disp_mode_t newmode) {} virtual bx_bool test_for_text_console() {return 1;} // user-defined option support - virtual int find_user_option(const char *keyword) {return -1;} virtual bx_bool register_user_option(const char *keyword, user_option_parser_t parser, user_option_save_t save_func) {return 0;} virtual bx_bool unregister_user_option(const char *keyword) {return 0;} - virtual Bit32s parse_user_option(int idx, const char *context, int num_params, char *params []) {return -1;} + virtual bx_bool is_user_option(const char *keyword) {return 0;} + virtual Bit32s parse_user_option(const char *context, int num_params, char *params []) {return -1;} virtual Bit32s save_user_options(FILE *fp) {return -1;} // save/restore support virtual void init_save_restore() {}