ack/util/amisc/asize.c

70 lines
1.2 KiB
C
Raw Permalink Normal View History

1987-03-09 19:15:41 +00:00
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
1994-06-24 11:31:16 +00:00
/* $Id$ */
1985-04-12 14:55:00 +00:00
#include <stdlib.h>
1985-04-12 14:55:00 +00:00
#include <stdio.h>
#include "object.h"
1985-04-12 14:55:00 +00:00
#include "out.h"
/*
asize -- determine object size
*/
2019-03-24 15:53:13 +00:00
int main(int argc, char **argv)
1985-04-12 14:55:00 +00:00
{
struct outhead buf;
struct outsect sbuf;
1991-12-18 09:45:26 +00:00
unsigned short nrsect;
1985-04-12 14:55:00 +00:00
long sum;
int gorp;
if (--argc == 0) {
argc = 1;
argv[1] = "a.out";
}
gorp = argc;
while(argc--) {
1987-01-15 22:06:16 +00:00
if (! rd_open(*++argv)) {
1985-04-12 14:55:00 +00:00
fprintf(stderr, "asize: cannot open %s\n", *argv);
continue;
}
1987-01-15 22:06:16 +00:00
rd_ohead(&buf);
1985-04-12 14:55:00 +00:00
if(BADMAGIC(buf)) {
fprintf(stderr, "asize: %s-- bad format\n", *argv);
1987-01-15 22:06:16 +00:00
rd_close();
1985-04-12 14:55:00 +00:00
continue;
}
nrsect = buf.oh_nsect;
if (nrsect == 0) {
fprintf(stderr, "asize: %s-- no sections\n", *argv);
1987-01-15 22:06:16 +00:00
rd_close();
1985-04-12 14:55:00 +00:00
continue;
}
if (gorp > 1)
printf("%s: ", *argv);
sum = 0;
while (nrsect-- > 0) {
1987-01-15 22:06:16 +00:00
rd_sect(&sbuf, 1);
1985-04-12 14:55:00 +00:00
printf("%ld", sbuf.os_size);
sum += sbuf.os_size;
if (nrsect > 0)
putchar('+');
}
printf(" = %ld = 0x%lx\n", sum, sum);
1987-01-15 22:06:16 +00:00
rd_close();
1985-04-12 14:55:00 +00:00
}
2019-03-24 15:53:13 +00:00
exit(EXIT_SUCCESS);
1985-04-12 14:55:00 +00:00
}
2019-03-24 15:53:13 +00:00
void rd_fatal(void)
1985-04-12 14:55:00 +00:00
{
1987-01-15 22:06:16 +00:00
fprintf(stderr, "read error\n");
exit(2);
1985-04-12 14:55:00 +00:00
}