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).
This commit is contained in:
Lephenixnoir 2021-01-13 16:21:13 +01:00
parent 94e1dd4da9
commit 7a43c1253d
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
3 changed files with 29 additions and 0 deletions

View file

@ -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)

View file

@ -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);

View file

@ -1,4 +1,5 @@
#include <string.h>
#include <ctype.h>
#include <endianness.h>
#include <fxg1a.h>
@ -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;
}