From 7a43c1253dcf2ec588d110788b9c7c95160b0459 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Wed, 13 Jan 2021 16:21:13 +0100 Subject: [PATCH] fxg1a: always add a sensible internal name The internal name is required to exist and have a certain format for the add-in to appear in the main menu; this should be enforced at the lowest possible level to avoid unpleasant surprises. This change defaults the internal name to essentially @INTERNAL, where the letters of INTERNAL are the upper-case variables of every letter found in the standard name (up to 7). --- fxg1a/fxg1a.h | 8 ++++++++ fxg1a/main.c | 6 ++++++ fxg1a/util.c | 15 +++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/fxg1a/fxg1a.h b/fxg1a/fxg1a.h index b084fa6..4e29d62 100644 --- a/fxg1a/fxg1a.h +++ b/fxg1a/fxg1a.h @@ -75,6 +75,14 @@ uint16_t checksum(struct g1a const *g1a, size_t size); @output Output file name */ void default_output(const char *name, const char *suffix, char *output); +/* default_internal(): Calculate default internal name + This function determines a default internal name, which is '@' followed by + at most 7 uppercase letters taken from the application name. + + @name Application name + @output Internal name string (9 bytes) */ +void default_internal(const char *name, char *output); + /* ** File manipulation (file.c) diff --git a/fxg1a/main.c b/fxg1a/main.c index c45ed29..d5707c5 100644 --- a/fxg1a/main.c +++ b/fxg1a/main.c @@ -174,6 +174,12 @@ int main(int argc, char **argv) strftime(date, 15, "%Y.%m%d.%H%M", now); edit_date(g1a, date); + /* Start with an uppercase name as internal name */ + char internal[9]; + default_internal(fields.name ? fields.name : g1a->header.name, + internal); + edit_internal(g1a, internal); + /* Edit the fields with user-customized values */ fields_edit(g1a, &fields); diff --git a/fxg1a/util.c b/fxg1a/util.c index fa3e0cb..fa2183d 100644 --- a/fxg1a/util.c +++ b/fxg1a/util.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -46,3 +47,17 @@ void default_output(const char *name, const char *suffix, char *output) strcpy(output + end, suffix); } } + +/* default_internal(): Calculate default internal name */ +void default_internal(const char *name, char *output) +{ + output[0] = '@'; + int i=1; + + for(int j=0; name[j] && i < 8; j++) + { + if(isalpha(name[j])) output[i++] = toupper(name[j]); + } + + output[i] = 0; +}