From b366078e6afd6a5a41ef9a392c67dbba1d8db86b Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Wed, 19 Jun 2024 00:27:26 +0100 Subject: [PATCH] Provide str_mcunames_signature() --- src/libavrdude.h | 1 + src/strutil.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/libavrdude.h b/src/libavrdude.h index 5b442212..1eec1ba5 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -1514,6 +1514,7 @@ char *str_nexttok(char *buf, const char *delim, char **next); const char *str_ccfrq(double f, int n); int str_levenshtein(const char *str1, const char *str2, int swap, int subst, int add, int del); size_t str_weighted_damerau_levenshtein(const char *str1, const char *str2); +int str_mcunames_signature(uint8_t *sigs, char *p, size_t n); int led_set(const PROGRAMMER *pgm, int led); int led_clr(const PROGRAMMER *pgm, int led); diff --git a/src/strutil.c b/src/strutil.c index a5906ad0..d959ef1d 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -1301,3 +1301,24 @@ size_t str_weighted_damerau_levenshtein(const char *s1, const char *s2) { mmt_free(row2); return i; } + + +// Puts a comma-separated list of matching MCU names into array p with n chars space +int str_mcunames_signature(uint8_t *sigs, char *p, size_t n) { + int matching = 0; + + for(size_t i=0; i < sizeof uP_table/sizeof *uP_table; i++) { + if(0 == memcmp(sigs, uP_table[i].sigs, sizeof uP_table->sigs)) { + if(matching && n > 2) + strcpy(p, ", "), n -= 2, p += 2; + size_t len = strlen(uP_table[i].name); + if(n > len) { + strcpy(p, uP_table[i].name); + n -= len; p += len; + } + matching++; + } + } + + return matching; +}