Skip to content
Snippets Groups Projects
Commit 1e84834a authored by Izzard, Robert Dr (Maths & Physics)'s avatar Izzard, Robert Dr (Maths & Physics)
Browse files

cleanup the new ALPHA_ARGS: free memory, replace magic numbers with macros

parent 6e62fee3
No related branches found
No related tags found
No related merge requests found
...@@ -1008,5 +1008,20 @@ ...@@ -1008,5 +1008,20 @@
#define NOVA_TYPE_HYDROGEN 0 #define NOVA_TYPE_HYDROGEN 0
#define NOVA_TYPE_HELIUM 1 #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 */ #endif /* BINARY_MACROS_H */
...@@ -71,7 +71,7 @@ void free_tmpstore(struct tmpstore_t * RESTRICT const tmpstore) ...@@ -71,7 +71,7 @@ void free_tmpstore(struct tmpstore_t * RESTRICT const tmpstore)
#endif #endif
#ifdef WTTS_LOG #ifdef WTTS_LOG
{ {
int i; unsigned int i;
for(i=0;i<=1;i++) for(i=0;i<=1;i++)
{ {
Safe_fclose(tmpstore->fp_star[i]); Safe_fclose(tmpstore->fp_star[i]);
...@@ -92,6 +92,18 @@ void free_tmpstore(struct tmpstore_t * RESTRICT const tmpstore) ...@@ -92,6 +92,18 @@ void free_tmpstore(struct tmpstore_t * RESTRICT const tmpstore)
Safe_free(tmpstore->rinterpolate_data); 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 * Free the memory in tmpstore, but don't set it
* to NULL * to NULL
......
...@@ -71,29 +71,31 @@ void parse_arguments(const int start, ...@@ -71,29 +71,31 @@ void parse_arguments(const int start,
* between 0 and 51 (inclusive). * between 0 and 51 (inclusive).
*/ */
tmpstore->cmd_line_args_alpha = 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 * 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; unsigned int u;
for(u=0;u<2;u++) for(u=0; u<NUMBER_OF_ALPHABETICAL_CASES; u++)
{ {
/* /*
* u = 0 -> lower case * u = 0 -> lower case
* u = 1 -> upper case * u = 1 -> upper case
*/ */
unsigned int a; unsigned int a;
const unsigned int offset = u == 0 ? 97 : 65; const unsigned int offset =
for(a=0;a<26;a++) (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 * Hence the char that is the first letter
*/ */
unsigned char c = offset + a; const unsigned char c = offset + a;
const unsigned int index = a + u * 26; const unsigned int index = a + u * NUMBER_OF_LETTERS_IN_THE_ALPHABET;
Aprint("allocate alpha structure %d (char %d = %c = %c)\n", Aprint("allocate alpha structure %d (char %d = %c = %c)\n",
a, a,
(int)c, (int)c,
...@@ -207,9 +209,11 @@ void parse_arguments(const int start, ...@@ -207,9 +209,11 @@ void parse_arguments(const int start,
/* /*
* First character is a letter: use the alpha map * First character is a letter: use the alpha map
*/ */
const unsigned int u = ASCII_lower_case(arg[0]) ? 0 : 1; const unsigned int u = ASCII_lower_case(arg[0])==TRUE ? 0 : 1;
const unsigned int offset = u == 0 ? 97 : 65; const unsigned int offset =
const unsigned int index = arg[0] - offset + 26 * u; (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]; arg_count = stardata->tmpstore->cmd_line_args_alpha_count[index];
cmd_line_args = stardata->tmpstore->cmd_line_args_alpha[index]; cmd_line_args = stardata->tmpstore->cmd_line_args_alpha[index];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment