aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2022-11-27 18:14:45 +0100
committerJavier <dev.git@javispedro.com>2022-11-27 18:14:45 +0100
commit544a184a4373fc29ba9d030bd8efb59fb56a28e2 (patch)
tree0b6909f24ad19cc3ef812fdb2c8667e592523460
parent4efa890a9c75b36ee78271b3361ee5cec991490a (diff)
downloadvbados-544a184a4373fc29ba9d030bd8efb59fb56a28e2.tar.gz
vbados-544a184a4373fc29ba9d030bd8efb59fb56a28e2.zip
search first for .tbl and kitten files in same path as exe
-rw-r--r--kitten.c30
-rw-r--r--sfmain.c33
2 files changed, 54 insertions, 9 deletions
diff --git a/kitten.c b/kitten.c
index f63cd96..f554047 100644
--- a/kitten.c
+++ b/kitten.c
@@ -74,7 +74,7 @@ int mystrtoul (char *src, int base, int size);
/* Globals */
nl_catd _kitten_catalog = 0; /* _kitten_catalog descriptor or 0 */
-char catfile[128]; /* full path to _kitten_catalog */
+char catfile[_MAX_PATH]; /* full path to _kitten_catalog */
char getlbuf[8192]; /* read buffer for better speed */
char *getlp; /* current point in buffer */
@@ -175,6 +175,20 @@ kittengets (int setnum, int msgnum, char *message)
return (catpoints[i].text);
}
+/**
+ * Obtains path to current exec.
+ */
+static char * get_cmd_path(char *buf)
+{
+ char cmd_drive[_MAX_DRIVE];
+ char cmd_dir[_MAX_DIR];
+
+ _splitpath(__argv[0], cmd_drive, cmd_dir, NULL, NULL);
+ _makepath(buf, cmd_drive, cmd_dir, "", NULL);
+
+ return buf;
+}
+
/**
* Initialize kitten for program (name).
@@ -241,7 +255,19 @@ kittenopen (char *name)
/* we copy the full LANG value or the part before "-" if "-" found */
catlang[2] = '\0';
- /* step through NLSPATH */
+
+ /* first try to find catalog file in the same path as exe */
+ get_cmd_path(catfile);
+
+ strcat (catfile, name);
+ strcat (catfile, ".");
+ strcat (catfile, catlang);
+ _kitten_catalog = catread (catfile);
+ if (_kitten_catalog)
+ return (_kitten_catalog);
+
+
+ /* otherwise step through NLSPATH */
nlsptr = getenv ("NLSPATH");
diff --git a/sfmain.c b/sfmain.c
index cc939f0..f2f6995 100644
--- a/sfmain.c
+++ b/sfmain.c
@@ -33,9 +33,8 @@
#include "dostsr.h"
#include "sftsr.h"
#include "unicode.h"
-#include "lfn.h"
-nl_catd cat;
+static nl_catd cat;
static char get_drive_letter(const char *path) {
if (!path || path[0] == '\0') return '\0';
@@ -387,6 +386,23 @@ static int get_nls(uint8_t __far * __far *file_upper_case, FCHAR __far * __far *
return 0;
}
+/** Tries to find a file with `name` in the same path as the current exec.
+ * @param buf MAX_PATH buffer to use
+ * @returns true if file exists
+ */
+static bool search_cmd_path(const char *name, char *buf)
+{
+ char cmd_drive[_MAX_DRIVE];
+ char cmd_dir[_MAX_DIR];
+ unsigned int attr;
+
+ _splitpath(__argv[0], cmd_drive, cmd_dir, NULL, NULL);
+ _makepath(buf, cmd_drive, cmd_dir, name, NULL);
+
+ // Check if file exists
+ return (_dos_getfileattr(buf, &attr) == 0);
+}
+
static void load_unicode_table(uint16_t far *unicode_table)
{
union REGS r;
@@ -412,17 +428,20 @@ static void load_unicode_table(uint16_t far *unicode_table)
if (r.x.cflag) {
// Can't get codepage. Use ASCII only
- //
fputs(_(2, 0, "Warning: Active code page not found"), stderr);
goto error;
}
sprintf(filename, r.x.bx > 999 ? "c%duni.tbl" : "cp%duni.tbl", r.x.bx);
- _searchenv(filename, "PATH", fullpath);
- if ( '\0' == fullpath[0] ) {
- fprintf(stderr, _(2, 1, "Warning: Can't find Unicode table: %s"), filename);
- goto error;
+ // Search in the same directory as the executable first
+ if (!search_cmd_path(filename, fullpath)) {
+ // Search in path if not found
+ _searchenv(filename, "PATH", fullpath);
+ if ('\0' == fullpath[0]) {
+ fprintf(stderr, _(2, 1, "Warning: Can't find Unicode table: %s"), filename);
+ goto error;
+ }
}
f = fopen(fullpath, "rb");