ack/util/misc/esize.c

167 lines
2.8 KiB
C
Raw Normal View History

1988-03-14 14:29:31 +00:00
/* esize: prints info from e.out header
2019-05-10 17:15:51 +00:00
*/
1988-03-14 14:29:31 +00:00
#include <stdlib.h>
#include <stdio.h>
1988-03-14 14:29:31 +00:00
#ifndef MAGIC
#define MAGIC 07255
#endif /* MAGIC */
1988-03-14 14:29:31 +00:00
FILE *load_fp;
int eof;
/* Much of the code has been borrowed from the EM interpreter
2019-05-10 17:15:51 +00:00
*/
1988-03-14 14:29:31 +00:00
2019-05-10 17:15:51 +00:00
typedef /* unsigned */long ptr; /* pointer to EM adress */
1988-03-14 14:29:31 +00:00
long magic;
long flags;
long uref;
long version;
long wsize;
long psize;
long int7;
long int8;
long ntext;
long ndata;
long nproc;
long entrypoint;
long nline;
long szdata;
long ptr7;
long ptr8;
2019-05-10 17:15:51 +00:00
/* Forward declarations. */
static void esize(char *);
static int rd_open(char*);
static int rd_byte(void);
static long rd_int(long n);
static int rd_header(void);
static void rd_close(void);
#define rd_ptr() ((ptr) rd_int(psize))
int main(int argc, char *argv[])
1988-03-14 14:29:31 +00:00
{
printf("TPFCRE uref vers w/p text nproc szdata\n");
2019-05-10 17:15:51 +00:00
if (argc == 1)
{
1988-03-14 14:29:31 +00:00
esize("e.out");
}
2019-05-10 17:15:51 +00:00
else
{
while (argc > 1)
{
1988-03-14 14:29:31 +00:00
esize(argv[1]);
argc--, argv++;
}
}
2019-05-10 17:15:51 +00:00
exit(EXIT_SUCCESS);
1988-03-14 14:29:31 +00:00
}
2019-05-10 17:15:51 +00:00
static void esize(char *fname)
1988-03-14 14:29:31 +00:00
{
eof = 0;
2019-05-10 17:15:51 +00:00
if (!rd_open(fname))
{
1988-03-14 14:29:31 +00:00
printf("%s: cannot open\n", fname);
}
2019-05-10 17:15:51 +00:00
else
{
if (!rd_header())
{
1988-03-14 14:29:31 +00:00
printf("%s: not EM object format\n", fname);
}
2019-05-10 17:15:51 +00:00
else
{
printf("%c", flags & 0001 ? 'T' : '-');
printf("%c", flags & 0002 ? 'P' : '-');
printf("%c", flags & 0004 ? 'F' : '-');
printf("%c", flags & 0010 ? 'C' : '-');
printf("%c", flags & 0020 ? 'R' : '-');
printf("%c", flags & 0040 ? 'E' : '-');
printf("%c", flags & 0100 ? '?' : ' ');
printf("%c", flags & 0200 ? '?' : ' ');
1988-03-14 14:29:31 +00:00
printf("%3ld ", uref);
printf("%3ld ", version);
printf("%1ld/%1ld", wsize, psize);
printf("%c", int7 ? '?' : ' ');
printf("%c", int8 ? '?' : ' ');
2019-05-10 17:15:51 +00:00
1988-03-14 14:29:31 +00:00
printf("%5ld ", ntext);
printf("%5ld ", nproc);
printf("%6ld", szdata);
printf("%c", ptr7 ? '?' : ' ');
printf("%c", ptr8 ? '?' : ' ');
printf("%s\n", fname);
}
rd_close();
}
}
#define btol(a) ((long)(((long) (a)) & 0xFF))
2019-05-10 17:15:51 +00:00
static int rd_open(char* load_file)
1988-03-14 14:29:31 +00:00
{
2019-05-10 17:15:51 +00:00
return (load_fp = fopen(load_file, "rb")) != NULL;
1988-03-14 14:29:31 +00:00
}
2019-05-10 17:15:51 +00:00
static int rd_byte(void)
1988-03-14 14:29:31 +00:00
{
int i;
if ((i = fgetc(load_fp)) == EOF)
eof = 1;
return (i);
}
2019-05-10 17:15:51 +00:00
static long rd_int(long n)
1988-03-14 14:29:31 +00:00
{
long l;
register int i;
l = btol(rd_byte());
for (i = 1; i < n; i++)
2019-05-10 17:15:51 +00:00
l = l | (btol(rd_byte()) << (long) (i * 8));
1988-03-14 14:29:31 +00:00
return (l);
}
2019-05-10 17:15:51 +00:00
/* read e.out header information */
static int rd_header(void)
1988-03-14 14:29:31 +00:00
{
magic = rd_int(2L);
if (magic != MAGIC || eof)
return 0;
2019-05-10 17:15:51 +00:00
1988-03-14 14:29:31 +00:00
flags = rd_int(2L);
uref = rd_int(2L);
version = rd_int(2L);
wsize = rd_int(2L);
psize = rd_int(2L);
2019-05-10 17:15:51 +00:00
int7 = rd_int(2L); /* Entry 7 is unused */
int8 = rd_int(2L); /* Entry 8 is unused */
1988-03-14 14:29:31 +00:00
ntext = rd_ptr();
ndata = rd_ptr();
nproc = rd_ptr();
entrypoint = rd_ptr();
nline = rd_ptr();
szdata = rd_ptr();
2019-05-10 17:15:51 +00:00
ptr7 = rd_ptr(); /* entry 7 is unused */
ptr8 = rd_ptr(); /* entry 8 is unused */
1988-03-14 14:29:31 +00:00
return !eof;
}
2019-05-10 17:15:51 +00:00
static void rd_close(void)
1988-03-14 14:29:31 +00:00
{
fclose(load_fp);
}