summaryrefslogtreecommitdiffstats
path: root/src/common/restext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/restext.cpp')
-rw-r--r--src/common/restext.cpp32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/common/restext.cpp b/src/common/restext.cpp
index d61fa63..c5d0ceb 100644
--- a/src/common/restext.cpp
+++ b/src/common/restext.cpp
@@ -776,9 +776,7 @@ static KeyDesc keyTable[22] =
bool SearchKey(const char *cmd, InputSlot &key)
{
- int i;
-
- for ( i=0 ; i<22 ; i++ )
+ for (int i = 0; i < 22 ;i++)
{
if ( strstr(cmd, keyTable[i].name) == cmd )
{
@@ -791,14 +789,11 @@ bool SearchKey(const char *cmd, InputSlot &key)
// Replaces the commands "\key name;" in a text.
-static void PutKeyName(char* dst, const char* src)
+static void PutKeyName(std::string& dst, const char* src)
{
- InputSlot key;
- char name[50];
- int s, d, n;
- unsigned int res;
+ dst.clear();
- s = d = 0;
+ int s = 0;
while ( src[s] != 0 )
{
if ( src[s+0] == '\\' &&
@@ -807,18 +802,16 @@ static void PutKeyName(char* dst, const char* src)
src[s+3] == 'y' &&
src[s+4] == ' ' )
{
+ InputSlot key;
if ( SearchKey(src+s+5, key) )
{
- res = CRobotMain::GetInstancePointer()->GetInputBinding(key).primary;
+ unsigned int res = CRobotMain::GetInstancePointer()->GetInputBinding(key).primary;
if (res != KEY_INVALID)
{
- if ( GetResource(RES_KEY, res, name) )
+ std::string keyName;
+ if ( GetResource(RES_KEY, res, keyName) )
{
- n = 0;
- while ( name[n] != 0 )
- {
- dst[d++] = name[n++];
- }
+ dst.append(keyName);
while ( src[s++] != ';' );
continue;
}
@@ -826,9 +819,8 @@ static void PutKeyName(char* dst, const char* src)
}
}
- dst[d++] = src[s++];
+ dst.append(1, src[s++]);
}
- dst[d++] = 0;
}
// Returns the translated text of a resource that needs key substitution
@@ -905,13 +897,13 @@ static const char* GetResourceBase(ResType type, int num)
// Returns the text of a resource.
-bool GetResource(ResType type, int num, char* text)
+bool GetResource(ResType type, int num, std::string& text)
{
const char *tmpl = GetResourceBase(type, num);
if (!tmpl)
{
- text[0] = 0;
+ text.clear();
return false;
}