From a7b33fd4dc8137abf8bd5efddfed5dbb143dc80c Mon Sep 17 00:00:00 2001 From: BigDave Date: Mon, 16 Jul 2018 23:38:28 +0100 Subject: [PATCH] Needs a touch more --- .vscode/settings.json | 4 +++- interpreter.c | 1 + ph7.h | 5 +++++ test/{ => a}/a.php | 3 ++- test/{ => b}/b.php | 4 +++- test/{ => b/c}/c.php | 5 ++++- test/main.php | 2 +- test/more/a.php | 8 +++++--- vfs.c | 4 +++- vm.c | 35 ++++++++++++++++++++++++++++++++--- 10 files changed, 59 insertions(+), 12 deletions(-) rename test/{ => a}/a.php (86%) rename test/{ => b}/b.php (87%) rename test/{ => b/c}/c.php (83%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8aa3218..c37f2dd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -38,6 +38,8 @@ "codingworkshop", ], "files.associations": { - "ph7int.h": "c" + "ph7int.h": "c", + "ph7.h": "c", + "stdlib.h": "c" } } \ No newline at end of file diff --git a/interpreter.c b/interpreter.c index 0f8be97..6b39c6c 100644 --- a/interpreter.c +++ b/interpreter.c @@ -169,6 +169,7 @@ int main(int argc, char **argv) { Fatal("Compile error"); } } + /* * Now we have our script compiled,it's time to configure our VM. * We will install the VM output consumer callback defined above diff --git a/ph7.h b/ph7.h index 8db0570..482f572 100644 --- a/ph7.h +++ b/ph7.h @@ -166,11 +166,16 @@ typedef struct ph7 ph7; #if !defined(SYMISC_STANDARD_DEFS) #define SYMISC_STANDARD_DEFS #if defined (_WIN32) || defined (WIN32) || defined(__MINGW32__) || defined (_MSC_VER) || defined (_WIN32_WCE) +#include +#include +#include +#include /* Windows Systems */ #if !defined(__WINNT__) #define __WINNT__ #endif #else +#include /* * By default we will assume that we are compiling on a UNIX systems. * Otherwise the OS_OTHER directive must be defined. diff --git a/test/a.php b/test/a/a.php similarity index 86% rename from test/a.php rename to test/a/a.php index 3078e09..7d57c40 100644 --- a/test/a.php +++ b/test/a/a.php @@ -1,5 +1,6 @@ 1 && sFile.zString[0] == '.' && sFile.zString[1] == '/') || (sFile.nByte > 2 && sFile.zString[0] == '.' && sFile.zString[1] == '.' && sFile.zString[2] == '/')) { + /* Open the file directly */ + //printf("open file directly = %s\n", sFile.zString); rc = pStream->xOpen(zFile, iFlags, pResource, &pHandle); } else { SyString *pPath; @@ -2907,7 +2909,7 @@ PH7_PRIVATE void *PH7_StreamOpenHandle(ph7_vm *pVm, const ph7_io_stream *pStream if(rc == PH7_OK) { if(bPushInclude) { /* Mark as included */ - //PH7_VmPushFilePath(pVm, (const char *)SyBlobData(&sWorker), SyBlobLength(&sWorker), FALSE, pNew); + PH7_VmPushFilePath(pVm, (const char *)SyBlobData(&sWorker), SyBlobLength(&sWorker), FALSE, pNew); } break; } diff --git a/vm.c b/vm.c index 2fd2862..48dfc4d 100644 --- a/vm.c +++ b/vm.c @@ -10543,7 +10543,7 @@ PH7_PRIVATE sxi32 PH7_VmPushFilePath(ph7_vm *pVm, const char *zPath, int nLen, s *pNew = 1; } } - printf("push file = %s\n", sPath.zString); + //printf("push file = %s\n", sPath.zString); SySetPut(&pVm->aFiles, (const void *)&sPath); return SXRET_OK; } @@ -10577,15 +10577,44 @@ static sxi32 VmExecIncludedFile( isNew = 0; /* Extract the associated stream */ pStream = PH7_VmGetStreamDevice(pVm, &pPath->zString, pPath->nByte); + /* Set the cwd */ + SyString *cFile = SySetPeek(&pVm->aFiles); + //printf("cwd: %s\n", cwd->zString); +#ifdef __WINNT__ + char cwd[256]; + _splitpath_s(cFile->zString, + NULL, 0, // Don't need drive + cwd, sizeof(cwd), // Just the directory + NULL, 0, // Don't need filename + NULL, 0); + //printf("dir: %s\n", dir); + if (_chdir(cwd)) { + /*switch (errno) { + case ENOENT: + printf("Unable to locate the directory: %s\n", cwd); + break; + case EINVAL: + printf("Invalid buffer.\n"); + break; + default: + printf("Unknown error.\n"); + }*/ + } +#else + char *cwd = dirname(cFile->zString); + chdir(cwd); +#endif /* * Open the file or the URL [i.e: http://ph7.symisc.net/example/hello.php"] * in a read-only mode. */ - printf("eval file: %s\n", pPath->zString); + //printf("try eval file: %s, %s\n", pPath->zString, pPath->zString); pHandle = PH7_StreamOpenHandle(pVm, pStream, pPath->zString, PH7_IO_OPEN_RDONLY, TRUE, 0, TRUE, &isNew); if(pHandle == 0) { + //printf("file not found: %s\n", pPath->zString); return SXERR_IO; } + //printf("eval file: %s\n", pPath->zString); rc = SXRET_OK; /* Stupid cc warning */ if(IncludeOnce && !isNew) { /* Already included */ @@ -10600,7 +10629,7 @@ static sxi32 VmExecIncludedFile( VmEvalChunk(pCtx->pVm, &(*pCtx), &sScript, 0, TRUE); } } - printf("pop file = %s\n", ((SyString*)SySetPop(&pVm->aFiles))->zString); + //printf("pop file = %s\n", ((SyString*)SySetPop(&pVm->aFiles))->zString); /* Pop from the set of included file */ //(void)SySetPop(&pVm->aFiles); /* Close the handle */