home *** CD-ROM | disk | FTP | other *** search
/ M.u.C.S. Disc 2000 / MUCS2000.iso / gnuc / util-41s.lzh / util-41 / size68.c < prev    next >
C/C++ Source or Header  |  1998-10-05  |  3KB  |  156 lines

  1. /*                             -*- Mode: Elec-C -*- 
  2.  * size68.c -- report segment sizes take from program header
  3.  * 
  4.  * Author          : probably J.R.Bammi
  5.  * Created On      : some years ago
  6.  * Last Modified By: Frank Ridderbusch
  7.  * Last Modified On: Wed Apr 14 21:22:02 1993
  8.  * Update Count    : 6
  9.  * Status          : Unknown, Use with caution!
  10.  */
  11.  
  12. /* HISTORY 
  13.  * 14-Apr-1993        Frank Ridderbusch    
  14.  *    Deleted the prgflags structure in this file, since it is in
  15.  *    <st-out.h>. Added code to report status on all prgflags defined
  16.  *    upto now.
  17.  */
  18.  
  19. #include <stdio.h>
  20. #ifdef CROSSATARI
  21. #include "cross-inc/st-out.h"
  22. #else
  23. #include <st-out.h>
  24. #endif
  25.  
  26. /*
  27.  * ldflgs - stolen from MiNT mem.h
  28.  */
  29.  
  30. #define    F_PROTMODE    0xf0        /* protection mode bits */
  31. #define F_PROT_P    0x00        /* no read or write */
  32. #define F_PROT_G    0x10        /* any access OK */
  33. #define F_PROT_S    0x20        /* any super access OK */
  34. #define F_PROT_PR    0x30        /* any read OK, no write */
  35.  
  36. extern FILE *fopen();
  37.  
  38. extern void dump_version(char *prog);
  39. char *progname = "size68";
  40.  
  41. main(argc, argv)
  42. int argc;
  43. char **argv;
  44. {
  45.   if (argv[0][0] != '\0')
  46.     progname = argv[0];
  47.  
  48.   if (argc == 2 && strcmp(argv[1], "-v") == 0)
  49.   {
  50.     dump_version(progname);
  51.     exit(0);
  52.   }
  53.  
  54.     while(--argc > 0)
  55.         showfile(*++argv);
  56.     return 0;
  57. }
  58.  
  59. showfile(name)
  60. char *name;
  61. {
  62.     register FILE *fp;
  63.     struct aexec h;
  64.     
  65.     if((fp = fopen(name, "rb")) == (FILE *)NULL)
  66.     {
  67.         perror(name);
  68.         exit(1);
  69.     }
  70. # ifndef WORD_ALIGNED
  71.     if(fread(&h, sizeof(struct aexec), 1, fp) != 1)
  72.     {
  73.         perror(name);
  74.         exit(2);
  75.     }
  76. #else
  77.     aligned_read(&h, fp);
  78. #endif
  79.     fclose(fp);
  80.     
  81.     if(h.a_magic != CMAGIC)
  82.     {
  83.         fprintf(stderr,"Bad Magic #: 0X%x\n", h.a_magic);
  84.         exit(3);
  85.     }
  86.     printf("%s:\n\ttext size\t%ld\n\tdata size\t%ld\n\tbss size\t%ld\
  87. \n\tsymbol size\t%ld\n\tFile %s relocatable.\n\
  88. \t%s cleared on startup.\n", name, h.a_text,
  89.      h.a_data, h.a_bss, h.a_syms,
  90.     (h.a_isreloc == ISRELOCINFO) ? "is" : "is not",
  91.     (h.a_AZero2 & F_FASTLOAD) ? "Only BSS" : "BSS and high mem");
  92.     printf("\tFile is loaded into %s\n", 
  93.         (h.a_AZero2 & F_ALTLOAD) ? "alternate ram" : "ST ram");
  94.     printf("\t and allocates memory from %s.\n", 
  95.         (h.a_AZero2 & F_ALTALLOC) ? "alternate ram" : "ST ram");
  96.     printf("\tFile runs with `%s' memory protection (under MultiTOS).\n", 
  97.         (((h.a_AZero2 & F_PROTMODE) == F_PROT_PR) ? "readable" : 
  98.     (((h.a_AZero2 & F_PROTMODE) == F_PROT_S)  ? "super" :
  99.     (((h.a_AZero2 & F_PROTMODE) == F_PROT_G)  ? "global" : "private"))));
  100. }
  101.  
  102. # ifdef WORD_ALIGNED
  103. void ckfread(buf, siz, n, fp)
  104. char *buf;
  105. int siz, n;
  106. FILE *fp;
  107. {
  108.     if(fread(buf, siz, n, fp) != n)
  109.     {
  110.         perror("reading");
  111.         exit(3);
  112.     }
  113. }
  114.  
  115. aligned_read(h, fp)
  116. struct aexec *h;
  117. FILE *fp;
  118. {
  119.     short i;
  120.     long j;
  121.  
  122.     ckfread(&i, 2, 1, fp);
  123.     h->a_magic = i;
  124.     ckfread(&j, 4, 1, fp);
  125.     h->a_text = j;
  126.     ckfread(&j, 4, 1, fp);
  127.     h->a_data = j;
  128.     ckfread(&j, 4, 1, fp);
  129.     h->a_bss = j;
  130.     ckfread(&j, 4, 1, fp);
  131.     h->a_syms = j;
  132.     ckfread(&j, 4, 1, fp);
  133.     h->a_AZero1 = j;
  134.     ckfread(&j, 4, 1, fp);
  135.     h->a_AZero2 = j;
  136.     ckfread(&i, 2, 1, fp);
  137.     h->a_isreloc = i;
  138. }
  139. #endif
  140.  
  141. #ifdef CROSSHPUX
  142. char *xmalloc(n)
  143. unsigned n;
  144. {
  145.     extern char *malloc();
  146.     char *ret = malloc(n);
  147.     
  148.     if(!ret)
  149.     {
  150.         fprintf(stderr,"Out of memory!\n");
  151.         exit(1);
  152.     }
  153.     return ret;
  154. }
  155. #endif
  156.