Exemplo n.º 1
0
eval_t *PR_FindGlobal(progfuncs_t *progfuncs, char *globname, progsnum_t pnum, etype_t *type)
{
	unsigned int i;
	ddef16_t *var16;
	ddef32_t *var32;
	if (pnum == PR_CURRENT)
		pnum = pr_typecurrent;
	if (pnum == PR_ANY)
	{
		eval_t *ev;
		for (i = 0; i < maxprogs; i++)
		{
			if (!pr_progstate[i].progs)
				continue;
			ev = PR_FindGlobal(progfuncs, globname, i, type);
			if (ev)
				return ev;
		}
		return NULL;
	}
	if (pnum < 0 || (unsigned)pnum >= maxprogs || !pr_progstate[pnum].progs)
		return NULL;
	switch(pr_progstate[pnum].structtype)
	{
	case PST_DEFAULT:
	case PST_KKQWSV:
		if (!(var16 = ED_FindGlobalFromProgs16(progfuncs, globname, pnum)))
			return NULL;

		if (type)
			*type = var16->type;
		return (eval_t *)&pr_progstate[pnum].globals[var16->ofs];
	case PST_QTEST:
	case PST_FTE32:
		if (!(var32 = ED_FindGlobalFromProgs32(progfuncs, globname, pnum)))
			return NULL;

		if (type)
			*type = var32->type;
		return (eval_t *)&pr_progstate[pnum].globals[var32->ofs];
	}
	Sys_Error("Error with def size (PR_FindGlobal)");
	return NULL;
}
Exemplo n.º 2
0
static int
menu_resolve_globals (progs_t *pr)
{
	const char *sym;
	ddef_t     *def;
	dfunction_t *f;
	size_t      i;

	for (i = 0;
		 i < sizeof (menu_functions) / sizeof (menu_functions[0]); i++) {
		sym = menu_functions[i].name;
		if (!(f = PR_FindFunction (pr, sym)))
			goto error;
		*menu_functions[i].func = (func_t) (f - menu_pr_state.pr_functions);
	}

	if (!(def = PR_FindGlobal (pr, sym = "time")))
		goto error;
	menu_pr_state.globals.time = &G_FLOAT (pr, def->ofs);
	return 1;
error:
	Sys_Printf ("%s: undefined symbol %s\n", pr->progs_name, sym);
	return 0;
}