mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 12:52:46 +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);
|
||||
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 *(*allocate_progs_mem)(progs_t *pr, int size);
|
||||
void (*free_progs_mem)(progs_t *pr, void *mem);
|
||||
|
|
|
@ -68,9 +68,11 @@ typedef struct {
|
|||
progs_t *pr;
|
||||
} file_t;
|
||||
|
||||
cvar_t *pr_debug;
|
||||
cvar_t *pr_source_path;
|
||||
static hashtab_t *file_hash;
|
||||
cvar_t *pr_debug;
|
||||
cvar_t *pr_source_path;
|
||||
static hashtab_t *file_hash;
|
||||
static char *source_path_string;
|
||||
static char **source_paths;
|
||||
|
||||
|
||||
static const char *
|
||||
|
@ -91,6 +93,30 @@ file_free (void *_f, void *unused)
|
|||
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
|
||||
PR_Debug_Init (void)
|
||||
{
|
||||
|
@ -102,26 +128,31 @@ PR_Debug_Init_Cvars (void)
|
|||
{
|
||||
pr_debug = Cvar_Get ("pr_debug", "0", CVAR_NONE, NULL,
|
||||
"enable progs debugging");
|
||||
pr_source_path = Cvar_Get ("pr_source_path", ".", CVAR_NONE, NULL, "where "
|
||||
"to look (within gamedir) for source files");
|
||||
pr_source_path = Cvar_Get ("pr_source_path", ".", CVAR_NONE, source_path_f,
|
||||
"where to look (within gamedir) for source "
|
||||
"files");
|
||||
}
|
||||
|
||||
static file_t *
|
||||
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);
|
||||
|
||||
if (f)
|
||||
return f;
|
||||
f = malloc (sizeof (file_t));
|
||||
f = calloc (1, sizeof (file_t));
|
||||
if (!f)
|
||||
return 0;
|
||||
path = Hunk_TempAlloc (strlen (pr_source_path->string) + strlen (fname) +
|
||||
2);
|
||||
sprintf (path, "%s/%s", pr_source_path->string, fname);
|
||||
f->text = pr->load_file (pr, path);
|
||||
for (dir = source_paths; *dir && !f->text; dir++) {
|
||||
int len;
|
||||
len = strlen (*dir) + strlen (fname) + 2;
|
||||
path = Hunk_TempAlloc (len);
|
||||
sprintf (path, "%s/%s", *dir, fname);
|
||||
f->text = pr->load_file (pr, path);
|
||||
}
|
||||
if (!f->text) {
|
||||
pr->file_error (pr, path);
|
||||
free (f);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -72,6 +72,12 @@ var_get_key (void *d, void *_pr)
|
|||
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 *
|
||||
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_edictareasize = edicts * pr->pr_edict_size;
|
||||
|
||||
if (!pr->file_error)
|
||||
pr->file_error = file_error;
|
||||
if (!pr->load_file)
|
||||
pr->load_file = load_file;
|
||||
if (!pr->allocate_progs_mem)
|
||||
|
|
|
@ -42,6 +42,7 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#ifdef HAVE_IO_H
|
||||
# include <io.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
@ -73,6 +74,7 @@ static const struct option long_options[] = {
|
|||
{"functions", no_argument, 0, 'F'},
|
||||
{"lines", no_argument, 0, 'l'},
|
||||
{"modules", no_argument, 0, 'M'},
|
||||
{"path", required_argument, 0, 'P'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{NULL, 0, NULL, 0},
|
||||
};
|
||||
|
@ -85,6 +87,7 @@ static void *membase;
|
|||
static int memsize = 1024*1024;
|
||||
|
||||
static int verbosity = 0;
|
||||
static const char *source_path = "";
|
||||
|
||||
static hashtab_t *func_tab;
|
||||
|
||||
|
@ -99,6 +102,12 @@ open_file (const char *path, int *len)
|
|||
return file;
|
||||
}
|
||||
|
||||
static void
|
||||
file_error (progs_t *pr, const char *name)
|
||||
{
|
||||
perror (name);
|
||||
}
|
||||
|
||||
static void *
|
||||
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);
|
||||
if (!file) {
|
||||
file = open_file (va ("%s.gz", name), &size);
|
||||
if (!file) {
|
||||
perror (name);
|
||||
if (!file)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
sym = malloc (size);
|
||||
Qread (file, sym, size);
|
||||
|
@ -166,12 +173,14 @@ init_qf (void)
|
|||
Memory_Init (membase, memsize);
|
||||
|
||||
Cvar_Get ("pr_debug", va ("%d", verbosity), 0, 0, "");
|
||||
Cvar_Get ("pr_source_path", source_path, 0, 0, "");
|
||||
PR_Init_Cvars ();
|
||||
PR_Init ();
|
||||
|
||||
pr.edicts = &edicts;
|
||||
pr.num_edicts = &num_edicts;
|
||||
pr.reserved_edicts = &reserved_edicts;
|
||||
pr.file_error = file_error;
|
||||
pr.load_file = load_file;
|
||||
pr.allocate_progs_mem = allocate_progs_mem;
|
||||
pr.free_progs_mem = free_progs_mem;
|
||||
|
@ -215,7 +224,8 @@ main (int argc, char **argv)
|
|||
int c;
|
||||
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) {
|
||||
case 'd':
|
||||
func = disassemble_progs;
|
||||
|
@ -238,6 +248,8 @@ main (int argc, char **argv)
|
|||
case 'M':
|
||||
func = dump_modules;
|
||||
break;
|
||||
case 'P':
|
||||
source_path = strdup (optarg);
|
||||
case 'v':
|
||||
verbosity++;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue