]> Zhao Yanbai Git Server - minix.git/commitdiff
Newer version of anm. Should be taken from the ACK source tree.
authorPhilip Homburg <philip@cs.vu.nl>
Thu, 23 Jun 2005 09:50:54 +0000 (09:50 +0000)
committerPhilip Homburg <philip@cs.vu.nl>
Thu, 23 Jun 2005 09:50:54 +0000 (09:50 +0000)
commands/autil/Makefile
commands/autil/anm.c
commands/autil/arch.h [new file with mode: 0644]
commands/autil/local.h [new file with mode: 0644]
commands/autil/obj.h [new file with mode: 0644]
commands/autil/object.h [new file with mode: 0644]
commands/autil/ranlib.h [new file with mode: 0644]
commands/autil/rd.c [new file with mode: 0644]
commands/autil/rd_arhdr.c [new file with mode: 0644]
commands/autil/rd_bytes.c [new file with mode: 0644]
commands/autil/rd_unsig2.c [new file with mode: 0644]

index 25c2c954c78b6a8883f77fb9a0a831f3e8a66208..960b6401b276c403a20c7450be5e40bbfb32bb5d 100755 (executable)
@@ -1,11 +1,11 @@
 # Makefile for commands/autil
 
-CFLAGS = -D_MINIX -D_POSIX_SOURCE -wo
+CFLAGS = -I. -D_MINIX -D_POSIX_SOURCE -wo
 CCLD   = $(CC) -i $(CFLAGS)
 
 all:   anm asize
 
-anm:   anm.c
+anm:   anm.c rd.c rd_arhdr.c rd_bytes.c rd_unsig2.c
        $(CCLD) -o $@ $?
        install -S 32kw $@
 
index e4e31ff12f5d81b380f9a971848769b29b0df1a2..92dd9908cb180434384fa2118b0957baf4527b9d 100755 (executable)
@@ -1,17 +1,21 @@
-/* @(#)anm.c   1.6 */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* $Id$ */
 /*
 **     print symbol tables for
 **     ACK object files
 **
 **     anm [-gopruns] [name ...]
 */
-#define        ushort  unsigned short
 
 #include       "out.h"
+#include       "arch.h"
+#include       "ranlib.h"
 
-#include       <stdlib.h>
-#include       <ctype.h>
 #include       <stdio.h>
+#include       <ctype.h>
 
 int    numsort_flg;
 int    sectsort_flg;
@@ -21,17 +25,19 @@ int globl_flg;
 int    nosort_flg;
 int    arch_flg;
 int    prep_flg;
+int    read_error;
 struct outhead hbuf;
 struct outsect sbuf;
-FILE   *fi;
 long   off;
+char   *malloc();
+char   *realloc();
 long   s_base[S_MAX];  /* for specially encoded bases */
+char   *filename;
+int    narg;
 
 main(argc, argv)
 char **argv;
 {
-       int     narg;
-       int     compare();
 
        if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) {
                argv++;
@@ -77,167 +83,218 @@ char **argv;
        narg = argc;
 
        while(argc--) {
-               struct  outname *nbufp = (struct outname *)NULL;
-               struct  outname nbuf;
-               char            *cbufp;
-               long            fi_to_co;
-               long            n;
-               unsigned        readcount;
-               int             i,j;
-
-               fi = fopen(*++argv,"r");
-               if (fi == (FILE *)NULL) {
-                       fprintf(stderr, "anm: cannot open %s\n", *argv);
-                       continue;
-               }
+               int fd;
 
-               getofmt((char *)&hbuf, SF_HEAD, fi);
-               if (BADMAGIC(hbuf)) {
-                       fprintf(stderr, "anm: %s-- bad format\n", *argv);
-                       fclose(fi);
+               filename = *++argv;
+               if ((fd = open(filename, 0)) < 0) {
+                       fprintf(stderr, "anm: cannot open %s\n", filename);
                        continue;
                }
-               if (narg > 1)
-                       printf("\n%s:\n", *argv);
+               process(fd);
+               close(fd);
+       }
+       exit(0);
+}
 
-               n = hbuf.oh_nname;
-               if (n == 0) {
-                       fprintf(stderr, "anm: %s-- no name list\n", *argv);
-                       fclose(fi);
-                       continue;
+extern int rd_unsigned2();
+extern long lseek();
+extern char *strncpy();
+
+process(fd)
+       int     fd;
+{
+       unsigned int    magic;
+       long            nextpos;
+       struct ar_hdr   archive_header;
+       static char     buf[sizeof(archive_header.ar_name)+1];
+
+       if (narg > 1) printf("\n%s:\n", filename);
+
+       magic = rd_unsigned2(fd);
+       switch(magic) {
+       case O_MAGIC:
+               lseek(fd, 0L, 0);
+               do_file(fd);
+               break;
+       case ARMAG:
+       case AALMAG:
+               while (rd_arhdr(fd, &archive_header)) {
+                       nextpos = lseek(fd, 0L, 1) + archive_header.ar_size;
+                       if (nextpos & 1) nextpos++;
+                       strncpy(buf,archive_header.ar_name,sizeof(archive_header.ar_name));
+                       filename = buf;
+                       if ( strcmp(filename, SYMDEF)) {
+                               printf("\n%s:\n", filename);
+                               do_file(fd);
+                       }
+                       lseek(fd, nextpos, 0);
                }
+               break;
+       default:
+               fprintf(stderr, "anm: %s -- bad format\n", filename);
+               break;
+       }
+}
 
-               if (hbuf.oh_nchar == 0) {
-                       fprintf(stderr, "anm: %s-- no names\n", *argv);
-                       fclose(fi);
-                       continue;
+do_file(fd)
+       int     fd;
+{
+       struct  outname *nbufp = NULL;
+       struct  outname nbuf;
+       char            *cbufp;
+       long            fi_to_co;
+       long            n;
+       unsigned        readcount;
+       int             i,j;
+       int             compare();
+
+       read_error = 0;
+       rd_fdopen(fd);
+
+       rd_ohead(&hbuf);
+       if (read_error) {
+               return;
+       }
+       if (BADMAGIC(hbuf)) {
+               return;
+       }
+
+       n = hbuf.oh_nname;
+       if (n == 0) {
+               fprintf(stderr, "anm: %s -- no name list\n", filename);
+               return;
+       }
+
+       if (hbuf.oh_nchar == 0) {
+               fprintf(stderr, "anm: %s -- no names\n", filename);
+               return;
+       }
+       if ((readcount = hbuf.oh_nchar) != hbuf.oh_nchar) {
+               fprintf(stderr, "anm: string area too big in %s\n", filename);
+               exit(2);
+       }
+
+       /* store special section bases ??? */
+       if (hbuf.oh_flags & HF_8086) {
+               rd_sect(&sbuf, hbuf.oh_nsect);
+               if (read_error) {
+                       return;
                }
-               if ((readcount = hbuf.oh_nchar) != hbuf.oh_nchar) {
-                       fprintf(stderr, "anm: string area too big in %s\n", *argv);
-                       exit(2);
+               for (i=0; i<hbuf.oh_nsect; i++) {
+                       s_base[i+S_MIN] =
+                               (sbuf.os_base>>12) & 03777760;
                }
+       }
 
-               /* store special section bases */
-               if (hbuf.oh_flags & HF_8086) {
-                       for (i=0; i<hbuf.oh_nsect; i++) {
-                               getofmt((char *)&sbuf, SF_SECT, fi);
-                               s_base[i+S_MIN] =
-                                       (sbuf.os_base>>12) & 03777760;
-                       }
+       if ((cbufp = (char *)malloc(readcount)) == NULL) {
+               fprintf(stderr, "anm: out of memory on %s\n", filename);
+               exit(2);
+       }
+       rd_string(cbufp, hbuf.oh_nchar);
+       if (read_error) {
+               free(cbufp);
+               return;
+       }
+
+       fi_to_co = (long) (cbufp - OFF_CHAR(hbuf));
+       i = 0;
+       while (--n >= 0) {
+               rd_name(&nbuf, 1);
+               if (read_error) {
+                       break;
                }
-                
-               if ((cbufp = (char *)malloc(readcount)) == (char *)NULL) {
-                       fprintf(stderr, "anm: out of memory on %s\n", *argv);
-                       exit(2);
+
+               if (globl_flg && (nbuf.on_type&S_EXT)==0)
+                       continue;
+
+               if (undef_flg
+                   &&
+                   ((nbuf.on_type&S_TYP)!=S_UND || (nbuf.on_type&S_ETC)!=0))
+                       continue;
+
+               if (nbuf.on_foff == 0) nbuf.on_mptr = 0;
+               else nbuf.on_mptr = (char *) (nbuf.on_foff + fi_to_co);
+
+               /* adjust value for specially encoded bases */
+               if (hbuf.oh_flags & HF_8086) {
+                   if (((nbuf.on_type&S_ETC) == 0) ||
+                       ((nbuf.on_type&S_ETC) == S_SCT)) {
+                       j = nbuf.on_type&S_TYP;
+                       if ((j>=S_MIN) && (j<=S_MAX))
+                           nbuf.on_valu += s_base[j];
+                   }
                }
-               fseek(fi, OFF_CHAR(hbuf), 0);
-               if (fread(cbufp, 1, readcount, fi) == 0) {
-                       fprintf(stderr, "anm: read error on %s\n", *argv);
+
+               if (nbufp == NULL)
+                       nbufp = (struct outname *)malloc(sizeof(struct outname));
+               else
+                       nbufp = (struct outname *)realloc(nbufp, (i+1)*sizeof(struct outname));
+               if (nbufp == NULL) {
+                       fprintf(stderr, "anm: out of memory on %s\n", filename);
                        exit(2);
                }
-               fi_to_co = (long)cbufp - OFF_CHAR(hbuf);
-
-               fseek(fi, OFF_NAME(hbuf), 0);
-               i = 0;
-               while (--n >= 0) {
-                       getofmt((char *)&nbuf, SF_NAME, fi);
-
-                       if (nbuf.on_foff == 0)
-                               continue; /* skip entries without names */
-
-                       if (globl_flg && (nbuf.on_type&S_EXT)==0)
-                               continue;
-
-                       if (undef_flg
-                           &&
-                           ((nbuf.on_type&S_TYP)!=S_UND || (nbuf.on_type&S_ETC)!=0))
-                               continue;
-
-                       nbuf.on_mptr = (char *)(nbuf.on_foff + fi_to_co);
-
-                       /* adjust value for specially encoded bases */
-                       if (hbuf.oh_flags & HF_8086) {
-                           if (((nbuf.on_type&S_ETC) == 0) ||
-                               ((nbuf.on_type&S_ETC) == S_SCT)) {
-                               j = nbuf.on_type&S_TYP;
-                               if ((j>=S_MIN) && (j<=S_MAX))
-                                   nbuf.on_valu += s_base[j];
-                           }
-                       }
+               nbufp[i++] = nbuf;
+       }
 
-                       if (nbufp == (struct outname *)NULL)
-                               nbufp = (struct outname *)malloc(sizeof(struct outname));
-                       else
-                               nbufp = (struct outname *)realloc(nbufp, (i+1)*sizeof(struct outname));
-                       if (nbufp == (struct outname *)NULL) {
-                               fprintf(stderr, "anm: out of memory on %s\n", *argv);
-                               exit(2);
-                       }
-                       nbufp[i++] = nbuf;
-               }
+       if (nbufp && nosort_flg==0)
+               qsort(nbufp, i, sizeof(struct outname), compare);
 
-               if (nbufp && nosort_flg==0)
-                       qsort(nbufp, i, sizeof(struct outname), compare);
+       for (n=0; n<i; n++) {
+               char    cs1[4];
+               char    cs2[4];
 
-               for (n=0; n<i; n++) {
-                       char    cs1[4];
-                       char    cs2[4];
+               if (prep_flg)
+                       printf("%s:", filename);
 
-                       if (prep_flg)
-                               printf("%s:", *argv);
+               switch(nbufp[n].on_type&S_ETC) {
+               case S_SCT:
+                       sprintf(cs1, "%2d", (nbufp[n].on_type&S_TYP) - S_MIN);
+                       sprintf(cs2, " S");
+                       break;
+               case S_FIL:
+                       sprintf(cs1, " -");
+                       sprintf(cs2, " F");
+                       break;
+               case S_MOD:
+                       sprintf(cs1, " -");
+                       sprintf(cs2, " M");
+                       break;
+               case S_COM:
+                       sprintf(cs1, " C");
+                       if (nbufp[n].on_type&S_EXT)
+                               sprintf(cs2, " E");
+                       else
+                               sprintf(cs2, " -");
+                       break;
+               case 0:
+                       if (nbufp[n].on_type&S_EXT)
+                               sprintf(cs2, " E");
+                       else
+                               sprintf(cs2, " -");
 
-                       switch(nbufp[n].on_type&S_ETC) {
-                       case S_SCT:
-                               sprintf(cs1, "%2d", (nbufp[n].on_type&S_TYP) - S_MIN);
-                               sprintf(cs2, " S");
-                               break;
-                       case S_FIL:
-                               sprintf(cs1, " -");
-                               sprintf(cs2, " F");
+                       switch(nbufp[n].on_type&S_TYP) {
+                       case S_UND:
+                               sprintf(cs1, " U");
                                break;
-                       case S_MOD:
-                               sprintf(cs1, " -");
-                               sprintf(cs2, " M");
-                               break;
-                       case S_COM:
-                               sprintf(cs1, " C");
-                               if (nbufp[n].on_type&S_EXT)
-                                       sprintf(cs2," E");
-                               else
-                                       sprintf(cs2," -");
-                               break;
-                       case 0:
-                               if (nbufp[n].on_type&S_EXT)
-                                       sprintf(cs2, " E");
-                               else
-                                       sprintf(cs2, " -");
-
-                               switch(nbufp[n].on_type&S_TYP) {
-                               case S_UND:
-                                       sprintf(cs1, " U");
-                                       break;
-                               case S_ABS:
-                                       sprintf(cs1, " A");
-                                       break;
-                               default:
-                                       sprintf(cs1, "%2d", (nbufp[n].on_type&S_TYP) - S_MIN);
-                               }
+                       case S_ABS:
+                               sprintf(cs1, " A");
                                break;
                        default:
-                               sprintf(cs1, "??");
-                               sprintf(cs2, " ?");
+                               sprintf(cs1, "%2d", (nbufp[n].on_type&S_TYP) - S_MIN);
                        }
-
-                       printf("%8lx %s %s %s\n",nbufp[n].on_valu,cs1,cs2,nbufp[n].on_mptr);
+                       break;
+               default:
+                       sprintf(cs1, "??");
+                       sprintf(cs2, " ?");
                }
 
-               if (nbufp)
-                       free((char *)nbufp);
-               if (cbufp)
-                       free((char *)cbufp);
-               fclose(fi);
+               printf("%8lx %s %s %s\n",nbufp[n].on_valu,cs1,cs2,nbufp[n].on_mptr ? nbufp[n].on_mptr : "(NULL)");
        }
-       exit(0);
+
+       if (nbufp)
+               free((char *)nbufp);
+       if (cbufp)
+               free((char *)cbufp);
 }
 
 compare(p1, p2)
@@ -259,6 +316,12 @@ struct outname     *p1, *p2;
                        return(-revsort_flg);
        }
 
+       if (! p1->on_mptr) {
+               if (! p2->on_mptr) return 0;
+               return -revsort_flg;
+       }
+       if (! p2->on_mptr) return revsort_flg;
+
        i = strcmp(p1->on_mptr, p2->on_mptr);
 
        if (i > 0)
@@ -269,36 +332,8 @@ struct outname     *p1, *p2;
        return(0);
 }
 
-getofmt(p, s, f)
-register char  *p;
-register char  *s;
-register FILE  *f;
+rd_fatal()
 {
-       register i;
-       register long l;
-
-       for (;;) {
-               switch (*s++) {
-/*             case '0': p++; continue; */
-               case '1':
-                       *p++ = getc(f);
-                       continue;
-               case '2':
-                       i = getc(f);
-                       i |= (getc(f) << 8);
-                       *((short *)p) = i; p += sizeof(short);
-                       continue;
-               case '4':
-                       l = (long)getc(f);
-                       l |= ((long)getc(f) << 8);
-                       l |= ((long)getc(f) << 16);
-                       l |= ((long)getc(f) << 24);
-                       *((long *)p) = l; p += sizeof(long);
-                       continue;
-               default:
-               case '\0':
-                       break;
-               }
-               break;
-       }
+       fprintf(stderr,"read error on %s\n", filename);
+       read_error = 1;
 }
diff --git a/commands/autil/arch.h b/commands/autil/arch.h
new file mode 100644 (file)
index 0000000..9d6e99c
--- /dev/null
@@ -0,0 +1,25 @@
+/* $Id$ */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+
+#ifndef __ARCH_H_INCLUDED
+#define __ARCH_H_INCLUDED
+
+#define        ARMAG   0177545
+#define AALMAG 0177454
+
+struct ar_hdr {
+       char    ar_name[14];
+       long    ar_date;
+       char    ar_uid;
+       char    ar_gid;
+       short   ar_mode;
+       long    ar_size;
+};
+
+#define AR_TOTAL       26
+#define AR_SIZE                22
+
+#endif /* __ARCH_H_INCLUDED */
diff --git a/commands/autil/local.h b/commands/autil/local.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/commands/autil/obj.h b/commands/autil/obj.h
new file mode 100644 (file)
index 0000000..1c02947
--- /dev/null
@@ -0,0 +1,79 @@
+/* $Id$ */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+#include <local.h>
+#include <stdio.h>
+#include <out.h>
+#include <ranlib.h>
+#include <arch.h>
+#include "object.h"
+
+#if ! defined(CHAR_UNSIGNED)
+#define CHAR_UNSIGNED 0
+#endif
+
+#if CHAR_UNSIGNED
+#define Xchar(ch)      (ch)
+#else
+#define Xchar(ch)      ((ch) & 0377)
+#endif
+
+#if ! defined(BYTE_ORDER)
+#define BYTE_ORDER 0x3210
+#endif
+
+#if (BYTE_ORDER == 0x3210 || BYTE_ORDER == 0x1032)
+#define uget2(c)       (Xchar((c)[0]) | ((unsigned) Xchar((c)[1]) << 8))
+#define Xput2(i, c)    (((c)[0] = (i)), ((c)[1] = (i) >> 8))
+#define put2(i, c)     { register int j = (i); Xput2(j, c); }
+#else
+#define uget2(c)       (* ((unsigned short *) (c)))
+#define Xput2(i, c)    (* ((short *) (c)) = (i))
+#define put2(i, c)     Xput2(i, c)
+#endif
+
+#define get2(c)                ((short) uget2(c))
+
+#if BYTE_ORDER != 0x0123
+#define get4(c)                (uget2(c) | ((long) uget2((c)+2) << 16))
+#define put4(l, c)     { register long x=(l); \
+                         Xput2((int)x,c); \
+                         Xput2((int)(x>>16),(c)+2); \
+                       }
+#else
+#define get4(c)                (* ((long *) (c)))
+#define put4(l, c)     (* ((long *) (c)) = (l))
+#endif
+
+#define SECTCNT        3       /* number of sections with own output buffer */
+#if BIGMACHINE
+#define WBUFSIZ        (8*BUFSIZ)
+#else
+#define WBUFSIZ        BUFSIZ
+#endif
+
+struct fil {
+       int     cnt;
+       char    *pnow;
+       char    *pbegin;
+       long    currpos;
+       int     fd;
+       char    pbuf[WBUFSIZ];
+};
+
+extern struct fil __parts[];
+
+#define        PARTEMIT        0
+#define        PARTRELO        (PARTEMIT+SECTCNT)
+#define        PARTNAME        (PARTRELO+1)
+#define        PARTCHAR        (PARTNAME+1)
+#ifdef SYMDBUG
+#define PARTDBUG       (PARTCHAR+1)
+#else
+#define PARTDBUG       (PARTCHAR+0)
+#endif
+#define        NPARTS          (PARTDBUG + 1)
+
+#define getsect(s)      (PARTEMIT+((s)>=(SECTCNT-1)?(SECTCNT-1):(s)))
diff --git a/commands/autil/object.h b/commands/autil/object.h
new file mode 100644 (file)
index 0000000..68a5ea9
--- /dev/null
@@ -0,0 +1,45 @@
+/* $Id$ */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+
+#include <ansi.h>
+
+#ifndef __OBJECT_INCLUDED__
+#define __OBJECT_INCLUDED__
+
+_PROTOTYPE(int wr_open, (char *f));
+_PROTOTYPE(void wr_close, (void));
+_PROTOTYPE(void wr_ohead, (struct outhead *h));
+_PROTOTYPE(void wr_sect, (struct outsect *s, unsigned int c));
+_PROTOTYPE(void wr_outsect, (int sectno));
+_PROTOTYPE(void wr_emit, (char *b, long c));
+_PROTOTYPE(void wr_putc, (int c));
+_PROTOTYPE(void wr_relo, (struct outrelo *r, unsigned int c));
+_PROTOTYPE(void wr_name, (struct outname *n, unsigned int c));
+_PROTOTYPE(void wr_string, (char *s, long c));
+_PROTOTYPE(void wr_arhdr, (int fd, struct ar_hdr *a));
+_PROTOTYPE(void wr_ranlib, (int fd, struct ranlib *r, long cnt));
+_PROTOTYPE(void wr_int2, (int fd, int i));
+_PROTOTYPE(void wr_long, (int fd, long l));
+_PROTOTYPE(void wr_bytes, (int fd, char *buf, long l));
+_PROTOTYPE(int rd_open, (char *f));
+_PROTOTYPE(int rd_fdopen, (int f));
+_PROTOTYPE(void rd_close, (void));
+_PROTOTYPE(void rd_ohead, (struct outhead *h));
+_PROTOTYPE(void rd_sect, (struct outsect *s, unsigned int c));
+_PROTOTYPE(void rd_outsect, (int sectno));
+_PROTOTYPE(void rd_emit, (char *b, long c));
+_PROTOTYPE(void rd_relo, (struct outrelo *r, unsigned int c));
+_PROTOTYPE(void rd_rew_relo, (struct outhead *head));
+_PROTOTYPE(void rd_name, (struct outname *n, unsigned int c));
+_PROTOTYPE(void rd_string, (char *s, long c));
+_PROTOTYPE(int rd_arhdr, (int fd, struct ar_hdr *a));
+_PROTOTYPE(void rd_ranlib, (int fd, struct ranlib *r, long cnt));
+_PROTOTYPE(int rd_int2, (int fd));
+_PROTOTYPE(long rd_long, (int fd));
+_PROTOTYPE(void rd_bytes, (int fd, char *buf, long l));
+_PROTOTYPE(int rd_fd, (void));
+
+#endif /* __OBJECT_INCLUDED__ */
diff --git a/commands/autil/ranlib.h b/commands/autil/ranlib.h
new file mode 100644 (file)
index 0000000..76e9166
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* $Id$ */
+
+#ifndef __RANLIB_H_INCLUDED
+#define __RANLIB_H_INCLUDED
+
+#ifndef SYMDEF
+#      define SYMDEF   "__.SYMDEF"
+#endif /* SYMDEF */
+
+/*
+ * Structure of the SYMDEF table of contents for an archive.
+ * SYMDEF begins with a long giving the number of ranlib
+ * structures that immediately follow, and then continues with a string
+ * table consisting of a long giving the number of bytes of
+ * strings that follow and then the strings themselves.
+ */
+struct ranlib {
+       union {
+         char  *ran__ptr;      /* symbol name (in core) */
+         long  ran__off;       /* symbol name (in file) */
+       }       ran_u;
+#define ran_ptr ran_u.ran__ptr
+#define ran_off ran_u.ran__off
+       long    ran_pos;        /* library member is at this position */
+};
+
+#define SZ_RAN 8
+#define SF_RAN "44"
+
+#endif /* __RANLIB_H_INCLUDED */
diff --git a/commands/autil/rd.c b/commands/autil/rd.c
new file mode 100644 (file)
index 0000000..2334b05
--- /dev/null
@@ -0,0 +1,260 @@
+/* $Id$ */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+#include "obj.h"
+
+extern long            lseek();
+
+/*
+ * Parts of the output file.
+ */
+#undef PARTEMIT
+#undef PARTRELO
+#undef PARTNAME
+#undef PARTCHAR
+#undef PARTDBUG
+#undef NPARTS
+
+#define        PARTEMIT        0
+#define        PARTRELO        1
+#define        PARTNAME        2
+#define        PARTCHAR        3
+#ifdef SYMDBUG
+#define PARTDBUG       4
+#else
+#define PARTDBUG       3
+#endif
+#define        NPARTS          (PARTDBUG + 1)
+
+static long            offset[MAXSECT];
+
+static int             outfile;
+static long            outseek[NPARTS];
+static long            currpos;
+static long            rd_base;
+#define OUTSECT(i) \
+       (outseek[PARTEMIT] = offset[i])
+#define BEGINSEEK(p, o) \
+       (outseek[(p)] = (o))
+
+static int sectionnr;
+
+static void
+OUTREAD(p, b, n)
+       char *b;
+       long n;
+{
+       register long l = outseek[p];
+
+       if (currpos != l) {
+               lseek(outfile, l, 0);
+       }
+       rd_bytes(outfile, b, n);
+       l += n;
+       currpos = l;
+       outseek[p] = l;
+}
+
+/*
+ * Open the output file according to the chosen strategy.
+ */
+int
+rd_open(f)
+       char *f;
+{
+
+       if ((outfile = open(f, 0)) < 0)
+               return 0;
+       return rd_fdopen(outfile);
+}
+
+static int offcnt;
+
+int
+rd_fdopen(fd)
+{
+       register int i;
+
+       for (i = 0; i < NPARTS; i++) outseek[i] = 0;
+       offcnt = 0;
+       rd_base = lseek(fd, 0L, 1);
+       if (rd_base < 0) {
+               return 0;
+       }
+       currpos = rd_base;
+       outseek[PARTEMIT] = currpos;
+       outfile = fd;
+       sectionnr = 0;
+       return 1;
+}
+
+void
+rd_close()
+{
+
+       close(outfile);
+       outfile = -1;
+}
+
+int
+rd_fd()
+{
+       return outfile;
+}
+
+void
+rd_ohead(head)
+       register struct outhead *head;
+{
+       register long off;
+
+       OUTREAD(PARTEMIT, (char *) head, (long) SZ_HEAD);
+#if BYTE_ORDER == 0x0123
+       if (sizeof(struct outhead) != SZ_HEAD)
+#endif
+       {
+               register char *c = (char *) head + (SZ_HEAD-4);
+               
+               head->oh_nchar = get4(c);
+               c -= 4; head->oh_nemit = get4(c);
+               c -= 2; head->oh_nname = uget2(c);
+               c -= 2; head->oh_nrelo = uget2(c);
+               c -= 2; head->oh_nsect = uget2(c);
+               c -= 2; head->oh_flags = uget2(c);
+               c -= 2; head->oh_stamp = uget2(c);
+               c -= 2; head->oh_magic = uget2(c);
+       }
+       off = OFF_RELO(*head) + rd_base;
+       BEGINSEEK(PARTRELO, off);
+       off += (long) head->oh_nrelo * SZ_RELO;
+       BEGINSEEK(PARTNAME, off);
+       off += (long) head->oh_nname * SZ_NAME;
+       BEGINSEEK(PARTCHAR, off);
+#ifdef SYMDBUG
+       off += head->oh_nchar;
+       BEGINSEEK(PARTDBUG, off);
+#endif
+}
+
+void
+rd_rew_relos(head)
+       register struct outhead *head;
+{
+       register long off = OFF_RELO(*head) + rd_base;
+
+       BEGINSEEK(PARTRELO, off);
+}
+
+void
+rd_sect(sect, cnt)
+       register struct outsect *sect;
+       register unsigned int   cnt;
+{
+       register char *c = (char *) sect + cnt * SZ_SECT;
+
+       OUTREAD(PARTEMIT, (char *) sect, (long)cnt * SZ_SECT);
+       sect += cnt;
+       offcnt += cnt;
+       while (cnt--) {
+               sect--;
+#if BYTE_ORDER == 0x0123
+               if (sizeof(struct outsect) != SZ_SECT)
+#endif
+               {
+                       c -= 4; sect->os_lign = get4(c);
+                       c -= 4; sect->os_flen = get4(c);
+                       c -= 4; sect->os_foff = get4(c);
+                       c -= 4; sect->os_size = get4(c);
+                       c -= 4; sect->os_base = get4(c);
+               }
+               offset[--offcnt] = sect->os_foff + rd_base;
+       }
+}
+
+void
+rd_outsect(s)
+{
+       OUTSECT(s);
+       sectionnr = s;
+}
+
+/*
+ * We don't have to worry about byte order here.
+ */
+void
+rd_emit(emit, cnt)
+       char            *emit;
+       long            cnt;
+{
+       OUTREAD(PARTEMIT, emit, cnt);
+       offset[sectionnr] += cnt;
+}
+
+void
+rd_relo(relo, cnt)
+       register struct outrelo *relo;
+       register unsigned int cnt;
+{
+
+       OUTREAD(PARTRELO, (char *) relo, (long) cnt * SZ_RELO);
+#if BYTE_ORDER == 0x0123
+       if (sizeof(struct outrelo) != SZ_RELO)
+#endif
+       {
+               register char *c = (char *) relo + (long) cnt * SZ_RELO;
+
+               relo += cnt;
+               while (cnt--) {
+                       relo--;
+                       c -= 4; relo->or_addr = get4(c);
+                       c -= 2; relo->or_nami = uget2(c);
+                       relo->or_sect = *--c;
+                       relo->or_type = *--c;
+               }
+       }
+}
+
+void
+rd_name(name, cnt)
+       register struct outname *name;
+       register unsigned int cnt;
+{
+
+       OUTREAD(PARTNAME, (char *) name, (long) cnt * SZ_NAME);
+#if BYTE_ORDER == 0x0123
+       if (sizeof(struct outname) != SZ_NAME)
+#endif
+       {
+               register char *c = (char *) name + (long) cnt * SZ_NAME;
+
+               name += cnt;
+               while (cnt--) {
+                       name--;
+                       c -= 4; name->on_valu = get4(c);
+                       c -= 2; name->on_desc = uget2(c);
+                       c -= 2; name->on_type = uget2(c);
+                       c -= 4; name->on_foff = get4(c);
+               }
+       }
+}
+
+void
+rd_string(addr, len)
+       char *addr;
+       long len;
+{
+       
+       OUTREAD(PARTCHAR, addr, len);
+}
+
+#ifdef SYMDBUG
+void
+rd_dbug(buf, size)
+       char            *buf;
+       long            size;
+{
+       OUTREAD(PARTDBUG, buf, size);
+}
+#endif
diff --git a/commands/autil/rd_arhdr.c b/commands/autil/rd_arhdr.c
new file mode 100644 (file)
index 0000000..a2807db
--- /dev/null
@@ -0,0 +1,34 @@
+/* $Id$ */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+#include "obj.h"
+
+int
+rd_arhdr(fd, arhdr)
+       register struct ar_hdr  *arhdr;
+{
+       char buf[AR_TOTAL];
+       register char *c = buf;
+       register char *p = arhdr->ar_name;
+       register int i;
+
+       i = read(fd, c, AR_TOTAL);
+       if (i == 0) return 0;
+       if (i != AR_TOTAL) {
+               rd_fatal();
+       }
+       i = 14;
+       while (i--) {
+               *p++ = *c++;
+       }
+       arhdr->ar_date = ((long) get2(c)) << 16; c += 2;
+       arhdr->ar_date |= ((long) get2(c)) & 0xffff; c += 2;
+       arhdr->ar_uid = *c++;
+       arhdr->ar_gid = *c++;
+       arhdr->ar_mode = get2(c); c += 2;
+       arhdr->ar_size = (long) get2(c) << 16; c += 2;
+       arhdr->ar_size |= (long) get2(c) & 0xffff;
+       return 1;
+}
diff --git a/commands/autil/rd_bytes.c b/commands/autil/rd_bytes.c
new file mode 100644 (file)
index 0000000..d3554a3
--- /dev/null
@@ -0,0 +1,35 @@
+/* $Id$ */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+
+#include "obj.h"
+
+#define MININT         (1 << (sizeof(int) * 8 - 1))
+#define MAXCHUNK       (~MININT)       /* Highest count we read(2).    */
+/* Unfortunately, MAXCHUNK is too large with some  compilers. Put it in
+   an int!
+*/
+
+static int maxchunk = MAXCHUNK;
+
+/*
+ * We don't have to worry about byte order here.
+ * Just read "cnt" bytes from file-descriptor "fd".
+ */
+void 
+rd_bytes(fd, string, cnt)
+       register char   *string;
+       register long   cnt;
+{
+
+       while (cnt) {
+               register int n = cnt >= maxchunk ? maxchunk : cnt;
+
+               if (read(fd, string, n) != n)
+                       rd_fatal();
+               string += n;
+               cnt -= n;
+       }
+}
diff --git a/commands/autil/rd_unsig2.c b/commands/autil/rd_unsig2.c
new file mode 100644 (file)
index 0000000..4e4ad74
--- /dev/null
@@ -0,0 +1,15 @@
+/* $Id$ */
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+#include "obj.h"
+
+unsigned int
+rd_unsigned2(fd)
+{
+       char buf[2];
+
+       rd_bytes(fd, buf, 2L);
+       return uget2(buf);
+}