allow sorting defs by address

This commit is contained in:
Bill Currie 2003-04-23 20:10:51 +00:00
parent 19980964d7
commit 2a127dd702
3 changed files with 34 additions and 3 deletions

View file

@ -5,4 +5,7 @@ struct progs_s;
struct dfunction_s *func_find (int st_num);
extern int sorted;
extern int verbosity;
#endif//__qfprogs_h

View file

@ -35,6 +35,12 @@ static __attribute__ ((unused)) const char rcsid[] =
"$Id$";
#include <stdlib.h>
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include "QF/progs.h"
#include "QF/va.h"
@ -42,6 +48,15 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "qfprogs.h"
#include "globals.h"
static int
cmp (const void *_a, const void *_b)
{
const ddef_t *a = (const ddef_t *)_a;
const ddef_t *b = (const ddef_t *)_b;
return a->ofs - b->ofs;
}
void
dump_globals (progs_t *pr)
{
@ -51,9 +66,16 @@ dump_globals (progs_t *pr)
int saveglobal;
int offset;
const char *comment;
ddef_t *global_defs = pr->pr_globaldefs;
if (sorted) {
global_defs = malloc (pr->progs->numglobaldefs * sizeof (ddef_t));
memcpy (global_defs, pr->pr_globaldefs,
pr->progs->numglobaldefs * sizeof (ddef_t));
qsort (global_defs, pr->progs->numglobaldefs, sizeof (ddef_t), cmp);
}
for (i = 0; i < pr->progs->numglobaldefs; i++) {
ddef_t *def = &pr->pr_globaldefs[i];
ddef_t *def = &global_defs[i];
if (!def->type && !def->ofs && !def->s_name)
continue;

View file

@ -66,6 +66,9 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "qfprogs.h"
#include "strings.h"
int sorted = 0;
int verbosity = 0;
static const struct option long_options[] = {
{"disassemble", no_argument, 0, 'd'},
{"globals", no_argument, 0, 'g'},
@ -76,6 +79,7 @@ static const struct option long_options[] = {
{"modules", no_argument, 0, 'M'},
{"path", required_argument, 0, 'P'},
{"verbose", no_argument, 0, 'v'},
{"numeric", no_argument, 0, 'n'},
{NULL, 0, NULL, 0},
};
@ -86,7 +90,6 @@ static progs_t pr;
static void *membase;
static int memsize = 1024*1024;
static int verbosity = 0;
static const char *source_path = "";
static hashtab_t *func_tab;
@ -225,7 +228,7 @@ main (int argc, char **argv)
void (*func)(progs_t *pr) = dump_globals;
while ((c = getopt_long (argc, argv,
"dgsfFlMP:v", long_options, 0)) != EOF) {
"dgsfFlMP:vn", long_options, 0)) != EOF) {
switch (c) {
case 'd':
func = disassemble_progs;
@ -254,6 +257,9 @@ main (int argc, char **argv)
case 'v':
verbosity++;
break;
case 'n':
sorted = 1;
break;
default:
return 1;
}