Using object library

This commit is contained in:
ceriel 1987-01-15 22:06:16 +00:00
parent 97cd4953b0
commit 382c88eb17
3 changed files with 88 additions and 234 deletions

View file

@ -1,6 +1,3 @@
#define DUK /* Modifications by Duk Bekema. */
/* @(#)anm.c 1.4 */
/* $Header$ */ /* $Header$ */
/* /*
** print symbol tables for ** print symbol tables for
@ -8,7 +5,6 @@
** **
** anm [-gopruns] [name ...] ** anm [-gopruns] [name ...]
*/ */
#define ushort unsigned short
#include "out.h" #include "out.h"
@ -23,13 +19,14 @@ int globl_flg;
int nosort_flg; int nosort_flg;
int arch_flg; int arch_flg;
int prep_flg; int prep_flg;
int read_error;
struct outhead hbuf; struct outhead hbuf;
struct outsect sbuf; struct outsect sbuf;
FILE *fi;
long off; long off;
char *malloc(); char *malloc();
char *realloc(); char *realloc();
long s_base[S_MAX]; /* for specially encoded bases */ long s_base[S_MAX]; /* for specially encoded bases */
char *filename;
main(argc, argv) main(argc, argv)
char **argv; char **argv;
@ -89,16 +86,21 @@ char **argv;
unsigned readcount; unsigned readcount;
int i,j; int i,j;
fi = fopen(*++argv,"r"); read_error = 0;
if (fi == NULL) { if (! rd_open(*++argv)) {
fprintf(stderr, "anm: cannot open %s\n", *argv); fprintf(stderr, "anm: cannot open %s\n", *argv);
continue; continue;
} }
getofmt((char *)&hbuf, SF_HEAD, fi); filename = *argv;
rd_ohead(&hbuf);
if (read_error) {
rd_close();
continue;
}
if (BADMAGIC(hbuf)) { if (BADMAGIC(hbuf)) {
fprintf(stderr, "anm: %s-- bad format\n", *argv); fprintf(stderr, "anm: %s -- bad format\n", *argv);
fclose(fi); rd_close();
continue; continue;
} }
if (narg > 1) if (narg > 1)
@ -106,14 +108,14 @@ char **argv;
n = hbuf.oh_nname; n = hbuf.oh_nname;
if (n == 0) { if (n == 0) {
fprintf(stderr, "anm: %s-- no name list\n", *argv); fprintf(stderr, "anm: %s -- no name list\n", *argv);
fclose(fi); rd_close();
continue; continue;
} }
if (hbuf.oh_nchar == 0) { if (hbuf.oh_nchar == 0) {
fprintf(stderr, "anm: %s-- no names\n", *argv); fprintf(stderr, "anm: %s -- no names\n", *argv);
fclose(fi); rd_close();
continue; continue;
} }
if ((readcount = hbuf.oh_nchar) != hbuf.oh_nchar) { if ((readcount = hbuf.oh_nchar) != hbuf.oh_nchar) {
@ -121,10 +123,14 @@ char **argv;
exit(2); exit(2);
} }
/* store special section bases */ /* store special section bases ??? */
if (hbuf.oh_flags & HF_8086) { if (hbuf.oh_flags & HF_8086) {
rd_sect(&sbuf, hbuf.oh_nsect);
if (read_error) {
rd_close();
continue;
}
for (i=0; i<hbuf.oh_nsect; i++) { for (i=0; i<hbuf.oh_nsect; i++) {
getofmt((char *)&sbuf, SF_SECT, fi);
s_base[i+S_MIN] = s_base[i+S_MIN] =
(sbuf.os_base>>12) & 03777760; (sbuf.os_base>>12) & 03777760;
} }
@ -134,17 +140,20 @@ char **argv;
fprintf(stderr, "anm: out of memory on %s\n", *argv); fprintf(stderr, "anm: out of memory on %s\n", *argv);
exit(2); exit(2);
} }
fseek(fi, OFF_CHAR(hbuf), 0); rd_string(cbufp, hbuf.oh_nchar);
if (fread(cbufp, 1, readcount, fi) == 0) { if (read_error) {
fprintf(stderr, "anm: read error on %s\n", *argv); free(cbufp);
exit(2); rd_close();
continue;
} }
fi_to_co = cbufp - OFF_CHAR(hbuf);
fseek(fi, OFF_NAME(hbuf), 0); fi_to_co = (long) (cbufp - OFF_CHAR(hbuf));
i = 0; i = 0;
while (--n >= 0) { while (--n >= 0) {
getofmt((char *)&nbuf, SF_NAME, fi); rd_name(&nbuf, 1);
if (read_error) {
break;
}
if (nbuf.on_foff == 0) if (nbuf.on_foff == 0)
continue; /* skip entries without names */ continue; /* skip entries without names */
@ -157,7 +166,7 @@ char **argv;
((nbuf.on_type&S_TYP)!=S_UND || (nbuf.on_type&S_ETC)!=0)) ((nbuf.on_type&S_TYP)!=S_UND || (nbuf.on_type&S_ETC)!=0))
continue; continue;
nbuf.on_mptr = nbuf.on_foff + fi_to_co; nbuf.on_mptr = (char *) (nbuf.on_foff + fi_to_co);
/* adjust value for specially encoded bases */ /* adjust value for specially encoded bases */
if (hbuf.oh_flags & HF_8086) { if (hbuf.oh_flags & HF_8086) {
@ -180,7 +189,7 @@ char **argv;
nbufp[i++] = nbuf; nbufp[i++] = nbuf;
} }
if (nosort_flg==0) if (nbufp && nosort_flg==0)
qsort(nbufp, i, sizeof(struct outname), compare); qsort(nbufp, i, sizeof(struct outname), compare);
for (n=0; n<i; n++) { for (n=0; n<i; n++) {
@ -231,7 +240,7 @@ char **argv;
free((char *)nbufp); free((char *)nbufp);
if (cbufp) if (cbufp)
free((char *)cbufp); free((char *)cbufp);
fclose(fi); rd_close();
} }
exit(0); exit(0);
} }
@ -265,46 +274,8 @@ struct outname *p1, *p2;
return(0); return(0);
} }
getofmt(p, s, f) rd_fatal()
register char *p;
register char *s;
register FILE *f;
{ {
register i; fprintf(stderr,"read error on %s\n", filename);
register long l; read_error = 1;
for (;;) {
switch (*s++) {
/* case '0': p++; continue; */
case '1':
*p++ = getc(f);
continue;
case '2':
i = getc(f);
i |= (getc(f) << 8);
#ifndef DUK
*((short *)p)++ = i;
#else DUK
*((short *)p) = i;
p += sizeof(short);
#endif DUK
continue;
case '4':
l = (long)getc(f);
l |= ((long)getc(f) << 8);
l |= ((long)getc(f) << 16);
l |= ((long)getc(f) << 24);
#ifndef DUK
*((long *)p)++ = l;
#else DUK
*((long *)p) = l;
p += sizeof(long);
#endif DUK
continue;
default:
case '\0':
break;
}
break;
}
} }

View file

@ -1,8 +1,4 @@
#define DUK /* Modifications by Duk Bekema. */
/* @(#)asize.c 1.2 */
/* $Header$ */ /* $Header$ */
#define ushort unsigned short
#include <stdio.h> #include <stdio.h>
#include "out.h" #include "out.h"
@ -20,7 +16,6 @@ char **argv;
ushort nrsect; ushort nrsect;
long sum; long sum;
int gorp; int gorp;
FILE *f;
if (--argc == 0) { if (--argc == 0) {
argc = 1; argc = 1;
@ -29,20 +24,20 @@ char **argv;
gorp = argc; gorp = argc;
while(argc--) { while(argc--) {
if ((f = fopen(*++argv, "r"))==NULL) { if (! rd_open(*++argv)) {
fprintf(stderr, "asize: cannot open %s\n", *argv); fprintf(stderr, "asize: cannot open %s\n", *argv);
continue; continue;
} }
getofmt ((char *)&buf, SF_HEAD , f); rd_ohead(&buf);
if(BADMAGIC(buf)) { if(BADMAGIC(buf)) {
fprintf(stderr, "asize: %s-- bad format\n", *argv); fprintf(stderr, "asize: %s-- bad format\n", *argv);
fclose(f); rd_close();
continue; continue;
} }
nrsect = buf.oh_nsect; nrsect = buf.oh_nsect;
if (nrsect == 0) { if (nrsect == 0) {
fprintf(stderr, "asize: %s-- no sections\n", *argv); fprintf(stderr, "asize: %s-- no sections\n", *argv);
fclose(f); rd_close();
continue; continue;
} }
if (gorp > 1) if (gorp > 1)
@ -50,57 +45,19 @@ char **argv;
sum = 0; sum = 0;
while (nrsect-- > 0) { while (nrsect-- > 0) {
getofmt ((char *)&sbuf, SF_SECT , f); rd_sect(&sbuf, 1);
printf("%ld", sbuf.os_size); printf("%ld", sbuf.os_size);
sum += sbuf.os_size; sum += sbuf.os_size;
if (nrsect > 0) if (nrsect > 0)
putchar('+'); putchar('+');
} }
printf(" = %ld = 0x%lx\n", sum, sum); printf(" = %ld = 0x%lx\n", sum, sum);
fclose(f); rd_close();
} }
} }
getofmt(p, s, f) rd_fatal()
register char *p;
register char *s;
register FILE *f;
{ {
register i; fprintf(stderr, "read error\n");
register long l; exit(2);
for (;;) {
switch (*s++) {
/* case '0': p++; continue; */
case '1':
*p++ = getc(f);
continue;
case '2':
i = getc(f);
i |= (getc(f) << 8);
#ifndef DUK
*((short *)p)++ = i;
#else DUK
*((short *)p) = i;
p += sizeof(short);
#endif DUK
continue;
case '4':
l = (long)getc(f);
l |= (long)(getc(f) << 8);
l |= ((long)getc(f) << 16);
l |= ((long)getc(f) << 24);
#ifndef DUK
*((long *)p)++ = l;
#else DUK
*((long *)p) = l;
p += sizeof(long);
#endif DUK
continue;
default:
case '\0':
break;
}
break;
}
} }

View file

@ -1,8 +1,4 @@
#define DUK /* Modifications by Duk Bekema. */
/* @(#)astrip.c 1.1 */
/* $Header$ */ /* $Header$ */
#define ushort unsigned short
#include "out.h" #include "out.h"
#include <signal.h> #include <signal.h>
@ -19,6 +15,7 @@ char *mktemp();
FILE *fopen(); FILE *fopen();
FILE *tf; FILE *tf;
struct outhead buf; struct outhead buf;
int readerror, writeerror;
main(argc, argv) main(argc, argv)
char **argv; char **argv;
@ -41,16 +38,17 @@ strip(name)
char *name; char *name;
{ {
long size; long size;
FILE *f;
if ((f = fopen(name,"r")) == NULL) { if (! rd_open(name)) {
fprintf(stderr, "astrip: cannot open %s\n", name); fprintf(stderr, "astrip: cannot open %s\n", name);
return(1); return(1);
} }
getofmt ((char *)&buf, SF_HEAD , f); readerror = 0;
if(BADMAGIC(buf)) { writeerror = 0;
rd_ohead(&buf);
if(readerror || BADMAGIC(buf)) {
fprintf(stderr, "astrip: %s-- bad format\n", name); fprintf(stderr, "astrip: %s-- bad format\n", name);
fclose(f); rd_close();
return(1); return(1);
} }
size = OFF_RELO(buf) - SZ_HEAD; size = OFF_RELO(buf) - SZ_HEAD;
@ -60,62 +58,68 @@ char *name;
buf.oh_nchar = 0; buf.oh_nchar = 0;
if ((tf = fopen(tname,"w")) == NULL) { if (! wr_open(tname)) {
fprintf(stderr, "astrip: cannot create temp file %s\n", tname); fprintf(stderr, "astrip: cannot create temp file %s\n", tname);
fclose(f); rd_close();
return(2); return(2);
} }
fseek(tf, (long)0, 0); wr_ohead(&buf);
putofmt((char *)&buf,SF_HEAD,tf,tname); if (writeerror) {
if(copy(name, tname, f, tf, size)) { fprintf(stderr, "astrip: write error on temp file %s\n", tname);
fclose(f); rd_close();
fclose(tf); wr_close();
return(1); return(1);
} }
fclose(f); if(copy(name, tname, size)) {
fclose(tf); rd_close();
wr_close();
return(1);
}
rd_close();
wr_close();
size += SZ_HEAD; size += SZ_HEAD;
if ((f = fopen(name,"w")) == NULL) { if (! wr_open(name)) {
fprintf(stderr, "astrip: cannot write %s\n", name); fprintf(stderr, "astrip: cannot write %s\n", name);
return(1); return(1);
} }
if ((tf = fopen(tname,"r")) == NULL) { if (! rd_open(tname)) {
fprintf(stderr, "astrip: cannot read temp file %s\n", tname); fprintf(stderr, "astrip: cannot read temp file %s\n", tname);
fclose(f); wr_close();
return(2); return(2);
} }
fseek(tf, (long)0, 0); if(copy(tname, name, size)) {
if(copy(tname, name, tf, f, size)) { wr_close();
fclose(f); rd_close();
fclose(tf);
return(2); return(2);
} }
fclose(f); wr_close();
fclose(tf); rd_close();
return(0); return(0);
} }
copy(fnam, tnam, fr, to, size) copy(fnam, tnam, size)
char *fnam; char *fnam;
char *tnam; char *tnam;
long size; long size;
FILE *fr,*to;
{ {
register s, n; register s, n;
char lbuf[512]; char lbuf[512];
int fr, fw;
fr = rd_fd();
fw = wr_fd();
while(size != (long)0) { while(size != (long)0) {
s = 512; s = 512;
if(size < 512) if(size < 512)
s = (int) size; s = (int) size;
n = fread(lbuf,1,s,fr); rd_bytes(fr, lbuf, (long) s);
if(n != s) { if (readerror) {
fprintf(stderr, "astrip: unexpected eof on %s\n", fnam); fprintf(stderr, "astrip: unexpected eof on %s\n", fnam);
return(1); return(1);
} }
n = fwrite(lbuf,1,s,to); wr_bytes(fw, lbuf, (long) s);
if(n != s) { if (writeerror) {
fprintf(stderr, "astrip: write error on %s\n", tnam); fprintf(stderr, "astrip: write error on %s\n", tnam);
return(1); return(1);
} }
@ -124,90 +128,12 @@ FILE *fr,*to;
return(0); return(0);
} }
getofmt(p, s, f) rd_fatal()
register char *p;
register char *s;
register FILE *f;
{ {
register i; readerror = 1;
register long l;
for (;;) {
switch (*s++) {
/* case '0': p++; continue; */
case '1':
*p++ = getc(f);
continue;
case '2':
i = getc(f);
i |= (getc(f) << 8);
#ifndef DUK
*((short *)p)++ = i;
#else DUK
*((short *)p) = i;
p += sizeof(short);
#endif DUK
continue;
case '4':
l = (long)getc(f);
l |= (long)(getc(f) << 8);
l |= ((long)getc(f) << 16);
l |= ((long)getc(f) << 24);
#ifndef DUK
*((long *)p)++ = l;
#else DUK
*((long *)p) = l;
p += sizeof(long);
#endif DUK
continue;
default:
case '\0':
break;
}
break;
}
} }
putofmt(p, s, f, fnam) wr_fatal()
register char *p;
register char *s;
register FILE *f;
char *fnam;
{ {
register i,j; writeerror = 1;
register long l;
while (j = *s++) {
switch (j -= '0') {
/* case 0: p++; break; */
case 1:
i = *p++; putc(i,f);
break;
case 2:
#ifndef DUK
i = *((short *)p)++;
#else DUK
i = *((short *)p);
p += sizeof(short);
#endif DUK
putc(i,f);
i>>=8; putc(i,f);
break;
case 4:
#ifndef DUK
l = *((long *)p)++;
#else DUK
l = *((long *)p);
p += sizeof(long);
#endif DUK
putc(l,f);
l >>=8; putc(l,f);
l >>=8; putc(l,f);
l >>=8; putc(l,f);
break;
default:
break;
}
if (ferror(f)) fprintf(stderr, "astrip: write error on %s\n", fnam);
}
} }