18 static MAP
*_grow(MAP
*pMap
)
22 if (pMap
->numSyms
== pMap
->maxSyms
) {
23 pMap
->maxSyms
= (pMap
->maxSyms
+ 1)*2;
24 pMap
->syms
= (SYM_ENTRY
*) realloc(pMap
->syms
, pMap
->maxSyms
*sizeof(*pMap
->syms
));
28 /* Already big enough. */
33 static char *_chomp(char *sz
)
36 char *p
= strrchr(sz
, '\n');
41 p
= strrchr(sz
, '\r');
52 MAP
*map_load(const char *fname
)
54 FILE *fp
= fopen(fname
, "r");
61 MAP
*pmap
= (MAP
*) calloc(1, sizeof(*pmap
));
63 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
67 /* Drop comment lines. */
71 /* Read in the segment and address. */
72 if (sscanf(line
, "%X:%X", &drop
, &addr
) != 2) {
76 start
= strrchr(line
, ' ');
83 /* Move on past the space. */
86 /* Drop any internal names, like the segment start and length
88 if (!strncmp(start
, "s__", 3)) {
93 pmap
->syms
[pmap
->numSyms
].addr
= addr
;
94 pmap
->syms
[pmap
->numSyms
].szName
= strdup(start
);
103 const char *map_find(MAP
*self
, uint16 addr
)
107 for (i
= 0; i
< self
->numSyms
; i
++) {
108 if (self
->syms
[i
].addr
== addr
) {
109 return self
->syms
[i
].szName
;
116 const char *map_lookup(MAP
*self
, uint16 addr
, char *pInto
)
120 for (i
= 0; i
< self
->numSyms
; i
++) {
121 if (self
->syms
[i
].addr
== addr
) {
122 return self
->syms
[i
].szName
;
126 sprintf(pInto
, "%04X", addr
);