Cleanup: reduce code c&p-ing somewhat

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2518 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2006-11-22 17:24:10 +00:00
parent ac82a58332
commit f870b23704
+27 -59
View File
@@ -360,65 +360,33 @@ main (int argc, char *argv[])
parseVolume (res_GetString ("config.speechvol"), parseVolume (res_GetString ("config.speechvol"),
&options.speechVolumeScale, "speech volume"); &options.speechVolumeScale, "speech volume");
} }
if (res_HasKey ("config.keys.1.name"))
{ { /* init control template names */
strncpy(input_templates[0].name, res_GetString ("config.keys.1.name"), 30); static const char* defaultNames[] =
input_templates[0].name[29] = 0; {
} "Arrows", "WASD", "Arrows (2)",
else "ESDF", "Joystick 1", "Joystick 2"
{ };
strcpy (input_templates[0].name, "Arrows"); int i;
res_PutString ("config.keys.1.name", input_templates[0].name);
} for (i = 0; i < 6; ++i)
if (res_HasKey ("config.keys.2.name")) {
{ char cfgkey[64];
strncpy(input_templates[1].name, res_GetString ("config.keys.2.name"), 30);
input_templates[1].name[29] = 0; snprintf(cfgkey, sizeof(cfgkey), "config.keys.%d.name", i + 1);
} cfgkey[sizeof(cfgkey) - 1] = '\0';
else
{ if (res_HasKey (cfgkey))
strcpy (input_templates[1].name, "WASD"); {
res_PutString ("config.keys.2.name", input_templates[1].name); strncpy (input_templates[i].name, res_GetString (cfgkey), 30);
} input_templates[i].name[29] = 0;
if (res_HasKey ("config.keys.3.name")) }
{ else
strncpy(input_templates[2].name, res_GetString ("config.keys.3.name"), 30); {
input_templates[2].name[29] = 0; strcpy (input_templates[i].name, defaultNames[i]);
} res_PutString (cfgkey, input_templates[i].name);
else }
{ }
strcpy (input_templates[2].name, "Arrows (2)");
res_PutString ("config.keys.3.name", input_templates[2].name);
}
if (res_HasKey ("config.keys.4.name"))
{
strncpy(input_templates[3].name, res_GetString ("config.keys.4.name"), 30);
input_templates[3].name[29] = 0;
}
else
{
strcpy (input_templates[3].name, "ESDF");
res_PutString ("config.keys.4.name", input_templates[3].name);
}
if (res_HasKey ("config.keys.5.name"))
{
strncpy(input_templates[4].name, res_GetString ("config.keys.5.name"), 30);
input_templates[4].name[29] = 0;
}
else
{
strcpy (input_templates[4].name, "Joystick 1");
res_PutString ("config.keys.5.name", input_templates[4].name);
}
if (res_HasKey ("config.keys.6.name"))
{
strncpy(input_templates[5].name, res_GetString ("config.keys.6.name"), 30);
input_templates[5].name[29] = 0;
}
else
{
strcpy (input_templates[5].name, "Joystick 2");
res_PutString ("config.keys.6.name", input_templates[5].name);
} }
optionsResult = parseOptions (argc, argv, &options); optionsResult = parseOptions (argc, argv, &options);