actually do some fixups, but it segs atm :/

This commit is contained in:
Bill Currie 2001-07-18 00:26:14 +00:00
parent 36af2c6078
commit c298d4919c
5 changed files with 126 additions and 9 deletions

View file

@ -23,4 +23,8 @@ def_t *Find_Global_Def_offs (int offs);
def_t *Find_Field_Def_name (const char *name);
def_t *Find_Field_Def_offs (int offs);
struct progs_s;
void fix_missing_globals (struct progs_s *pr, def_t *globals);
void fix_missing_fields (struct progs_s *pr, def_t *fields);
#endif//__def_h

View file

@ -5,7 +5,7 @@ INCLUDES= -I$(top_srcdir)/include
bin_PROGRAMS= qfdefs
noinst_PROGRAMS= gendefs
qfdefs_SOURCES= defs.c defs_nq.c defs_qw.c qfdefs.c
qfdefs_SOURCES= defs.c defs_nq.c defs_qw.c fix_globals.c qfdefs.c
qfdefs_LDADD= -lQFgamecode -lQFutil
gendefs_SOURCES= gendefs.c

View file

@ -0,0 +1,103 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <QF/progs.h>
#include "def.h"
extern char *type_name[];
void
update_offsets (dprograms_t *pr, int mark, int count)
{
if (pr->ofs_statements > mark)
pr->ofs_statements += count;
if (pr->ofs_globaldefs > mark)
pr->ofs_globaldefs += count;
if (pr->ofs_fielddefs > mark)
pr->ofs_fielddefs += count;
if (pr->ofs_functions > mark)
pr->ofs_functions += count;
if (pr->ofs_strings > mark)
pr->ofs_strings += count;
if (pr->ofs_globals > mark)
pr->ofs_globals += count;
}
void
fix_missing_globals (progs_t *pr, def_t *globals)
{
int defs_count = 0;
int strings_size = 0;
int defs_size;
int i;
def_t *def;
ddef_t **new_defs, *d, **n;
char *new_strings;
dprograms_t *progs;
for (def = globals; def->name; def ++) {
if (!PR_FindGlobal (pr, def->name)) {
defs_count++;
}
}
n = new_defs = calloc (defs_count, sizeof (def_t **));
for (def = globals; def->name; def ++) {
d = ED_GlobalAtOfs (pr, def->offset);
if (d) {
if (d->type != (def->type)) {
fprintf (stderr,
"global def %s at %d has mismatched type (%s, %s)\n",
def->name, def->offset,
type_name[def->type & ~DEF_SAVEGLOBAL],
type_name[d->type & ~DEF_SAVEGLOBAL]);
exit (1);
}
if (strcmp (def->name, PR_GetString (pr, d->s_name)) == 0)
continue; // this one is ok
d->s_name = strings_size;
*n++ = d;
strings_size += strlen (def->name) + 1;
} else {
*n = calloc (sizeof (ddef_t), 1);
(*n)->type = (def->type | DEF_SAVEGLOBAL);
(*n)->ofs = def->offset;
(*n)->s_name = strings_size;
n++;
strings_size += strlen (def->name) + 1;
}
}
new_strings = calloc (strings_size, 1);
for (i = 0; i < 0; i++) {
def = Find_Global_Def_offs (n[i]->ofs);
strcpy (new_strings + n[i]->s_name, def->name);
n[i]->s_name += pr->pr_stringsize;
}
defs_size = defs_count * sizeof (ddef_t);
progs = malloc (pr->progs_size + strings_size + defs_size);
memcpy (progs, pr->progs, pr->progs_size);
memmove ((char*)progs + progs->ofs_globaldefs + defs_size,
(char*)progs + progs->ofs_globaldefs
+ progs->numglobaldefs * sizeof (ddef_t),
pr->progs_size - (progs->ofs_globaldefs + progs->numglobaldefs));
memcpy ((char*)progs + progs->ofs_globaldefs
+ progs->numglobaldefs * sizeof (ddef_t),
new_defs, defs_size);
progs->numglobaldefs += defs_count;
pr->progs_size += defs_size;
update_offsets (progs, progs->ofs_globaldefs, defs_size);
memmove ((char*)progs + progs->ofs_strings + strings_size,
(char*)progs + progs->ofs_strings + progs->numstrings,
pr->progs_size - (progs->ofs_strings + progs->numstrings));
memcpy ((char*)progs + progs->ofs_globaldefs + progs->numstrings,
new_strings, strings_size);
progs->numstrings += strings_size;
pr->progs_size += strings_size;
update_offsets (progs, progs->ofs_strings, strings_size);
pr->progs = progs;
}

View file

@ -20,19 +20,19 @@ output_def (FILE *out, const char *line)
for (name_e = name; *name_e && !isspace (*name_e) && *name_e != ';'; name_e++)
;
if (strncmp ("int", type, type_e - type) == 0) {
fprintf (out, "\t{ev_entity,\t%d,\t\"%.*s\"},\n",
fprintf (out, "\t{ev_entity | DEF_SAVEGLOBAL,\t%d,\t\"%.*s\"},\n",
offset, name_e - name, name);
offset += 1;
} else if (strncmp ("float", type, type_e - type) == 0) {
fprintf (out, "\t{ev_float,\t%d,\t\"%.*s\"},\n",
fprintf (out, "\t{ev_float | DEF_SAVEGLOBAL,\t%d,\t\"%.*s\"},\n",
offset, name_e - name, name);
offset += 1;
} else if (strncmp ("string_t", type, type_e - type) == 0) {
fprintf (out, "\t{ev_string,\t%d,\t\"%.*s\"},\n",
fprintf (out, "\t{ev_string | DEF_SAVEGLOBAL,\t%d,\t\"%.*s\"},\n",
offset, name_e - name, name);
offset += 1;
} else if (strncmp ("vec3_t", type, type_e - type) == 0) {
fprintf (out, "\t{ev_vector,\t%d,\t\"%.*s\"},\n",
fprintf (out, "\t{ev_vector | DEF_SAVEGLOBAL,\t%d,\t\"%.*s\"},\n",
offset, name_e - name, name);
offset += 3;
} else if (strncmp ("func_t", type, type_e - type) == 0) {

View file

@ -10,6 +10,7 @@
#include "QF/progs.h"
#include <QF/vfs.h>
#include <QF/sys.h>
#include <QF/va.h>
#include <QF/zone.h>
#include "def.h"
@ -17,8 +18,6 @@
void *membase;
int memsize = 16*1024*1024;
extern char *type_name[];
progs_t progs;
int
@ -48,6 +47,7 @@ main (int argc, char **argv)
return 1;
}
while (--argc) {
int fix = 0;
PR_LoadProgsFile (&progs, *++argv);
if (!progs.progs) {
fprintf (stderr, "failed to load %s\n", *argv);
@ -79,15 +79,25 @@ main (int argc, char **argv)
break;
if (!def->name)
printf ("%s: all system globals accounted for\n", *argv);
else
else {
printf ("%s: some system globals missing\n", *argv);
fix_missing_globals (&progs, globals);
fix++;
}
for (def = fields; def->name; def++)
if (!ED_FindField (&progs, def->name))
break;
if (!def->name)
printf ("%s: all system fields accounted for\n", *argv);
else
else {
printf ("%s: some system fields missing\n", *argv);
}
if (fix) {
//XXX FIXME endian fixups
FILE *f = fopen (va ("%s.new", *argv), "wb");
fwrite (progs.progs, progs.progs_size, 1, f);
fclose (f);
}
}
return 0;
}