Made HOME optional and added some caching at the _fullpath()

This commit is contained in:
George Sokianos 2021-12-26 17:04:00 +00:00
parent 2c711138d7
commit 14d813cea1
3 changed files with 22 additions and 11 deletions

View File

@ -25,7 +25,7 @@ SetEnv SAVE HOME "Sys:home/"
## TODO list
- Free lost Gfx memory
DONE - Make the keyboard shortcuts work. Now, everything can be done with mouse clicks at the toolbar at the bottom of the file list at the left.
- If `HOME` is not set, set it to program folder on program run, having that as an ENV variable, without saving it (only in ENV:)
DONE - If `HOME` is not set, set it to program folder on program run.
- Make the application aknowledge of the executable file name. Now it works only with the filename `lite`
- Add Amiga versioning
- Fix the resolution of the fullscreen mode

View File

@ -13,6 +13,8 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xresource.h>
#elif __amigaos4__
#include "platform/amigaos4.h"
#elif __APPLE__
#include <mach-o/dyld.h>
#endif
@ -71,7 +73,6 @@ static void get_exe_filename(char *buf, int sz) {
_NSGetExecutablePath(exepath, &size);
realpath(exepath, buf);
#elif __amigaos4__
#include "platform/amigaos4.h"
strcpy(buf, _fullpath("."));
#else
strcpy(buf, "./lite");
@ -174,6 +175,9 @@ init_lua:
" HOME = os.getenv('" LITE_OS_HOME "')\n"
" local exedir = EXEFILE:match(\"^(.*)" LITE_PATHSEP_PATTERN LITE_NONPATHSEP_PATTERN "$\")\n"
" local prefix = exedir:match(\"^(.*)" LITE_PATHSEP_PATTERN "bin$\")\n"
" if not HOME then\n"
" HOME = exedir\n"
" end\n"
" dofile((MACOS_RESOURCES or (prefix and prefix .. '/share/lite-xl' or exedir .. '/data')) .. '/core/start.lua')\n"
" core = require('core')\n"
" core.init()\n"

View File

@ -5,17 +5,15 @@
#include "amigaos4.h"
// TODO: check if this is set in SDK
#define MAX_PATH_SIZE 255
static char *getFullPath(const char *path)
{
char *appPath = malloc(sizeof(char) * MAX_PATH_SIZE);
char *appPath = malloc(sizeof(char) * MAX_DOS_NAME);
BPTR pathLock = Lock(path, SHARED_LOCK);
if (pathLock)
{
NameFromLock(pathLock, appPath, sizeof(char) * MAX_PATH_SIZE);
NameFromLock(pathLock, appPath, sizeof(char) * MAX_DOS_NAME);
// printf("DBG: getFullPath() path: %s\nappPath: %s\n", path, appPath);
UnLock(pathLock);
return appPath;
@ -26,16 +24,25 @@ static char *getFullPath(const char *path)
char *_fullpath(const char *path)
{
if (strcmp(path, "."))
static char prvPath[MAX_DOS_NAME];
static char result[MAX_DOS_NAME];
// printf("DBG: prvPath: %s\npath: %s\nresult:%s\n", prvPath, path, result);
if (!strcmp(path, prvPath))
{
return getFullPath(path);
return result;
}
strcpy(prvPath, path);
if (!strcmp(path, "."))
{
// TODO: Add code to get the name of the executable
return getFullPath("PROGDIR:lite");
strcpy(result, getFullPath("PROGDIR:lite"));
// printf("DBG: result:%s\n", result);
return result;
}
return NULL;
strcpy(result, getFullPath(path));
return result;
}