From 91c4039495a6ab233e724ccf0121b7c88a0794f6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 16 May 2002 23:44:53 +0000 Subject: [PATCH] add some functionality to qfprogs (globals and strings dumping) --- tools/qfprogs/include/globals.h | 8 ++++ tools/qfprogs/include/strings.h | 8 ++++ tools/qfprogs/source/Makefile.am | 2 +- tools/qfprogs/source/globals.c | 58 ++++++++++++++++++++++++++ tools/qfprogs/source/qfprogs.c | 34 +++++++++++++-- tools/qfprogs/source/strings.c | 71 ++++++++++++++++++++++++++++++++ 6 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 tools/qfprogs/include/globals.h create mode 100644 tools/qfprogs/include/strings.h create mode 100644 tools/qfprogs/source/globals.c create mode 100644 tools/qfprogs/source/strings.c diff --git a/tools/qfprogs/include/globals.h b/tools/qfprogs/include/globals.h new file mode 100644 index 000000000..9425e9bd0 --- /dev/null +++ b/tools/qfprogs/include/globals.h @@ -0,0 +1,8 @@ +#ifndef __globals_h +#define __globals_h + +struct progs_s; + +void dump_globals (struct progs_s *pr); + +#endif//__globals_h diff --git a/tools/qfprogs/include/strings.h b/tools/qfprogs/include/strings.h new file mode 100644 index 000000000..dd3ed97db --- /dev/null +++ b/tools/qfprogs/include/strings.h @@ -0,0 +1,8 @@ +#ifndef __strings_h +#define __strings_h + +struct progs_s; + +void dump_strings (struct progs_s *pr); + +#endif//__strings_h diff --git a/tools/qfprogs/source/Makefile.am b/tools/qfprogs/source/Makefile.am index aa0dbb358..174ecf60c 100644 --- a/tools/qfprogs/source/Makefile.am +++ b/tools/qfprogs/source/Makefile.am @@ -10,6 +10,6 @@ bin_PROGRAMS= qfprogs #man_MANS= qfprogs.1 -qfprogs_SOURCES= disassemble.c qfprogs.c +qfprogs_SOURCES= disassemble.c globals.c qfprogs.c strings.c qfprogs_LDADD= $(QFPROGS_LIBS) qfprogs_DEPENDENCIES= $(QFPROGS_DEPS) diff --git a/tools/qfprogs/source/globals.c b/tools/qfprogs/source/globals.c new file mode 100644 index 000000000..3652f36c2 --- /dev/null +++ b/tools/qfprogs/source/globals.c @@ -0,0 +1,58 @@ +/* + #FILENAME# + + #DESCRIPTION# + + Copyright (C) 2001 #AUTHOR# + + Author: #AUTHOR# + Date: #DATE# + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ +static const char rcsid[] = + "$Id$"; + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "QF/progs.h" + +#include "qfprogs.h" +#include "globals.h" + +void +dump_globals (progs_t *pr) +{ + int i; + + for (i = 0; i < pr->progs->numglobaldefs; i++) { + ddef_t *def = &pr->pr_globaldefs[i]; + + printf ("%s %d %d %s\n", + pr_type_name[def->type & ~DEF_SAVEGLOBAL], + (def->type & DEF_SAVEGLOBAL) != 0, + def->ofs, + PR_GetString (pr, def->s_name)); + } +} diff --git a/tools/qfprogs/source/qfprogs.c b/tools/qfprogs/source/qfprogs.c index 69f6835bb..8a3b44eba 100644 --- a/tools/qfprogs/source/qfprogs.c +++ b/tools/qfprogs/source/qfprogs.c @@ -42,6 +42,7 @@ static const char rcsid[] = #ifdef HAVE_IO_H # include #endif +#include #include #include @@ -57,6 +58,15 @@ static const char rcsid[] = #include "QF/vfile.h" #include "disassemble.h" +#include "globals.h" +#include "strings.h" + +static const struct option long_options[] = { + {"disassemble", no_argument, 0, 'd'}, + {"globals", no_argument, 0, 'g'}, + {"strings", no_argument, 0, 's'}, + {NULL, 0, NULL, 0}, +}; static edict_t *edicts; static int num_edicts; @@ -185,10 +195,28 @@ load_progs (const char *name) int main (int argc, char **argv) { + int c; + void (*func)(progs_t *pr) = dump_globals; + init_qf (); - while (*++argv) { - load_progs (*argv); - disassemble_progs (&pr); + while ((c = getopt_long (argc, argv, "dgs", long_options, 0)) != EOF) { + switch (c) { + case 'd': + func = disassemble_progs; + break; + case 'g': + func = dump_globals; + break; + case 's': + func = dump_strings; + break; + default: + return 1; + } + } + while (optind < argc) { + load_progs (argv[optind++]); + func (&pr); } return 0; } diff --git a/tools/qfprogs/source/strings.c b/tools/qfprogs/source/strings.c new file mode 100644 index 000000000..9b91541c3 --- /dev/null +++ b/tools/qfprogs/source/strings.c @@ -0,0 +1,71 @@ +/* + #FILENAME# + + #DESCRIPTION# + + Copyright (C) 2001 #AUTHOR# + + Author: #AUTHOR# + Date: #DATE# + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ +static const char rcsid[] = + "$Id$"; + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "QF/progs.h" +#include "QF/sys.h" + +#include "qfprogs.h" +#include "strings.h" + +void +dump_strings (progs_t *pr) +{ + int i = 0; + char *s = pr->pr_strings; + + while (i++ < pr->pr_stringsize) { + switch (*s) { + case 0: + fputs ("\n", stdout); + break; + case 9: + fputs ("\\t", stdout); + break; + case 10: + fputs ("\\n", stdout); + break; + case 13: + fputs ("\\r", stdout); + break; + default: + fputc (sys_char_map[(unsigned char)*s], stdout); + break; + } + s++; + } +}