Browse Source

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).
pull/6/head
Lephenixnoir 11 months ago
parent
commit
7a43c1253d
Signed by: Lephenixnoir GPG Key ID: 1BBA026E13FC0495
  1. 8
      fxg1a/fxg1a.h
  2. 6
      fxg1a/main.c
  3. 15
      fxg1a/util.c

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

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

15
fxg1a/util.c

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

Loading…
Cancel
Save