1985-04-12 15:06:05 +00:00
|
|
|
#define DUK /* Modifications by Duk Bekema. */
|
|
|
|
|
1985-04-12 14:55:00 +00:00
|
|
|
/* @(#)asize.c 1.2 */
|
1985-04-12 15:06:05 +00:00
|
|
|
/* $Header$ */
|
1985-04-12 14:55:00 +00:00
|
|
|
#define ushort unsigned short
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "out.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
asize -- determine object size
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
main(argc, argv)
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
struct outhead buf;
|
|
|
|
struct outsect sbuf;
|
|
|
|
ushort nrsect;
|
|
|
|
long sum;
|
|
|
|
int gorp;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
if (--argc == 0) {
|
|
|
|
argc = 1;
|
|
|
|
argv[1] = "a.out";
|
|
|
|
}
|
|
|
|
gorp = argc;
|
|
|
|
|
|
|
|
while(argc--) {
|
|
|
|
if ((f = fopen(*++argv, "r"))==NULL) {
|
|
|
|
fprintf(stderr, "asize: cannot open %s\n", *argv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
getofmt ((char *)&buf, SF_HEAD , f);
|
|
|
|
if(BADMAGIC(buf)) {
|
|
|
|
fprintf(stderr, "asize: %s-- bad format\n", *argv);
|
|
|
|
fclose(f);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nrsect = buf.oh_nsect;
|
|
|
|
if (nrsect == 0) {
|
|
|
|
fprintf(stderr, "asize: %s-- no sections\n", *argv);
|
|
|
|
fclose(f);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (gorp > 1)
|
|
|
|
printf("%s: ", *argv);
|
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
while (nrsect-- > 0) {
|
|
|
|
getofmt ((char *)&sbuf, SF_SECT , f);
|
|
|
|
printf("%ld", sbuf.os_size);
|
|
|
|
sum += sbuf.os_size;
|
|
|
|
if (nrsect > 0)
|
|
|
|
putchar('+');
|
|
|
|
}
|
|
|
|
printf(" = %ld = 0x%lx\n", sum, sum);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getofmt(p, s, f)
|
|
|
|
register char *p;
|
|
|
|
register char *s;
|
|
|
|
register FILE *f;
|
|
|
|
{
|
|
|
|
register i;
|
|
|
|
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);
|
1985-04-12 15:06:05 +00:00
|
|
|
#ifndef DUK
|
|
|
|
*((short *)p)++ = i;
|
|
|
|
#else DUK
|
1985-04-12 14:59:45 +00:00
|
|
|
*((short *)p) = i;
|
|
|
|
p += sizeof(short);
|
1985-04-12 15:06:05 +00:00
|
|
|
#endif DUK
|
1985-04-12 14:55:00 +00:00
|
|
|
continue;
|
|
|
|
case '4':
|
|
|
|
l = (long)getc(f);
|
|
|
|
l |= (long)(getc(f) << 8);
|
|
|
|
l |= ((long)getc(f) << 16);
|
|
|
|
l |= ((long)getc(f) << 24);
|
1985-04-12 15:06:05 +00:00
|
|
|
#ifndef DUK
|
|
|
|
*((long *)p)++ = l;
|
|
|
|
#else DUK
|
1985-04-12 14:59:45 +00:00
|
|
|
*((long *)p) = l;
|
|
|
|
p += sizeof(long);
|
1985-04-12 15:06:05 +00:00
|
|
|
#endif DUK
|
1985-04-12 14:55:00 +00:00
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
case '\0':
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|