The reading of the input is now machine independent.
This commit is contained in:
parent
89a37681fc
commit
a0a7a48c3b
1 changed files with 65 additions and 3 deletions
|
@ -1,6 +1,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "out.h"
|
#include "out.h"
|
||||||
|
|
||||||
|
#ifndef NORCSID
|
||||||
|
static char rcs_id[] = "$Header$" ;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ASSERT(x) switch (2) { case 0: case (x): ; }
|
#define ASSERT(x) switch (2) { case 0: case (x): ; }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -12,6 +16,8 @@ struct outsect outsect[S_MAX];
|
||||||
char *output_file;
|
char *output_file;
|
||||||
int output_file_created;
|
int output_file_created;
|
||||||
|
|
||||||
|
char *program ;
|
||||||
|
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
char *argv[];
|
char *argv[];
|
||||||
|
@ -25,6 +31,7 @@ main(argc, argv)
|
||||||
ASSERT(sizeof(struct outsect) == SZ_SECT);
|
ASSERT(sizeof(struct outsect) == SZ_SECT);
|
||||||
|
|
||||||
input = stdin; output = stdout;
|
input = stdin; output = stdout;
|
||||||
|
program= argv[0] ;
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 1: break;
|
case 1: break;
|
||||||
case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0)
|
case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0)
|
||||||
|
@ -37,15 +44,16 @@ main(argc, argv)
|
||||||
break;
|
break;
|
||||||
default:fatal("Usage: %s <as object> <dl object>.\n", argv[0]);
|
default:fatal("Usage: %s <as object> <dl object>.\n", argv[0]);
|
||||||
}
|
}
|
||||||
if (fread((char *)&outhead, SZ_HEAD, 1, input) != 1)
|
if ( !rhead(input,&outhead) )
|
||||||
fatal("Reading header failed.\n");
|
fatal("Reading header failed.\n");
|
||||||
if (BADMAGIC(outhead))
|
if (BADMAGIC(outhead))
|
||||||
fatal("Not an ack object file.\n");
|
fatal("Not an ack object file.\n");
|
||||||
if (outhead.oh_nrelo > 0)
|
if (outhead.oh_nrelo > 0)
|
||||||
fprintf(stderr, "Warning: relocation information present.\n");
|
fprintf(stderr, "Warning: relocation information present.\n");
|
||||||
nsect = outhead.oh_nsect;
|
for ( nsect=0 ; nsect<outhead.oh_nsect ; nsect++ )
|
||||||
if (fread((char *)outsect, SZ_SECT, nsect, input) != nsect)
|
if ( !rsect(input,&outsect[nsect]) )
|
||||||
fatal("Reading section table failed.\n");
|
fatal("Reading section table failed.\n");
|
||||||
|
nsect = outhead.oh_nsect;
|
||||||
sectp = outsect;
|
sectp = outsect;
|
||||||
while (nsect--) {
|
while (nsect--) {
|
||||||
register long flen;
|
register long flen;
|
||||||
|
@ -93,10 +101,64 @@ main(argc, argv)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rhead(f,head) struct outhead *head ; FILE *f ; {
|
||||||
|
char buf[SZ_HEAD] ;
|
||||||
|
if ( fread(buf,SZ_HEAD,1,f)!=1 ) return 0 ;
|
||||||
|
iconvert(buf,(char *)head,SF_HEAD) ;
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
rsect(f,sect) struct outsect *sect ; FILE *f ; {
|
||||||
|
char buf[SZ_SECT] ;
|
||||||
|
if ( fread(buf,SZ_SECT,1,f)!=1 ) return 0 ;
|
||||||
|
iconvert(buf,(char *)sect,SF_SECT) ;
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
rrelo(f,relo) struct outrelo *relo ; FILE *f ; {
|
||||||
|
char buf[SZ_RELO] ;
|
||||||
|
if ( fread(buf,SZ_RELO,1,f)!=1 ) return 0 ;
|
||||||
|
iconvert(buf,(char *)relo,SF_RELO) ;
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
rname(f,name) struct outname *name ; FILE *f ; {
|
||||||
|
char buf[SZ_NAME] ;
|
||||||
|
if ( fread(buf,SZ_NAME,1,f)!=1 ) return 0 ;
|
||||||
|
iconvert(buf,(char *)name,SF_NAME) ;
|
||||||
|
return 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
iconvert(buf,str,fmt) char *buf, *str, *fmt ; {
|
||||||
|
register char *nf, *ni, *no ;
|
||||||
|
int last, i ;
|
||||||
|
long value ;
|
||||||
|
ni=buf ; no=str ; nf=fmt ;
|
||||||
|
while ( last = *nf++ ) {
|
||||||
|
last -= '0' ;
|
||||||
|
if ( last<1 || last >9 ) fatal("illegal out.h format string\n");
|
||||||
|
value=0 ;
|
||||||
|
i=last ;
|
||||||
|
while ( i-- ) {
|
||||||
|
value = (value<<8) + (ni[i]&0xFF) ;
|
||||||
|
}
|
||||||
|
switch ( last ) {
|
||||||
|
case 0 : break ;
|
||||||
|
case 1 : *no= value ; break ;
|
||||||
|
case 2 : *(unsigned short *)no = value ; break ;
|
||||||
|
case 4 : *(long *)no = value ; break ;
|
||||||
|
default :
|
||||||
|
fatal("illegal out.h format string\n");
|
||||||
|
}
|
||||||
|
ni += last ; no += last ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* VARARGS1 */
|
/* VARARGS1 */
|
||||||
fatal(s, a1, a2)
|
fatal(s, a1, a2)
|
||||||
char *s;
|
char *s;
|
||||||
{
|
{
|
||||||
|
fprintf(stderr,"%s: ",program) ;
|
||||||
fprintf(stderr, s, a1, a2);
|
fprintf(stderr, s, a1, a2);
|
||||||
if (output_file_created)
|
if (output_file_created)
|
||||||
unlink(output_file);
|
unlink(output_file);
|
||||||
|
|
Loading…
Add table
Reference in a new issue