/* Copyright (c) 1982 Regents of the University of California */
static char sccsid
[] = "@(#)readobj.c 1.5 5/19/82";
* Read in the namelist from the obj file.
#include "mappings/filetab.h"
#include "mappings/linetab.h"
LOCAL SYM
*sym
[MAXSYMNO
];
if ((fp
= fopen(file
, "r")) == NIL
) {
panic("can't open %s", file
);
if (hdr
.magicnum
!= MAGICNUM
) {
fseek(fp
, (long) (HEADER_BYTES
- sizeof(struct pxhdr
)), 0);
if (hdr
.magicnum
!= MAGICNUM
) {
fatal("%s is not a Pascal object file", file
);
if (hdr
.symtabsize
== 0) {
fatal("%s doesn't have symbolic information", file
);
fseek(fp
, (long) objsize
, 1);
if (get(fp
, nlhdr
) != 1) {
panic("can't read nlhdr");
printf("\nHeader information:\n");
printf("\tobject size %d\n", objsize
);
printf("\tsymtab size %d\n", hdr
.symtabsize
);
printf("\tstringsize %d\n", nlhdr
.stringsize
);
printf("\tnsyms %d\n", nlhdr
.nsyms
);
printf("\tnfiles %d\n", nlhdr
.nfiles
);
printf("\tnlines %d\n", nlhdr
.nlines
);
stringtab
= alloc(nlhdr
.stringsize
, char);
fread(stringtab
, sizeof(char), nlhdr
.stringsize
, fp
);
* Allocate and read in file name information table.
filetab
= alloc(nlhdr
.nfiles
, FILETAB
);
for (i
= 0; i
< nlhdr
.nfiles
; i
++) {
fread(&temp
, sizeof(FILETAB
), 1, fp
);
if (temp
.addr
!= prevaddr
) {
ftp
->filename
+= (int) stringtab
;
nlhdr
.nfiles
= (ftp
- &filetab
[0]) + 1;
skimsource(filetab
[0].filename
);
dotpfile
= filetab
[0].filename
;
* Allocate and read in line number information table.
linetab
= alloc(nlhdr
.nlines
, LINETAB
);
for (lp
= &linetab
[0]; lp
< &linetab
[nlhdr
.nlines
]; lp
++) {
for (ftp
= &filetab
[0]; ftp
< &filetab
[nlhdr
.nfiles
]; ftp
++) {
if (ftp
->lineindex
< nlhdr
.nlines
) {
linetab
[ftp
->lineindex
].line
= ftp
->line
;
for (lp
= &linetab
[0]; lp
< &linetab
[nlhdr
.nlines
]; lp
++) {
info
.together
= getw(fp
);
oline
+= info
.separate
.lineincr
;
oaddr
+= info
.separate
.addrincr
;
symtab
= st_creat(nlhdr
.nsyms
);
for (i
= 0; i
< nlhdr
.nsyms
; i
++) {
panic("symbol number too large");
sym
[symno
] = readsym(fp
);
panic("patchlist not empty after reading namelist");
typedef struct patchinfo
{
struct patchinfo
*next_patch
;
* Go through patchlist looking for symbol numbers for which the
* sym array now has a non-NIL entry.
* Afterwards, zap the sym array.
register PATCH
*p
, *last
, *next
;
for (p
= phead
; p
!= NIL
; p
= next
) {
if ((s
= sym
[(int) *t
]) != NIL
) {
for (t
= &sym
[0]; t
< &sym
[MAXSYMNO
]; t
++) {
* Check to see if the given pointer (really symbol number) should
* be added to the patch list. The argument is double indirect
* to do call by reference passing.
if ((t
= sym
[(int) s
]) != NIL
) {
patch
->next_patch
= phead
;
* Free all the object information.
for (i
= 0; i
< MAXSYMNO
; i
++) {