Defs: Add token "renamefile", which renames a file in a GRP or SSI file, in memory. 8.3 restrictions apply.

git-svn-id: https://svn.eduke32.com/eduke32@5061 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2015-03-23 06:28:08 +00:00
parent 2f0f38b6e6
commit ddf7720451
3 changed files with 47 additions and 0 deletions

View file

@ -39,6 +39,8 @@ int32_t kfilelength(int32_t handle);
int32_t ktell(int32_t handle); int32_t ktell(int32_t handle);
void kclose(int32_t handle); void kclose(int32_t handle);
void krename(const char *filename, const char *newname);
typedef struct { intptr_t *hand; int32_t leng; char *lock ; } cactype; typedef struct { intptr_t *hand; int32_t leng; char *lock ; } cactype;
enum { enum {

View file

@ -1039,6 +1039,40 @@ static int32_t kopen_internal(const char *filename, char **lastpfn, char searchf
return -1; return -1;
} }
void krename(const char *filename, const char *newname)
{
int32_t i, j, k;
char bad, *gfileptr;
for (k=numgroupfiles-1; k>=0; k--)
{
if (groupfil[k] >= 0)
{
for (i=gnumfiles[k]-1; i>=0; i--)
{
gfileptr = (char *)&gfilelist[k][i<<4];
bad = 0;
for (j=0; j<13; j++)
{
if (!filename[j]) break;
if (toupperlookup[filename[j]] != toupperlookup[gfileptr[j]])
{
bad = 1;
break;
}
}
if (bad) continue;
if (j<13 && gfileptr[j]) continue; // JBF: because e1l1.map might exist before e1l1
if (j==13 && filename[j]) continue; // JBF: long file name
Bstrncpy(gfileptr, newname, 12);
return;
}
}
}
}
int32_t kopen4load(const char *filename, char searchfirst) int32_t kopen4load(const char *filename, char searchfirst)
{ {
int32_t newhandle = MAXOPENFILES-1; int32_t newhandle = MAXOPENFILES-1;

View file

@ -93,6 +93,7 @@ enum scripttoken_t
T_MAPINFO, T_MAPFILE, T_MAPTITLE, T_MAPMD4, T_MHKFILE, T_MAPINFO, T_MAPFILE, T_MAPTITLE, T_MAPMD4, T_MHKFILE,
T_ECHO, T_ECHO,
T_GLOBALFLAGS, T_GLOBALFLAGS,
T_RENAMEFILE,
}; };
static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0; static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0;
@ -279,6 +280,7 @@ static int32_t defsparser(scriptfile *script)
{ "mapinfo", T_MAPINFO }, { "mapinfo", T_MAPINFO },
{ "echo", T_ECHO }, { "echo", T_ECHO },
{ "globalflags", T_GLOBALFLAGS }, { "globalflags", T_GLOBALFLAGS },
{ "renamefile", T_RENAMEFILE },
}; };
while (1) while (1)
@ -2218,6 +2220,15 @@ static int32_t defsparser(scriptfile *script)
} }
break; break;
case T_RENAMEFILE:
{
char *filename = NULL, *newname = NULL;
if (scriptfile_getstring(script,&filename)) break;
if (scriptfile_getstring(script,&newname)) break;
krename(filename, newname);
}
break;
default: default:
initprintf("Unknown token.\n"); break; initprintf("Unknown token.\n"); break;
} }