anm also works on aal archives now

This commit is contained in:
ceriel 1991-11-18 09:46:53 +00:00
parent 839165633b
commit e9a6af1a42
2 changed files with 212 additions and 169 deletions

View file

@ -7,7 +7,8 @@ anm [ \-gnoprus ] [ file ... ]
.I Anm
prints the name list (symbol table) of each ack.out(5) format object
.I file
in the argument list.
in the argument list. If an argument is an aal(1) or arch(1) archive,
a listing of each object file in the archive will be produced.
If no
.I file
is given, the symbols in

View file

@ -11,6 +11,8 @@
*/
#include "out.h"
#include "arch.h"
#include "ranlib.h"
#include <stdio.h>
#include <ctype.h>
@ -31,12 +33,11 @@ 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++;
@ -82,6 +83,62 @@ char **argv;
narg = argc;
while(argc--) {
int fd;
filename = *++argv;
if ((fd = open(filename, 0)) < 0) {
fprintf(stderr, "anm: cannot open %s\n", filename);
continue;
}
process(fd);
close(fd);
}
exit(0);
}
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;
}
}
do_file(fd)
int fd;
{
struct outname *nbufp = NULL;
struct outname nbuf;
char *cbufp;
@ -89,41 +146,31 @@ char **argv;
long n;
unsigned readcount;
int i,j;
int compare();
read_error = 0;
if (! rd_open(*++argv)) {
fprintf(stderr, "anm: cannot open %s\n", *argv);
continue;
}
rd_fdopen(fd);
filename = *argv;
rd_ohead(&hbuf);
if (read_error) {
rd_close();
continue;
return;
}
if (BADMAGIC(hbuf)) {
fprintf(stderr, "anm: %s -- bad format\n", *argv);
rd_close();
continue;
return;
}
if (narg > 1)
printf("\n%s:\n", *argv);
n = hbuf.oh_nname;
if (n == 0) {
fprintf(stderr, "anm: %s -- no name list\n", *argv);
rd_close();
continue;
fprintf(stderr, "anm: %s -- no name list\n", filename);
return;
}
if (hbuf.oh_nchar == 0) {
fprintf(stderr, "anm: %s -- no names\n", *argv);
rd_close();
continue;
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", *argv);
fprintf(stderr, "anm: string area too big in %s\n", filename);
exit(2);
}
@ -131,8 +178,7 @@ char **argv;
if (hbuf.oh_flags & HF_8086) {
rd_sect(&sbuf, hbuf.oh_nsect);
if (read_error) {
rd_close();
continue;
return;
}
for (i=0; i<hbuf.oh_nsect; i++) {
s_base[i+S_MIN] =
@ -141,14 +187,13 @@ char **argv;
}
if ((cbufp = (char *)malloc(readcount)) == NULL) {
fprintf(stderr, "anm: out of memory on %s\n", *argv);
fprintf(stderr, "anm: out of memory on %s\n", filename);
exit(2);
}
rd_string(cbufp, hbuf.oh_nchar);
if (read_error) {
free(cbufp);
rd_close();
continue;
return;
}
fi_to_co = (long) (cbufp - OFF_CHAR(hbuf));
@ -185,7 +230,7 @@ char **argv;
else
nbufp = (struct outname *)realloc(nbufp, (i+1)*sizeof(struct outname));
if (nbufp == NULL) {
fprintf(stderr, "anm: out of memory on %s\n", *argv);
fprintf(stderr, "anm: out of memory on %s\n", filename);
exit(2);
}
nbufp[i++] = nbuf;
@ -199,7 +244,7 @@ char **argv;
char cs2[4];
if (prep_flg)
printf("%s:", *argv);
printf("%s:", filename);
switch(nbufp[n].on_type&S_ETC) {
case S_SCT:
@ -250,9 +295,6 @@ char **argv;
free((char *)nbufp);
if (cbufp)
free((char *)cbufp);
rd_close();
}
exit(0);
}
compare(p1, p2)