diff --git a/src/binary_c_macros.h b/src/binary_c_macros.h index c63056d94b2dc1d161450a5c80bc8f28fca573f7..a244e3d77467a0bd7cabce410c81e06e34a49262 100644 --- a/src/binary_c_macros.h +++ b/src/binary_c_macros.h @@ -1008,5 +1008,20 @@ #define NOVA_TYPE_HYDROGEN 0 #define NOVA_TYPE_HELIUM 1 +/* + * Number of letters in the (English) alphabet + */ +#define NUMBER_OF_LETTERS_IN_THE_ALPHABET 26 + +/* + * Number of alphabetical cases + */ +#define NUMBER_OF_ALPHABETICAL_CASES 2 + +/* + * Alpha-args parameters list size (see parse_arguments.c) + */ +#define ALPHA_ARGS_SIZE \ + (NUMBER_OF_LETTERS_IN_THE_ALPHABET * NUMBER_OF_ALPHABETICAL_CASES) #endif /* BINARY_MACROS_H */ diff --git a/src/memory/free_tmpstore.c b/src/memory/free_tmpstore.c index 3aa7ceed9d5e5a7dbf1f16cbd2754b32a2d094a7..8b629bbb91bf484b4445ba6286c3b7861382efe4 100644 --- a/src/memory/free_tmpstore.c +++ b/src/memory/free_tmpstore.c @@ -71,7 +71,7 @@ void free_tmpstore(struct tmpstore_t * RESTRICT const tmpstore) #endif #ifdef WTTS_LOG { - int i; + unsigned int i; for(i=0;i<=1;i++) { Safe_fclose(tmpstore->fp_star[i]); @@ -92,6 +92,18 @@ void free_tmpstore(struct tmpstore_t * RESTRICT const tmpstore) Safe_free(tmpstore->rinterpolate_data); } +#ifdef ALPHA_ARGS + { + unsigned int i; + for(i=0;i < ALPHA_ARGS_SIZE;i++) + { + Safe_free(tmpstore->cmd_line_args_alpha[i]); + } + Safe_free(tmpstore->cmd_line_args_alpha); + Safe_free(tmpstore->cmd_line_args_alpha_count); + } +#endif + /* * Free the memory in tmpstore, but don't set it * to NULL diff --git a/src/setup/parse_arguments.c b/src/setup/parse_arguments.c index 1255761d9fed219ea11532df0e12d0b0e2fefecb..6bf6eec5f16274205538e8f0df7166a70e153340 100644 --- a/src/setup/parse_arguments.c +++ b/src/setup/parse_arguments.c @@ -71,29 +71,31 @@ void parse_arguments(const int start, * between 0 and 51 (inclusive). */ tmpstore->cmd_line_args_alpha = - Malloc(sizeof(struct cmd_line_arg_t *)*26*2); + Malloc(sizeof(struct cmd_line_arg_t *)*ALPHA_ARGS_SIZE); /* * Set all counts to zero */ - tmpstore->cmd_line_args_alpha_count = Calloc(26*2,sizeof(unsigned int)); + tmpstore->cmd_line_args_alpha_count = + Calloc(ALPHA_ARGS_SIZE,sizeof(unsigned int)); unsigned int u; - for(u=0;u<2;u++) + for(u=0; u<NUMBER_OF_ALPHABETICAL_CASES; u++) { /* * u = 0 -> lower case * u = 1 -> upper case */ unsigned int a; - const unsigned int offset = u == 0 ? 97 : 65; - for(a=0;a<26;a++) + const unsigned int offset = + (const unsigned int) (u == 0 ? 'a' : 'A'); + for(a=0; a<NUMBER_OF_LETTERS_IN_THE_ALPHABET; a++) { /* * Hence the char that is the first letter */ - unsigned char c = offset + a; - const unsigned int index = a + u * 26; + const unsigned char c = offset + a; + const unsigned int index = a + u * NUMBER_OF_LETTERS_IN_THE_ALPHABET; Aprint("allocate alpha structure %d (char %d = %c = %c)\n", a, (int)c, @@ -207,9 +209,11 @@ void parse_arguments(const int start, /* * First character is a letter: use the alpha map */ - const unsigned int u = ASCII_lower_case(arg[0]) ? 0 : 1; - const unsigned int offset = u == 0 ? 97 : 65; - const unsigned int index = arg[0] - offset + 26 * u; + const unsigned int u = ASCII_lower_case(arg[0])==TRUE ? 0 : 1; + const unsigned int offset = + (const unsigned int) u == 0 ? 'a' : 'A'; + const unsigned int index = + arg[0] - offset + NUMBER_OF_LETTERS_IN_THE_ALPHABET * u; arg_count = stardata->tmpstore->cmd_line_args_alpha_count[index]; cmd_line_args = stardata->tmpstore->cmd_line_args_alpha[index];