From ddf7720451ea029d0e9eab579c86419c50c6a1a9 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 23 Mar 2015 06:28:08 +0000 Subject: [PATCH] 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 --- polymer/eduke32/build/include/cache1d.h | 2 ++ polymer/eduke32/build/src/cache1d.c | 34 +++++++++++++++++++++++++ polymer/eduke32/build/src/defs.c | 11 ++++++++ 3 files changed, 47 insertions(+) diff --git a/polymer/eduke32/build/include/cache1d.h b/polymer/eduke32/build/include/cache1d.h index e0b50a8a8..8f006aac5 100644 --- a/polymer/eduke32/build/include/cache1d.h +++ b/polymer/eduke32/build/include/cache1d.h @@ -39,6 +39,8 @@ int32_t kfilelength(int32_t handle); int32_t ktell(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; enum { diff --git a/polymer/eduke32/build/src/cache1d.c b/polymer/eduke32/build/src/cache1d.c index f666f4826..94c3381a8 100644 --- a/polymer/eduke32/build/src/cache1d.c +++ b/polymer/eduke32/build/src/cache1d.c @@ -1039,6 +1039,40 @@ static int32_t kopen_internal(const char *filename, char **lastpfn, char searchf 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 newhandle = MAXOPENFILES-1; diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index 01fbce4af..c1bbda884 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -93,6 +93,7 @@ enum scripttoken_t T_MAPINFO, T_MAPFILE, T_MAPTITLE, T_MAPMD4, T_MHKFILE, T_ECHO, T_GLOBALFLAGS, + T_RENAMEFILE, }; 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 }, { "echo", T_ECHO }, { "globalflags", T_GLOBALFLAGS }, + { "renamefile", T_RENAMEFILE }, }; while (1) @@ -2218,6 +2220,15 @@ static int32_t defsparser(scriptfile *script) } 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: initprintf("Unknown token.\n"); break; }