Pristine Ack-5.5
[Ack-5.5.git] / util / amisc / asize.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 /* $Id: asize.c,v 1.8 1994/06/24 10:13:48 ceriel Exp $ */
6
7 #include        <stdio.h>
8 #include        "out.h"
9
10 /*
11         asize -- determine object size
12
13 */
14
15 main(argc, argv)
16 char **argv;
17 {
18         struct outhead  buf;
19         struct outsect  sbuf;
20         unsigned short  nrsect;
21         long            sum;
22         int             gorp;
23
24         if (--argc == 0) {
25                 argc = 1;
26                 argv[1] = "a.out";
27         }
28         gorp = argc;
29
30         while(argc--) {
31                 if (! rd_open(*++argv)) {
32                         fprintf(stderr, "asize: cannot open %s\n", *argv);
33                         continue;
34                 }
35                 rd_ohead(&buf);
36                 if(BADMAGIC(buf)) {
37                         fprintf(stderr, "asize: %s-- bad format\n", *argv);
38                         rd_close();
39                         continue;
40                 }
41                 nrsect = buf.oh_nsect;
42                 if (nrsect == 0) {
43                         fprintf(stderr, "asize: %s-- no sections\n", *argv);
44                         rd_close();
45                         continue;
46                 }
47                 if (gorp > 1)
48                         printf("%s: ", *argv);
49
50                 sum = 0;
51                 while (nrsect-- > 0) {
52                         rd_sect(&sbuf, 1);
53                         printf("%ld", sbuf.os_size);
54                         sum += sbuf.os_size;
55                         if (nrsect > 0)
56                                 putchar('+');
57                 }
58                 printf(" = %ld = 0x%lx\n", sum, sum);
59                 rd_close();
60         }
61         exit(0);
62 }
63
64 rd_fatal()
65 {
66         fprintf(stderr, "read error\n");
67         exit(2);
68 }