mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-05-31 08:41:11 +00:00
make pr_source_path a ; separated list of dirs and make it controllable in
qfprogs
This commit is contained in:
parent
15781b2f19
commit
71a60717d9
4 changed files with 67 additions and 15 deletions
|
@ -337,6 +337,7 @@ struct progs_s {
|
||||||
int (*prune_edict)(progs_t *pr, edict_t *ent);
|
int (*prune_edict)(progs_t *pr, edict_t *ent);
|
||||||
void (*free_edict)(progs_t *pr, edict_t *ent);
|
void (*free_edict)(progs_t *pr, edict_t *ent);
|
||||||
|
|
||||||
|
void (*file_error)(progs_t *pr, const char *path);
|
||||||
void *(*load_file)(progs_t *pr, const char *path);
|
void *(*load_file)(progs_t *pr, const char *path);
|
||||||
void *(*allocate_progs_mem)(progs_t *pr, int size);
|
void *(*allocate_progs_mem)(progs_t *pr, int size);
|
||||||
void (*free_progs_mem)(progs_t *pr, void *mem);
|
void (*free_progs_mem)(progs_t *pr, void *mem);
|
||||||
|
|
|
@ -68,9 +68,11 @@ typedef struct {
|
||||||
progs_t *pr;
|
progs_t *pr;
|
||||||
} file_t;
|
} file_t;
|
||||||
|
|
||||||
cvar_t *pr_debug;
|
cvar_t *pr_debug;
|
||||||
cvar_t *pr_source_path;
|
cvar_t *pr_source_path;
|
||||||
static hashtab_t *file_hash;
|
static hashtab_t *file_hash;
|
||||||
|
static char *source_path_string;
|
||||||
|
static char **source_paths;
|
||||||
|
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
|
@ -91,6 +93,30 @@ file_free (void *_f, void *unused)
|
||||||
free (f);
|
free (f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
source_path_f (cvar_t *var)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
if (source_path_string)
|
||||||
|
free (source_path_string);
|
||||||
|
source_path_string = strdup (var->string);
|
||||||
|
if (source_paths)
|
||||||
|
free (source_paths);
|
||||||
|
for (i = 2, s = source_path_string; *s; s++)
|
||||||
|
if (*s == ';')
|
||||||
|
i++;
|
||||||
|
source_paths = malloc (i * sizeof (char **));
|
||||||
|
source_paths[0] = source_path_string;
|
||||||
|
for (i = 1, s = source_path_string; *s; s++)
|
||||||
|
if (*s == ';') {
|
||||||
|
*s++ = 0;
|
||||||
|
source_paths[i++] = s;
|
||||||
|
}
|
||||||
|
source_paths[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PR_Debug_Init (void)
|
PR_Debug_Init (void)
|
||||||
{
|
{
|
||||||
|
@ -102,26 +128,31 @@ PR_Debug_Init_Cvars (void)
|
||||||
{
|
{
|
||||||
pr_debug = Cvar_Get ("pr_debug", "0", CVAR_NONE, NULL,
|
pr_debug = Cvar_Get ("pr_debug", "0", CVAR_NONE, NULL,
|
||||||
"enable progs debugging");
|
"enable progs debugging");
|
||||||
pr_source_path = Cvar_Get ("pr_source_path", ".", CVAR_NONE, NULL, "where "
|
pr_source_path = Cvar_Get ("pr_source_path", ".", CVAR_NONE, source_path_f,
|
||||||
"to look (within gamedir) for source files");
|
"where to look (within gamedir) for source "
|
||||||
|
"files");
|
||||||
}
|
}
|
||||||
|
|
||||||
static file_t *
|
static file_t *
|
||||||
PR_Load_Source_File (progs_t *pr, const char *fname)
|
PR_Load_Source_File (progs_t *pr, const char *fname)
|
||||||
{
|
{
|
||||||
char *path, *l;
|
char *path, *l, **dir;
|
||||||
file_t *f = Hash_Find (file_hash, fname);
|
file_t *f = Hash_Find (file_hash, fname);
|
||||||
|
|
||||||
if (f)
|
if (f)
|
||||||
return f;
|
return f;
|
||||||
f = malloc (sizeof (file_t));
|
f = calloc (1, sizeof (file_t));
|
||||||
if (!f)
|
if (!f)
|
||||||
return 0;
|
return 0;
|
||||||
path = Hunk_TempAlloc (strlen (pr_source_path->string) + strlen (fname) +
|
for (dir = source_paths; *dir && !f->text; dir++) {
|
||||||
2);
|
int len;
|
||||||
sprintf (path, "%s/%s", pr_source_path->string, fname);
|
len = strlen (*dir) + strlen (fname) + 2;
|
||||||
f->text = pr->load_file (pr, path);
|
path = Hunk_TempAlloc (len);
|
||||||
|
sprintf (path, "%s/%s", *dir, fname);
|
||||||
|
f->text = pr->load_file (pr, path);
|
||||||
|
}
|
||||||
if (!f->text) {
|
if (!f->text) {
|
||||||
|
pr->file_error (pr, path);
|
||||||
free (f);
|
free (f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,12 @@ var_get_key (void *d, void *_pr)
|
||||||
return PR_GetString (pr, def->s_name);
|
return PR_GetString (pr, def->s_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
file_error (progs_t *pr, const char *path)
|
||||||
|
{
|
||||||
|
Sys_Printf ("failed to load %s\n", path);
|
||||||
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
load_file (progs_t *pr, const char *path)
|
load_file (progs_t *pr, const char *path)
|
||||||
{
|
{
|
||||||
|
@ -155,6 +161,8 @@ PR_LoadProgsFile (progs_t * pr, QFile *file, int size, int edicts, int zone)
|
||||||
pr->pr_edict_size &= ~(sizeof (void*) - 1);
|
pr->pr_edict_size &= ~(sizeof (void*) - 1);
|
||||||
pr->pr_edictareasize = edicts * pr->pr_edict_size;
|
pr->pr_edictareasize = edicts * pr->pr_edict_size;
|
||||||
|
|
||||||
|
if (!pr->file_error)
|
||||||
|
pr->file_error = file_error;
|
||||||
if (!pr->load_file)
|
if (!pr->load_file)
|
||||||
pr->load_file = load_file;
|
pr->load_file = load_file;
|
||||||
if (!pr->allocate_progs_mem)
|
if (!pr->allocate_progs_mem)
|
||||||
|
|
|
@ -42,6 +42,7 @@ static __attribute__ ((unused)) const char rcsid[] =
|
||||||
#ifdef HAVE_IO_H
|
#ifdef HAVE_IO_H
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
|
@ -73,6 +74,7 @@ static const struct option long_options[] = {
|
||||||
{"functions", no_argument, 0, 'F'},
|
{"functions", no_argument, 0, 'F'},
|
||||||
{"lines", no_argument, 0, 'l'},
|
{"lines", no_argument, 0, 'l'},
|
||||||
{"modules", no_argument, 0, 'M'},
|
{"modules", no_argument, 0, 'M'},
|
||||||
|
{"path", required_argument, 0, 'P'},
|
||||||
{"verbose", no_argument, 0, 'v'},
|
{"verbose", no_argument, 0, 'v'},
|
||||||
{NULL, 0, NULL, 0},
|
{NULL, 0, NULL, 0},
|
||||||
};
|
};
|
||||||
|
@ -85,6 +87,7 @@ static void *membase;
|
||||||
static int memsize = 1024*1024;
|
static int memsize = 1024*1024;
|
||||||
|
|
||||||
static int verbosity = 0;
|
static int verbosity = 0;
|
||||||
|
static const char *source_path = "";
|
||||||
|
|
||||||
static hashtab_t *func_tab;
|
static hashtab_t *func_tab;
|
||||||
|
|
||||||
|
@ -99,6 +102,12 @@ open_file (const char *path, int *len)
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
file_error (progs_t *pr, const char *name)
|
||||||
|
{
|
||||||
|
perror (name);
|
||||||
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
load_file (progs_t *pr, const char *name)
|
load_file (progs_t *pr, const char *name)
|
||||||
{
|
{
|
||||||
|
@ -109,10 +118,8 @@ load_file (progs_t *pr, const char *name)
|
||||||
file = open_file (name, &size);
|
file = open_file (name, &size);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
file = open_file (va ("%s.gz", name), &size);
|
file = open_file (va ("%s.gz", name), &size);
|
||||||
if (!file) {
|
if (!file)
|
||||||
perror (name);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sym = malloc (size);
|
sym = malloc (size);
|
||||||
Qread (file, sym, size);
|
Qread (file, sym, size);
|
||||||
|
@ -166,12 +173,14 @@ init_qf (void)
|
||||||
Memory_Init (membase, memsize);
|
Memory_Init (membase, memsize);
|
||||||
|
|
||||||
Cvar_Get ("pr_debug", va ("%d", verbosity), 0, 0, "");
|
Cvar_Get ("pr_debug", va ("%d", verbosity), 0, 0, "");
|
||||||
|
Cvar_Get ("pr_source_path", source_path, 0, 0, "");
|
||||||
PR_Init_Cvars ();
|
PR_Init_Cvars ();
|
||||||
PR_Init ();
|
PR_Init ();
|
||||||
|
|
||||||
pr.edicts = &edicts;
|
pr.edicts = &edicts;
|
||||||
pr.num_edicts = &num_edicts;
|
pr.num_edicts = &num_edicts;
|
||||||
pr.reserved_edicts = &reserved_edicts;
|
pr.reserved_edicts = &reserved_edicts;
|
||||||
|
pr.file_error = file_error;
|
||||||
pr.load_file = load_file;
|
pr.load_file = load_file;
|
||||||
pr.allocate_progs_mem = allocate_progs_mem;
|
pr.allocate_progs_mem = allocate_progs_mem;
|
||||||
pr.free_progs_mem = free_progs_mem;
|
pr.free_progs_mem = free_progs_mem;
|
||||||
|
@ -215,7 +224,8 @@ main (int argc, char **argv)
|
||||||
int c;
|
int c;
|
||||||
void (*func)(progs_t *pr) = dump_globals;
|
void (*func)(progs_t *pr) = dump_globals;
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, "dgsfFlMv", long_options, 0)) != EOF) {
|
while ((c = getopt_long (argc, argv,
|
||||||
|
"dgsfFlMP:v", long_options, 0)) != EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'd':
|
case 'd':
|
||||||
func = disassemble_progs;
|
func = disassemble_progs;
|
||||||
|
@ -238,6 +248,8 @@ main (int argc, char **argv)
|
||||||
case 'M':
|
case 'M':
|
||||||
func = dump_modules;
|
func = dump_modules;
|
||||||
break;
|
break;
|
||||||
|
case 'P':
|
||||||
|
source_path = strdup (optarg);
|
||||||
case 'v':
|
case 'v':
|
||||||
verbosity++;
|
verbosity++;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue