mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-07 00:11:39 +00:00
Make the cbuf api use a supplied cbuf rather than allocating its own. Kills
a FIXME and (Closes: #32)
This commit is contained in:
parent
8f9d7079e4
commit
8adad57941
3 changed files with 48 additions and 10 deletions
|
@ -35,8 +35,10 @@
|
||||||
void BI_Init ();
|
void BI_Init ();
|
||||||
|
|
||||||
struct progs_s;
|
struct progs_s;
|
||||||
|
struct cbuf_s;
|
||||||
|
|
||||||
void Cbuf_Progs_Init (struct progs_s *pr);
|
void Cbuf_Progs_Init (struct progs_s *pr);
|
||||||
|
void Cbuf_Progs_SetCbuf (struct progs_s *pr, struct cbuf_s *cbuf);
|
||||||
void Cmd_Progs_Init (struct progs_s *pr);
|
void Cmd_Progs_Init (struct progs_s *pr);
|
||||||
void Cvar_Progs_Init (struct progs_s *pr);
|
void Cvar_Progs_Init (struct progs_s *pr);
|
||||||
void File_Progs_Init (struct progs_s *pr);
|
void File_Progs_Init (struct progs_s *pr);
|
||||||
|
|
|
@ -476,6 +476,7 @@ Menu_Load (void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PR_InitRuntime (&menu_pr_state);
|
PR_InitRuntime (&menu_pr_state);
|
||||||
|
Cbuf_Progs_SetCbuf (&menu_pr_state, con_data.cbuf);
|
||||||
PR_ExecuteProgram (&menu_pr_state, menu_init);
|
PR_ExecuteProgram (&menu_pr_state, menu_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,25 +30,46 @@ static const char rcsid[] =
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "QF/cbuf.h"
|
#include "QF/cbuf.h"
|
||||||
#include "QF/idparse.h" // For now, use the id console parser
|
#include "QF/idparse.h" // For now, use the id console parser
|
||||||
#include "QF/progs.h"
|
#include "QF/progs.h"
|
||||||
|
|
||||||
static cbuf_t *cbuf; //FIXME use a properly allocated cbuf rather than this hack
|
|
||||||
|
|
||||||
static inline void
|
typedef struct {
|
||||||
check_cbuf (void)
|
cbuf_t *cbuf;
|
||||||
|
} cbuf_resources_t;
|
||||||
|
|
||||||
|
static cbuf_t *
|
||||||
|
get_cbuf (progs_t *pr, int arg, const char *func)
|
||||||
{
|
{
|
||||||
|
pr_type_t *handle;
|
||||||
|
cbuf_t *cbuf;
|
||||||
|
|
||||||
|
if (arg == 0) {
|
||||||
|
cbuf_resources_t *res = PR_Resources_Find (pr, "Cbuf");
|
||||||
|
cbuf = res->cbuf;
|
||||||
|
} else {
|
||||||
|
if (arg <= ((pr_type_t *) pr->zone - pr->pr_globals)
|
||||||
|
|| arg >= (pr->zone_size / sizeof (pr_type_t)))
|
||||||
|
PR_RunError (pr, "%s: Invalid cbuf_t", func);
|
||||||
|
|
||||||
|
handle = pr->pr_globals + arg;
|
||||||
|
|
||||||
|
cbuf = *(cbuf_t **)handle;
|
||||||
|
}
|
||||||
if (!cbuf)
|
if (!cbuf)
|
||||||
cbuf = Cbuf_New (&id_interp);
|
PR_RunError (pr, "Invalid cbuf_t");
|
||||||
|
|
||||||
|
return cbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bi_Cbuf_AddText (progs_t *pr)
|
bi_Cbuf_AddText (progs_t *pr)
|
||||||
{
|
{
|
||||||
const char *text = P_STRING (pr, 0);
|
const char *text = P_STRING (pr, 0);
|
||||||
|
cbuf_t *cbuf = get_cbuf (pr, 0, __FUNCTION__);
|
||||||
check_cbuf ();
|
|
||||||
Cbuf_AddText (cbuf, text);
|
Cbuf_AddText (cbuf, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,30 +77,44 @@ static void
|
||||||
bi_Cbuf_InsertText (progs_t *pr)
|
bi_Cbuf_InsertText (progs_t *pr)
|
||||||
{
|
{
|
||||||
const char *text = P_STRING (pr, 0);
|
const char *text = P_STRING (pr, 0);
|
||||||
|
cbuf_t *cbuf = get_cbuf (pr, 0, __FUNCTION__);
|
||||||
check_cbuf ();
|
|
||||||
Cbuf_InsertText (cbuf, text);
|
Cbuf_InsertText (cbuf, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bi_Cbuf_Execute (progs_t *pr)
|
bi_Cbuf_Execute (progs_t *pr)
|
||||||
{
|
{
|
||||||
check_cbuf ();
|
cbuf_t *cbuf = get_cbuf (pr, 0, __FUNCTION__);
|
||||||
Cbuf_Execute (cbuf);
|
Cbuf_Execute (cbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bi_Cbuf_Execute_Sets (progs_t *pr)
|
bi_Cbuf_Execute_Sets (progs_t *pr)
|
||||||
{
|
{
|
||||||
check_cbuf ();
|
cbuf_t *cbuf = get_cbuf (pr, 0, __FUNCTION__);
|
||||||
Cbuf_Execute_Sets (cbuf);
|
Cbuf_Execute_Sets (cbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bi_cbuf_clear (progs_t *pr, void *data)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Cbuf_Progs_Init (progs_t *pr)
|
Cbuf_Progs_Init (progs_t *pr)
|
||||||
{
|
{
|
||||||
|
cbuf_resources_t *res = calloc (sizeof (cbuf_resources_t), 0);
|
||||||
|
PR_Resources_Register (pr, "Cbuf", res, bi_cbuf_clear);
|
||||||
|
|
||||||
PR_AddBuiltin (pr, "Cbuf_AddText", bi_Cbuf_AddText, -1);
|
PR_AddBuiltin (pr, "Cbuf_AddText", bi_Cbuf_AddText, -1);
|
||||||
PR_AddBuiltin (pr, "Cbuf_InsertText", bi_Cbuf_InsertText, -1);
|
PR_AddBuiltin (pr, "Cbuf_InsertText", bi_Cbuf_InsertText, -1);
|
||||||
PR_AddBuiltin (pr, "Cbuf_Execute", bi_Cbuf_Execute, -1);
|
PR_AddBuiltin (pr, "Cbuf_Execute", bi_Cbuf_Execute, -1);
|
||||||
PR_AddBuiltin (pr, "Cbuf_Execute_Sets", bi_Cbuf_Execute_Sets, -1);
|
PR_AddBuiltin (pr, "Cbuf_Execute_Sets", bi_Cbuf_Execute_Sets, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Cbuf_Progs_SetCbuf (progs_t *pr, cbuf_t *cbuf)
|
||||||
|
{
|
||||||
|
cbuf_resources_t *res = PR_Resources_Find (pr, "Cbuf");
|
||||||
|
res->cbuf = cbuf;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue