Specifying the full memory name now always works

... even if a memory with longer name and same initial part exists
This commit is contained in:
Stefan Rueger 2022-08-13 20:51:12 +01:00
parent 533feec4ed
commit c9736a9db5
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
1 changed files with 18 additions and 43 deletions

View File

@ -423,88 +423,63 @@ void avr_free_memalias(AVRMEM_ALIAS *m) {
AVRMEM_ALIAS *avr_locate_memalias(const AVRPART *p, const char *desc) { AVRMEM_ALIAS *avr_locate_memalias(const AVRPART *p, const char *desc) {
AVRMEM_ALIAS * m, * match; AVRMEM_ALIAS * m, * match;
LNODEID ln; LNODEID ln;
int matches; int matches, exact;
int l; int l;
if(!p || !desc || !p->mem_alias) if(!p || !desc || !p->mem_alias)
return NULL; return NULL;
l = strlen(desc); l = strlen(desc);
matches = 0; matches = exact = 0;
match = NULL; match = NULL;
for (ln=lfirst(p->mem_alias); ln; ln=lnext(ln)) { for (ln=lfirst(p->mem_alias); ln; ln=lnext(ln)) {
m = ldata(ln); m = ldata(ln);
if (strncmp(desc, m->desc, l) == 0) { if (strncmp(m->desc, desc, l) == 0) { // Partial initial match
match = m; match = m;
matches++; matches++;
if(m->desc[l] == 0) // Exact match between arg and memory
exact++;
} }
} }
if (matches == 1) return exact == 1 || matches == 1? match: NULL;
return match;
return NULL;
} }
AVRMEM *avr_locate_mem_noalias(const AVRPART *p, const char *desc) { AVRMEM *avr_locate_mem_noalias(const AVRPART *p, const char *desc) {
AVRMEM * m, * match; AVRMEM * m, * match;
LNODEID ln; LNODEID ln;
int matches; int matches, exact;
int l; int l;
if(!p || !desc || !p->mem) if(!p || !desc || !p->mem)
return NULL; return NULL;
l = strlen(desc); l = strlen(desc);
matches = 0; matches = exact = 0;
match = NULL; match = NULL;
for (ln=lfirst(p->mem); ln; ln=lnext(ln)) { for (ln=lfirst(p->mem); ln; ln=lnext(ln)) {
m = ldata(ln); m = ldata(ln);
if (strncmp(desc, m->desc, l) == 0) { if (strncmp(m->desc, desc, l) == 0) { // Partial initial match
match = m; match = m;
matches++; matches++;
if(m->desc[l] == 0) // Exact match between arg and memory
exact++;
} }
} }
if (matches == 1) return exact == 1 || matches == 1? match: NULL;
return match;
return NULL;
} }
AVRMEM *avr_locate_mem(const AVRPART *p, const char *desc) { AVRMEM *avr_locate_mem(const AVRPART *p, const char *desc) {
AVRMEM * m, * match; AVRMEM *m = avr_locate_mem_noalias(p, desc);
AVRMEM_ALIAS * alias;
LNODEID ln;
int matches;
int l;
if(!p || !desc) if(m)
return NULL; return m;
l = strlen(desc); // Not yet found: look for matching alias name
matches = 0; AVRMEM_ALIAS *a = avr_locate_memalias(p, desc);
match = NULL; return a? a->aliased_mem: NULL;
if(p->mem) {
for (ln=lfirst(p->mem); ln; ln=lnext(ln)) {
m = ldata(ln);
if (strncmp(desc, m->desc, l) == 0) {
match = m;
matches++;
}
}
}
if (matches == 1)
return match;
/* not yet found: look for matching alias name */
alias = avr_locate_memalias(p, desc);
if (alias != NULL)
return alias->aliased_mem;
return NULL;
} }
AVRMEM_ALIAS *avr_find_memalias(const AVRPART *p, const AVRMEM *m_orig) { AVRMEM_ALIAS *avr_find_memalias(const AVRPART *p, const AVRMEM *m_orig) {