asize.c 1.1 KB

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