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