Browse Source

Added the esize program

ceriel 36 years ago
parent
commit
e8f4ce0886
4 changed files with 198 additions and 13 deletions
  1. 2 0
      util/misc/.distr
  2. 20 13
      util/misc/Makefile
  3. 20 0
      util/misc/esize.1
  4. 156 0
      util/misc/esize.c

+ 2 - 0
util/misc/.distr

@@ -1,3 +1,5 @@
 Makefile
 convert.c
 em_decode.6
+esize.1
+esize.c

+ 20 - 13
util/misc/Makefile

@@ -1,10 +1,10 @@
 # $Header$
 
-d=../..
-h=$d/h
-l=$d/lib
-ml=$d/modules/lib
-mh=$d/modules/h
+EMHOME=../..
+h=$(EMHOME)/h
+l=$(EMHOME)/lib
+ml=$(EMHOME)/modules/lib
+mh=$(EMHOME)/modules/h
 
 DEC_PATH=decode
 ENC_PATH=encode
@@ -19,13 +19,16 @@ HFILES=$h/em_mnem.h $h/em_spec.h $h/em_pseu.h $h/em_flag.h $h/em_ptyp.h  \
 CFLAGS=-O -I$(mh) -I$h
 LDFLAGS = -i
 
-all:            $(DEC_PATH) $(ENC_PATH)
+all:            $(DEC_PATH) $(ENC_PATH) esize
 
 $(DEC_PATH):    decode.o $(DATA_PATH)
-		cc $(LDFLAGS) -o $(DEC_PATH) decode.o $(DECLIBS) $(DATA_PATH)
+		$(CC) $(LDFLAGS) -o $(DEC_PATH) decode.o $(DECLIBS) $(DATA_PATH)
 
 $(ENC_PATH):    encode.o $(DATA_PATH)
-		cc $(LDFLAGS) -o $(ENC_PATH) encode.o $(ENCLIBS) $(DATA_PATH)
+		$(CC) $(LDFLAGS) -o $(ENC_PATH) encode.o $(ENCLIBS) $(DATA_PATH)
+
+esize:		esize.o
+		$(CC) -o esize esize.o
 
 convert.o:	$(HFILES)
 
@@ -36,20 +39,24 @@ decode.o:	convert.o
 		cp convert.o decode.o
 
 clean:
-		rm -f $(DEC_PATH) $(ENC_PATH) *.o *.old
+		rm -f $(DEC_PATH) $(ENC_PATH) esize *.o *.old
 
 install :       all
-		rm -f $l/em_$(DEC_PATH) $l/em_$(ENC_PATH) $d/man/em_decode.6
+		rm -f $l/em_$(DEC_PATH) $l/em_$(ENC_PATH) $(EMHOME)/bin/esize $(EMHOME)/man/em_decode.6 $(EMHOME)/man/esize.1
 		cp $(DEC_PATH) $l/em_$(DEC_PATH)
 		cp $(ENC_PATH) $l/em_$(ENC_PATH)
-		cp em_decode.6 $d/man/em_decode.6
+		cp esize $(EMHOME)/bin/esize
+		cp em_decode.6 $(EMHOME)/man/em_decode.6
+		cp esize.1 $(EMHOME)/man/esize.1
 
 cmp :           all
 		-cmp $(DEC_PATH) $l/em_$(DEC_PATH)
 		-cmp $(ENC_PATH) $l/em_$(ENC_PATH)
-		-cmp em_decode.6 $d/man/em_decode.6
+		-cmp esize $(EMHOME)/bin/esize
+		-cmp em_decode.6 $(EMHOME)/man/em_decode.6
+		-cmp esize.1 $(EMHOME)/man/esize.1
 
 opr:
 		make pr ^ opr
 pr:
-		@pr -n Makefile convert.c
+		@pr -n Makefile convert.c esize.c

+ 20 - 0
util/misc/esize.1

@@ -0,0 +1,20 @@
+.TH ESIZE I
+.SH NAME
+esize \- print info from e.out header
+.SH SYNOPSIS
+.B esize
+[ file ... ]
+.SH DESCRIPTION
+.I Esize
+prints information from the
+.I e.out
+headers of the indicated files, including flags, word and pointer sizes,
+text and data sizes, etc. All values are in decimal.
+.PP
+If no parameters are given, the header of
+.I e.out
+is examined.
+.SH SEE ALSO
+The EM Manual, for the precise header information
+.SH AUTHOR
+Dick Grune

+ 156 - 0
util/misc/esize.c

@@ -0,0 +1,156 @@
+/*	esize:		prints info from e.out header
+*/
+
+#include	<stdio.h>
+
+#ifndef	MAGIC
+#define	MAGIC		07255
+#endif	MAGIC
+
+FILE *load_fp;
+int eof;
+
+/*	Much of the code has been borrowed from the EM interpreter
+*/
+
+typedef	unsigned long ptr;	/* pointer to EM adress */
+
+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;
+
+main(argc, argv)
+	int argc;
+	char *argv[];
+{
+	printf("TPFCRE uref vers  w/p   text  nproc  szdata\n");
+	
+	if (argc == 1)	{
+		esize("e.out");
+	}
+	else	{
+		while (argc > 1)	{
+			esize(argv[1]);
+			argc--, argv++;
+		}
+	}
+	exit(0);
+}
+
+esize(fname)
+	char *fname;
+{
+	eof = 0;
+	if (!rd_open(fname))	{
+		printf("%s: cannot open\n", fname);
+	}
+	else	{
+		if (!rd_header())	{
+			printf("%s: not EM object format\n", fname);
+		}
+		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 ? '?' : ' ');
+			
+			printf("%3ld  ", uref);
+			printf("%3ld  ", version);
+			printf("%1ld/%1ld", wsize, psize);
+			printf("%c", int7 ? '?' : ' ');
+			printf("%c", int8 ? '?' : ' ');
+				
+			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))
+
+int
+rd_open(load_file)
+	char *load_file;
+{
+	return (load_fp = fopen(load_file, "r")) != NULL;
+}
+
+int
+rd_byte()
+{
+	int i;
+
+	if ((i = fgetc(load_fp)) == EOF)
+		eof = 1;
+	return (i);
+}
+
+long
+rd_int(n)
+	long n;
+{
+	long l;
+	register int i;
+
+	l = btol(rd_byte());
+	for (i = 1; i < n; i++)
+		l = l | (btol(rd_byte()) << (long) (i*8));
+	return (l);
+}
+
+#define	rd_ptr()	((ptr) rd_int(psize))
+
+int
+rd_header()
+{
+	magic = rd_int(2L);
+	if (magic != MAGIC || eof)
+		return 0;
+	
+	flags = rd_int(2L);
+	uref = rd_int(2L);
+	version = rd_int(2L);
+	wsize = rd_int(2L);
+	psize = rd_int(2L);
+	int7 = rd_int(2L);	/* Entry 7 is unused */
+	int8 = rd_int(2L);	/* Entry 8 is unused */
+
+	ntext = rd_ptr();
+	ndata = rd_ptr();
+	nproc = rd_ptr();
+	entrypoint = rd_ptr();
+	nline = rd_ptr();
+	szdata = rd_ptr();
+	ptr7 = rd_ptr();	/* entry 7 is unused */
+	ptr8 = rd_ptr();	/* entry 8 is unused */
+	
+	return !eof;
+}
+
+rd_close()
+{
+	fclose(load_fp);
+}
+