Fix loading of a user's previous "SelectedGRP" file.

git-svn-id: https://svn.eduke32.com/eduke32@3617 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2013-03-28 09:04:54 +00:00
parent cd235d2ec2
commit 2bfb7736cb
4 changed files with 91 additions and 105 deletions

View file

@ -618,8 +618,8 @@ int32_t CONFIG_ReadSetup(void)
} }
// #endif // #endif
if (g_grpNamePtr != NULL && !Bstrcmp(g_grpNamePtr,defaultgamegrp[0])) if (g_grpNamePtr == NULL)
SCRIPT_GetString(ud.config.scripthandle, "Setup","SelectedGRP",&g_grpNamePtr[0]); SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup","SelectedGRP",&g_grpNamePtr);
if (!NAM) if (!NAM)
{ {

View file

@ -575,24 +575,43 @@ char * SCRIPT_GetRaw(int32_t scripthandle, char * sectionname, char * entryname)
return e->value; return e->value;
} }
int32_t SCRIPT_GetString(int32_t scripthandle, char * sectionname, char * entryname, char * dest) static char * SCRIPT_ParseString(char ** dest, char * p)
{ {
ScriptSectionType *s; int32_t c = 0;
ScriptEntryType *e; char ch;
char *p, ch;
int32_t c;
if (!SC(scripthandle)) return 1; if (!(*dest))
if (!SCRIPT(scripthandle,script)) return 1; {
// find length
char *q = p;
s = SCRIPT_SectionExists(scripthandle, sectionname); if (*q == '\"')
e = SCRIPT_EntryExists(s, entryname); {
// quoted string
q++;
while ((ch = *(q++)) && ch != '\"')
{
if (ch == '\\')
{
ch = *(q++);
//dest[0] = 0; if (!ch)
if (!e) return 1; break;
}
p = e->value; c++;
}
}
else
{
while ((ch = *(q++)) && ch != ' ' && ch != '\t')
c++;
}
// allocate
*dest = (char*)Bcalloc(c+1,sizeof(char));
c = 0; c = 0;
}
if (*p == '\"') if (*p == '\"')
{ {
@ -606,40 +625,67 @@ int32_t SCRIPT_GetString(int32_t scripthandle, char * sectionname, char * entryn
ch = *(p++); ch = *(p++);
switch (ch) switch (ch)
{ {
case 0: return 0; case 0: return p;
case 'n': dest[c++] = '\n'; break; case 'n': (*dest)[c++] = '\n'; break;
case 'r': dest[c++] = '\r'; break; case 'r': (*dest)[c++] = '\r'; break;
case 't': dest[c++] = '\t'; break; case 't': (*dest)[c++] = '\t'; break;
default: dest[c++] = ch; break; default: (*dest)[c++] = ch; break;
} }
break; break;
case '\"': case '\"':
dest[c] = 0; (*dest)[c] = 0;
return 0; return p;
default: default:
dest[c++] = ch; (*dest)[c++] = ch;
break; break;
} }
} }
if (ch == 0) return p;
} }
else else
{ {
while ((ch = *(p++))) while ((ch = *(p++)))
{ {
if (ch == ' ' || ch == '\t') { dest[c] = 0; break; } if (ch == ' ' || ch == '\t') { (*dest)[c] = 0; break; }
else dest[c++] = ch; else (*dest)[c++] = ch;
} }
} }
return p;
}
int32_t SCRIPT_GetStringPtr(int32_t scripthandle, char * sectionname, char * entryname, char ** dest)
{
ScriptSectionType *s;
ScriptEntryType *e;
char *p;
if (!SC(scripthandle)) return 1;
if (!SCRIPT(scripthandle,script)) return 1;
s = SCRIPT_SectionExists(scripthandle, sectionname);
e = SCRIPT_EntryExists(s, entryname);
//dest[0] = 0;
if (!e) return 1;
p = e->value;
SCRIPT_ParseString(dest, p);
return 0; return 0;
} }
int32_t SCRIPT_GetString(int32_t scripthandle, char * sectionname, char * entryname, char * dest)
{
return SCRIPT_GetStringPtr(scripthandle, sectionname, entryname, &dest);
}
int32_t SCRIPT_GetDoubleString(int32_t scripthandle, char * sectionname, char * entryname, char * dest1, char * dest2) int32_t SCRIPT_GetDoubleString(int32_t scripthandle, char * sectionname, char * entryname, char * dest1, char * dest2)
{ {
ScriptSectionType *s; ScriptSectionType *s;
ScriptEntryType *e; ScriptEntryType *e;
char *p, ch; char *p;
int32_t c;
if (!SC(scripthandle)) return 1; if (!SC(scripthandle)) return 1;
if (!SCRIPT(scripthandle,script)) return 1; if (!SCRIPT(scripthandle,script)) return 1;
@ -652,88 +698,16 @@ int32_t SCRIPT_GetDoubleString(int32_t scripthandle, char * sectionname, char *
if (!e) return 1; if (!e) return 1;
p = e->value; p = e->value;
c = 0;
if (*p == '\"') p = SCRIPT_ParseString(&dest1, p);
{
// quoted string if (*(p-1) != '\"')
p++; return 0;
while ((ch = *(p++)))
{
switch (ch)
{
case '\\':
ch = *(p++);
switch (ch)
{
case 0: return 0;
case 'n': dest1[c++] = '\n'; break;
case 'r': dest1[c++] = '\r'; break;
case 't': dest1[c++] = '\t'; break;
default: dest1[c++] = ch; break;
}
break;
case '\"':
dest1[c] = 0;
goto breakme;
default:
dest1[c++] = ch;
break;
}
}
if (ch == 0) return 0;
}
else
{
while ((ch = *(p++)))
{
if (ch == ' ' || ch == '\t') { dest1[c] = 0; break; }
else dest1[c++] = ch;
}
}
breakme:
while (*p == ' ' || *p == '\t') p++; while (*p == ' ' || *p == '\t') p++;
if (*p == 0) return 0; if (*p == 0) return 0;
c = 0; SCRIPT_ParseString(&dest2, p);
if (*p == '\"')
{
// quoted string
p++;
while ((ch = *(p++)))
{
switch (ch)
{
case '\\':
ch = *(p++);
switch (ch)
{
case 0: return 0;
case 'n': dest2[c++] = '\n'; break;
case 'r': dest2[c++] = '\r'; break;
case 't': dest2[c++] = '\t'; break;
default: dest2[c++] = ch; break;
}
break;
case '\"':
dest2[c] = 0;
return 0;
default:
dest2[c++] = ch;
break;
}
}
}
else
{
while ((ch = *(p++)))
{
if (ch == ' ' || ch == '\t') { dest2[c] = 0; break; }
else dest2[c++] = ch;
}
}
return 0; return 0;
} }

View file

@ -128,6 +128,13 @@ char * SCRIPT_GetRaw(int32_t scripthandle, char * sectionname, char * entryname)
= =
============== ==============
*/ */
int32_t SCRIPT_GetStringPtr
(
int32_t scripthandle,
char * sectionname,
char * entryname,
char ** dest
);
int32_t SCRIPT_GetString int32_t SCRIPT_GetString
( (
int32_t scripthandle, int32_t scripthandle,

View file

@ -266,7 +266,12 @@ static void PopulateForm(int32_t pgs)
Bsprintf(buf, "%s\t%s", grpfiles[i].name, fg->name); Bsprintf(buf, "%s\t%s", grpfiles[i].name, fg->name);
j = ListBox_AddString(hwnd, buf); j = ListBox_AddString(hwnd, buf);
(void)ListBox_SetItemData(hwnd, j, (LPARAM)fg); (void)ListBox_SetItemData(hwnd, j, (LPARAM)fg);
if (!Bstrcasecmp(fg->name, settings.selectedgrp))(void)ListBox_SetCurSel(hwnd, j); if (!Bstrcasecmp(fg->name, settings.selectedgrp))
{
(void)ListBox_SetCurSel(hwnd, j);
settings.game = fg->game;
settings.crcval = fg->crcval;
}
} }
} }
} }