mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-20 01:11:18 +00:00
[qwaq] Add builtin to get a file's full path
If the file's base directory cannot be found, the file name is returned as-is.
This commit is contained in:
parent
cf7c4780eb
commit
63714c7c55
3 changed files with 29 additions and 0 deletions
|
@ -44,6 +44,7 @@
|
|||
#include "QF/dstring.h"
|
||||
#include "QF/hash.h"
|
||||
#include "QF/keys.h"
|
||||
#include "QF/quakefs.h"
|
||||
#include "QF/sys.h"
|
||||
|
||||
#include "qwaq.h"
|
||||
|
@ -427,6 +428,31 @@ qdb_get_string (progs_t *pr)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
qdb_get_file_path (progs_t *pr)
|
||||
{
|
||||
__auto_type debug = PR_Resources_Find (pr, "qwaq-debug");
|
||||
pointer_t handle = P_INT (pr, 0);
|
||||
qwaq_target_t *target = get_target (debug, __FUNCTION__, handle);
|
||||
progs_t *tpr = target->pr;
|
||||
const char *file = P_GSTRING (pr, 1);
|
||||
const char *basedir = PR_Debug_GetBaseDirectory (tpr, file);
|
||||
|
||||
if (basedir) {
|
||||
size_t baselen = strlen (basedir);
|
||||
size_t filelen = strlen (file);
|
||||
char *path = alloca (baselen + filelen + 2);
|
||||
strcpy (path, basedir);
|
||||
path[baselen] = '/';
|
||||
strcpy (path + baselen + 1, file);
|
||||
path = QFS_CompressPath (path);
|
||||
RETURN_STRING (pr, path);
|
||||
free (path);
|
||||
} else {
|
||||
R_STRING (pr) = P_STRING (pr, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
qdb_find_global (progs_t *pr)
|
||||
{
|
||||
|
@ -603,6 +629,7 @@ static builtin_t builtins[] = {
|
|||
{"qdb_get_data", qdb_get_data, -1},
|
||||
{"qdb_get_string|{tag qdb_target_s=}i", qdb_get_string, -1},
|
||||
{"qdb_get_string|{tag qdb_target_s=}*", qdb_get_string, -1},
|
||||
{"qdb_get_file_path", qdb_get_file_path, -1},
|
||||
{"qdb_find_global", qdb_find_global, -1},
|
||||
{"qdb_find_field", qdb_find_field, -1},
|
||||
{"qdb_find_function", qdb_find_function, -1},
|
||||
|
|
|
@ -87,6 +87,7 @@ int qdb_get_data (qdb_target_t target, unsigned src, unsigned len, void *dst);
|
|||
// note: str is likely not valid in the host progs, it's just a convinience to
|
||||
// avoid cast shenanigans when getting type encoding strings
|
||||
@overload string qdb_get_string (qdb_target_t target, string str);
|
||||
string qdb_get_file_path (qdb_target_t target, string file);
|
||||
qdb_def_t qdb_find_global (qdb_target_t target, string name);
|
||||
qdb_def_t qdb_find_field (qdb_target_t target, string name);
|
||||
qdb_function_t *qdb_find_function (qdb_target_t target, string name);
|
||||
|
|
|
@ -17,6 +17,7 @@ int qdb_get_data (qdb_target_t target, unsigned src, unsigned len,
|
|||
void *dst) = #0;
|
||||
string qdb_get_string (qdb_target_t target, unsigned str) = #0;
|
||||
string qdb_get_string (qdb_target_t target, string str) = #0;
|
||||
string qdb_get_file_path (qdb_target_t target, string file) = #0;
|
||||
qdb_def_t qdb_find_global (qdb_target_t target, string name) = #0;
|
||||
qdb_def_t qdb_find_field (qdb_target_t target, string name) = #0;
|
||||
qdb_function_t *qdb_find_function (qdb_target_t target, string name) = #0;
|
||||
|
|
Loading…
Reference in a new issue