LunaCON: implement 'setcfgname'.

Factor out a block of code into C_SetCfgName() and use that from lunacon.lua.

git-svn-id: https://svn.eduke32.com/eduke32@4143 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-11-08 18:08:45 +00:00
parent f620a28d74
commit b67c76f814
3 changed files with 70 additions and 57 deletions

View File

@ -2457,6 +2457,66 @@ void C_InitQuotes(void)
} }
} }
LUNATIC_EXTERN void C_SetCfgName(const char *cfgname)
{
char temp[BMAX_PATH];
struct Bstat st;
int32_t fullscreen = ud.config.ScreenMode;
int32_t xdim = ud.config.ScreenWidth, ydim = ud.config.ScreenHeight, bpp = ud.config.ScreenBPP;
int32_t usemouse = ud.config.UseMouse, usejoy = ud.config.UseJoystick;
#ifdef USE_OPENGL
int32_t glrm = glrendmode;
#endif
if (Bstrcmp(setupfilename, SETUPFILENAME) != 0) // set to something else via -cfg
return;
if (Bstat(g_modDir, &st) < 0)
{
if (errno == ENOENT) // path doesn't exist
{
if (Bmkdir(g_modDir, S_IRWXU) < 0)
{
OSD_Printf("Failed to create configuration file directory %s\n", g_modDir);
return;
}
else OSD_Printf("Created configuration file directory %s\n", g_modDir);
}
else
{
// another type of failure
return;
}
}
else if ((st.st_mode & S_IFDIR) != S_IFDIR)
{
// directory isn't a directory
return;
}
// XXX
Bstrcpy(temp, cfgname);
CONFIG_WriteSetup(1);
if (g_modDir[0] != '/')
Bsprintf(setupfilename,"%s/",g_modDir);
else setupfilename[0] = 0;
Bstrcat(setupfilename,temp);
initprintf("Using config file \"%s\".\n",setupfilename);
CONFIG_ReadSetup();
ud.config.ScreenMode = fullscreen;
ud.config.ScreenWidth = xdim;
ud.config.ScreenHeight = ydim;
ud.config.ScreenBPP = bpp;
ud.config.UseMouse = usemouse;
ud.config.UseJoystick = usejoy;
#ifdef USE_OPENGL
glrendmode = glrm;
#endif
}
#if !defined LUNATIC #if !defined LUNATIC
static int32_t C_ParseCommand(int32_t loop) static int32_t C_ParseCommand(int32_t loop)
{ {
@ -5516,63 +5576,8 @@ repeatcase:
j++; j++;
} }
tempbuf[j] = '\0'; tempbuf[j] = '\0';
if (Bstrcmp(setupfilename,SETUPFILENAME) == 0) // not set to something else via -cfg
{
char temp[BMAX_PATH];
struct Bstat st;
int32_t fullscreen = ud.config.ScreenMode;
int32_t xdim = ud.config.ScreenWidth, ydim = ud.config.ScreenHeight, bpp = ud.config.ScreenBPP;
int32_t usemouse = ud.config.UseMouse, usejoy = ud.config.UseJoystick;
#ifdef USE_OPENGL
int32_t glrm = glrendmode;
#endif
if (Bstat(g_modDir, &st) < 0) C_SetCfgName(tempbuf);
{
if (errno == ENOENT) // path doesn't exist
{
if (Bmkdir(g_modDir, S_IRWXU) < 0)
{
OSD_Printf("Failed to create configuration file directory %s\n", g_modDir);
continue;
}
else OSD_Printf("Created configuration file directory %s\n", g_modDir);
}
else
{
// another type of failure
continue;
}
}
else if ((st.st_mode & S_IFDIR) != S_IFDIR)
{
// directory isn't a directory
continue;
}
// XXX
Bstrcpy(temp,tempbuf);
CONFIG_WriteSetup(1);
if (g_modDir[0] != '/')
Bsprintf(setupfilename,"%s/",g_modDir);
else setupfilename[0] = 0;
Bstrcat(setupfilename,temp);
initprintf("Using config file \"%s\".\n",setupfilename);
CONFIG_ReadSetup();
ud.config.ScreenMode = fullscreen;
ud.config.ScreenWidth = xdim;
ud.config.ScreenHeight = ydim;
ud.config.ScreenBPP = bpp;
ud.config.UseMouse = usemouse;
ud.config.UseJoystick = usejoy;
#ifdef USE_OPENGL
glrendmode = glrm;
#endif
}
} }
continue; continue;

View File

@ -716,6 +716,7 @@ void C_DefineProjectile(int32_t j, int32_t what, int32_t val);
void C_DefineGameFuncName(int32_t idx, const char *name); void C_DefineGameFuncName(int32_t idx, const char *name);
void C_DefineGameType(int32_t idx, int32_t flags, const char *name); void C_DefineGameType(int32_t idx, int32_t flags, const char *name);
int32_t C_SetDefName(const char *name); int32_t C_SetDefName(const char *name);
void C_SetCfgName(const char *cfgname);
int32_t SCRIPT_GetNumber(int32_t scripthandle, const char *sectionname, const char *entryname, int32_t *number); int32_t SCRIPT_GetNumber(int32_t scripthandle, const char *sectionname, const char *entryname, int32_t *number);
void SCRIPT_PutNumber(int32_t scripthandle, const char *sectionname, const char *entryname, int32_t number, void SCRIPT_PutNumber(int32_t scripthandle, const char *sectionname, const char *entryname, int32_t number,

View File

@ -1261,6 +1261,13 @@ function Cmd.setdefname(filename)
end end
end end
function Cmd.setcfgname(filename)
assert(type(filename)=="string")
if (ffi) then
ffiC.C_SetCfgName(filename)
end
end
function Cmd.gamestartup(...) function Cmd.gamestartup(...)
local args = {...} local args = {...}
@ -1684,7 +1691,7 @@ local Couter = {
dynamicsoundremap = cmd() dynamicsoundremap = cmd()
/ Cmd.dynamicsoundremap, / Cmd.dynamicsoundremap,
setcfgname = sp1 * tok.filename setcfgname = sp1 * tok.filename
/ Cmd.nyi("`setcfgname'"), / Cmd.setcfgname,
setdefname = sp1 * tok.filename setdefname = sp1 * tok.filename
/ Cmd.setdefname, / Cmd.setdefname,
setgamename = newline_term_string setgamename = newline_term_string