From 631460dc33a02b110ac3b44227afbb4d19cd969d Mon Sep 17 00:00:00 2001 From: dresk Date: Sun, 8 Jul 2007 23:04:59 +0000 Subject: [PATCH] Added optional wildcard support for prvm_edict, prvm_edicts and prvm_globals commads. In prvm_edict/s, wildcard is for field names; in prvm_globals, wildcard is for generic names. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7473 d7cf8633-e32d-0410-b094-e92efae38249 --- progsvm.h | 4 ++-- prvm_cmds.c | 6 ++--- prvm_edict.c | 63 ++++++++++++++++++++++++++++++++++++++++------------ prvm_exec.c | 2 +- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/progsvm.h b/progsvm.h index 15c3e5a1..f2fe16bc 100644 --- a/progsvm.h +++ b/progsvm.h @@ -476,7 +476,7 @@ void PRVM_ED_Free (prvm_edict_t *ed); void PRVM_ED_ClearEdict (prvm_edict_t *e); void PRVM_PrintFunctionStatements (const char *name); -void PRVM_ED_Print(prvm_edict_t *ed); +void PRVM_ED_Print(prvm_edict_t *ed, const char *wildcard_fieldname); void PRVM_ED_Write (qfile_t *f, prvm_edict_t *ed); const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent); @@ -521,7 +521,7 @@ extern int prvm_type_size[8]; // for consistency : I think a goal of this sub-p void PRVM_Init_Exec(void); void PRVM_ED_PrintEdicts_f (void); -void PRVM_ED_PrintNum (int ent); +void PRVM_ED_PrintNum (int ent, const char *wildcard_fieldname); const char *PRVM_GetString(int num); int PRVM_SetEngineString(const char *s); diff --git a/prvm_cmds.c b/prvm_cmds.c index 34ca11ad..16644d01 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -115,7 +115,7 @@ void VM_error (void) if (prog->globaloffsets.self >= 0) { ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict); - PRVM_ED_Print(ed); + PRVM_ED_Print(ed, NULL); } PRVM_ERROR ("%s: Program error in function %s:\n%s\nTip: read above for entity information\n", PRVM_NAME, PRVM_GetString(prog->xfunction->s_name), string); @@ -141,7 +141,7 @@ void VM_objerror (void) if (prog->globaloffsets.self >= 0) { ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict); - PRVM_ED_Print(ed); + PRVM_ED_Print(ed, NULL); PRVM_ED_Free (ed); } @@ -1108,7 +1108,7 @@ void VM_eprint (void) { VM_SAFEPARMCOUNT(1,VM_eprint); - PRVM_ED_PrintNum (PRVM_G_EDICTNUM(OFS_PARM0)); + PRVM_ED_PrintNum (PRVM_G_EDICTNUM(OFS_PARM0), NULL); } /* diff --git a/prvm_edict.c b/prvm_edict.c index ed069ea7..bec4765f 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -574,7 +574,7 @@ For debugging */ // LordHavoc: optimized this to print out much more quickly (tempstring) // LordHavoc: changed to print out every 4096 characters (incase there are a lot of fields to print) -void PRVM_ED_Print(prvm_edict_t *ed) +void PRVM_ED_Print(prvm_edict_t *ed, const char *wildcard_fieldname) { size_t l; ddef_t *d; @@ -599,6 +599,12 @@ void PRVM_ED_Print(prvm_edict_t *ed) if (name[strlen(name)-2] == '_') continue; // skip _x, _y, _z vars + // Check Field Name Wildcard + if(wildcard_fieldname) + if( !matchpattern(name, wildcard_fieldname, 1) ) + // Didn't match; skip + continue; + v = (int *)((char *)ed->fields.vp + d->ofs*4); // if the value is still all 0, skip the field @@ -689,9 +695,9 @@ void PRVM_ED_Write (qfile_t *f, prvm_edict_t *ed) FS_Print(f, "}\n"); } -void PRVM_ED_PrintNum (int ent) +void PRVM_ED_PrintNum (int ent, const char *wildcard_fieldname) { - PRVM_ED_Print(PRVM_EDICT_NUM(ent)); + PRVM_ED_Print(PRVM_EDICT_NUM(ent), wildcard_fieldname); } /* @@ -704,10 +710,11 @@ For debugging, prints all the entities in the current server void PRVM_ED_PrintEdicts_f (void) { int i; + const char *wildcard_fieldname; - if(Cmd_Argc() != 2) + if(Cmd_Argc() < 2 || Cmd_Argc() > 3) { - Con_Print("prvm_edicts \n"); + Con_Print("prvm_edicts \n"); return; } @@ -715,9 +722,14 @@ void PRVM_ED_PrintEdicts_f (void) if(!PRVM_SetProgFromString(Cmd_Argv(1))) return; + if( Cmd_Argc() == 3) + wildcard_fieldname = Cmd_Argv(2); + else + wildcard_fieldname = NULL; + Con_Printf("%s: %i entities\n", PRVM_NAME, prog->num_edicts); for (i=0 ; inum_edicts ; i++) - PRVM_ED_PrintNum (i); + PRVM_ED_PrintNum (i, wildcard_fieldname); PRVM_End; } @@ -732,10 +744,11 @@ For debugging, prints a single edict void PRVM_ED_PrintEdict_f (void) { int i; + const char *wildcard_fieldname; - if(Cmd_Argc() != 3) + if(Cmd_Argc() < 3 || Cmd_Argc() > 4) { - Con_Print("prvm_edict \n"); + Con_Print("prvm_edict \n"); return; } @@ -750,7 +763,13 @@ void PRVM_ED_PrintEdict_f (void) PRVM_End; return; } - PRVM_ED_PrintNum (i); + if( Cmd_Argc() == 4) + // Optional Wildcard Provided + wildcard_fieldname = Cmd_Argv(3); + else + // Use All + wildcard_fieldname = NULL; + PRVM_ED_PrintNum (i, wildcard_fieldname); PRVM_End; } @@ -1255,7 +1274,7 @@ void PRVM_ED_LoadFromFile (const char *data) if (!handle) { Con_Print("No classname for:\n"); - PRVM_ED_Print(ent); + PRVM_ED_Print(ent, NULL); PRVM_ED_Free (ent); continue; } @@ -1268,7 +1287,7 @@ void PRVM_ED_LoadFromFile (const char *data) if (developer.integer) // don't confuse non-developers with errors { Con_Print("No spawn function for:\n"); - PRVM_ED_Print(ent); + PRVM_ED_Print(ent, NULL); } PRVM_ED_Free (ent); continue; @@ -1888,15 +1907,18 @@ void PRVM_Fields_f (void) void PRVM_Globals_f (void) { int i; + const char *wildcard; + int numculled; + numculled = 0; // TODO /*if (!sv.active) { Con_Print("no progs loaded\n"); return; }*/ - if(Cmd_Argc () != 2) + if(Cmd_Argc () < 2 || Cmd_Argc() > 3) { - Con_Print("prvm_globals \n"); + Con_Print("prvm_globals \n"); return; } @@ -1904,11 +1926,24 @@ void PRVM_Globals_f (void) if(!PRVM_SetProgFromString (Cmd_Argv (1))) return; + if( Cmd_Argc() == 3) + wildcard = Cmd_Argv(2); + else + wildcard = NULL; + Con_Printf("%s :", PRVM_NAME); for (i = 0;i < prog->progs->numglobaldefs;i++) + { + if(wildcard) + if( !matchpattern( PRVM_GetString(prog->globaldefs[i].s_name), wildcard, 1) ) + { + numculled++; + continue; + } Con_Printf("%s\n", PRVM_GetString(prog->globaldefs[i].s_name)); - Con_Printf("%i global variables, totalling %i bytes\n", prog->progs->numglobals, prog->progs->numglobals * 4); + } + Con_Printf("%i global variables, %i culled, totalling %i bytes\n", prog->progs->numglobals, numculled, prog->progs->numglobals * 4); PRVM_End; } diff --git a/prvm_exec.c b/prvm_exec.c index 2a6d44aa..a889f66b 100644 --- a/prvm_exec.c +++ b/prvm_exec.c @@ -501,7 +501,7 @@ void PRVM_ExecuteProgram (func_t fnum, const char *errormessage) if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions) { if (prog->globaloffsets.self >= 0 && PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict) - PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict)); + PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict), NULL); PRVM_ERROR ("PRVM_ExecuteProgram: %s", errormessage); } -- 2.39.2