add some functionality to qfprogs (globals and strings dumping)

This commit is contained in:
Bill Currie 2002-05-16 23:44:53 +00:00
parent 372c391737
commit 91c4039495
6 changed files with 177 additions and 4 deletions

View file

@ -0,0 +1,8 @@
#ifndef __globals_h
#define __globals_h
struct progs_s;
void dump_globals (struct progs_s *pr);
#endif//__globals_h

View file

@ -0,0 +1,8 @@
#ifndef __strings_h
#define __strings_h
struct progs_s;
void dump_strings (struct progs_s *pr);
#endif//__strings_h

View file

@ -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)

View file

@ -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 <stdlib.h>
#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));
}
}

View file

@ -42,6 +42,7 @@ static const char rcsid[] =
#ifdef HAVE_IO_H
# include <io.h>
#endif
#include <getopt.h>
#include <sys/types.h>
#include <sys/fcntl.h>
@ -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;
}

View file

@ -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 <stdlib.h>
#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++;
}
}