aboutsummaryrefslogtreecommitdiff
path: root/unix/shlib/coff.c
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /unix/shlib/coff.c
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'unix/shlib/coff.c')
-rw-r--r--unix/shlib/coff.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/unix/shlib/coff.c b/unix/shlib/coff.c
new file mode 100644
index 00000000..a0a0128c
--- /dev/null
+++ b/unix/shlib/coff.c
@@ -0,0 +1,87 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+ */
+
+#include <stdio.h>
+#include <filehdr.h>
+#include <aouthdr.h>
+#include <scnhdr.h>
+
+/* COFF -- Examine the header of a COFF file.
+ */
+main (argc, argv)
+int argc;
+char *argv[];
+{
+ struct filehdr fh;
+ struct aouthdr sh;
+ struct scnhdr nh;
+ int fd;
+
+ if (argc < 2) {
+ fprintf (stderr, "Usage: coff <filename>\n");
+ exit (0);
+ }
+
+ if ((fd = open (argv[1], 0)) == -1) {
+ fprintf (stderr, "cannot open %s\n", argv[1]);
+ exit (1);
+ }
+
+ /* Show file header. */
+ if (read (fd, &fh, sizeof(fh)) != sizeof(fh))
+ goto readerr;
+ else if (!ISCOFF(fh.f_magic)) {
+ fprintf (stderr, "not a COFF format file\n");
+ /* exit (2); */
+ }
+
+ printf ("File header:\n");
+ printf ("%16s: %10d %10x %012o\n",
+ "f_magic", fh.f_magic, fh.f_magic, fh.f_magic);
+ printf ("%16s: %10d %10x %012o\n",
+ "f_nscns", fh.f_nscns, fh.f_nscns, fh.f_nscns);
+ printf ("%16s: %10d %10x %012o\n",
+ "f_timdat", fh.f_timdat, fh.f_timdat, fh.f_timdat);
+ printf ("%16s: %10d %10x %012o\n",
+ "f_symptr", fh.f_symptr, fh.f_symptr, fh.f_symptr);
+ printf ("%16s: %10d %10x %012o\n",
+ "f_nsyms", fh.f_nsyms, fh.f_nsyms, fh.f_nsyms);
+ printf ("%16s: %10d %10x %012o\n",
+ "f_opthdr", fh.f_opthdr, fh.f_opthdr, fh.f_opthdr);
+ printf ("%16s: %10d %10x %012o\n",
+ "f_flags", fh.f_flags, fh.f_flags, fh.f_flags);
+
+ /* Show system header. */
+ if (read (fd, &sh, sizeof(sh)) != sizeof(sh))
+ goto readerr;
+ else if (sh.magic != 0413) {
+ fprintf (stderr, "bad magic %o in system header\n", sh.magic);
+ exit (3);
+ }
+
+ printf ("System header:\n");
+ printf ("%16s: %10d %10x %012o\n",
+ "magic", sh.magic, sh.magic, sh.magic);
+ printf ("%16s: %10d %10x %012o\n",
+ "vstamp", sh.vstamp, sh.vstamp, sh.vstamp);
+ printf ("%16s: %10d %10x %012o\n",
+ "tsize", sh.tsize, sh.tsize, sh.tsize);
+ printf ("%16s: %10d %10x %012o\n",
+ "dsize", sh.dsize, sh.dsize, sh.dsize);
+ printf ("%16s: %10d %10x %012o\n",
+ "bsize", sh.bsize, sh.bsize, sh.bsize);
+ printf ("%16s: %10d %10x %012o\n",
+ "entry", sh.entry, sh.entry, sh.entry);
+ printf ("%16s: %10d %10x %012o\n",
+ "text_start", sh.text_start, sh.text_start, sh.text_start);
+ printf ("%16s: %10d %10x %012o\n",
+ "data_start", sh.data_start, sh.data_start, sh.data_start);
+
+ fflush (stdout);
+ close (fd);
+ exit (0);
+
+readerr:
+ fprintf (stderr, "file read error\n");
+ exit (4);
+}