From 82c0b45aeb611238c1cb44c13ea2de6d63cb586b Mon Sep 17 00:00:00 2001 From: Philip Homburg Date: Thu, 23 Jun 2005 09:50:54 +0000 Subject: [PATCH] Newer version of anm. Should be taken from the ACK source tree. --- commands/autil/Makefile | 4 +- commands/autil/anm.c | 423 ++++++++++++++++++++----------------- commands/autil/arch.h | 25 +++ commands/autil/local.h | 0 commands/autil/obj.h | 79 +++++++ commands/autil/object.h | 45 ++++ commands/autil/ranlib.h | 34 +++ commands/autil/rd.c | 260 +++++++++++++++++++++++ commands/autil/rd_arhdr.c | 34 +++ commands/autil/rd_bytes.c | 35 +++ commands/autil/rd_unsig2.c | 15 ++ 11 files changed, 758 insertions(+), 196 deletions(-) create mode 100644 commands/autil/arch.h create mode 100644 commands/autil/local.h create mode 100644 commands/autil/obj.h create mode 100644 commands/autil/object.h create mode 100644 commands/autil/ranlib.h create mode 100644 commands/autil/rd.c create mode 100644 commands/autil/rd_arhdr.c create mode 100644 commands/autil/rd_bytes.c create mode 100644 commands/autil/rd_unsig2.c diff --git a/commands/autil/Makefile b/commands/autil/Makefile index 25c2c954c..960b6401b 100755 --- a/commands/autil/Makefile +++ b/commands/autil/Makefile @@ -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 $@ diff --git a/commands/autil/anm.c b/commands/autil/anm.c index e4e31ff12..92dd9908c 100755 --- a/commands/autil/anm.c +++ b/commands/autil/anm.c @@ -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 -#include #include +#include 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,169 +83,220 @@ 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; + int fd; - fi = fopen(*++argv,"r"); - if (fi == (FILE *)NULL) { - fprintf(stderr, "anm: cannot open %s\n", *argv); + filename = *++argv; + if ((fd = open(filename, 0)) < 0) { + fprintf(stderr, "anm: cannot open %s\n", filename); continue; } - - getofmt((char *)&hbuf, SF_HEAD, fi); - if (BADMAGIC(hbuf)) { - fprintf(stderr, "anm: %s-- bad format\n", *argv); - fclose(fi); - continue; - } - if (narg > 1) - printf("\n%s:\n", *argv); - - n = hbuf.oh_nname; - if (n == 0) { - fprintf(stderr, "anm: %s-- no name list\n", *argv); - fclose(fi); - continue; - } - - if (hbuf.oh_nchar == 0) { - fprintf(stderr, "anm: %s-- no names\n", *argv); - fclose(fi); - continue; - } - if ((readcount = hbuf.oh_nchar) != hbuf.oh_nchar) { - fprintf(stderr, "anm: string area too big in %s\n", *argv); - exit(2); - } - - /* store special section bases */ - if (hbuf.oh_flags & HF_8086) { - for (i=0; i>12) & 03777760; - } - } - - if ((cbufp = (char *)malloc(readcount)) == (char *)NULL) { - fprintf(stderr, "anm: out of memory on %s\n", *argv); - exit(2); - } - fseek(fi, OFF_CHAR(hbuf), 0); - if (fread(cbufp, 1, readcount, fi) == 0) { - fprintf(stderr, "anm: read error on %s\n", *argv); - 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]; - } - } - - 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); - - for (n=0; n 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; + } +} + +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; + } + for (i=0; i>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 (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]; + } + } + + 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); + } + nbufp[i++] = nbuf; + } + + if (nbufp && nosort_flg==0) + qsort(nbufp, i, sizeof(struct outname), compare); + + for (n=0; non_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 index 000000000..9d6e99cd8 --- /dev/null +++ b/commands/autil/arch.h @@ -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 index 000000000..e69de29bb diff --git a/commands/autil/obj.h b/commands/autil/obj.h new file mode 100644 index 000000000..1c0294774 --- /dev/null +++ b/commands/autil/obj.h @@ -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 +#include +#include +#include +#include +#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 index 000000000..68a5ea99f --- /dev/null +++ b/commands/autil/object.h @@ -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 + +#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 index 000000000..76e9166d4 --- /dev/null +++ b/commands/autil/ranlib.h @@ -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 index 000000000..2334b0589 --- /dev/null +++ b/commands/autil/rd.c @@ -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 index 000000000..a2807dbe8 --- /dev/null +++ b/commands/autil/rd_arhdr.c @@ -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 index 000000000..d3554a392 --- /dev/null +++ b/commands/autil/rd_bytes.c @@ -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 index 000000000..4e4ad7485 --- /dev/null +++ b/commands/autil/rd_unsig2.c @@ -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); +}