scc

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

commit 6acacf91976286d477c1a5c16046eac597f86f73
parent 74082f4925966f86b2d20c7f95246a239119c0d8
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 19 Feb 2019 09:09:01 +0000

[libmach] Remove array files

Diffstat:
Minclude/scc/scc/mach.h | 2+-
Msrc/cmd/ld.c | 3++-
Msrc/cmd/ranlib.c | 9+++++----
Msrc/libmach/.gitignore | 12------------
Msrc/libmach/Makefile | 27---------------------------
Msrc/libmach/coff32/Makefile | 1-
Dsrc/libmach/coff32/coff32namidx.c | 9---------
Msrc/libmach/coff32/coff32new.c | 1+
Msrc/libmach/getindex.c | 9+++++----
Msrc/libmach/libmach.h | 12------------
Dsrc/libmach/mktbl | 35-----------------------------------
Dsrc/libmach/namindex.c | 20--------------------
Msrc/libmach/objfree.c | 8++++----
Msrc/libmach/objnew.c | 8++++----
Msrc/libmach/objread.c | 8++++----
Msrc/libmach/objsect.c | 8++++----
Msrc/libmach/objstrip.c | 8++++----
Msrc/libmach/objsyms.c | 8++++----
Msrc/libmach/objtype.c | 10++++++----
Msrc/libmach/objwrite.c | 9+++++----
Msrc/libmach/setindex.c | 9+++++----
21 files changed, 54 insertions(+), 162 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -42,6 +42,7 @@ struct objsymdef { struct object { int type; + char *index; Objsym *htab[NR_SYMHASH]; Objsym *syms;; Objsect *secs; @@ -69,7 +70,6 @@ extern int archive(FILE *fp); extern long armember(FILE *fp, char *member); extern long setindex(int type, long nsyms, Objsymdef *def, FILE *fp); extern int getindex(int type, long *nsyms, Objsymdef **def, FILE *fp); -extern char *namindex(int type); /* TODO */ extern int objload(Obj *obj, Obj *to); diff --git a/src/cmd/ld.c b/src/cmd/ld.c @@ -327,7 +327,8 @@ newmember(FILE *fp, char *name, void *data) } if (*nmemb++ == 0) { - if(!strncmp(name, namindex(bintype), SARNAM)) { + if (!strncmp(name, "/", SARNAM) || + !strncmp(name, "__.SYMDEF", SARNAM)) { loadlib(fp); return 0; } diff --git a/src/cmd/ranlib.c b/src/cmd/ranlib.c @@ -16,6 +16,7 @@ #define NR_SYMDEF 32 +static char *namidx; static long nsymbols; static int status, artype, nolib; static char *filename, *membname; @@ -143,6 +144,7 @@ newmember(FILE *fp, char *nam, void *data) error("out of memory"); return 0; } + namidx = obj->index; if (objread(obj, fp) < 0 || objsyms(obj) < 0) { error("file corrupted"); @@ -198,7 +200,7 @@ static int merge(FILE *to, struct fprop *prop, FILE *lib, FILE *idx) { int c; - char *index, mtime[13]; + char mtime[13]; struct ar_hdr first; rewind(lib); @@ -208,8 +210,7 @@ merge(FILE *to, struct fprop *prop, FILE *lib, FILE *idx) if (fread(&first, sizeof(first), 1, lib) != 1) return 0; - index = namindex(artype); - if (!strncmp(first.ar_name, index, SARNAM)) + if (!strncmp(first.ar_name, namidx, SARNAM)) fseek(lib, atol(first.ar_size), SEEK_CUR); else fseek(lib, SARMAG, SEEK_SET); @@ -219,7 +220,7 @@ merge(FILE *to, struct fprop *prop, FILE *lib, FILE *idx) strftime(mtime, sizeof(mtime), "%s", gmtime(&prop->time)); fprintf(to, "%-16.16s%-12s%-6u%-6u%-8lo%-10ld`\n", - index, + namidx, mtime, prop->uid, prop->gid, diff --git a/src/libmach/.gitignore b/src/libmach/.gitignore @@ -1,13 +1 @@ objlst.mk -del.c -index.c -new.c -probe.c -read.c -strip.c -write.c -getidx.c -setidx.c -namidx.c -getsect.c -getsyms.c diff --git a/src/libmach/Makefile b/src/libmach/Makefile @@ -18,38 +18,14 @@ OBJS = objnew.o \ objlookup.o \ getindex.o \ setindex.o \ - namindex.o \ formember.o \ objtype.o \ objwrite.o \ pack.o \ unpack.o \ - new.o \ - read.o \ - del.o \ - strip.o \ - probe.o \ - write.o \ - getidx.o \ - setidx.o \ - namidx.o \ - getsect.o \ - getsyms.o \ DIRS = coff32 -TBLS = setidx.c \ - getidx.c \ - getsect.c \ - getsyms.c \ - namidx.c \ - new.c \ - read.c \ - del.c \ - strip.c \ - probe.c \ - write.c \ - all: $(OBJS) $(DIRS) objlst.mk +@$(MAKE) -f Makefile.mach @@ -57,9 +33,6 @@ all: $(OBJS) $(DIRS) objlst.mk $(DIRS): FORCE +@cd $@ && $(MAKE) -$(TBLS): formats.lst - mktbl -t `echo $@ | sed 's/\.c//'` -o $@ - objlst.mk: $(OBJS) $(DIRS) mklst $@ diff --git a/src/libmach/coff32/Makefile b/src/libmach/coff32/Makefile @@ -12,7 +12,6 @@ OBJS = coff32del.o \ coff32getindex.o \ coff32setidx.o \ coff32getidx.o \ - coff32namidx.o \ coff32getsect.o \ coff32getsyms.o \ diff --git a/src/libmach/coff32/coff32namidx.c b/src/libmach/coff32/coff32namidx.c @@ -1,9 +0,0 @@ -#include <stdio.h> - -#include <scc/mach.h> - -char * -coff32namidx(void) -{ - return "/"; -} diff --git a/src/libmach/coff32/coff32new.c b/src/libmach/coff32/coff32new.c @@ -14,5 +14,6 @@ coff32new(Obj *obj) if ((coff = calloc(1, sizeof(*coff))) == NULL) return -1; obj->data = coff; + obj->index = "/"; return 0; } diff --git a/src/libmach/getindex.c b/src/libmach/getindex.c @@ -4,17 +4,18 @@ #include "libmach.h" -extern getidxfun_t getidxv[]; +static int (*funv[])(int, long*, Objsymdef**, FILE*) = { + [COFF32] = coff32getidx, +}; int getindex(int type, long *nsyms, Objsymdef **head, FILE *fp) { int fmt; - getidxfun_t fn; fmt = FORMAT(type); if (fmt >= NFORMATS) return -1; - fn = getidxv[fmt]; - return (*fn)(type, nsyms, head, fp); + + return (*funv[fmt])(type, nsyms, head, fp); } diff --git a/src/libmach/libmach.h b/src/libmach/libmach.h @@ -28,18 +28,6 @@ enum deltype { TARGETDEL = 1 << 1, }; -typedef int (*newfun_t)(Obj *obj); -typedef int (*readfun_t)(Obj *obj, FILE *fp); -typedef void (*delfun_t)(Obj *new); -typedef void (*stripfun_t)(Obj *obj); -typedef int (*probefun_t)(unsigned char *buf, char **name); -typedef int (*writefun_t)(Obj *obj, FILE *fp); -typedef long (*setidxfun_t)(int, long, Objsymdef *, FILE *); -typedef int (*getidxfun_t)(int t, long *n, Objsymdef **def, FILE *fp); -typedef int (*getsectfun_t)(Obj *obj); -typedef char *(*namidxfun_t)(void); -typedef int (*getsymsfun_t)(Obj *obj); - /* common functions */ extern int pack(int order, unsigned char *dst, char *fmt, ...); extern int unpack(int order, unsigned char *src, char *fmt, ...); diff --git a/src/libmach/mktbl b/src/libmach/mktbl @@ -1,35 +0,0 @@ -#!/bin/sh - -for i -do - case "$1" in - -t) - target=$2 - shift 2 - ;; - -o) - out=$2 - shift 2 - ;; - -*) - echo mktbl [-t target][-o file] >&2 - exit 1 - ;; - *) - break - ;; - esac -done - -cat < formats.lst > $out <<EOF -#include <stdio.h> -#include <scc/mach.h> -#include "libmach.h" - -${target}fun_t ${target}v[] = { -`while read i - do - printf "\t%s," ${i}${target} - done` -}; -EOF diff --git a/src/libmach/namindex.c b/src/libmach/namindex.c @@ -1,20 +0,0 @@ -#include <stdio.h> - -#include <scc/mach.h> - -#include "libmach.h" - -extern namidxfun_t namidxv[]; - -char * -namindex(int type) -{ - int fmt; - namidxfun_t fn; - - fmt = FORMAT(type); - if (fmt >= NFORMATS) - return NULL; - fn = namidxv[fmt]; - return (*fn)(); -} diff --git a/src/libmach/objfree.c b/src/libmach/objfree.c @@ -6,20 +6,20 @@ #include "libmach.h" -extern delfun_t delv[]; +static void (*funv[])(Obj *) = { + [COFF32] = coff32del, +}; int objfree(Obj *obj, int what) { int fmt; - delfun_t fn; if (what & TARGETDEL) { fmt = FORMAT(obj->type); if (fmt < NFORMATS) return -1; - fn = delv[fmt]; - (*fn)(obj); + (*funv[fmt])(obj); } if (what & GENERICDEL) { diff --git a/src/libmach/objnew.c b/src/libmach/objnew.c @@ -6,14 +6,15 @@ #include "libmach.h" -extern newfun_t newv[]; +static int (*funv[])(Obj *) = { + [COFF32] = coff32new, +}; Obj * objnew(int type) { Obj *obj; int fmt; - newfun_t fn; fmt = FORMAT(type); if (fmt >= NFORMATS) @@ -29,8 +30,7 @@ objnew(int type) obj->nsecs = 0; memset(obj->htab, 0, sizeof(obj->htab)); - fn = newv[fmt]; - if ((*fn)(obj) < 0) { + if ((*funv[fmt])(obj) < 0) { free(obj); return NULL; } diff --git a/src/libmach/objread.c b/src/libmach/objread.c @@ -4,20 +4,20 @@ #include "libmach.h" -extern readfun_t readv[]; +static int (*funv[])(Obj *, FILE *) = { + [COFF32] = coff32read, +}; int objread(Obj *obj, FILE *fp) { int fmt; - readfun_t fn; fmt = FORMAT(obj->type); if (fmt >= NFORMATS) return -1; - fn = readv[fmt]; - if ((*fn)(obj, fp) < 0) + if ((*funv[fmt])(obj, fp) < 0) return -1; return 0; } diff --git a/src/libmach/objsect.c b/src/libmach/objsect.c @@ -4,18 +4,18 @@ #include "libmach.h" -extern getsectfun_t getsectv[]; +static int (*funv[])(Obj *) = { + [COFF32] = coff32getsect, +}; int objsect(Obj *obj) { int fmt; - getsectfun_t fn; fmt = FORMAT(obj->type); if (fmt >= NFORMATS) return -1; - fn = getsectv[fmt]; - return (*fn)(obj); + return (*funv[fmt])(obj); } diff --git a/src/libmach/objstrip.c b/src/libmach/objstrip.c @@ -4,19 +4,19 @@ #include "libmach.h" -extern stripfun_t stripv[]; +static void (*funv[])(Obj *) = { + [COFF32] = coff32strip, +}; int objstrip(Obj *obj) { int fmt; - stripfun_t fn; fmt = FORMAT(obj->type); if (fmt >= NFORMATS) return -1; - fn = stripv[fmt]; - (*fn)(obj); + (*funv[fmt])(obj); objfree(obj, GENERICDEL); diff --git a/src/libmach/objsyms.c b/src/libmach/objsyms.c @@ -4,18 +4,18 @@ #include "libmach.h" -extern getsymsfun_t getsymsv[]; +static int (*funv[])(Obj *) = { + [COFF32] = coff32getsyms, +}; int objsyms(Obj *obj) { int fmt; - getsymsfun_t fn; fmt = FORMAT(obj->type); if (fmt >= NFORMATS) return -1; - fn = getsymsv[fmt]; - return (*fn)(obj); + return (*funv[fmt])(obj); } diff --git a/src/libmach/objtype.c b/src/libmach/objtype.c @@ -4,13 +4,15 @@ #include "libmach.h" -extern probefun_t probev[]; +static int (*funv[])(unsigned char *, char **) = { + [COFF32] = coff32probe, +}; int objtype(FILE *fp, char **name) { int n, i; - probefun_t *fn; + int (**fn)(unsigned char *, char **); fpos_t pos; unsigned char buf[NBYTES]; @@ -21,8 +23,8 @@ objtype(FILE *fp, char **name) if (n != 1 || ferror(fp)) return -1; - for (fn = probev; fn < &probev[NFORMATS]; ++fn) { - n = (*fn)(buf, name); + for (fn = funv; fn < &funv[NFORMATS]; ++fn) { + n = (**fn)(buf, name); if (n == -1) continue; return n; diff --git a/src/libmach/objwrite.c b/src/libmach/objwrite.c @@ -4,19 +4,20 @@ #include "libmach.h" -extern writefun_t writev[]; +static int (*funv[])(Obj *, FILE *) = { + [COFF32] = coff32write, +}; int objwrite(Obj *obj, FILE *fp) { int fmt; - writefun_t fn; fmt = FORMAT(obj->type); if (fmt >= NFORMATS) return -1; - fn = writev[fmt]; - if ((*fn)(obj, fp) < 0) + + if ((*funv[fmt])(obj, fp) < 0) return -1; return 0; } diff --git a/src/libmach/setindex.c b/src/libmach/setindex.c @@ -4,17 +4,18 @@ #include "libmach.h" -extern setidxfun_t setidxv[]; +static long (*funv[])(int, long, Objsymdef *, FILE *) = { + [COFF32] = coff32setidx, +}; long setindex(int type, long nsyms, Objsymdef *head, FILE *fp) { int fmt; - setidxfun_t fn; fmt = FORMAT(type); if (fmt >= NFORMATS) return -1; - fn = setidxv[fmt]; - return (*fn)(type, nsyms, head, fp); + + return (*funv[fmt])(type, nsyms, head, fp); }