Shorten redundant programmer description for -c \? -p part

This commit is contained in:
Stefan Rueger 2022-09-20 21:37:49 +01:00
parent 4070ca9012
commit 97c5ac312a
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
2 changed files with 42 additions and 5 deletions

View File

@ -1783,7 +1783,7 @@ programmer
programmer programmer
id = "jtagmkII_avr32"; id = "jtagmkII_avr32";
desc = "Atmel JTAG ICE mkII im AVR32 mode"; desc = "Atmel JTAG ICE mkII in AVR32 mode";
type = "jtagmkii_avr32"; type = "jtagmkii_avr32";
prog_modes = PM_aWire; prog_modes = PM_aWire;
connection_type = usb; connection_type = usb;
@ -1813,7 +1813,7 @@ programmer
programmer programmer
id = "jtag2pdi"; id = "jtag2pdi";
desc = "Atmel JTAG ICE mkII PDI mode"; desc = "Atmel JTAG ICE mkII in PDI mode";
type = "jtagmkii_pdi"; type = "jtagmkii_pdi";
prog_modes = PM_PDI; prog_modes = PM_PDI;
connection_type = usb; connection_type = usb;

View File

@ -173,6 +173,35 @@ static char *via_prog_modes(int pm) {
return type + (type[1] == 0? 0: 3); return type + (type[1] == 0? 0: 3);
} }
// Potentially shorten copy of prog description if it's the suggested mode
static void pmshorten(char *desc, const char *modes) {
struct { const char *end, *mode; } pairs[] = {
{" in parallel programming mode", "HVPP"},
{" in PP mode", "HVPP"},
{" in high-voltage serial programming mode", "HVSP"},
{" in HVSP mode", "HVSP"},
{" in ISP mode", "ISP"},
{" in debugWire mode", "debugWIRE"},
{" in AVR32 mode", "aWire"},
{" in PDI mode", "PDI"},
{" in UPDI mode", "UPDI"},
{" in JTAG mode", "JTAG"},
{" in JTAG mode", "JTAGmkI"},
{" in JTAG mode", "XMEGAJTAG"},
{" in JTAG mode", "AVR32JTAG"},
};
size_t len = strlen(desc);
for(size_t i=0; i<sizeof pairs/sizeof*pairs; i++) {
size_t elen = strlen(pairs[i].end);
if(len > elen && strcmp(desc+len-elen, pairs[i].end) == 0 && strcmp(modes, pairs[i].mode) == 0) {
desc[len-elen] = 0;
break;
}
}
}
static void list_programmers(FILE *f, const char *prefix, LISTID programmers, int pm) { static void list_programmers(FILE *f, const char *prefix, LISTID programmers, int pm) {
LNODEID ln1; LNODEID ln1;
LNODEID ln2; LNODEID ln2;
@ -200,15 +229,23 @@ static void list_programmers(FILE *f, const char *prefix, LISTID programmers, in
// List programmer if pm or prog_modes uninitialised or if they are compatible otherwise // List programmer if pm or prog_modes uninitialised or if they are compatible otherwise
if(!pm || !pgm->prog_modes || (pm & pgm->prog_modes)) { if(!pm || !pgm->prog_modes || (pm & pgm->prog_modes)) {
const char *id = ldata(ln2); const char *id = ldata(ln2);
char *desc = cfg_strdup("list_programmers()", pgm->desc);
const char *modes = via_prog_modes(pm & pgm->prog_modes);
if(pm != ~0)
pmshorten(desc, modes);
if(*id == 0 || *id == '.') if(*id == 0 || *id == '.')
continue; continue;
if(verbose) if(verbose)
fprintf(f, "%s%-*s = %-30s [%s:%d]", prefix, maxlen, id, pgm->desc, pgm->config_file, pgm->lineno); fprintf(f, "%s%-*s = %-30s [%s:%d]", prefix, maxlen, id, desc, pgm->config_file, pgm->lineno);
else else
fprintf(f, "%s%-*s = %-s", prefix, maxlen, id, pgm->desc); fprintf(f, "%s%-*s = %-s", prefix, maxlen, id, desc);
if(pm != ~0) if(pm != ~0)
fprintf(f, " via %s", via_prog_modes(pm & pgm->prog_modes)); fprintf(f, " via %s", modes);
fprintf(f, "\n"); fprintf(f, "\n");
free(desc);
} }
} }
} }