source: trunk/minix/commands/autil/asize.c@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.5 KB
Line 
1/* @(#)asize.c 1.4 */
2#define ushort unsigned short
3
4#include <stdio.h>
5#include "out.h"
6
7/*
8 asize -- determine object size
9
10*/
11
12main(argc, argv)
13char **argv;
14{
15 struct outhead buf;
16 struct outsect sbuf;
17 ushort nrsect;
18 long sum;
19 int gorp;
20 FILE *f;
21
22 if (--argc == 0) {
23 argc = 1;
24 argv[1] = "a.out";
25 }
26 gorp = argc;
27
28 while(argc--) {
29 if ((f = fopen(*++argv, "r"))==NULL) {
30 fprintf(stderr, "asize: cannot open %s\n", *argv);
31 continue;
32 }
33 getofmt ((char *)&buf, SF_HEAD , f);
34 if(BADMAGIC(buf)) {
35 fprintf(stderr, "asize: %s-- bad format\n", *argv);
36 fclose(f);
37 continue;
38 }
39 nrsect = buf.oh_nsect;
40 if (nrsect == 0) {
41 fprintf(stderr, "asize: %s-- no sections\n", *argv);
42 fclose(f);
43 continue;
44 }
45 if (gorp > 1)
46 printf("%s: ", *argv);
47
48 sum = 0;
49 while (nrsect-- > 0) {
50 getofmt ((char *)&sbuf, SF_SECT , f);
51 printf("%ld", sbuf.os_size);
52 sum += sbuf.os_size;
53 if (nrsect > 0)
54 putchar('+');
55 }
56 printf(" = %ld = 0x%lx\n", sum, sum);
57 fclose(f);
58 }
59}
60
61getofmt(p, s, f)
62register char *p;
63register char *s;
64register FILE *f;
65{
66 register i;
67 register long l;
68
69 for (;;) {
70 switch (*s++) {
71/* case '0': p++; continue; */
72 case '1':
73 *p++ = getc(f);
74 continue;
75 case '2':
76 i = getc(f);
77 i |= (getc(f) << 8);
78 *((short *)p) = i; p += sizeof(short);
79 continue;
80 case '4':
81 l = (long)getc(f);
82 l |= ((long)getc(f) << 8);
83 l |= ((long)getc(f) << 16);
84 l |= ((long)getc(f) << 24);
85 *((long *)p) = l; p += sizeof(long);
86 continue;
87 default:
88 case '\0':
89 break;
90 }
91 break;
92 }
93}
Note: See TracBrowser for help on using the repository browser.