parse serial, parallel and sound bochsrc options using the parameter list

- fixed small bug in the ne2k parser code
- added warnings to the new parser code
This commit is contained in:
Volker Ruppert 2013-01-26 18:17:23 +00:00
parent b1cc217ea8
commit 2daadfcd85
9 changed files with 40 additions and 58 deletions

View File

@ -122,6 +122,7 @@ void bx_set_log_actions_by_device(bx_bool panic_flag);
// special config parameter and options functions for plugins
void bx_init_std_nic_options(const char *name, bx_list_c *menu);
void bx_init_usb_options(const char *usb_name, const char *pname, int maxports);
int bx_parse_param_from_list(const char *context, const char *input, bx_list_c *list);
int bx_parse_nic_params(const char *context, const char *param, bx_list_c *base);
int bx_parse_usb_port_params(const char *context, bx_bool devopt,
const char *param, int maxports, bx_list_c *base);

View File

@ -2034,27 +2034,30 @@ static int parse_param_bool(const char *input, int len, const char *param)
return -1;
}
static int parse_param_from_list(const char *input, bx_list_c *list)
int bx_parse_param_from_list(const char *context, const char *input, bx_list_c *list)
{
char *propval, *property, *value;
bx_param_c *param;
int ret = 0;
if (list == NULL) {
return -1; // list null
PARSE_WARN(("%s: parameter list == NULL!", context));
return -1;
}
propval = strdup(input);
property = strtok(propval, "=");
value = strtok(NULL, "");
if (!strcmp(property, input)) {
free(propval);
return -2; // no equals
PARSE_WARN(("%s: incorrect parameter format", context));
return -1;
}
param = list->get_by_name(property);
if (param != NULL) {
if (!param->get_enabled()) {
free(propval);
return -4; // parameter disabled
PARSE_WARN(("%s: parameter '%s' disabled", context, property));
return -1;
}
switch (param->get_type()) {
case BXT_PARAM_NUM:
@ -2071,14 +2074,16 @@ static int parse_param_from_list(const char *input, bx_list_c *list)
if (!strcmp(value, "0") || !strcmp(value, "1")) {
((bx_param_bool_c*)param)->set(atol(value));
} else {
ret = -6; // wrong value
PARSE_WARN(("%s: wrong value for parameter '%s'", context, property));
ret = -1;
}
}
break;
case BXT_PARAM_ENUM:
if (value != NULL) {
if (!((bx_param_enum_c*)param)->set_by_name(value)) {
ret = -6; // wrong value
PARSE_WARN(("%s: invalid choice '%s' parameter '%s'", context, value, property));
ret = -1;
}
}
break;
@ -2090,10 +2095,12 @@ static int parse_param_from_list(const char *input, bx_list_c *list)
}
break;
default:
ret = -5; // unknown type
PARSE_WARN(("%s: parameter '%s': unknown type", context, property));
ret = -1;
}
} else {
ret = -3; // unknown parameter
PARSE_WARN(("%s: unknown parameter '%s'", context, property));
ret = -1;
}
free(propval);
return ret;
@ -2149,7 +2156,7 @@ int bx_parse_nic_params(const char *context, const char *param, bx_list_c *base)
} else if (!strncmp(param, "ethmod=", 7)) {
if (!SIM->get_param_enum("ethmod", base)->set_by_name(&param[7]))
PARSE_ERR(("%s: ethernet module '%s' not available", context, &param[7]));
} else if (parse_param_from_list(param, base) < 0) {
} else if (bx_parse_param_from_list(context, param, base) < 0) {
PARSE_WARN(("%s: expected parameter '%s' for '%s' ignored.", context, param, base->get_name()));
return -1;
}
@ -2290,7 +2297,7 @@ static int parse_line_formatted(const char *context, int num_params, char *param
}
sprintf(tmpname, "ata.%d.resources", channel);
for (i=1; i<num_params; i++) {
if (parse_param_from_list(params[i], (bx_list_c*) SIM->get_param(tmpname)) < 0) {
if (bx_parse_param_from_list(context, params[i], (bx_list_c*) SIM->get_param(tmpname)) < 0) {
PARSE_ERR(("%s: ataX directive malformed.", context));
}
}
@ -2334,7 +2341,7 @@ static int parse_line_formatted(const char *context, int num_params, char *param
sectors = atol(&params[i][4]);
} else if (!strcmp(params[i], "translation=echs")) { // synonym of large
SIM->get_param_enum("translation", base)->set(BX_ATA_TRANSLATION_LARGE);
} else if (parse_param_from_list(params[i], base) < 0) {
} else if (bx_parse_param_from_list(context, params[i], base) < 0) {
PARSE_ERR(("%s: ataX-master/slave directive malformed.", context));
}
}
@ -2500,7 +2507,7 @@ static int parse_line_formatted(const char *context, int num_params, char *param
PARSE_ERR(("%s: cpuid directive malformed.", context));
}
for (i=1; i<num_params; i++) {
if (parse_param_from_list(params[i], (bx_list_c*) SIM->get_param("cpuid")) < 0) {
if (bx_parse_param_from_list(context, params[i], (bx_list_c*) SIM->get_param("cpuid")) < 0) {
PARSE_ERR(("%s: cpuid directive malformed.", context));
}
}
@ -2676,7 +2683,7 @@ static int parse_line_formatted(const char *context, int num_params, char *param
PARSE_ERR(("%s: mouse directive malformed.", context));
}
for (i=1; i<num_params; i++) {
if (parse_param_from_list(params[i], (bx_list_c*) SIM->get_param(BXPN_MOUSE)) < 0) {
if (bx_parse_param_from_list(context, params[i], (bx_list_c*) SIM->get_param(BXPN_MOUSE)) < 0) {
PARSE_ERR(("%s: mouse directive malformed.", context));
}
}

View File

@ -200,6 +200,7 @@ public:
virtual bx_bool opt_plugin_ctrl(const char *plugname, bx_bool load);
virtual void init_std_nic_options(const char *name, bx_list_c *menu);
virtual void init_usb_options(const char *usb_name, const char *pname, int maxports);
virtual int parse_param_from_list(const char *context, const char *param, bx_list_c *base);
virtual int parse_nic_params(const char *context, const char *param, bx_list_c *base);
virtual int parse_usb_port_params(const char *context, bx_bool devopt,
const char *param, int maxports, bx_list_c *base);
@ -1457,6 +1458,11 @@ void bx_real_sim_c::init_usb_options(const char *usb_name, const char *pname, in
bx_init_usb_options(usb_name, pname, maxports);
}
int bx_real_sim_c::parse_param_from_list(const char *context, const char *param, bx_list_c *base)
{
return bx_parse_param_from_list(context, param, base);
}
int bx_real_sim_c::parse_nic_params(const char *context, const char *param, bx_list_c *base)
{
return bx_parse_nic_params(context, param, base);

View File

@ -765,6 +765,7 @@ public:
virtual bx_bool opt_plugin_ctrl(const char *plugname, bx_bool load) {return 0;}
virtual void init_std_nic_options(const char *name, bx_list_c *menu) {}
virtual void init_usb_options(const char *usb_name, const char *pname, int maxports) {}
virtual int parse_param_from_list(const char *context, const char *param, bx_list_c *base) {return 0;}
virtual int parse_nic_params(const char *context, const char *param, bx_list_c *base) {return 0;}
virtual int parse_usb_port_params(const char *context, bx_bool devopt,
const char *param, int maxports, bx_list_c *base) {return 0;}

View File

@ -99,17 +99,15 @@ Bit32s ne2k_options_parser(const char *context, int num_params, char *params[])
SIM->get_param_num("irq", base)->set(atol(&params[i][4]));
valid |= 0x02;
} else {
if (valid == 0x07) {
SIM->get_param_bool("enabled", base)->set(1);
}
ret = SIM->parse_nic_params(context, params[i], base);
if (ret > 0) {
valid |= ret;
}
}
}
if (!SIM->get_param_bool("enabled", base)->get()) {
if (valid == 0x07) {
SIM->get_param_bool("enabled", base)->set(1);
}
}
if (valid < 0x80) {
if ((valid & 0x03) != 0x03) {
BX_ERROR(("%s: 'ne2k' directive incomplete (ioaddr and irq are required)", context));

View File

@ -77,12 +77,7 @@ Bit32s parport_options_parser(const char *context, int num_params, char *params[
sprintf(tmpname, "ports.parallel.%d", idx);
bx_list_c *base = (bx_list_c*) SIM->get_param(tmpname);
for (int i=1; i<num_params; i++) {
if (!strncmp(params[i], "enabled=", 8)) {
SIM->get_param_bool("enabled", base)->set(atol(&params[i][8]));
} else if (!strncmp(params[i], "file=", 5)) {
SIM->get_param_string("file", base)->set(&params[i][5]);
SIM->get_param_bool("enabled", base)->set(1);
} else {
if (SIM->parse_param_from_list(context, params[i], base) < 0) {
BX_ERROR(("%s: unknown parameter for parport%d ignored.", context, idx));
}
}

View File

@ -116,16 +116,7 @@ Bit32s serial_options_parser(const char *context, int num_params, char *params[]
sprintf(tmpname, "ports.serial.%d", idx);
bx_list_c *base = (bx_list_c*) SIM->get_param(tmpname);
for (int i=1; i<num_params; i++) {
if (!strncmp(params[i], "enabled=", 8)) {
SIM->get_param_bool("enabled", base)->set(atol(&params[i][8]));
} else if (!strncmp(params[i], "mode=", 5)) {
if (!SIM->get_param_enum("mode", base)->set_by_name(&params[i][5]))
BX_PANIC(("%s: com%d serial port mode '%s' not available", context, idx, &params[i][5]));
SIM->get_param_bool("enabled", base)->set(1);
} else if (!strncmp(params[i], "dev=", 4)) {
SIM->get_param_string("dev", base)->set(&params[i][4]);
SIM->get_param_bool("enabled", base)->set(1);
} else {
if (SIM->parse_param_from_list(context, params[i], base) < 0) {
BX_ERROR(("%s: unknown parameter for com%d ignored.", context, idx));
}
}

View File

@ -123,11 +123,7 @@ Bit32s es1370_options_parser(const char *context, int num_params, char *params[]
if (!strcmp(params[0], "es1370")) {
bx_list_c *base = (bx_list_c*) SIM->get_param(BXPN_SOUND_ES1370);
for (int i = 1; i < num_params; i++) {
if (!strncmp(params[i], "enabled=", 8)) {
SIM->get_param_bool("enabled", base)->set(atol(&params[i][8]));
} else if (!strncmp(params[i], "wavedev=", 8)) {
SIM->get_param_string("wavedev", base)->set(&params[i][8]);
} else {
if (SIM->parse_param_from_list(context, params[i], base) < 0) {
BX_ERROR(("%s: unknown parameter for es1370 ignored.", context));
}
}

View File

@ -120,33 +120,20 @@ void sb16_init_options(void)
Bit32s sb16_options_parser(const char *context, int num_params, char *params[])
{
if (!strcmp(params[0], "sb16")) {
int enable = 1;
bx_list_c *base = (bx_list_c*) SIM->get_param(BXPN_SOUND_SB16);
int enable = 1;
SIM->get_param_bool("enabled", base)->set(1);
for (int i = 1; i < num_params; i++) {
if (!strncmp(params[i], "enabled=", 8)) {
enable = atol(&params[i][8]);
} else if (!strncmp(params[i], "midi=", 5)) {
SIM->get_param_string("midi", base)->set(&params[i][5]);
} else if (!strncmp(params[i], "midimode=", 9)) {
SIM->get_param_num("midimode", base)->set(atol(&params[i][9]));
} else if (!strncmp(params[i], "wave=", 5)) {
SIM->get_param_string("wave", base)->set(&params[i][5]);
} else if (!strncmp(params[i], "wavemode=", 9)) {
SIM->get_param_num("wavemode", base)->set(atol(&params[i][9]));
} else if (!strncmp(params[i], "log=", 4)) {
SIM->get_param_string("log", base)->set(&params[i][4]);
} else if (!strncmp(params[i], "loglevel=", 9)) {
SIM->get_param_num("loglevel", base)->set(atol(&params[i][9]));
} else if (!strncmp(params[i], "dmatimer=", 9)) {
SIM->get_param_num("dmatimer", base)->set(atol(&params[i][9]));
} else {
SIM->get_param_bool("enabled", base)->set(enable);
} else if (SIM->parse_param_from_list(context, params[i], base) < 0) {
BX_ERROR(("%s: unknown parameter for sb16 ignored.", context));
}
}
if ((enable != 0) && (SIM->get_param_num("dmatimer", base)->get() > 0))
SIM->get_param_bool("enabled", base)->set(1);
else
if ((enable != 0) && (SIM->get_param_num("dmatimer", base)->get() == 0)) {
SIM->get_param_bool("enabled", base)->set(0);
}
} else {
BX_PANIC(("%s: unknown directive '%s'", context, params[0]));
}