asize.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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$ */
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include "out.h"
  9. /*
  10. asize -- determine object size
  11. */
  12. main(argc, argv)
  13. char **argv;
  14. {
  15. struct outhead buf;
  16. struct outsect sbuf;
  17. unsigned short nrsect;
  18. long sum;
  19. int gorp;
  20. if (--argc == 0) {
  21. argc = 1;
  22. argv[1] = "a.out";
  23. }
  24. gorp = argc;
  25. while(argc--) {
  26. if (! rd_open(*++argv)) {
  27. fprintf(stderr, "asize: cannot open %s\n", *argv);
  28. continue;
  29. }
  30. rd_ohead(&buf);
  31. if(BADMAGIC(buf)) {
  32. fprintf(stderr, "asize: %s-- bad format\n", *argv);
  33. rd_close();
  34. continue;
  35. }
  36. nrsect = buf.oh_nsect;
  37. if (nrsect == 0) {
  38. fprintf(stderr, "asize: %s-- no sections\n", *argv);
  39. rd_close();
  40. continue;
  41. }
  42. if (gorp > 1)
  43. printf("%s: ", *argv);
  44. sum = 0;
  45. while (nrsect-- > 0) {
  46. rd_sect(&sbuf, 1);
  47. printf("%ld", sbuf.os_size);
  48. sum += sbuf.os_size;
  49. if (nrsect > 0)
  50. putchar('+');
  51. }
  52. printf(" = %ld = 0x%lx\n", sum, sum);
  53. rd_close();
  54. }
  55. exit(0);
  56. }
  57. rd_fatal()
  58. {
  59. fprintf(stderr, "read error\n");
  60. exit(2);
  61. }