|
|
1.1 ! root 1: /* ! 2: * Take ast - generated list files, take a.sym, produce a ! 3: * list file with updated PC's. ! 4: */ ! 5: #include <stdio.h> ! 6: #define TRUE 1 ! 7: #define FALSE 0 ! 8: #define NSYM 4000 ! 9: ! 10: struct symbol { ! 11: char name[13]; ! 12: long value; ! 13: } symbol[NSYM]; ! 14: ! 15: long basevalue, knownstart; ! 16: char lastsymbol[13]; ! 17: char line[200]; ! 18: FILE *asym, *source = stdin; ! 19: char *symfil = "a.sym"; ! 20: ! 21: main(argc, argv) ! 22: int argc; ! 23: char *argv[]; ! 24: { ! 25: long eof, i; ! 26: ! 27: if (argc > 3) { ! 28: printf("Usage : %s [listfile] [symbolsfile]\n", argv[0]); ! 29: exit(1); ! 30: } ! 31: if (argc >= 2) { ! 32: source = fopen(argv[1], "r"); ! 33: if (source == NULL) { ! 34: printf("Cannot open %s\n", argv[1]); ! 35: exit(1); ! 36: } ! 37: } ! 38: if (argc == 3) ! 39: symfil = argv[2]; ! 40: asym = fopen (symfil, "r"); ! 41: if (asym == NULL) { ! 42: printf("Cannot open %s\n", symfil); ! 43: exit(1); ! 44: } ! 45: eof = FALSE; ! 46: for (i=0; i < NSYM && !eof; i++) { ! 47: if (fgets(line, 80, asym)==NULL) eof = TRUE; ! 48: sscanf(line, "%s %x", symbol[i].name, &symbol[i].value); ! 49: } ! 50: ! 51: eof = FALSE; /* source file now */ ! 52: while (!eof) { ! 53: if (fgets(line,200, source)==NULL) eof =TRUE; ! 54: if (!knownstart) checkline(); ! 55: if (knownstart) transform(); ! 56: printf("%s", line); ! 57: } ! 58: } ! 59: ! 60: /* ! 61: * Check line for symbols and for start of text. ! 62: */ ! 63: checkline() ! 64: { ! 65: int i, j, place; ! 66: ! 67: i = 0; ! 68: while (line[i] != '_' && line[i] != '\0' && line[i] != '\n') i++; ! 69: if (line[i] == '_' && (i==0 || ! 70: line[i-1] == ' ' || line[i-1] == '\t')) { ! 71: place = 0; ! 72: for (j=0; j<13; j++) lastsymbol[j] = '\0'; ! 73: while (line[i] != ':' && line[i] != '\0' ! 74: && line[i] != '\n' && place<13 ) ! 75: lastsymbol[place++] = line[i++]; ! 76: } ! 77: if (line[3] == ' ' || line[15] == '*' || line[18] == ' ') return; ! 78: /* ! 79: * Found start of text ! 80: */ ! 81: for (i=0; i< NSYM && !knownstart; i++) { ! 82: if (strncmp(symbol[i].name, lastsymbol, place)==0) { ! 83: knownstart = TRUE; ! 84: sscanf(&line[6] , "%x", &j); ! 85: basevalue = symbol[i].value - j; ! 86: } ! 87: } ! 88: if (!knownstart) printf("Symbol %s not found ---\n", lastsymbol); ! 89: } ! 90: ! 91: /* ! 92: * Transform text lines ! 93: */ ! 94: transform() ! 95: { ! 96: ! 97: long i; ! 98: ! 99: if (line[3] == ' ' || line[15] == '*') return; ! 100: sscanf(&line[6] , "%x", &i); ! 101: i += basevalue; ! 102: sprintf(&line[6], "%08x", i); line[14] = ' '; ! 103: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.