|
|
Power 6/32 Unix version 1.21
/*
* Take ast - generated list files, take a.sym, produce a
* list file with updated PC's.
*/
#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define NSYM 4000
struct symbol {
char name[13];
long value;
} symbol[NSYM];
long basevalue, knownstart;
char lastsymbol[13];
char line[200];
FILE *asym, *source = stdin;
char *symfil = "a.sym";
main(argc, argv)
int argc;
char *argv[];
{
long eof, i;
if (argc > 3) {
printf("Usage : %s [listfile] [symbolsfile]\n", argv[0]);
exit(1);
}
if (argc >= 2) {
source = fopen(argv[1], "r");
if (source == NULL) {
printf("Cannot open %s\n", argv[1]);
exit(1);
}
}
if (argc == 3)
symfil = argv[2];
asym = fopen (symfil, "r");
if (asym == NULL) {
printf("Cannot open %s\n", symfil);
exit(1);
}
eof = FALSE;
for (i=0; i < NSYM && !eof; i++) {
if (fgets(line, 80, asym)==NULL) eof = TRUE;
sscanf(line, "%s %x", symbol[i].name, &symbol[i].value);
}
eof = FALSE; /* source file now */
while (!eof) {
if (fgets(line,200, source)==NULL) eof =TRUE;
if (!knownstart) checkline();
if (knownstart) transform();
printf("%s", line);
}
}
/*
* Check line for symbols and for start of text.
*/
checkline()
{
int i, j, place;
i = 0;
while (line[i] != '_' && line[i] != '\0' && line[i] != '\n') i++;
if (line[i] == '_' && (i==0 ||
line[i-1] == ' ' || line[i-1] == '\t')) {
place = 0;
for (j=0; j<13; j++) lastsymbol[j] = '\0';
while (line[i] != ':' && line[i] != '\0'
&& line[i] != '\n' && place<13 )
lastsymbol[place++] = line[i++];
}
if (line[3] == ' ' || line[15] == '*' || line[18] == ' ') return;
/*
* Found start of text
*/
for (i=0; i< NSYM && !knownstart; i++) {
if (strncmp(symbol[i].name, lastsymbol, place)==0) {
knownstart = TRUE;
sscanf(&line[6] , "%x", &j);
basevalue = symbol[i].value - j;
}
}
if (!knownstart) printf("Symbol %s not found ---\n", lastsymbol);
}
/*
* Transform text lines
*/
transform()
{
long i;
if (line[3] == ' ' || line[15] == '*') return;
sscanf(&line[6] , "%x", &i);
i += basevalue;
sprintf(&line[6], "%08x", i); line[14] = ' ';
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.