scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 45aeb7595a61f2f6b015a0beb08d99e520e20ffa
parent 212fd613473787dd0e59d312cbc3ee20dbee8862
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 23 Aug 2019 18:26:04 +0100

[libmach] Add probe method to Objops

Diffstat:
Minclude/scc/scc/mach.h | 1+
Msrc/libmach/coff32/coff32.h | 1+
Msrc/libmach/libmach.h | 1-
Msrc/libmach/objtype.c | 11+++--------
4 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -45,6 +45,7 @@ struct objsymdef { }; struct objops { + int (*probe)(unsigned char *buf, char **name); int (*new)(Obj *obj); int (*read)(Obj *obj, FILE *fp); int (*addr2line)(Obj *, unsigned long long , char *, int *); diff --git a/src/libmach/coff32/coff32.h b/src/libmach/coff32/coff32.h @@ -32,6 +32,7 @@ extern int coff32addr2line(Obj *, unsigned long long , char *, int *); extern int coff32strip(Obj *obj); extern void coff32del(Obj *obj); extern int coff32write(Obj *obj, FILE *fp); +extern int coff32probe(unsigned char *buf, char **name); extern int coff32xsetidx(int order, long nsyms, Objsymdef *head, FILE *fp); extern int coff32xgetidx(int order, long *nsyms, Objsymdef **def, FILE *fp); diff --git a/src/libmach/libmach.h b/src/libmach/libmach.h @@ -30,7 +30,6 @@ extern void objdel(Obj *obj); /* coff32 functions */ /* TODO: Move this functions to a coff32 files */ -extern int coff32probe(unsigned char *buf, char **name); extern char *coff32namidx(void); diff --git a/src/libmach/objtype.c b/src/libmach/objtype.c @@ -4,16 +4,12 @@ #include "libmach.h" -static int (*funv[])(unsigned char *, char **) = { - [COFF32] = coff32probe, -}; - int objtype(FILE *fp, char **name) { int n, i; - int (**fn)(unsigned char *, char **); fpos_t pos; + Objops **opsp, *ops; unsigned char buf[NBYTES]; fgetpos(fp, &pos); @@ -23,9 +19,8 @@ objtype(FILE *fp, char **name) if (n != 1 || ferror(fp)) return -1; - for (fn = funv; fn < &funv[NFORMATS]; ++fn) { - n = (**fn)(buf, name); - if (n == -1) + for (opsp = objops; ops = *opsp; ++opsp) { + if ((*ops->probe)(buf, name) < 0) continue; return n; }